From 23d5587f8a4a4dfa5fb2f5d9497d04733cdfe8df Mon Sep 17 00:00:00 2001 From: antelder Date: Mon, 21 Dec 2009 11:58:17 +0000 Subject: Copy 1.x trunk to branches for start of 1.6 release git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@892786 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca-java-1.6/modules/assembly-xml/LICENSE | 205 +++ .../sca-java-1.6/modules/assembly-xml/NOTICE | 6 + .../sca-java-1.6/modules/assembly-xml/pom.xml | 141 ++ .../sca/assembly/xml/BaseAssemblyProcessor.java | 915 +++++++++++ .../xml/ComponentTypeDocumentProcessor.java | 143 ++ .../assembly/xml/ComponentTypeModelResolver.java | 95 ++ .../sca/assembly/xml/ComponentTypeProcessor.java | 390 +++++ .../assembly/xml/CompositeDocumentProcessor.java | 266 ++++ .../sca/assembly/xml/CompositeModelResolver.java | 83 + .../sca/assembly/xml/CompositeProcessor.java | 1243 +++++++++++++++ .../assembly/xml/ConfiguredOperationProcessor.java | 108 ++ .../apache/tuscany/sca/assembly/xml/Constants.java | 97 ++ .../xml/ConstrainingTypeDocumentProcessor.java | 144 ++ .../xml/ConstrainingTypeModelResolver.java | 83 + .../assembly/xml/ConstrainingTypeProcessor.java | 292 ++++ .../assembly/xml/DefaultBeanModelProcessor.java | 258 ++++ .../assembly/xml/PolicyAttachPointProcessor.java | 257 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 21 + ...sca.contribution.processor.URLArtifactProcessor | 21 + ...tuscany.sca.contribution.resolver.ModelResolver | 20 + .../assembly-xml-validation-messages.properties | 30 + .../sca/assembly/xml/BuildPolicyTestCase.java | 148 ++ .../xml/MultiplicityReadWriteTestCase.java | 86 ++ .../tuscany/sca/assembly/xml/ReadAllTestCase.java | 145 ++ .../sca/assembly/xml/ReadDocumentTestCase.java | 207 +++ .../tuscany/sca/assembly/xml/ReadTestCase.java | 88 ++ .../xml/ReadWriteAnyAttributeTestCase.java | 173 +++ .../assembly/xml/ReadWriteAnyElementTestCase.java | 148 ++ .../xml/ReadWriteLocalCompositeTestCase.java | 94 ++ .../sca/assembly/xml/ResolvePolicyTestCase.java | 161 ++ .../tuscany/sca/assembly/xml/ResolveTestCase.java | 97 ++ .../sca/assembly/xml/TestAttributeProcessor.java | 60 + .../sca/assembly/xml/TestPolicyProcessor.java | 73 + .../assembly/xml/TestSCABindingFactoryImpl.java | 35 + .../sca/assembly/xml/TestSCABindingImpl.java | 214 +++ .../tuscany/sca/assembly/xml/WireTestCase.java | 147 ++ .../tuscany/sca/assembly/xml/WriteAllTestCase.java | 160 ++ .../sca/assembly/xml/WriteNamespacesTestCase.java | 91 ++ .../tuscany/sca/assembly/xml/Calculator.composite | 59 + .../xml/CalculatorComponent.constrainingType | 34 + .../sca/assembly/xml/CalculatorImpl.componentType | 31 + .../sca/assembly/xml/JavaScriptReference.composite | 37 + .../sca/assembly/xml/Multiplicity.composite | 30 + .../sca/assembly/xml/NestedCalculator.composite | 29 + .../sca/assembly/xml/RMIBindingTest.composite | 43 + .../sca/assembly/xml/TestAllCalculator.composite | 128 ++ .../sca/assembly/xml/TestAllDivide.composite | 56 + .../assembly/xml/TestAllPolicyCalculator.composite | 129 ++ .../sca/assembly/xml/another_test_definitions.xml | 97 ++ .../tuscany/sca/assembly/xml/local.composite | 27 + .../tuscany/sca/assembly/xml/test_definitions.xml | 175 +++ .../sca-java-1.6/modules/assembly-xsd/LICENSE | 281 ++++ .../sca-java-1.6/modules/assembly-xsd/NOTICE | 23 + .../sca-java-1.6/modules/assembly-xsd/pom.xml | 49 + ...any.sca.contribution.processor.ValidationSchema | 18 + .../assembly-xsd/src/main/resources/sca-all.xsd | 34 + .../src/main/resources/sca-binding-ejb.xsd | 43 + .../src/main/resources/sca-binding-jms.xsd | 148 ++ .../src/main/resources/sca-binding-sca.xsd | 23 + .../src/main/resources/sca-binding-webservice.xsd | 36 + .../src/main/resources/sca-contributions.xsd | 65 + .../assembly-xsd/src/main/resources/sca-core.xsd | 348 +++++ .../src/main/resources/sca-definitions.xsd | 25 + .../src/main/resources/sca-implementation-bpel.xsd | 43 + .../resources/sca-implementation-composite.xsd | 23 + .../src/main/resources/sca-implementation-cpp.xsd | 53 + .../src/main/resources/sca-implementation-ejb.xsd | 25 + .../src/main/resources/sca-implementation-java.xsd | 24 + .../src/main/resources/sca-implementation-jee.xsd | 23 + .../main/resources/sca-implementation-spring.xsd | 24 + .../src/main/resources/sca-implementation-web.xsd | 24 + .../src/main/resources/sca-interface-cpp.xsd | 40 + .../src/main/resources/sca-interface-java.xsd | 23 + .../src/main/resources/sca-interface-wsdl.xsd | 23 + .../assembly-xsd/src/main/resources/sca-policy.xsd | 77 + .../assembly-xsd/src/main/resources/sca.xsd | 25 + .../src/main/resources/tuscany-core.xsd | 37 + .../main/resources/tuscany-sca-binding-atom.xsd | 42 + .../main/resources/tuscany-sca-binding-corba.xsd | 43 + .../src/main/resources/tuscany-sca-binding-dwr.xsd | 41 + .../main/resources/tuscany-sca-binding-gdata.xsd | 43 + .../main/resources/tuscany-sca-binding-http.xsd | 43 + .../src/main/resources/tuscany-sca-binding-jms.xsd | 132 ++ .../main/resources/tuscany-sca-binding-jsonrpc.xsd | 41 + .../resources/tuscany-sca-binding-notification.xsd | 42 + .../src/main/resources/tuscany-sca-binding-rmi.xsd | 43 + .../src/main/resources/tuscany-sca-binding-rss.xsd | 42 + .../main/resources/tuscany-sca-contributions.xsd | 62 + .../resources/tuscany-sca-implementation-node.xsd | 43 + .../tuscany-sca-implementation-notification.xsd | 42 + .../resources/tuscany-sca-implementation-osgi.xsd | 43 + .../tuscany-sca-implementation-resource.xsd | 42 + .../tuscany-sca-implementation-script.xsd | 43 + .../tuscany-sca-implementation-widget.xsd | 42 + .../tuscany-sca-implementation-xquery.xsd | 42 + .../src/main/resources/tuscany-sca.xsd | 53 + .../assembly-xsd/src/main/resources/ws-addr.xsd | 137 ++ .../assembly-xsd/src/main/resources/wsdli.xsd | 34 + .../branches/sca-java-1.6/modules/assembly/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/assembly/NOTICE | 6 + .../branches/sca-java-1.6/modules/assembly/pom.xml | 76 + .../tuscany/sca/assembly/AbstractContract.java | 77 + .../tuscany/sca/assembly/AbstractProperty.java | 124 ++ .../tuscany/sca/assembly/AbstractReference.java | 43 + .../tuscany/sca/assembly/AbstractService.java | 28 + .../tuscany/sca/assembly/AssemblyFactory.java | 155 ++ .../java/org/apache/tuscany/sca/assembly/Base.java | 43 + .../org/apache/tuscany/sca/assembly/Binding.java | 63 + .../apache/tuscany/sca/assembly/BindingRRB.java | 41 + .../org/apache/tuscany/sca/assembly/Callback.java | 40 + .../org/apache/tuscany/sca/assembly/Component.java | 132 ++ .../tuscany/sca/assembly/ComponentProperty.java | 88 ++ .../tuscany/sca/assembly/ComponentReference.java | 83 + .../tuscany/sca/assembly/ComponentService.java | 59 + .../apache/tuscany/sca/assembly/ComponentType.java | 77 + .../org/apache/tuscany/sca/assembly/Composite.java | 110 ++ .../tuscany/sca/assembly/CompositeReference.java | 37 + .../tuscany/sca/assembly/CompositeService.java | 56 + .../tuscany/sca/assembly/ConfiguredOperation.java | 86 ++ .../tuscany/sca/assembly/ConstrainingType.java | 72 + .../org/apache/tuscany/sca/assembly/Contract.java | 95 ++ .../sca/assembly/DefaultAssemblyFactory.java | 31 + .../sca/assembly/DefaultEndpointFactory.java | 32 + .../sca/assembly/DefaultExtensionFactory.java | 36 + .../tuscany/sca/assembly/DefinitionElement.java | 40 + .../org/apache/tuscany/sca/assembly/Endpoint.java | 167 ++ .../tuscany/sca/assembly/EndpointFactory.java | 37 + .../apache/tuscany/sca/assembly/Extensible.java | 44 + .../org/apache/tuscany/sca/assembly/Extension.java | 65 + .../tuscany/sca/assembly/ExtensionFactory.java | 28 + .../tuscany/sca/assembly/Implementation.java | 27 + .../apache/tuscany/sca/assembly/Multiplicity.java | 49 + .../tuscany/sca/assembly/OperationSelector.java | 29 + .../sca/assembly/OperationsConfigurator.java | 33 + .../tuscany/sca/assembly/OptimizableBinding.java | 66 + .../org/apache/tuscany/sca/assembly/Property.java | 41 + .../org/apache/tuscany/sca/assembly/Reference.java | 74 + .../apache/tuscany/sca/assembly/SCABinding.java | 27 + .../tuscany/sca/assembly/SCABindingFactory.java | 36 + .../org/apache/tuscany/sca/assembly/Service.java | 29 + .../java/org/apache/tuscany/sca/assembly/Wire.java | 67 + .../apache/tuscany/sca/assembly/WireFormat.java | 29 + .../sca/assembly/builder/AutomaticBinding.java | 39 + .../sca/assembly/builder/BindingBuilder.java | 42 + .../assembly/builder/BindingBuilderExtension.java | 44 + .../assembly/builder/ComponentPreProcessor.java | 33 + .../sca/assembly/builder/CompositeBuilder.java | 40 + .../builder/CompositeBuilderException.java | 45 + .../assembly/builder/DefaultEndpointBuilder.java | 36 + .../sca/assembly/builder/DomainBuilder.java | 80 + .../sca/assembly/builder/EndpointBuilder.java | 40 + .../builder/impl/BaseConfigurationBuilderImpl.java | 1515 +++++++++++++++++++ .../assembly/builder/impl/BaseWireBuilderImpl.java | 1154 ++++++++++++++ .../builder/impl/BindingConfigurationUtil.java | 170 +++ .../impl/ComponentConfigurationBuilderImpl.java | 68 + .../impl/ComponentReferenceBindingBuilderImpl.java | 71 + ...ComponentReferencePromotionWireBuilderImpl.java | 165 ++ .../impl/ComponentReferenceWireBuilderImpl.java | 48 + .../impl/ComponentServiceBindingBuilderImpl.java | 76 + .../impl/ComponentServicePromotionBuilderImpl.java | 105 ++ .../impl/CompositeBindingURIBuilderImpl.java | 68 + .../builder/impl/CompositeBuilderImpl.java | 278 ++++ .../builder/impl/CompositeCloneBuilderImpl.java | 118 ++ .../builder/impl/CompositeIncludeBuilderImpl.java | 111 ++ .../builder/impl/CompositePolicyBuilderImpl.java | 47 + .../impl/CompositePromotionBuilderImpl.java | 46 + ...CompositeReferenceConfigurationBuilderImpl.java | 224 +++ .../impl/CompositeReferenceWireBuilderImpl.java | 96 ++ .../impl/CompositeServiceBindingBuilderImpl.java | 71 + .../CompositeServiceConfigurationBuilderImpl.java | 194 +++ .../impl/CompositeServicePromotionBuilderImpl.java | 83 + .../assembly/builder/impl/EndpointBuilderImpl.java | 133 ++ .../builder/impl/PolicyConfigurationException.java | 38 + .../builder/impl/PolicyConfigurationUtil.java | 758 ++++++++++ .../sca/assembly/builder/impl/PrintUtil.java | 273 ++++ .../builder/impl/PropertyConfigurationUtil.java | 213 +++ .../builder/impl/ReferenceConfigurationUtil.java | 265 ++++ .../builder/impl/ServiceConfigurationUtil.java | 88 ++ .../sca/assembly/impl/AbstractPropertyImpl.java | 114 ++ .../sca/assembly/impl/AbstractReferenceImpl.java | 46 + .../sca/assembly/impl/AbstractServiceImpl.java | 36 + .../sca/assembly/impl/AssemblyFactoryImpl.java | 121 ++ .../apache/tuscany/sca/assembly/impl/BaseImpl.java | 45 + .../tuscany/sca/assembly/impl/CallbackImpl.java | 82 + .../tuscany/sca/assembly/impl/ComponentImpl.java | 174 +++ .../sca/assembly/impl/ComponentPropertyImpl.java | 93 ++ .../sca/assembly/impl/ComponentReferenceImpl.java | 113 ++ .../sca/assembly/impl/ComponentServiceImpl.java | 71 + .../sca/assembly/impl/ComponentTypeImpl.java | 115 ++ .../tuscany/sca/assembly/impl/CompositeImpl.java | 153 ++ .../sca/assembly/impl/CompositeReferenceImpl.java | 53 + .../sca/assembly/impl/CompositeServiceImpl.java | 62 + .../sca/assembly/impl/ConfiguredOperationImpl.java | 97 ++ .../sca/assembly/impl/ConstrainingTypeImpl.java | 105 ++ .../tuscany/sca/assembly/impl/ContractImpl.java | 96 ++ .../sca/assembly/impl/EndpointFactoryImpl.java | 41 + .../tuscany/sca/assembly/impl/EndpointImpl.java | 154 ++ .../tuscany/sca/assembly/impl/ExtensibleImpl.java | 50 + .../tuscany/sca/assembly/impl/ExtensionImpl.java | 63 + .../sca/assembly/impl/ImplementationImpl.java | 75 + .../tuscany/sca/assembly/impl/PropertyImpl.java | 59 + .../tuscany/sca/assembly/impl/ReferenceImpl.java | 133 ++ .../tuscany/sca/assembly/impl/ServiceImpl.java | 107 ++ .../apache/tuscany/sca/assembly/impl/WireImpl.java | 96 ++ ...org.apache.tuscany.sca.assembly.AssemblyFactory | 18 + ...org.apache.tuscany.sca.assembly.EndpointFactory | 18 + ...rg.apache.tuscany.sca.assembly.ExtensionFactory | 18 + .../assembly-validation-messages.properties | 62 + .../assembly-validation-messages_it.properties | 30 + .../sca/assembly/AssemblyFactoryTestCase.java | 209 +++ .../apache/tuscany/sca/assembly/TestBinding.java | 56 + .../tuscany/sca/assembly/TestImplementation.java | 61 + .../apache/tuscany/sca/assembly/TestInterface.java | 42 + .../sca/assembly/TestInterfaceContract.java | 41 + .../apache/tuscany/sca/assembly/TestOperation.java | 30 + .../builder/impl/CompositeBuilderTestCase.java | 128 ++ .../assembly/builder/impl/PrintUtilTestCase.java | 229 +++ .../modules/binding-atom-abdera/LICENSE | 205 +++ .../modules/binding-atom-abdera/NOTICE | 6 + .../modules/binding-atom-abdera/pom.xml | 233 +++ .../sca/binding/atom/collection/Collection.java | 81 + .../binding/atom/collection/MediaCollection.java | 55 + .../binding/atom/collection/NotFoundException.java | 45 + .../binding/atom/provider/AtomBindingInvoker.java | 516 +++++++ .../atom/provider/AtomBindingListenerServlet.java | 914 +++++++++++ .../atom/provider/AtomBindingProviderFactory.java | 71 + .../sca/binding/atom/provider/AtomBindingUtil.java | 165 ++ .../provider/AtomReferenceBindingProvider.java | 179 +++ .../atom/provider/AtomServiceBindingProvider.java | 112 ++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../sca/binding/atom/AtomDeleteTestCase.java | 114 ++ .../binding/atom/AtomFeedNonCollectionTest.java | 202 +++ .../tuscany/sca/binding/atom/AtomGetTestCase.java | 119 ++ .../tuscany/sca/binding/atom/AtomPostTestCase.java | 108 ++ .../tuscany/sca/binding/atom/AtomPutTestCase.java | 126 ++ .../sca/binding/atom/AtomTestCaseUtils.java | 96 ++ .../apache/tuscany/sca/binding/atom/Consumer.java | 35 + .../binding/atom/ConsumerProviderAtomTestCase.java | 155 ++ .../sca/binding/atom/ContentNegotiationTest.java | 241 +++ .../tuscany/sca/binding/atom/CustomerClient.java | 29 + .../sca/binding/atom/CustomerClientImpl.java | 99 ++ .../sca/binding/atom/CustomerCollectionImpl.java | 149 ++ .../binding/atom/CustomerNonCollectionImpl.java | 53 + .../sca/binding/atom/MediaCollectionImpl.java | 209 +++ .../sca/binding/atom/MediaCollectionTestCase.java | 279 ++++ .../apache/tuscany/sca/binding/atom/Provider.java | 41 + .../atom/ProviderEntryEntityTagsTestCase.java | 421 ++++++ .../atom/ProviderFeedEntityTagsTestCase.java | 375 +++++ .../atom/ProviderServiceDocumentTestCase.java | 204 +++ .../sca/binding/atom/aggregator/Aggregator.java | 29 + .../binding/atom/aggregator/AggregatorImpl.java | 127 ++ .../atom/aggregator/AggregatorTestCase.java | 68 + .../tuscany/sca/binding/atom/aggregator/Sort.java | 38 + .../sca/binding/atom/aggregator/SortImpl.java | 62 + .../tuscany/sca/binding/atom/news/Headline.java | 54 + .../tuscany/sca/binding/atom/news/NewsService.java | 32 + .../sca/binding/atom/news/NewsServiceImpl.java | 90 ++ .../sca/binding/atom/news/NewsServiceTestCase.java | 69 + .../src/test/resources/ReceiptToms.gif | Bin 0 -> 14205 bytes .../src/test/resources/ReceiptValue.jpg | Bin 0 -> 21373 bytes .../tuscany/sca/binding/atom/Consumer.composite | 32 + .../tuscany/sca/binding/atom/Provider.composite | 33 + .../binding/atom/ProviderNonCollection.composite | 34 + .../sca/binding/atom/ReceiptProvider.composite | 33 + .../atom/aggregator/FeedAggregator.composite | 46 + .../tuscany/sca/binding/atom/news/news.composite | 32 + .../modules/binding-atom-js-dojo/LICENSE | 205 +++ .../modules/binding-atom-js-dojo/NOTICE | 6 + .../modules/binding-atom-js-dojo/pom.xml | 74 + .../AtomBindingJavascriptProxyFactoryImpl.java | 60 + ...scany.sca.web.javascript.JavascriptProxyFactory | 19 + .../sca-java-1.6/modules/binding-atom-js/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-atom-js/NOTICE | 6 + .../sca-java-1.6/modules/binding-atom-js/pom.xml | 74 + .../js/AtomBindingJavascriptProxyFactoryImpl.java | 66 + ...scany.sca.web.javascript.JavascriptProxyFactory | 19 + .../src/main/resources/binding-atom.js | 137 ++ .../sca-java-1.6/modules/binding-atom/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-atom/NOTICE | 6 + .../sca-java-1.6/modules/binding-atom/pom.xml | 82 + .../tuscany/sca/binding/atom/AtomBinding.java | 56 + .../sca/binding/atom/AtomBindingFactory.java | 35 + .../binding/atom/impl/AtomBindingFactoryImpl.java | 36 + .../sca/binding/atom/impl/AtomBindingImpl.java | 132 ++ ...che.tuscany.sca.binding.atom.AtomBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../binding/atom/AtomBindingProcessorTestCase.java | 89 ++ .../modules/binding-corba-runtime/LICENSE | 205 +++ .../modules/binding-corba-runtime/NOTICE | 6 + .../modules/binding-corba-runtime/pom.xml | 143 ++ .../corba/impl/CorbaBindingProviderFactory.java | 70 + .../sca/binding/corba/impl/CorbaInvoker.java | 89 ++ .../corba/impl/CorbaReferenceBindingProvider.java | 100 ++ .../corba/impl/CorbaServiceBindingProvider.java | 92 ++ .../corba/impl/exceptions/CorbaException.java | 34 + .../exceptions/RequestConfigurationException.java | 43 + .../corba/impl/reference/DynaCorbaRequest.java | 253 ++++ .../corba/impl/reference/DynaCorbaResponse.java | 39 + .../impl/reference/InterfaceInstanceCreator.java | 70 + .../impl/reference/InterfaceMethodInterceptor.java | 65 + .../impl/service/ComponentInvocationProxy.java | 120 ++ .../corba/impl/service/DynaCorbaServant.java | 137 ++ .../corba/impl/service/InvocationException.java | 43 + .../corba/impl/service/InvocationProxy.java | 46 + .../binding/corba/impl/service/OperationTypes.java | 51 + .../corba/impl/types/AnnotationAttributes.java | 46 + .../sca/binding/corba/impl/types/NodeType.java | 28 + .../sca/binding/corba/impl/types/TypeTree.java | 50 + .../binding/corba/impl/types/TypeTreeCreator.java | 497 ++++++ .../sca/binding/corba/impl/types/TypeTreeNode.java | 75 + .../binding/corba/impl/types/UnionAttributes.java | 59 + .../corba/impl/types/util/ArrayTypeHelper.java | 53 + .../corba/impl/types/util/BooleanTypeHelper.java | 39 + .../corba/impl/types/util/ByteTypeHelper.java | 39 + .../corba/impl/types/util/CharTypeHelper.java | 39 + .../corba/impl/types/util/DoubleTypeHelper.java | 39 + .../corba/impl/types/util/EnumTypeHelper.java | 59 + .../corba/impl/types/util/FloatTypeHelper.java | 39 + .../corba/impl/types/util/IntTypeHelper.java | 39 + .../corba/impl/types/util/LongTypeHelper.java | 39 + .../corba/impl/types/util/ReferenceTypeHelper.java | 42 + .../corba/impl/types/util/SequenceTypeHelper.java | 70 + .../corba/impl/types/util/ShortTypeHelper.java | 39 + .../corba/impl/types/util/StringTypeHelper.java | 39 + .../corba/impl/types/util/StructTypeHelper.java | 69 + .../binding/corba/impl/types/util/TypeHelper.java | 47 + .../corba/impl/types/util/TypeHelpersProxy.java | 119 ++ .../corba/impl/types/util/UnionTypeHelper.java | 92 ++ .../sca/binding/corba/impl/types/util/Utils.java | 40 + .../sca/binding/corba/impl/util/MethodFinder.java | 97 ++ .../binding/corba/impl/util/OperationMapper.java | 578 +++++++ .../tuscany/sca/binding/corba/meta/CorbaArray.java | 34 + .../sca/binding/corba/meta/CorbaUnionElement.java | 37 + .../binding/corba/meta/CorbaUnionElementType.java | 28 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../corba/testing/CorbaServantTestCase.java | 564 +++++++ .../binding/corba/testing/CorbaTypesTestCase.java | 841 +++++++++++ .../corba/testing/MappingTestInterface.java | 46 + .../corba/testing/MethodFinderTestCase.java | 70 + .../corba/testing/OperationMappingTestCase.java | 67 + .../sca/binding/corba/testing/TestConstants.java | 87 ++ .../testing/arrays_unions/ArraysUnionsTests.java | 31 + .../arrays_unions/ArraysUnionsTestsHelper.java | 103 ++ .../arrays_unions/ArraysUnionsTestsHolder.java | 56 + .../arrays_unions/ArraysUnionsTestsOperations.java | 34 + .../corba/testing/arrays_unions/InnerUnion.java | 130 ++ .../testing/arrays_unions/InnerUnionHelper.java | 124 ++ .../testing/arrays_unions/InnerUnionHolder.java | 56 + .../corba/testing/arrays_unions/RichUnion.java | 195 +++ .../testing/arrays_unions/RichUnionHelper.java | 175 +++ .../testing/arrays_unions/RichUnionHolder.java | 56 + .../testing/arrays_unions/StringArrayHelper.java | 94 ++ .../testing/arrays_unions/StringArrayHolder.java | 57 + .../corba/testing/arrays_unions/TestStruct.java | 46 + .../testing/arrays_unions/TestStructHelper.java | 167 ++ .../testing/arrays_unions/TestStructHolder.java | 56 + .../arrays_unions/_ArraysUnionsTestsImplBase.java | 104 ++ .../arrays_unions/_ArraysUnionsTestsStub.java | 118 ++ .../sca/binding/corba/testing/enums/Color.java | 60 + .../binding/corba/testing/enums/ColorHelper.java | 69 + .../binding/corba/testing/enums/ColorHolder.java | 51 + .../binding/corba/testing/enums/EnumManager.java | 30 + .../corba/testing/enums/EnumManagerHelper.java | 98 ++ .../corba/testing/enums/EnumManagerHolder.java | 51 + .../corba/testing/enums/EnumManagerOperations.java | 32 + .../corba/testing/enums/_EnumManagerImplBase.java | 76 + .../corba/testing/enums/_EnumManagerStub.java | 75 + .../sca/binding/corba/testing/exceptions/Calc.java | 30 + .../corba/testing/exceptions/CalcHelper.java | 98 ++ .../corba/testing/exceptions/CalcHolder.java | 51 + .../corba/testing/exceptions/CalcOperations.java | 36 + .../testing/exceptions/CalcPackage/Arguments.java | 41 + .../exceptions/CalcPackage/ArgumentsHelper.java | 94 ++ .../exceptions/CalcPackage/ArgumentsHolder.java | 51 + .../testing/exceptions/CalcPackage/DivByZero.java | 52 + .../exceptions/CalcPackage/DivByZeroHelper.java | 100 ++ .../exceptions/CalcPackage/DivByZeroHolder.java | 51 + .../exceptions/CalcPackage/NotSupported.java | 46 + .../exceptions/CalcPackage/NotSupportedHelper.java | 93 ++ .../exceptions/CalcPackage/NotSupportedHolder.java | 51 + .../corba/testing/exceptions/_CalcImplBase.java | 102 ++ .../corba/testing/exceptions/_CalcStub.java | 106 ++ .../corba/testing/generated/ArraysSetter.java | 30 + .../testing/generated/ArraysSetterHelper.java | 100 ++ .../testing/generated/ArraysSetterHolder.java | 51 + .../testing/generated/ArraysSetterOperations.java | 59 + .../corba/testing/generated/PrimitivesSetter.java | 31 + .../testing/generated/PrimitivesSetterHelper.java | 100 ++ .../testing/generated/PrimitivesSetterHolder.java | 51 + .../generated/PrimitivesSetterOperations.java | 59 + .../corba/testing/generated/RemoteObject.java | 30 + .../testing/generated/RemoteObjectHelper.java | 100 ++ .../testing/generated/RemoteObjectHolder.java | 51 + .../testing/generated/RemoteObjectOperations.java | 30 + .../corba/testing/generated/SimpleStruct.java | 41 + .../testing/generated/SimpleStructHelper.java | 93 ++ .../testing/generated/SimpleStructHolder.java | 51 + .../corba/testing/generated/SomeStruct.java | 51 + .../corba/testing/generated/SomeStructHelper.java | 146 ++ .../corba/testing/generated/SomeStructHolder.java | 51 + .../corba/testing/generated/TestObject.java | 30 + .../corba/testing/generated/TestObjectHelper.java | 99 ++ .../corba/testing/generated/TestObjectHolder.java | 51 + .../testing/generated/TestObjectOperations.java | 44 + .../testing/generated/_ArraysSetterImplBase.java | 232 +++ .../corba/testing/generated/_ArraysSetterStub.java | 343 +++++ .../generated/_PrimitivesSetterImplBase.java | 230 +++ .../testing/generated/_PrimitivesSetterStub.java | 341 +++++ .../testing/generated/_RemoteObjectImplBase.java | 59 + .../corba/testing/generated/_RemoteObjectStub.java | 55 + .../testing/generated/_TestObjectImplBase.java | 149 ++ .../corba/testing/generated/_TestObjectStub.java | 182 +++ .../testing/generated/boolean_listHelper.java | 75 + .../testing/generated/boolean_listHolder.java | 51 + .../corba/testing/generated/char_listHelper.java | 75 + .../corba/testing/generated/char_listHolder.java | 51 + .../corba/testing/generated/double_listHelper.java | 75 + .../corba/testing/generated/double_listHolder.java | 51 + .../corba/testing/generated/float_listHelper.java | 75 + .../corba/testing/generated/float_listHolder.java | 51 + .../corba/testing/generated/long_listHelper.java | 75 + .../corba/testing/generated/long_listHolder.java | 51 + .../testing/generated/long_long_listHelper.java | 75 + .../testing/generated/long_long_listHolder.java | 51 + .../corba/testing/generated/long_seq1Helper.java | 75 + .../corba/testing/generated/long_seq1Holder.java | 51 + .../corba/testing/generated/long_seq2Helper.java | 83 + .../corba/testing/generated/long_seq2Holder.java | 51 + .../corba/testing/generated/long_seq3Helper.java | 89 ++ .../corba/testing/generated/long_seq3Holder.java | 51 + .../corba/testing/generated/octet_listHelper.java | 75 + .../corba/testing/generated/octet_listHolder.java | 51 + .../generated/remote_object_listHelper.java | 80 + .../generated/remote_object_listHolder.java | 51 + .../corba/testing/generated/short_listHelper.java | 75 + .../corba/testing/generated/short_listHolder.java | 51 + .../corba/testing/generated/string_listHelper.java | 77 + .../corba/testing/generated/string_listHolder.java | 51 + .../generated/unsigned_long_listHelper.java | 76 + .../generated/unsigned_long_listHolder.java | 51 + .../generated/unsigned_long_long_listHelper.java | 78 + .../generated/unsigned_long_long_listHolder.java | 51 + .../generated/unsigned_short_listHelper.java | 76 + .../generated/unsigned_short_listHolder.java | 51 + .../corba/testing/generated/wchar_listHelper.java | 75 + .../corba/testing/generated/wchar_listHolder.java | 51 + .../testing/generated/wstring_listHelper.java | 77 + .../testing/generated/wstring_listHolder.java | 51 + .../corba/testing/hierarchy/ArraysTestStruct.java | 45 + .../sca/binding/corba/testing/hierarchy/Calc.java | 30 + .../corba/testing/hierarchy/DummyObject.java | 28 + .../corba/testing/hierarchy/InnerUnion.java | 55 + .../corba/testing/hierarchy/InvalidCorbaArray.java | 38 + .../corba/testing/hierarchy/InvalidEnum1.java | 36 + .../corba/testing/hierarchy/InvalidEnum2.java | 33 + .../corba/testing/hierarchy/InvalidEnum3.java | 33 + .../corba/testing/hierarchy/InvalidStruct1.java | 28 + .../corba/testing/hierarchy/InvalidStruct2.java | 31 + .../corba/testing/hierarchy/InvalidStruct3.java | 36 + .../corba/testing/hierarchy/InvalidUnion1.java | 37 + .../corba/testing/hierarchy/InvalidUnion2.java | 34 + .../corba/testing/hierarchy/InvalidUnion3.java | 35 + .../corba/testing/hierarchy/InvalidUnion4.java | 39 + .../corba/testing/hierarchy/InvalidUnion5.java | 42 + .../corba/testing/hierarchy/NonCorbaException.java | 28 + .../binding/corba/testing/hierarchy/RichUnion.java | 91 ++ .../corba/testing/hierarchy/SimpleStruct.java | 30 + .../corba/testing/hierarchy/SomeStruct.java | 33 + .../corba/testing/references/DummyObject.java | 30 + .../testing/references/DummyObjectHelper.java | 100 ++ .../testing/references/DummyObjectHolder.java | 51 + .../testing/references/DummyObjectOperations.java | 33 + .../corba/testing/references/ObjectManager.java | 30 + .../testing/references/ObjectManagerHelper.java | 100 ++ .../testing/references/ObjectManagerHolder.java | 51 + .../references/ObjectManagerOperations.java | 33 + .../testing/references/_DummyObjectImplBase.java | 84 ++ .../corba/testing/references/_DummyObjectStub.java | 92 ++ .../testing/references/_ObjectManagerImplBase.java | 86 ++ .../testing/references/_ObjectManagerStub.java | 94 ++ .../testing/servants/ArraysSetterServant.java | 89 ++ .../testing/servants/ArraysUnionsServant.java | 42 + .../servants/ArraysUnionsTuscanyServant.java | 43 + .../corba/testing/servants/CalcServant.java | 52 + .../corba/testing/servants/DummyObjectServant.java | 42 + .../corba/testing/servants/EnumManagerServant.java | 33 + .../testing/servants/InvalidTestObjectServant.java | 24 + .../testing/servants/InvalidTypesServant.java | 34 + .../corba/testing/servants/NonCorbaServant.java | 36 + .../testing/servants/ObjectManagerServant.java | 37 + .../testing/servants/PrimitivesSetterServant.java | 89 ++ .../corba/testing/servants/TestObjectServant.java | 71 + .../corba/testing/service/mocks/TestDataType.java | 88 ++ .../corba/testing/service/mocks/TestInterface.java | 148 ++ .../service/mocks/TestInterfaceContract.java | 58 + .../corba/testing/service/mocks/TestOperation.java | 195 +++ .../service/mocks/TestRuntimeComponentService.java | 239 +++ .../testing/service/mocks/TestRuntimeWire.java | 107 ++ .../src/test/resources/arrays_unions.idl | 69 + .../src/test/resources/enums.idl | 44 + .../src/test/resources/exceptions.idl | 58 + .../src/test/resources/general_tests.idl | 124 ++ .../src/test/resources/references.idl | 50 + .../sca-java-1.6/modules/binding-corba/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-corba/NOTICE | 6 + .../sca-java-1.6/modules/binding-corba/pom.xml | 71 + .../tuscany/sca/binding/corba/CorbaBinding.java | 46 + .../sca/binding/corba/CorbaBindingFactory.java | 31 + .../corba/impl/CorbaBindingFactoryImpl.java | 37 + .../sca/binding/corba/impl/CorbaBindingImpl.java | 132 ++ .../binding/corba/impl/CorbaBindingProcessor.java | 134 ++ ...e.tuscany.sca.binding.corba.CorbaBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../sca-java-1.6/modules/binding-dwr/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-dwr/NOTICE | 6 + .../sca-java-1.6/modules/binding-dwr/pom.xml | 95 ++ .../apache/tuscany/sca/binding/dwr/DWRBinding.java | 31 + .../sca/binding/dwr/DWRBindingActivator.java | 56 + .../apache/tuscany/sca/binding/dwr/DWRInvoker.java | 93 ++ .../tuscany/sca/binding/dwr/DWRInvokerFactory.java | 67 + .../apache/tuscany/sca/binding/dwr/DWRService.java | 81 + .../apache/tuscany/sca/binding/dwr/DWRServlet.java | 247 +++ ...e.tuscany.sca.extension.helper.BindingActivator | 19 + .../modules/binding-ejb-runtime/LICENSE | 205 +++ .../modules/binding-ejb-runtime/NOTICE | 6 + .../modules/binding-ejb-runtime/pom.xml | 195 +++ .../sca/binding/ejb/corba/ClassLoadingUtil.java | 365 +++++ .../binding/ejb/corba/DynamicStubClassLoader.java | 150 ++ .../sca/binding/ejb/corba/Java2IDLUtil.java | 811 ++++++++++ .../binding/ejb/corba/ObjectInputStreamExt.java | 61 + .../binding/ejb/corba/StubMethodInterceptor.java | 154 ++ .../sca/binding/ejb/corba/UtilInitializer.java | 69 + .../binding/ejb/provider/EJBBindingInvoker.java | 92 ++ .../ejb/provider/EJBBindingProviderFactory.java | 56 + .../EJBBindingReferenceBindingProvider.java | 86 ++ .../tuscany/sca/binding/ejb/util/EJBHandler.java | 338 +++++ .../tuscany/sca/binding/ejb/util/EJBLocator.java | 483 ++++++ .../sca/binding/ejb/util/EJBObjectFactory.java | 209 +++ .../sca/binding/ejb/util/EJBStubHelper.java | 69 + .../sca/binding/ejb/util/InterfaceInfo.java | 117 ++ .../binding/ejb/util/JavaReflectionAdapter.java | 157 ++ .../tuscany/sca/binding/ejb/util/MethodInfo.java | 189 +++ .../sca/binding/ejb/util/NamingEndpoint.java | 124 ++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../binding-ejb-validation-messages.properties | 23 + .../src/test/java/account/BankManagerFacade.java | 33 + .../src/test/java/account/Customer.java | 36 + .../src/test/java/account/CustomerImpl.java | 57 + .../src/test/java/calculator/AddServiceRemote.java | 26 + .../samples/bank/ejb/BankManagerFacade.java | 44 + .../samples/bank/ejb/BankManagerFacadeHome.java | 44 + .../binding/ejb/tests/EJBReferenceTestCase.java | 71 + .../tuscany/sca/binding/ejb/tests/MockServer.java | 140 ++ .../sca/binding/ejb/tests/SocketTracer.java | 138 ++ .../src/test/resources/account/account.composite | 35 + .../resources/calculator-ejb/calculator-ejb.jar | Bin 0 -> 5449 bytes .../sca-java-1.6/modules/binding-ejb/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-ejb/NOTICE | 6 + .../sca-java-1.6/modules/binding-ejb/pom.xml | 91 ++ .../apache/tuscany/sca/binding/ejb/EJBBinding.java | 95 ++ .../sca/binding/ejb/EJBBindingException.java | 56 + .../tuscany/sca/binding/ejb/EJBBindingFactory.java | 35 + .../binding/ejb/impl/EJBBindingFactoryImpl.java | 36 + .../sca/binding/ejb/impl/EJBBindingImpl.java | 184 +++ .../sca/binding/ejb/impl/EJBBindingProcessor.java | 231 +++ ...pache.tuscany.sca.binding.ejb.EJBBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../binding-ejb-validation-messages.properties | 23 + .../ejb/impl/ReadWriteAnyAttributeTestCase.java | 133 ++ .../modules/binding-erlang-runtime/LICENSE | 205 +++ .../modules/binding-erlang-runtime/NOTICE | 6 + .../modules/binding-erlang-runtime/pom.xml | 91 ++ .../erlang/impl/ErlangBindingProviderFactory.java | 94 ++ .../sca/binding/erlang/impl/ErlangInvoker.java | 209 +++ .../sca/binding/erlang/impl/ErlangNode.java | 118 ++ .../sca/binding/erlang/impl/ErlangNodeElement.java | 50 + .../impl/ErlangReferenceBindingProvider.java | 87 ++ .../erlang/impl/ErlangServiceBindingProvider.java | 83 + .../sca/binding/erlang/impl/MessageHelper.java | 127 ++ .../sca/binding/erlang/impl/ServiceExecutor.java | 378 +++++ .../binding/erlang/impl/TypeMismatchException.java | 50 + .../erlang/impl/exceptions/ErlangException.java | 37 + .../erlang/impl/types/AnnotatedListTypeHelper.java | 71 + .../binding/erlang/impl/types/AtomTypeHelper.java | 39 + .../erlang/impl/types/BinaryTypeHelper.java | 39 + .../erlang/impl/types/BooleanTypeHelper.java | 44 + .../binding/erlang/impl/types/ByteTypeHelper.java | 39 + .../binding/erlang/impl/types/CharTypeHelper.java | 40 + .../erlang/impl/types/DoubleTypeHelper.java | 39 + .../binding/erlang/impl/types/FloatTypeHelper.java | 39 + .../binding/erlang/impl/types/IntTypeHelper.java | 40 + .../binding/erlang/impl/types/ListTypeHelper.java | 65 + .../binding/erlang/impl/types/LongTypeHelper.java | 39 + .../binding/erlang/impl/types/ShortTypeHelper.java | 40 + .../erlang/impl/types/StringTypeHelper.java | 39 + .../binding/erlang/impl/types/TupleTypeHelper.java | 70 + .../sca/binding/erlang/impl/types/TypeHelper.java | 33 + .../erlang/impl/types/TypeHelpersProxy.java | 291 ++++ .../sca/binding/erlang/meta/ErlangAtom.java | 28 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../sca/binding/erlang/testing/AtomTuple.java | 30 + .../sca/binding/erlang/testing/MboxInterface.java | 65 + .../sca/binding/erlang/testing/MboxListener.java | 97 ++ .../binding/erlang/testing/ModuleInterface.java | 31 + .../erlang/testing/ReferenceServiceTestCase.java | 924 ++++++++++++ .../erlang/testing/ReferenceTestComponent.java | 27 + .../erlang/testing/ReferenceTestComponentImpl.java | 110 ++ .../binding/erlang/testing/ServiceInterface.java | 45 + .../erlang/testing/ServiceTestComponent.java | 40 + .../erlang/testing/ServiceTestComponentImpl.java | 48 + .../testing/ServiceTestComponentImplClone.java | 48 + .../testing/ServiceTestComponentImplTimeout.java | 65 + .../sca/binding/erlang/testing/SmallTuple.java | 35 + .../binding/erlang/testing/StructuredTuple.java | 37 + .../erlang/testing/dynaignore/IgnorableRunner.java | 139 ++ .../erlang/testing/dynaignore/IgnoreTest.java | 29 + .../src/test/resources/ErlangReference.composite | 58 + .../src/test/resources/ErlangService.composite | 54 + .../sca-java-1.6/modules/binding-erlang/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-erlang/NOTICE | 6 + .../sca-java-1.6/modules/binding-erlang/pom.xml | 65 + .../tuscany/sca/binding/erlang/ErlangBinding.java | 70 + .../sca/binding/erlang/ErlangBindingFactory.java | 31 + .../erlang/impl/ErlangBindingFactoryImpl.java | 37 + .../sca/binding/erlang/impl/ErlangBindingImpl.java | 166 ++ .../erlang/impl/ErlangBindingProcessor.java | 160 ++ ...tuscany.sca.binding.erlang.ErlangBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../testing/ErlangBindingProcessorTestCase.java | 154 ++ .../sca-java-1.6/modules/binding-feed/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-feed/NOTICE | 6 + .../sca-java-1.6/modules/binding-feed/pom.xml | 165 ++ .../tuscany/sca/binding/feed/AtomBinding.java | 30 + .../sca/binding/feed/AtomBindingFactory.java | 35 + .../tuscany/sca/binding/feed/RSSBinding.java | 30 + .../sca/binding/feed/RSSBindingFactory.java | 35 + .../sca/binding/feed/collection/Collection.java | 72 + .../binding/feed/collection/MediaCollection.java | 55 + .../binding/feed/collection/NotFoundException.java | 45 + .../binding/feed/impl/AtomBindingFactoryImpl.java | 36 + .../sca/binding/feed/impl/AtomBindingImpl.java | 96 ++ .../binding/feed/impl/RSSBindingFactoryImpl.java | 36 + .../sca/binding/feed/impl/RSSBindingImpl.java | 101 ++ .../binding/feed/provider/AtomBindingInvoker.java | 345 +++++ .../feed/provider/AtomBindingProviderFactory.java | 71 + .../binding/feed/provider/AtomFeedEntryUtil.java | 117 ++ .../provider/AtomReferenceBindingProvider.java | 116 ++ .../feed/provider/AtomServiceBindingProvider.java | 87 ++ .../feed/provider/FeedBindingListenerServlet.java | 788 ++++++++++ .../binding/feed/provider/RSSBindingInvoker.java | 91 ++ .../feed/provider/RSSBindingProviderFactory.java | 71 + .../feed/provider/RSSReferenceBindingProvider.java | 65 + .../feed/provider/RSSServiceBindingProvider.java | 85 ++ ...che.tuscany.sca.binding.feed.AtomBindingFactory | 19 + ...ache.tuscany.sca.binding.feed.RSSBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 20 + ...che.tuscany.sca.provider.BindingProviderFactory | 20 + .../apache/tuscany/sca/binding/feed/Consumer.java | 35 + .../tuscany/sca/binding/feed/CustomerClient.java | 25 + .../sca/binding/feed/CustomerClientImpl.java | 97 ++ .../sca/binding/feed/CustomerCollectionImpl.java | 136 ++ .../apache/tuscany/sca/binding/feed/Provider.java | 41 + .../tuscany/sca/binding/feed/Consumer.composite | 32 + .../tuscany/sca/binding/feed/Provider.composite | 33 + .../modules/binding-gdata-runtime/LICENSE | 205 +++ .../modules/binding-gdata-runtime/NOTICE | 6 + .../modules/binding-gdata-runtime/pom.xml | 210 +++ .../sca/binding/gdata/collection/Collection.java | 81 + .../binding/gdata/collection/MediaCollection.java | 55 + .../gdata/collection/NotFoundException.java | 45 + .../gdata/provider/GdataBindingInvoker.java | 419 ++++++ .../provider/GdataBindingListenerServlet.java | 746 +++++++++ .../provider/GdataBindingProviderFactory.java | 79 + .../binding/gdata/provider/GdataBindingUtil.java | 171 +++ .../provider/GdataReferenceBindingProvider.java | 229 +++ .../provider/GdataServiceBindingProvider.java | 90 ++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../tuscany/sca/binding/gdata/Constants.java | 24 + .../apache/tuscany/sca/binding/gdata/Consumer.java | 60 + .../binding/gdata/ConsumerProviderTestCase.java | 136 ++ .../tuscany/sca/binding/gdata/CustomerClient.java | 40 + .../sca/binding/gdata/CustomerClientImpl.java | 120 ++ .../sca/binding/gdata/CustomerCollectionImpl.java | 142 ++ .../gdata/GoogleBloggerServiceTestCase.java | 141 ++ .../gdata/GoogleCalendarServiceTestCase.java | 149 ++ .../gdata/GoogleContactsServiceTestCase.java | 168 +++ .../gdata/GoogleWebAlbumServiceTestCase.java | 115 ++ .../apache/tuscany/sca/binding/gdata/Provider.java | 41 + .../sca/binding/gdata/StartLocalhostServlet.java | 41 + .../src/test/resources/log4j.properties | 25 + .../tuscany/sca/binding/gdata/Consumer.composite | 32 + .../binding/gdata/ConsumerGoogleBlogger.composite | 32 + .../binding/gdata/ConsumerGoogleCalendar.composite | 32 + .../binding/gdata/ConsumerGoogleContacts.composite | 32 + .../binding/gdata/ConsumerGoogleWebAlbum.composite | 32 + .../tuscany/sca/binding/gdata/Provider.composite | 33 + .../sca-java-1.6/modules/binding-gdata/LICENSE | 202 +++ .../sca-java-1.6/modules/binding-gdata/NOTICE | 8 + .../sca-java-1.6/modules/binding-gdata/pom.xml | 79 + .../tuscany/sca/binding/gdata/GdataBinding.java | 78 + .../sca/binding/gdata/GdataBindingFactory.java | 35 + .../gdata/impl/GdataBindingFactoryImpl.java | 36 + .../sca/binding/gdata/impl/GdataBindingImpl.java | 141 ++ .../binding/gdata/impl/GdataBindingProcessor.java | 121 ++ ...e.tuscany.sca.binding.gdata.GdataBindingFactory | 18 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../sca-java-1.6/modules/binding-hessian/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-hessian/NOTICE | 6 + .../sca-java-1.6/modules/binding-hessian/pom.xml | 107 ++ .../sca/binding/hessian/impl/HessianBinding.java | 94 ++ .../hessian/impl/HessianBindingException.java | 40 + .../hessian/impl/HessianBindingProcessor.java | 135 ++ .../hessian/provider/HessianBindingInvoker.java | 73 + .../provider/HessianBindingProviderFactory.java | 67 + .../provider/HessianReferenceBindingProvider.java | 62 + .../provider/HessianServiceBindingProvider.java | 87 ++ .../provider/HessianServiceListenerServlet.java | 335 +++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...any.sca.contribution.processor.ValidationSchema | 19 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../src/main/resources/binding-hessian.xsd | 36 + .../org/zhulei/test/hessian/first/FirstImpl.java | 19 + .../zhulei/test/hessian/first/FirstTestCase.java | 70 + .../java/org/zhulei/test/hessian/first/IFirst.java | 11 + .../org/zhulei/test/hessian/second/ISecond.java | 7 + .../org/zhulei/test/hessian/second/SecondImpl.java | 19 + .../zhulei/test/hessian/second/SecondTestCase.java | 72 + .../src/test/resources/first_hessian.composite | 21 + .../src/test/resources/second_hessian.composite | 27 + .../modules/binding-http-jsonrpc-runtime/LICENSE | 205 +++ .../modules/binding-http-jsonrpc-runtime/NOTICE | 6 + .../modules/binding-http-jsonrpc-runtime/pom.xml | 130 ++ .../JSONRPCOperationSelectorInterceptor.java | 129 ++ .../JSONRPCOperationSelectorProviderFactory.java | 58 + .../JSONRPCOperationSelectorServiceProvider.java | 76 + .../provider/JSONRPCWireFormatInterceptor.java | 172 +++ .../provider/JSONRPCWireFormatProviderFactory.java | 59 + .../JSONRPCWireFormatReferenceProvider.java | 57 + .../provider/JSONRPCWireFormatServiceProvider.java | 122 ++ .../wireformat/jsonrpc/provider/JavaToSmd.java | 56 + ...y.sca.provider.OperationSelectorProviderFactory | 18 + ....tuscany.sca.provider.WireFormatProviderFactory | 19 + .../modules/binding-http-jsonrpc/LICENSE | 205 +++ .../modules/binding-http-jsonrpc/NOTICE | 6 + .../modules/binding-http-jsonrpc/pom.xml | 94 ++ .../jsonrpc/JSONRPCOperationSelector.java | 39 + .../jsonrpc/JSONRPCOperationSelectorFactory.java | 35 + .../impl/JSONRPCOperationSelectorFactoryImpl.java | 35 + .../jsonrpc/impl/JSONRPCOperationSelectorImpl.java | 44 + .../http/wireformat/jsonrpc/JSONRPCWireFormat.java | 39 + .../jsonrpc/JSONRPCWireFormatFactory.java | 33 + .../jsonrpc/impl/JSONRPCWireFormatFactoryImpl.java | 37 + .../jsonrpc/impl/JSONRPCWireFormatImpl.java | 44 + ...elector.jsonrpc.JSONRPCOperationSelectorFactory | 19 + ...ttp.wireformat.jsonrpc.JSONRPCWireFormatFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 20 + .../JSONRPCOperationSelectorProcessorTestCase.java | 126 ++ .../impl/JSONRPCWireFormatProcessorTestCase.java | 130 ++ .../modules/binding-http-runtime/LICENSE | 205 +++ .../modules/binding-http-runtime/NOTICE | 6 + .../modules/binding-http-runtime/pom.xml | 120 ++ .../http/provider/HTTPBindingListenerServlet.java | 516 +++++++ .../http/provider/HTTPBindingProviderFactory.java | 65 + .../http/provider/HTTPGetListenerServlet.java | 94 ++ .../http/provider/HTTPRRBListenerServlet.java | 102 ++ .../http/provider/HTTPServiceBindingProvider.java | 265 ++++ .../http/provider/HTTPServiceListenerServlet.java | 136 ++ .../sca/binding/http/util/HTTPHeadersParser.java | 50 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../sca/binding/http/HTTPBindingCacheTestCase.java | 855 +++++++++++ .../sca/binding/http/HTTPBindingTestCase.java | 147 ++ .../sca/binding/http/NotModifiedException.java | 44 + .../binding/http/PreconditionFailedException.java | 44 + .../sca/binding/http/TestBindingCacheImpl.java | 241 +++ .../tuscany/sca/binding/http/TestGetImpl.java | 37 + .../sca/binding/http/TestServiceCacheImpl.java | 61 + .../tuscany/sca/binding/http/TestServiceImpl.java | 61 + .../src/test/resources/content/test.html | 21 + .../src/test/resources/test.composite | 47 + .../src/test/resources/testCache.composite | 33 + .../sca-java-1.6/modules/binding-http/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-http/NOTICE | 6 + .../sca-java-1.6/modules/binding-http/pom.xml | 87 ++ .../tuscany/sca/binding/http/HTTPBinding.java | 31 + .../sca/binding/http/HTTPBindingContext.java | 47 + .../sca/binding/http/HTTPBindingFactory.java | 35 + .../tuscany/sca/binding/http/HTTPCacheContext.java | 257 ++++ .../tuscany/sca/binding/http/HTTPHeader.java | 51 + .../binding/http/impl/HTTPBindingFactoryImpl.java | 36 + .../sca/binding/http/impl/HTTPBindingImpl.java | 139 ++ .../sca/binding/http/xml/HTTPBindingProcessor.java | 181 +++ ...che.tuscany.sca.binding.http.HTTPBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../modules/binding-jms-policy/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-jms-policy/NOTICE | 6 + .../modules/binding-jms-policy/pom.xml | 94 ++ .../jms/policy/JMSBindingDefinitionsProvider.java | 66 + .../token/JMSTokenAuthenticationPolicy.java | 56 + .../JMSTokenAuthenticationPolicyProcessor.java | 112 ++ ...MSTokenAuthenticationPolicyProviderFactory.java | 75 + ...enAuthenticationReferencePolicyInterceptor.java | 100 ++ ...TokenAuthenticationReferencePolicyProvider.java | 91 ++ ...okenAuthenticationServicePolicyInterceptor.java | 100 ++ ...MSTokenAuthenticationServicePolicyProvider.java | 88 ++ .../binding/jms/policy/header/JMSHeaderPolicy.java | 131 ++ .../policy/header/JMSHeaderPolicyProcessor.java | 210 +++ .../header/JMSHeaderPolicyProviderFactory.java | 75 + .../JMSHeaderReferencePolicyInterceptor.java | 101 ++ .../header/JMSHeaderReferencePolicyProvider.java | 90 ++ ...ca.contribution.processor.StAXArtifactProcessor | 20 + ...ache.tuscany.sca.provider.PolicyProviderFactory | 19 + ...che.tuscany.sca.provider.SCADefinitionsProvider | 19 + ...nding-jms-policy-validation-messages.properties | 23 + .../tuscany/sca/binding/jms/policy/definitions.xml | 84 ++ .../jms/policy/PolicyProcessorTestCase.java | 91 ++ .../binding/jms/policy/mock_policy_definitions.xml | 39 + .../modules/binding-jms-runtime/LICENSE | 205 +++ .../modules/binding-jms-runtime/NOTICE | 6 + .../modules/binding-jms-runtime/pom.xml | 142 ++ .../sca/binding/jms/context/JMSBindingContext.java | 143 ++ .../jms/headers/HeaderReferenceInterceptor.java | 182 +++ ...OperationSelectorJMSDefaultProviderFactory.java | 69 + ...rationSelectorJMSDefaultServiceInterceptor.java | 196 +++ ...OperationSelectorJMSDefaultServiceProvider.java | 59 + ...perationSelectorJMSUserPropProviderFactory.java | 62 + ...ationSelectorJMSUserPropServiceInterceptor.java | 107 ++ ...perationSelectorJMSUserPropServiceProvider.java | 54 + .../jms/provider/AbstractMessageProcessor.java | 136 ++ .../jms/provider/BytesMessageProcessor.java | 124 ++ .../DefaultJMSResourceFactoryExtensionPoint.java | 30 + .../jms/provider/DefaultMessageProcessor.java | 287 ++++ .../jms/provider/JMSBindingProviderFactory.java | 70 + .../JMSBindingReferenceBindingProvider.java | 170 +++ .../provider/JMSBindingServiceBindingProvider.java | 228 +++ .../binding/jms/provider/JMSMessageProcessor.java | 55 + .../jms/provider/JMSMessageProcessorUtil.java | 75 + .../binding/jms/provider/JMSResourceFactory.java | 95 ++ .../provider/JMSResourceFactoryExtensionPoint.java | 28 + .../jms/provider/JMSResourceFactoryImpl.java | 282 ++++ .../jms/provider/ObjectMessageProcessor.java | 230 +++ .../binding/jms/provider/RRBJMSBindingInvoker.java | 270 ++++ .../binding/jms/provider/TextMessageProcessor.java | 79 + .../jms/provider/XMLBytesMessageProcessor.java | 134 ++ .../jms/provider/XMLTextMessageProcessor.java | 129 ++ .../transport/TransportReferenceInterceptor.java | 163 ++ .../jms/transport/TransportServiceInterceptor.java | 188 +++ .../jms/wire/CallbackDestinationInterceptor.java | 96 ++ .../jms/wire/OperationPropertiesInterceptor.java | 78 + .../runtime/WireFormatJMSBytesProviderFactory.java | 66 + .../WireFormatJMSBytesReferenceInterceptor.java | 123 ++ .../WireFormatJMSBytesReferenceProvider.java | 97 ++ .../WireFormatJMSBytesServiceInterceptor.java | 114 ++ .../runtime/WireFormatJMSBytesServiceProvider.java | 101 ++ .../WireFormatJMSBytesXMLProviderFactory.java | 70 + .../WireFormatJMSBytesXMLReferenceInterceptor.java | 122 ++ .../WireFormatJMSBytesXMLReferenceProvider.java | 105 ++ .../WireFormatJMSBytesXMLServiceInterceptor.java | 109 ++ .../WireFormatJMSBytesXMLServiceProvider.java | 114 ++ .../WireFormatJMSDefaultProviderFactory.java | 69 + .../WireFormatJMSDefaultReferenceInterceptor.java | 176 +++ .../WireFormatJMSDefaultReferenceProvider.java | 199 +++ .../WireFormatJMSDefaultServiceInterceptor.java | 176 +++ .../WireFormatJMSDefaultServiceProvider.java | 191 +++ .../WireFormatJMSObjectProviderFactory.java | 66 + .../WireFormatJMSObjectReferenceInterceptor.java | 143 ++ .../WireFormatJMSObjectReferenceProvider.java | 116 ++ .../WireFormatJMSObjectServiceInterceptor.java | 138 ++ .../WireFormatJMSObjectServiceProvider.java | 122 ++ .../runtime/WireFormatJMSTextProviderFactory.java | 66 + .../WireFormatJMSTextReferenceInterceptor.java | 125 ++ .../WireFormatJMSTextReferenceProvider.java | 106 ++ .../WireFormatJMSTextServiceInterceptor.java | 114 ++ .../runtime/WireFormatJMSTextServiceProvider.java | 108 ++ .../WireFormatJMSTextXMLProviderFactory.java | 72 + .../WireFormatJMSTextXMLReferenceInterceptor.java | 128 ++ .../WireFormatJMSTextXMLReferenceProvider.java | 118 ++ .../WireFormatJMSTextXMLServiceInterceptor.java | 115 ++ .../WireFormatJMSTextXMLServiceProvider.java | 111 ++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + ...y.sca.provider.OperationSelectorProviderFactory | 20 + ....tuscany.sca.provider.WireFormatProviderFactory | 24 + .../sca/binding/jms/HelloWorldClientImpl.java | 43 + .../tuscany/sca/binding/jms/HelloWorldService.java | 31 + .../sca/binding/jms/HelloWorldServiceImpl.java | 32 + .../jms/OperationSelectionTestCaseFIXME.java | 237 +++ .../src/test/resources/simple/client.composite | 38 + .../src/test/resources/simple/service.composite | 35 + .../sca-java-1.6/modules/binding-jms/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-jms/NOTICE | 6 + .../sca-java-1.6/modules/binding-jms/pom.xml | 66 + .../sca/binding/jms/impl/BindingProperty.java | 71 + .../tuscany/sca/binding/jms/impl/JMSBinding.java | 970 ++++++++++++ .../sca/binding/jms/impl/JMSBindingConstants.java | 75 + .../sca/binding/jms/impl/JMSBindingException.java | 45 + .../sca/binding/jms/impl/JMSBindingProcessor.java | 1560 +++++++++++++++++++ .../jmsdefault/OperationSelectorJMSDefault.java | 45 + .../OperationSelectorJMSDefaultProcessor.java | 76 + .../jmsuserprop/OperationSelectorJMSUserProp.java | 57 + .../OperationSelectorJMSUserPropProcessor.java | 87 ++ .../wireformat/jmsbytes/WireFormatJMSBytes.java | 45 + .../jmsbytes/WireFormatJMSBytesProcessor.java | 78 + .../jmsbytesxml/WireFormatJMSBytesXML.java | 40 + .../WireFormatJMSBytesXMLProcessor.java | 75 + .../jmsdefault/WireFormatJMSDefault.java | 64 + .../jmsdefault/WireFormatJMSDefaultProcessor.java | 93 ++ .../wireformat/jmsobject/WireFormatJMSObject.java | 57 + .../jmsobject/WireFormatJMSObjectProcessor.java | 91 ++ .../jms/wireformat/jmstext/WireFormatJMSText.java | 45 + .../jmstext/WireFormatJMSTextProcessor.java | 78 + .../jmstextxml/WireFormatJMSTextXML.java | 48 + .../jmstextxml/WireFormatJMSTextXMLProcessor.java | 78 + ...ca.contribution.processor.StAXArtifactProcessor | 27 + .../binding-jms-validation-messages.properties | 50 + .../jms/impl/JMSBindingProcessorTestCase.java | 783 ++++++++++ .../jms/impl/JMSBindingProcessorWriteTestCase.java | 456 ++++++ .../modules/binding-jsonrpc-js-dojo/LICENSE | 205 +++ .../modules/binding-jsonrpc-js-dojo/NOTICE | 6 + .../modules/binding-jsonrpc-js-dojo/pom.xml | 74 + .../JSONRPCBindingJavascriptProxyFactoryImpl.java | 60 + ...scany.sca.web.javascript.JavascriptProxyFactory | 19 + .../modules/binding-jsonrpc-js/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-jsonrpc-js/NOTICE | 6 + .../modules/binding-jsonrpc-js/pom.xml | 74 + .../JSONRPCBindingJavascriptProxyFactoryImpl.java | 66 + ...scany.sca.web.javascript.JavascriptProxyFactory | 19 + .../src/main/resources/binding-jsonrpc.js | 492 ++++++ .../modules/binding-jsonrpc-runtime/LICENSE | 205 +++ .../modules/binding-jsonrpc-runtime/NOTICE | 6 + .../modules/binding-jsonrpc-runtime/pom.xml | 164 ++ .../jsonrpc/provider/JSONRPCBindingInvoker.java | 45 + .../provider/JSONRPCBindingProviderFactory.java | 70 + .../provider/JSONRPCReferenceBindingProvider.java | 70 + .../provider/JSONRPCServiceBindingProvider.java | 189 +++ .../jsonrpc/provider/JSONRPCServiceServlet.java | 316 ++++ .../sca/binding/jsonrpc/provider/JavaToSmd.java | 56 + .../jsonrpc/provider/ScaDomainScriptServlet.java | 114 ++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../sca/binding/jsonrpc/provider/jsonrpc.js | 493 ++++++ .../src/test/java/bean/TestBean.java | 51 + .../src/test/java/echo/Echo.java | 64 + .../src/test/java/echo/EchoBusinessException.java | 29 + .../src/test/java/echo/EchoComponentImpl.java | 103 ++ .../binding/jsonrpc/JSONRPCDataTypeTestCase.java | 193 +++ .../binding/jsonrpc/JSONRPCExceptionTestCase.java | 86 ++ .../binding/jsonrpc/JSONRPCServiceTestCase.java | 70 + .../sca/binding/jsonrpc/JSONRPCSmdTestCase.java | 73 + .../src/test/resources/JSONRPCBinding.composite | 35 + .../sca-java-1.6/modules/binding-jsonrpc/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-jsonrpc/NOTICE | 6 + .../sca-java-1.6/modules/binding-jsonrpc/pom.xml | 78 + .../sca/binding/jsonrpc/JSONRPCBinding.java | 32 + .../sca/binding/jsonrpc/JSONRPCBindingFactory.java | 35 + .../jsonrpc/impl/JSONRPCBindingFactoryImpl.java | 38 + .../binding/jsonrpc/impl/JSONRPCBindingImpl.java | 105 ++ ...scany.sca.binding.jsonrpc.JSONRPCBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../modules/binding-notification/LICENSE | 205 +++ .../modules/binding-notification/NOTICE | 6 + .../modules/binding-notification/pom.xml | 150 ++ .../DefaultNotificationBindingFactory.java | 31 + .../binding/notification/NotificationBinding.java | 37 + .../notification/NotificationBindingFactory.java | 27 + .../notification/NotificationBindingImpl.java | 75 + .../NotificationBindingModuleActivator.java | 68 + .../notification/NotificationBindingProcessor.java | 97 ++ .../NotificationBindingProviderFactory.java | 342 +++++ .../notification/NotificationBrokerManager.java | 40 + .../NotificationReferenceBindingInvoker.java | 126 ++ .../NotificationReferenceBindingProvider.java | 338 +++++ .../NotificationServiceBindingProvider.java | 317 ++++ .../notification/NotificationTypeManager.java | 43 + .../notification/NotificationTypeManagerImpl.java | 669 ++++++++ .../notification/encoding/AbstractBroker.java | 44 + .../encoding/AbstractBrokerEnDeCoder.java | 86 ++ .../notification/encoding/AbstractEnDeCoder.java | 50 + .../sca/binding/notification/encoding/Broker.java | 25 + .../encoding/BrokerConsumerReference.java | 26 + .../encoding/BrokerConsumerReferenceEnDeCoder.java | 44 + .../notification/encoding/BrokerEnDeCoder.java | 46 + .../binding/notification/encoding/BrokerID.java | 41 + .../notification/encoding/BrokerIDEnDeCoder.java | 90 ++ .../encoding/BrokerProducerReference.java | 26 + .../encoding/BrokerProducerReferenceEnDeCoder.java | 44 + .../sca/binding/notification/encoding/Brokers.java | 41 + .../notification/encoding/BrokersEnDeCoder.java | 89 ++ .../notification/encoding/ConnectionOverride.java | 35 + .../encoding/ConnectionOverrideEnDeCoder.java | 83 + .../encoding/ConnectionOverrideResponse.java | 25 + .../ConnectionOverrideResponseEnDeCoder.java | 77 + .../binding/notification/encoding/Constants.java | 74 + .../notification/encoding/ConsumerReference.java | 26 + .../encoding/ConsumerReferenceEnDeCoder.java | 44 + .../encoding/DefaultEncodingRegistry.java | 78 + .../binding/notification/encoding/EnDeCoder.java | 62 + .../notification/encoding/EncodingException.java | 49 + .../notification/encoding/EncodingObject.java | 26 + .../notification/encoding/EncodingRegistry.java | 57 + .../notification/encoding/EncodingUtils.java | 83 + .../notification/encoding/EndConsumers.java | 26 + .../encoding/EndConsumersEnDeCoder.java | 61 + .../notification/encoding/EndProducers.java | 26 + .../encoding/EndProducersEnDeCoder.java | 61 + .../notification/encoding/EndpointAddress.java | 45 + .../encoding/EndpointAddressEnDeCoder.java | 90 ++ .../notification/encoding/EndpointReference.java | 44 + .../encoding/EndpointReferenceEnDeCoder.java | 99 ++ .../encoding/EndpointReferenceSequence.java | 54 + .../EndpointReferenceSequenceEnDeCoder.java | 85 ++ .../encoding/EndpointReferenceWrapper.java | 35 + .../EndpointReferenceWrapperEnDeCoder.java | 74 + .../encoding/NeighborBrokerConsumers.java | 26 + .../encoding/NeighborBrokerConsumersEnDeCoder.java | 61 + .../binding/notification/encoding/Neighbors.java | 45 + .../notification/encoding/NeighborsEnDeCoder.java | 89 ++ .../binding/notification/encoding/NewBroker.java | 25 + .../notification/encoding/NewBrokerAck.java | 25 + .../encoding/NewBrokerAckEnDeCoder.java | 77 + .../notification/encoding/NewBrokerEnDeCoder.java | 46 + .../notification/encoding/NewBrokerResponse.java | 62 + .../encoding/NewBrokerResponseEnDeCoder.java | 115 ++ .../binding/notification/encoding/NewConsumer.java | 26 + .../encoding/NewConsumerEnDeCoder.java | 44 + .../notification/encoding/NewConsumerResponse.java | 26 + .../encoding/NewConsumerResponseEnDeCoder.java | 61 + .../binding/notification/encoding/NewProducer.java | 26 + .../encoding/NewProducerEnDeCoder.java | 44 + .../notification/encoding/NewProducerResponse.java | 26 + .../encoding/NewProducerResponseEnDeCoder.java | 61 + .../notification/encoding/ReferenceProperties.java | 54 + .../encoding/ReferencePropertiesEnDeCoder.java | 87 ++ .../notification/encoding/RemoveBroker.java | 44 + .../encoding/RemoveBrokerEnDeCoder.java | 99 ++ .../notification/encoding/RemovedBroker.java | 26 + .../encoding/RemovedBrokerEnDeCoder.java | 44 + .../encoding/ReplaceBrokerConnection.java | 44 + .../encoding/ReplaceBrokerConnectionEnDeCoder.java | 99 ++ .../binding/notification/encoding/Subscribe.java | 35 + .../notification/encoding/SubscribeEnDeCoder.java | 83 + .../sca/binding/notification/util/IOUtils.java | 176 +++ .../notification/util/NotificationServlet.java | 89 ++ .../sca/binding/notification/util/URIUtil.java | 41 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../notification/encoding/AxiomTestCase.java | 56 + .../notification/encoding/EncodingTestCase.java | 470 ++++++ .../modules/binding-rmi-runtime/LICENSE | 205 +++ .../modules/binding-rmi-runtime/NOTICE | 6 + .../modules/binding-rmi-runtime/pom.xml | 99 ++ .../rmi/provider/RMIBindingProviderFactory.java | 62 + .../rmi/provider/RMIReferenceBindingProvider.java | 80 + .../binding/rmi/provider/RMIReferenceInvoker.java | 88 ++ .../rmi/provider/RMIServiceBindingProvider.java | 213 +++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../src/test/java/helloworld/HelloException.java | 60 + .../src/test/java/helloworld/HelloWorldImpl.java | 42 + .../test/java/helloworld/HelloWorldRmiImpl.java | 50 + .../test/java/helloworld/HelloWorldRmiService.java | 31 + .../test/java/helloworld/HelloWorldService.java | 31 + .../tuscany/sca/binding/rmi/BindingTestCase.java | 78 + .../test/resources/HelloWorldImpl.componentType | 23 + .../test/resources/HelloWorldRmiImpl.componentType | 27 + .../src/test/resources/RMIBindingTest.composite | 43 + .../sca-java-1.6/modules/binding-rmi/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-rmi/NOTICE | 6 + .../sca-java-1.6/modules/binding-rmi/pom.xml | 93 ++ .../apache/tuscany/sca/binding/rmi/RMIBinding.java | 61 + .../tuscany/sca/binding/rmi/RMIBindingFactory.java | 31 + .../binding/rmi/impl/RMIBindingFactoryImpl.java | 34 + .../sca/binding/rmi/impl/RMIBindingImpl.java | 157 ++ ...pache.tuscany.sca.binding.rmi.RMIBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../sca-java-1.6/modules/binding-rss-rome/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-rss-rome/NOTICE | 6 + .../sca-java-1.6/modules/binding-rss-rome/pom.xml | 171 +++ .../sca/binding/rss/collection/Collection.java | 58 + .../binding/rss/collection/MediaCollection.java | 55 + .../binding/rss/collection/NotFoundException.java | 45 + .../binding/rss/provider/RSSBindingInvoker.java | 76 + .../rss/provider/RSSBindingListenerServlet.java | 397 +++++ .../rss/provider/RSSBindingProviderFactory.java | 71 + .../rss/provider/RSSReferenceBindingProvider.java | 65 + .../rss/provider/RSSServiceBindingProvider.java | 85 ++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../apache/tuscany/sca/binding/rss/Consumer.java | 35 + .../tuscany/sca/binding/rss/CustomerClient.java | 25 + .../sca/binding/rss/CustomerClientImpl.java | 45 + .../sca/binding/rss/CustomerCollectionImpl.java | 114 ++ .../apache/tuscany/sca/binding/rss/Provider.java | 41 + .../tuscany/sca/binding/rss/RSSGetTestCase.java | 67 + .../tuscany/sca/binding/rss/Consumer.composite | 32 + .../tuscany/sca/binding/rss/Provider.composite | 33 + .../sca-java-1.6/modules/binding-rss/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-rss/NOTICE | 6 + .../sca-java-1.6/modules/binding-rss/pom.xml | 98 ++ .../apache/tuscany/sca/binding/rss/RSSBinding.java | 28 + .../tuscany/sca/binding/rss/RSSBindingFactory.java | 35 + .../binding/rss/impl/RSSBindingFactoryImpl.java | 36 + .../sca/binding/rss/impl/RSSBindingImpl.java | 99 ++ ...pache.tuscany.sca.binding.rss.RSSBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../sca-java-1.6/modules/binding-sca-axis2/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-sca-axis2/NOTICE | 6 + .../sca-java-1.6/modules/binding-sca-axis2/pom.xml | 103 ++ .../sca/axis2/impl/Axis2SCABindingInvoker.java | 100 ++ .../axis2/impl/Axis2SCABindingProviderFactory.java | 67 + .../impl/Axis2SCAReferenceBindingProvider.java | 184 +++ .../axis2/impl/Axis2SCAServiceBindingProvider.java | 127 ++ .../sca/axis2/impl/Axis2SCAServiceProvider.java | 88 ++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../sca/binding/sca/axis2/AsynchTestCase.java | 73 + .../BindingScaEndpointResolverFactoryImpl.java | 50 + .../sca/axis2/BindingScaEndpointResolverImpl.java | 69 + .../sca/binding/sca/axis2/CallbackTestCase.java | 77 + .../sca/binding/sca/axis2/PromotionTestCase.java | 66 + .../sca/binding/sca/axis2/SimpleTestCase.java | 105 ++ .../tuscany/sca/binding/sca/axis2/TestNode.java | 232 +++ .../axis2/helloworld/HelloWorldCallbackRemote.java | 29 + .../sca/axis2/helloworld/HelloWorldClient.java | 27 + .../HelloWorldServiceCallbackOnewayRemote.java | 33 + .../HelloWorldServiceCallbackRemote.java | 31 + .../axis2/helloworld/HelloWorldServiceLocal.java | 27 + .../axis2/helloworld/HelloWorldServiceRemote.java | 29 + .../axis2/helloworld/HelloWorldServiceRemote2.java | 29 + .../HelloWorldClientCallbackOnewayRemoteImpl.java | 43 + .../impl/HelloWorldClientCallbackRemoteImpl.java | 42 + .../helloworld/impl/HelloWorldClientLocalImpl.java | 35 + .../impl/HelloWorldClientRemote2Impl.java | 35 + .../impl/HelloWorldClientRemoteImpl.java | 35 + .../HelloWorldServiceCallbackOnewayRemoteImpl.java | 36 + .../impl/HelloWorldServiceCallbackRemoteImpl.java | 35 + .../impl/HelloWorldServiceLocalImpl.java | 30 + .../HelloWorldServiceMultipleServicesImpl.java | 41 + .../impl/HelloWorldServiceRemoteImpl.java | 30 + ...ny.sca.endpointresolver.EndpointResolverFactory | 19 + .../src/test/resources/nodeA/HelloWorld.composite | 75 + .../resources/nodeA/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeB/HelloWorld.composite | 84 ++ .../resources/nodeB/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeC/HelloWorld.composite | 35 + .../resources/nodeC/HelloWorldComponent.composite | 37 + .../resources/nodeC/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeD/HelloWorld.composite | 35 + .../resources/nodeD/HelloWorldComponent.composite | 37 + .../resources/nodeD/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeE/HelloWorld.composite | 36 + .../resources/nodeE/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeF/HelloWorld.composite | 43 + .../resources/nodeF/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeG/HelloWorld.composite | 36 + .../resources/nodeG/META-INF/sca-contribution.xml | 23 + .../src/test/resources/nodeH/HelloWorld.composite | 38 + .../resources/nodeH/META-INF/sca-contribution.xml | 23 + .../sca-java-1.6/modules/binding-sca-corba/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-sca-corba/NOTICE | 6 + .../sca-java-1.6/modules/binding-sca-corba/pom.xml | 114 ++ .../corba/impl/CorbaSCABindingProviderFactory.java | 64 + .../sca/corba/impl/CorbaSCAInvocationProxy.java | 111 ++ .../binding/sca/corba/impl/CorbaSCAInvoker.java | 99 ++ .../impl/CorbaSCAReferenceBindingProvider.java | 95 ++ .../corba/impl/CorbaSCAServiceBindingProvider.java | 97 ++ .../sca/corba/impl/WrappedSCAException.java | 56 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../sca-java-1.6/modules/binding-sca-jms/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-sca-jms/NOTICE | 6 + .../sca-java-1.6/modules/binding-sca-jms/pom.xml | 115 ++ .../sca/binding/sca/jms/AMQJMSResourceFactory.java | 39 + .../sca/jms/AMQResourceFactoryExtensionPoint.java | 32 + .../tuscany/sca/binding/sca/jms/JMSBroker.java | 75 + .../sca/jms/JMSSCABindingProviderFactory.java | 108 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../sca-java-1.6/modules/binding-sca-xml/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-sca-xml/NOTICE | 6 + .../sca-java-1.6/modules/binding-sca-xml/pom.xml | 77 + .../sca/binding/sca/xml/SCABindingProcessor.java | 171 +++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../tuscany/sca/binding/sca/xml/ReadTestCase.java | 108 ++ .../sca/xml/ReadWriteAnyAttributeTestCase.java | 140 ++ .../tuscany/sca/binding/sca/xml/WriteTestCase.java | 77 + .../src/test/resources/Calculator.composite | 59 + .../resources/CalculatorServiceImpl.componentType | 33 + .../sca-java-1.6/modules/binding-sca/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-sca/NOTICE | 6 + .../sca-java-1.6/modules/binding-sca/pom.xml | 93 ++ .../sca/binding/sca/DistributedSCABinding.java | 37 + .../binding/sca/SCABindingDefinitionsProvider.java | 73 + .../sca/impl/DistributedSCABindingImpl.java | 116 ++ .../sca/binding/sca/impl/RemoteBindingHelper.java | 44 + .../sca/impl/RuntimeSCABindingProvider.java | 61 + .../sca/impl/RuntimeSCABindingProviderFactory.java | 62 + .../impl/RuntimeSCAReferenceBindingProvider.java | 252 ++++ .../sca/impl/RuntimeSCAServiceBindingProvider.java | 154 ++ .../binding/sca/impl/SCABindingFactoryImpl.java | 40 + .../sca/binding/sca/impl/SCABindingImpl.java | 224 +++ .../sca/binding/sca/impl/SCABindingInvoker.java | 71 + ...g.apache.tuscany.sca.assembly.SCABindingFactory | 18 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + ...che.tuscany.sca.provider.SCADefinitionsProvider | 19 + .../apache/tuscany/sca/binding/sca/definitions.xml | 26 + .../sca/binding/sca/SCABindingTestCase.java | 113 ++ .../src/test/resources/Calculator.composite | 52 + .../modules/binding-ws-axis2-policy/LICENSE | 205 +++ .../modules/binding-ws-axis2-policy/NOTICE | 6 + .../modules/binding-ws-axis2-policy/pom.xml | 149 ++ .../token/Axis2TokenAuthenticationPolicy.java | 56 + .../Axis2TokenAuthenticationPolicyProcessor.java | 112 ++ ...s2TokenAuthenticationPolicyProviderFactory.java | 75 + ...enAuthenticationReferencePolicyInterceptor.java | 100 ++ ...TokenAuthenticationReferencePolicyProvider.java | 90 ++ ...okenAuthenticationServicePolicyInterceptor.java | 94 ++ ...s2TokenAuthenticationServicePolicyProvider.java | 88 ++ .../configuration/Axis2ConfigParamPolicy.java | 54 + .../Axis2ConfigParamPolicyHandler.java | 79 + .../Axis2ConfigParamPolicyProcessor.java | 157 ++ .../Axis2ConfigParamPolicyProviderFactory.java | 99 ++ .../ws/axis2/policy/header/Axis2HeaderPolicy.java | 56 + .../policy/header/Axis2HeaderPolicyProcessor.java | 114 ++ .../header/Axis2HeaderPolicyProviderFactory.java | 75 + .../axis2/policy/header/Axis2HeaderPolicyUtil.java | 50 + .../Axis2HeaderReferencePolicyInterceptor.java | 88 ++ .../header/Axis2HeaderReferencePolicyProvider.java | 90 ++ .../Axis2HeaderServicePolicyInterceptor.java | 77 + .../header/Axis2HeaderServicePolicyProvider.java | 88 ++ .../ws/axis2/policy/header/Axis2SOAPHeader.java | 60 + .../axis2/policy/header/Axis2SOAPHeaderString.java | 60 + .../policy/wspolicy/WSSecurityPolicyHandler.java | 80 + ...ca.contribution.processor.StAXArtifactProcessor | 21 + ...rg.apache.tuscany.sca.policy.util.PolicyHandler | 25 + ...ache.tuscany.sca.provider.PolicyProviderFactory | 20 + .../policy/configuration/PolicyReadTestCase.java | 60 + .../axis2/policy/configuration/mock_policies.xml | 36 + .../sca-java-1.6/modules/binding-ws-axis2/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-ws-axis2/NOTICE | 6 + .../sca-java-1.6/modules/binding-ws-axis2/pom.xml | 351 +++++ .../sca/binding/ws/axis2/Axis2BindingInvoker.java | 300 ++++ .../ws/axis2/Axis2BindingProviderFactory.java | 89 ++ .../ws/axis2/Axis2OneWayBindingInvoker.java | 71 + .../ws/axis2/Axis2ReferenceBindingProvider.java | 87 ++ .../ws/axis2/Axis2ServiceBindingProvider.java | 86 ++ .../sca/binding/ws/axis2/Axis2ServiceClient.java | 503 +++++++ .../ws/axis2/Axis2ServiceInMessageReceiver.java | 79 + .../Axis2ServiceInOutSyncMessageReceiver.java | 103 ++ .../sca/binding/ws/axis2/Axis2ServiceProvider.java | 849 +++++++++++ .../sca/binding/ws/axis2/Axis2ServiceServlet.java | 356 +++++ .../sca/binding/ws/axis2/AxisPolicyHelper.java | 79 + .../binding/ws/axis2/TuscanyAxisConfigurator.java | 207 +++ .../sca/binding/ws/axis2/TuscanyDispatcher.java | 105 ++ .../binding/ws/axis2/TuscanyListenerManager.java | 107 ++ .../sca/binding/ws/axis2/TuscanyListingAgent.java | 237 +++ .../ws/axis2/WSBindingDefinitionsProvider.java | 66 + .../sca/binding/ws/axis2/jms/AxisJMSException.java | 35 + .../binding/ws/axis2/jms/JMSConnectionFactory.java | 605 ++++++++ .../sca/binding/ws/axis2/jms/JMSListener.java | 527 +++++++ .../binding/ws/axis2/jms/JMSMessageReceiver.java | 270 ++++ .../binding/ws/axis2/jms/JMSOutTransportInfo.java | 220 +++ .../sca/binding/ws/axis2/jms/JMSSender.java | 389 +++++ .../apache/tuscany/sca/binding/ws/axis2/jms/README | 14 + ...xis2BindingBasicAuthenticationConfigurator.java | 121 ++ .../Axis2BindingHeaderConfigurator.java | 69 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + ...che.tuscany.sca.provider.SCADefinitionsProvider | 19 + .../tuscany/sca/binding/ws/axis2/definitions.xml | 54 + .../sca/binding/ws/axis2/engine/config/axis2.xml | 504 +++++++ .../ws/axis2/engine/config/modules/modules.list | 1 + .../ws/axis2/engine/config/modules/rampart-1.4.mar | Bin 0 -> 2796 bytes .../ws/axis2/engine/config/services/services.list | 0 .../binding/ws/axis2/Axis2ReferenceTestCase.java | 83 + .../sca/binding/ws/axis2/Axis2ServiceTestCase.java | 104 ++ .../tuscany/sca/binding/ws/axis2/Greeter.java | 31 + .../sca/binding/ws/axis2/GreetingCallback.java | 24 + .../sca/binding/ws/axis2/itests/Account.java | 34 + .../binding/ws/axis2/itests/AccountService.java | 33 + .../tuscany/sca/binding/ws/axis2/itests/Bar.java | 58 + .../ws/axis2/itests/CustomerProfileData.java | 103 ++ .../tuscany/sca/binding/ws/axis2/itests/Echo.java | 29 + .../sca/binding/ws/axis2/itests/EchoComponent.java | 33 + .../sca/binding/ws/axis2/itests/EchoImpl.java | 29 + .../tuscany/sca/binding/ws/axis2/itests/Foo.java | 36 + .../sca/binding/ws/axis2/itests/HelloWorld.java | 29 + .../ws/axis2/itests/HelloWorldComponent.java | 33 + .../ws/axis2/itests/HelloWorldMultiService.java | 51 + .../ws/axis2/itests/HelloWorldNoWSDLTestCase.java | 77 + .../sca/binding/ws/axis2/itests/HelloWorldOM.java | 30 + .../sca/binding/ws/axis2/itests/HelloWorldOM2.java | 30 + .../ws/axis2/itests/HelloWorldOMComponent.java | 34 + .../ws/axis2/itests/HelloWorldOMService.java | 41 + .../ws/axis2/itests/HelloWorldOMTestCase.java | 58 + .../binding/ws/axis2/itests/HelloWorldService.java | 28 + .../ws/axis2/itests/HelloWorldTestCase.java | 46 + .../axis2/itests/HelloWorldWSDLMergedTestCase.java | 58 + .../itests/QuestionMarkWSDLImportTestCase.java | 94 ++ .../itests/QuestionMarkWSDLIncludeTestCase.java | 94 ++ .../ws/axis2/itests/QuestionMarkWSDLTestCase.java | 121 ++ .../ws/axis2/itests/UriPrecedenceTestCase.java | 68 + .../endpoints/AbstractHelloWorldOMTestCase.java | 64 + .../endpoints/DefaultMultiServiceTestCase.java | 24 + .../endpoints/DefaultSingleServiceTestCase.java | 24 + .../itests/endpoints/WSDLExplicitURITestCase.java | 24 + .../itests/endpoints/WSDLRelativeURITestCase.java | 24 + .../ws/axis2/itests/epr/HelloWorldTestCase.java | 47 + .../ws/axis2/itests/mtom/FileTransferClient.java | 57 + .../itests/mtom/FileTransferMTOMTestCase.java | 122 ++ .../ws/axis2/itests/mtom/FileTransferService.java | 46 + .../itests/mtom/FileTransferServiceClient.java | 42 + .../axis2/itests/mtom/FileTransferServiceImpl.java | 57 + .../binding/ws/axis2/itests/mtom/MyException.java | 26 + .../ws/axis2/itests/mtom/MyExceptionAdapter.java | 31 + .../ws/axis2/itests/mtom/MyExceptionImpl.java | 26 + .../sca/binding/ws/axis2/itests/pojo/Data.java | 53 + .../sca/binding/ws/axis2/itests/pojo/Data2.java | 35 + .../ws/axis2/itests/pojo/POJOWSTestCase.java | 48 + .../binding/ws/axis2/itests/pojo/TestService.java | 29 + .../ws/axis2/itests/pojo/TestServiceImpl.java | 59 + .../binding/ws/axis2/itests/pojo/package-info.java | 21 + .../configparams/AbstractHelloWorldOMTestCase.java | 64 + .../policy/configparams/ClientPWCBHandler.java | 45 + .../policy/configparams/IntegrityPWCBHandler.java | 45 + .../policy/configparams/ServerPWCBHandler.java | 45 + .../WSSecurityAuthenticationTestCaseFIXME.java | 24 + ...onfidentialityTestCaseFIXBouncyCastleIssue.java | 42 + .../configparams/WSSecurityIntegrityTestCase.java | 24 + .../policy/mixed/AbstractHelloWorldOMTestCase.java | 67 + .../itests/policy/mixed/ClientPWCBHandler.java | 50 + .../itests/policy/mixed/IntegrityPWCBHandler.java | 50 + .../itests/policy/mixed/ServerPWCBHandler.java | 49 + .../policy/mixed/WSSecurityMixedTestCase.java | 24 + .../wspolicy/AbstractHelloWorldOMTestCase.java | 64 + .../itests/policy/wspolicy/ClientPWCBHandler.java | 45 + .../policy/wspolicy/IntegrityPWCBHandler.java | 45 + .../itests/policy/wspolicy/ServerPWCBHandler.java | 45 + .../wspolicy/WSSecurityAuthenticationTestCase.java | 24 + ...onfidentialityTestCaseFIXBouncyCastleIssue.java | 42 + .../wspolicy/WSSecurityIntegrityTestCase.java | 24 + .../itests/soap12/HelloWorldSOAP12TestCase.java | 58 + .../itests/soap12/QuestionMarkWSDLTestCase.java | 134 ++ ...rg.apache.tuscany.sca.policy.util.PolicyHandler | 20 + .../binding/ws/axis2/itests/HelloWorld.composite | 50 + .../ws/axis2/itests/HelloWorldNoWSDL.composite | 61 + .../sca/binding/ws/axis2/itests/customerdata.xsd | 36 + .../sca/binding/ws/axis2/itests/customerdefs.xsd | 27 + .../sca/binding/ws/axis2/itests/customerinfo.xsd | 31 + .../itests/endpoints/DefaultMultiService.composite | 51 + .../endpoints/DefaultSingleService.composite | 51 + .../itests/endpoints/WSDLExplicitURI.composite | 49 + .../itests/endpoints/WSDLRelativeURI.composite | 49 + .../endpoints/helloworld-om-relative-uri.wsdl | 78 + .../ws/axis2/itests/epr/HelloWorld.composite | 50 + .../ws/axis2/itests/helloworld-om-binding.wsdl | 45 + .../ws/axis2/itests/helloworld-om-merged.composite | 42 + .../ws/axis2/itests/helloworld-om-porttype.wsdl | 59 + .../binding/ws/axis2/itests/helloworld-om-uri.wsdl | 78 + .../ws/axis2/itests/helloworld-om.composite | 43 + .../sca/binding/ws/axis2/itests/helloworld-om.wsdl | 78 + .../ws/axis2/itests/helloworld-prec.composite | 47 + .../binding/ws/axis2/itests/helloworld-prec.wsdl | 81 + .../sca/binding/ws/axis2/itests/helloworld.wsdl | 86 ++ .../binding/ws/axis2/itests/mtom/filetransfer.wsdl | 220 +++ .../itests/mtom/filetransferservice.composite | 42 + .../binding/ws/axis2/itests/pojo/test.composite | 32 + .../WSSecurityAuthentication.composite | 50 + .../WSSecurityConfidentiality.composite | 49 + .../configparams/WSSecurityIntegrity.composite | 49 + .../itests/policy/configparams/definitions.xml | 101 ++ .../itests/policy/configparams/security.properties | 20 + .../itests/policy/configparams/tuscanyKeys.jks | Bin 0 -> 1366 bytes .../ws/axis2/itests/policy/intent/definitions.xml | 32 + .../itests/policy/mixed/WSSecurityMixed.composite | 52 + .../ws/axis2/itests/policy/mixed/definitions.xml | 323 ++++ .../axis2/itests/policy/mixed/security.properties | 20 + .../ws/axis2/itests/policy/mixed/tuscanyKeys.jks | Bin 0 -> 1366 bytes .../wspolicy/WSSecurityAuthentication.composite | 50 + .../wspolicy/WSSecurityConfidentiality.composite | 49 + .../policy/wspolicy/WSSecurityIntegrity.composite | 50 + .../axis2/itests/policy/wspolicy/definitions.xml | 204 +++ .../axis2/itests/policy/wspolicy/tuscanyKeys.jks | Bin 0 -> 1352 bytes .../axis2/itests/questionmark-import-nested.wsdl | 70 + .../ws/axis2/itests/questionmark-import.wsdl | 49 + .../ws/axis2/itests/questionmark-include.wsdl | 94 ++ .../itests/questionmark-wsdl-import.composite | 31 + .../itests/questionmark-wsdl-include.composite | 31 + .../ws/axis2/itests/questionmark-wsdl.composite | 39 + .../axis2/itests/soap12/HelloWorldSOAP12.composite | 71 + .../itests/soap12/questionmark-wsdl.composite | 40 + .../modules/binding-ws-wsdlgen/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-ws-wsdlgen/NOTICE | 6 + .../modules/binding-ws-wsdlgen/pom.xml | 108 ++ .../binding/ws/wsdlgen/BindingWSDLGenerator.java | 345 +++++ .../ws/wsdlgen/Interface2WSDLGenerator.java | 1174 +++++++++++++++ .../ws/wsdlgen/WSDLDefinitionGenerator.java | 316 ++++ .../ws/wsdlgen/WSDLGenerationException.java | 54 + .../binding/ws/wsdlgen/WSDLServiceGenerator.java | 542 +++++++ .../wsdlgen-validation-messages.properties | 31 + .../apache/tuscany/sca/binding/ws/other/Other.java | 34 + .../tuscany/sca/binding/ws/other/package-info.java | 21 + .../ws/wsdlgen/BindingWSDLGeneratorTestCase.java | 86 ++ .../wsdlgen/Interface2WSDLGeneratorTestCase.java | 66 + .../sca/binding/ws/wsdlgen/TestException.java | 47 + .../tuscany/sca/binding/ws/wsdlgen/TestFault.java | 46 + .../sca/binding/ws/wsdlgen/TestFaultBean.java | 54 + .../sca/binding/ws/wsdlgen/TestJavaClass.java | 32 + .../sca/binding/ws/wsdlgen/TestJavaInterface.java | 67 + .../sca-java-1.6/modules/binding-ws-xml/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-ws-xml/NOTICE | 6 + .../sca-java-1.6/modules/binding-ws-xml/pom.xml | 100 ++ .../sca/binding/ws/xml/BindingBuilderImpl.java | 51 + .../binding/ws/xml/EndPointReferenceHelper.java | 230 +++ .../binding/ws/xml/WebServiceBindingProcessor.java | 484 ++++++ .../sca/binding/ws/xml/WebServiceConstants.java | 44 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../binding-wsxml-validation-messages.properties | 27 + .../tuscany/sca/binding/ws/xml/ReadTestCase.java | 127 ++ .../ws/xml/ReadWriteAnyAttributeTestCase.java | 133 ++ .../tuscany/sca/binding/ws/xml/WriteTestCase.java | 78 + .../ws/xml/Calculator-bad-wsdlElement.composite | 59 + .../sca/binding/ws/xml/Calculator.composite | 63 + .../binding/ws/xml/CalculatorImpl.componentType | 45 + .../binding/ws/xml/PoliciedCalculator.composite | 60 + .../apache/tuscany/sca/binding/ws/xml/example.wsdl | 26 + .../sca/binding/ws/xml/invalid-stockquote.wsdl | 58 + .../org/apache/tuscany/sca/binding/ws/xml/ipo.xsd | 136 ++ .../tuscany/sca/binding/ws/xml/stockquote.wsdl | 58 + .../apache/tuscany/sca/binding/ws/xml/test1.wsdl | 45 + .../apache/tuscany/sca/binding/ws/xml/test1.xsd | 33 + .../apache/tuscany/sca/binding/ws/xml/test2.wsdl | 63 + .../sca/binding/ws/xml/unwrapped-stockquote.wsdl | 76 + .../sca-java-1.6/modules/binding-ws/LICENSE | 205 +++ .../sca-java-1.6/modules/binding-ws/NOTICE | 6 + .../sca-java-1.6/modules/binding-ws/pom.xml | 85 ++ .../ws/DefaultWebServiceBindingFactory.java | 31 + .../tuscany/sca/binding/ws/WebServiceBinding.java | 215 +++ .../sca/binding/ws/WebServiceBindingFactory.java | 35 + .../binding/ws/addressing/EndPointReference.java | 62 + .../ws/impl/WebServiceBindingFactoryImpl.java | 35 + .../sca/binding/ws/impl/WebServiceBindingImpl.java | 321 ++++ ...tuscany.sca.binding.ws.WebServiceBindingFactory | 19 + .../modules/contribution-groovy/LICENSE | 205 +++ .../modules/contribution-groovy/NOTICE | 8 + .../modules/contribution-groovy/pom.xml | 84 ++ .../sca/contribution/groovy/GroovyArtifact.java | 41 + .../groovy/GroovyArtifactProcessor.java | 57 + .../contribution/groovy/GroovyModelResolver.java | 69 + ...sca.contribution.processor.URLArtifactProcessor | 20 + ...tuscany.sca.contribution.resolver.ModelResolver | 18 + .../sca/contribution/groovy/HelloWorld.java | 31 + .../contribution/groovy/HelloWorldTestCase.java | 55 + .../sca/contribution/groovy/HelloWorld.groovy | 27 + .../sca/contribution/groovy/helloworld.composite | 29 + .../sca-java-1.6/modules/contribution-impl/LICENSE | 205 +++ .../sca-java-1.6/modules/contribution-impl/NOTICE | 6 + .../sca-java-1.6/modules/contribution-impl/pom.xml | 76 + .../impl/FolderContributionProcessor.java | 160 ++ .../processor/impl/JarContributionProcessor.java | 130 ++ .../service/impl/ContributionRepositoryImpl.java | 469 ++++++ .../service/impl/ContributionServiceImpl.java | 640 ++++++++ .../service/impl/PackageTypeDescriberImpl.java | 122 ++ .../sca/contribution/service/util/FileHelper.java | 701 +++++++++ .../sca/contribution/service/util/IOHelper.java | 190 +++ ...any.sca.contribution.processor.PackageProcessor | 19 + ...ontribution-impl-validation-messages.properties | 28 + ...FolderContributionPackageProcessorTestCase.java | 46 + .../JarContributionPackageProcessorTestCase.java | 55 + ...URLartifactProcessorExtensionPointTestCase.java | 114 ++ .../resolver/DefaultModelResolverTestCase.java | 86 ++ .../resolver/ExtensibleModelResolverTestCase.java | 126 ++ .../contribution/resolver/TestModelResolver.java | 58 + .../impl/ContributionRepositoryTestCase.java | 81 + .../impl/PackageTypeDescriberImplTestCase.java | 63 + .../resources/deployables/sample-calculator.jar | Bin 0 -> 26901 bytes .../resources/repository/sample-calculator.jar | Bin 0 -> 10037 bytes .../test/resources/repository3/contribution.zip | Bin 0 -> 5478 bytes .../src/test/resources/test.composite | 22 + .../contribution-impl/src/test/resources/test.ext | 0 .../sca-java-1.6/modules/contribution-java/LICENSE | 205 +++ .../sca-java-1.6/modules/contribution-java/NOTICE | 6 + .../sca-java-1.6/modules/contribution-java/pom.xml | 77 + .../java/ContributionClassLoaderProvider.java | 44 + ...tributionClassloaderProviderExtensionPoint.java | 55 + .../DefaultContributionClassLoaderProvider.java | 47 + ...tributionClassloaderProviderExtensionPoint.java | 144 ++ .../java/DefaultJavaImportExportFactory.java | 30 + .../tuscany/sca/contribution/java/JavaExport.java | 43 + .../tuscany/sca/contribution/java/JavaImport.java | 58 + .../contribution/java/JavaImportExportFactory.java | 42 + .../java/impl/ClassLoaderModelResolver.java | 165 ++ .../java/impl/ClassReferenceModelResolver.java | 177 +++ .../java/impl/ContributionClassLoader.java | 390 +++++ .../contribution/java/impl/ContributionHelper.java | 96 ++ .../sca/contribution/java/impl/JavaExportImpl.java | 59 + .../java/impl/JavaExportModelResolver.java | 76 + .../java/impl/JavaExportProcessor.java | 163 ++ .../java/impl/JavaImportExportFactoryImpl.java | 41 + .../java/impl/JavaImportExportListener.java | 157 ++ .../sca/contribution/java/impl/JavaImportImpl.java | 111 ++ .../java/impl/JavaImportModelResolver.java | 62 + .../java/impl/JavaImportProcessor.java | 168 +++ ...ntribution.java.ContributionClassLoaderProvider | 21 + ...a.ContributionClassloaderProviderExtensionPoint | 18 + ...y.sca.contribution.java.JavaImportExportFactory | 18 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...tuscany.sca.contribution.resolver.ModelResolver | 18 + ...y.sca.contribution.service.ContributionListener | 18 + ...ontribution-java-validation-messages.properties | 23 + .../ClassReferenceArtifactResolverTestCase.java | 70 + .../java/impl/ContributionClassLoaderTestCase.java | 262 ++++ .../java/impl/JavaExportProcessorTestCase.java | 103 ++ .../java/impl/JavaImportProcessorTestCase.java | 105 ++ .../resources/deployables/sample-calculator.jar | Bin 0 -> 26901 bytes .../modules/contribution-jee-impl/LICENSE | 205 +++ .../modules/contribution-jee-impl/NOTICE | 6 + .../modules/contribution-jee-impl/pom.xml | 127 ++ .../contribution/jee/JEEDefinitionsProvider.java | 73 + .../sca/contribution/jee/JavaEEModuleHelper.java | 123 ++ .../jee/impl/EARContributionClassLoader.java | 201 +++ .../impl/EARContributionClassLoaderProvider.java | 49 + .../jee/impl/JavaEEIntrospectorImpl.java | 427 ++++++ .../jee/impl/WARContributionClassLoader.java | 191 +++ .../impl/WARContributionClassLoaderProvider.java | 49 + ...ntribution.java.ContributionClassLoaderProvider | 18 + ...tuscany.sca.contribution.jee.JavaEEIntrospector | 18 + ...che.tuscany.sca.provider.SCADefinitionsProvider | 19 + .../tuscany/sca/contribution/jee/definitions.xml | 35 + .../sca-java-1.6/modules/contribution-jee/LICENSE | 205 +++ .../sca-java-1.6/modules/contribution-jee/NOTICE | 6 + .../sca-java-1.6/modules/contribution-jee/pom.xml | 106 ++ .../jee/EJBImplementationGenerated.java | 56 + .../tuscany/sca/contribution/jee/EjbInfo.java | 39 + .../sca/contribution/jee/EjbModuleInfo.java | 39 + .../contribution/jee/EjbModuleModelResolver.java | 70 + .../sca/contribution/jee/EjbReferenceInfo.java | 34 + .../tuscany/sca/contribution/jee/EnvEntryInfo.java | 29 + .../sca/contribution/jee/ExternalEarInfo.java | 31 + .../sca/contribution/jee/InjectionTarget.java | 28 + .../contribution/jee/JavaEEApplicationInfo.java | 38 + .../jee/JavaEEApplicationModelResolver.java | 70 + .../sca/contribution/jee/JavaEEExtension.java | 38 + .../sca/contribution/jee/JavaEEIntrospector.java | 34 + .../contribution/jee/JavaEEOptionalExtension.java | 41 + .../sca/contribution/jee/JspReferenceTagInfo.java | 30 + .../tuscany/sca/contribution/jee/ModelObject.java | 32 + .../contribution/jee/ModelObjectModelResolver.java | 73 + .../jee/WebImplementationGenerated.java | 43 + .../sca/contribution/jee/WebModuleInfo.java | 50 + .../contribution/jee/WebModuleModelResolver.java | 70 + .../jee/impl/EJBImplementationGeneratedImpl.java | 77 + .../impl/EJBImplementationGeneratedProcessor.java | 67 + .../jee/impl/EarContributionProcessor.java | 158 ++ .../contribution/jee/impl/EjbArchiveProcessor.java | 69 + .../contribution/jee/impl/EjbModuleInfoImpl.java | 66 + .../jee/impl/JavaEEApplicationInfoImpl.java | 68 + .../jee/impl/JavaEEArchiveProcessor.java | 59 + .../contribution/jee/impl/JavaEEExtensionImpl.java | 262 ++++ .../jee/impl/JavaEEOptionalExtensionImpl.java | 398 +++++ .../sca/contribution/jee/impl/ModelObjectImpl.java | 51 + .../jee/impl/WarContributionProcessor.java | 36 + .../contribution/jee/impl/WebArchiveProcessor.java | 59 + .../jee/impl/WebImplementationGeneratedImpl.java | 60 + .../impl/WebImplementationGeneratedProcessor.java | 66 + .../contribution/jee/impl/WebModuleInfoImpl.java | 109 ++ ...he.tuscany.sca.contribution.jee.JavaEEExtension | 18 + ...ny.sca.contribution.jee.JavaEEOptionalExtension | 18 + ...any.sca.contribution.processor.PackageProcessor | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 22 + ...sca.contribution.processor.URLArtifactProcessor | 21 + ...tuscany.sca.contribution.resolver.ModelResolver | 21 + .../jee/EarContributionProcessorTestCase.java | 57 + .../jee/WarContributionProcessorTestCase.java | 57 + .../src/test/resources/ejb-injection-sample.ear | Bin 0 -> 19015 bytes .../src/test/resources/ejb-injection-sample.jar | Bin 0 -> 11042 bytes .../src/test/resources/sample-web-app.war | Bin 0 -> 12454 bytes .../modules/contribution-namespace/LICENSE | 205 +++ .../modules/contribution-namespace/NOTICE | 6 + .../modules/contribution-namespace/pom.xml | 76 + .../DefaultNamespaceImportExportFactory.java | 30 + .../contribution/namespace/NamespaceExport.java | 46 + .../contribution/namespace/NamespaceImport.java | 59 + .../namespace/NamespaceImportExportFactory.java | 42 + .../namespace/impl/NamespaceExportImpl.java | 55 + .../impl/NamespaceExportModelResolver.java | 54 + .../namespace/impl/NamespaceExportProcessor.java | 182 +++ .../impl/NamespaceImportExportFactoryImpl.java | 41 + .../impl/NamespaceImportExportListener.java | 98 ++ .../namespace/impl/NamespaceImportImpl.java | 93 ++ .../namespace/impl/NamespaceImportProcessor.java | 186 +++ ...ribution.namespace.NamespaceImportExportFactory | 18 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...y.sca.contribution.service.ContributionListener | 18 + ...bution-namespace-validation-messages.properties | 23 + .../impl/NamespaceExportProcessorTestCase.java | 107 ++ .../impl/NamespaceImportProcessorTestCase.java | 111 ++ .../sca-java-1.6/modules/contribution-osgi/LICENSE | 205 +++ .../sca-java-1.6/modules/contribution-osgi/NOTICE | 6 + .../sca-java-1.6/modules/contribution-osgi/pom.xml | 96 ++ .../sca/contribution/osgi/BundleReference.java | 161 ++ .../osgi/impl/OSGiBundleContributionProcessor.java | 161 ++ .../osgi/impl/OSGiBundleProcessor.java | 141 ++ .../impl/OSGiBundleReferenceModelResolver.java | 154 ++ .../osgi/impl/OSGiClassReferenceModelResolver.java | 137 ++ .../osgi/impl/OSGiImportExportListener.java | 215 +++ .../osgi/impl/OSGiModelResolverImpl.java | 119 ++ ...any.sca.contribution.processor.PackageProcessor | 18 + ...tuscany.sca.contribution.resolver.ModelResolver | 18 + ...y.sca.contribution.service.ContributionListener | 18 + .../modules/contribution-resource/LICENSE | 205 +++ .../modules/contribution-resource/NOTICE | 6 + .../modules/contribution-resource/pom.xml | 76 + .../sca/contribution/resource/ResourceExport.java | 46 + .../sca/contribution/resource/ResourceImport.java | 59 + .../resource/ResourceImportExportFactory.java | 42 + .../resource/impl/ArtifactModelResolver.java | 87 ++ .../resource/impl/ResourceExportImpl.java | 59 + .../resource/impl/ResourceExportModelResolver.java | 65 + .../resource/impl/ResourceExportProcessor.java | 162 ++ .../impl/ResourceImportExportFactoryImpl.java | 41 + .../impl/ResourceImportExportListener.java | 97 ++ .../resource/impl/ResourceImportImpl.java | 107 ++ .../resource/impl/ResourceImportProcessor.java | 168 +++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...tuscany.sca.contribution.resolver.ModelResolver | 18 + ...ntribution.resource.ResourceImportExportFactory | 18 + ...y.sca.contribution.service.ContributionListener | 18 + ...ibution-resource-validation-messages.properties | 23 + .../impl/ResourceExportProcessorTestCase.java | 104 ++ .../impl/ResourceImportProcessorTestCase.java | 106 ++ .../sca-java-1.6/modules/contribution-xml/LICENSE | 205 +++ .../sca-java-1.6/modules/contribution-xml/NOTICE | 6 + .../sca-java-1.6/modules/contribution-xml/pom.xml | 70 + .../processor/xml/AnyAttributeProcessor.java | 76 + .../processor/xml/AnyElementProcessor.java | 164 ++ .../processor/xml/XMLDocumentStreamReader.java | 486 ++++++ .../processor/xml/XMLEventsStreamReader.java | 448 ++++++ .../processor/xml/XMLFragmentStreamReader.java | 53 + ...ributionGeneratedMetadataDocumentProcessor.java | 50 + .../xml/ContributionMetadataDocumentProcessor.java | 132 ++ .../xml/ContributionMetadataProcessor.java | 259 ++++ .../xml/ContributionModelResolver.java | 72 + ...ca.contribution.processor.StAXArtifactProcessor | 20 + ...a.contribution.processor.StAXAttributeProcessor | 19 + ...sca.contribution.processor.URLArtifactProcessor | 20 + ...tuscany.sca.contribution.resolver.ModelResolver | 18 + ...contribution-xml-validation-messages.properties | 24 + .../xml/ContributionMetadataProcessorTestCase.java | 144 ++ .../sca-java-1.6/modules/contribution/LICENSE | 205 +++ .../sca-java-1.6/modules/contribution/NOTICE | 6 + .../sca-java-1.6/modules/contribution/pom.xml | 69 + .../apache/tuscany/sca/contribution/Artifact.java | 74 + .../apache/tuscany/sca/contribution/Constants.java | 32 + .../tuscany/sca/contribution/ContentType.java | 40 + .../tuscany/sca/contribution/Contribution.java | 132 ++ .../sca/contribution/ContributionFactory.java | 73 + .../sca/contribution/ContributionMetadata.java | 56 + .../contribution/DefaultContributionFactory.java | 32 + .../tuscany/sca/contribution/DefaultExport.java | 30 + .../tuscany/sca/contribution/DefaultImport.java | 30 + .../DefaultModelFactoryExtensionPoint.java | 130 ++ .../tuscany/sca/contribution/DeployedArtifact.java | 29 + .../apache/tuscany/sca/contribution/Export.java | 48 + .../apache/tuscany/sca/contribution/Import.java | 57 + .../contribution/ModelFactoryExtensionPoint.java | 54 + .../tuscany/sca/contribution/PackageType.java | 57 + .../sca/contribution/impl/ArtifactImpl.java | 94 ++ .../contribution/impl/ContributionFactoryImpl.java | 67 + .../sca/contribution/impl/ContributionImpl.java | 164 ++ .../impl/ContributionMetadataImpl.java | 65 + .../sca/contribution/impl/DefaultExportImpl.java | 46 + .../sca/contribution/impl/DefaultImportImpl.java | 56 + .../contribution/processor/ArtifactProcessor.java | 48 + .../processor/ArtifactProcessorExtensionPoint.java | 58 + .../processor/BaseStAXArtifactProcessor.java | 618 ++++++++ .../DefaultArtifactProcessorExtensionPoint.java | 66 + .../DefaultPackageProcessorExtensionPoint.java | 129 ++ ...DefaultStAXArtifactProcessorExtensionPoint.java | 392 +++++ ...efaultStAXAttributeProcessorExtensionPoint.java | 327 ++++ .../DefaultURLArtifactProcessorExtensionPoint.java | 244 +++ .../DefaultValidatingXMLInputFactory.java | 317 ++++ .../DefaultValidationSchemaExtensionPoint.java | 95 ++ .../processor/ExtensiblePackageProcessor.java | 99 ++ .../processor/ExtensibleStAXArtifactProcessor.java | 264 ++++ .../ExtensibleStAXAttributeProcessor.java | 247 +++ .../processor/ExtensibleURLArtifactProcessor.java | 143 ++ .../contribution/processor/PackageProcessor.java | 70 + .../processor/PackageProcessorExtensionPoint.java | 50 + .../processor/StAXArtifactProcessor.java | 61 + .../StAXArtifactProcessorExtensionPoint.java | 29 + .../processor/StAXAttributeProcessor.java | 63 + .../StAXAttributeProcessorExtensionPoint.java | 29 + .../processor/TuscanyNamespaceContext.java | 111 ++ .../processor/TuscanyXMLStreamReader.java | 131 ++ .../processor/URLArtifactProcessor.java | 51 + .../URLArtifactProcessorExtensionPoint.java | 29 + .../processor/ValidatingXMLInputFactory.java | 42 + .../processor/ValidatingXMLStreamReader.java | 396 +++++ .../processor/ValidationSchemaExtensionPoint.java | 52 + .../sca/contribution/resolver/ClassReference.java | 107 ++ .../resolver/DefaultDelegatingModelResolver.java | 68 + .../resolver/DefaultImportAllModelResolver.java | 80 + .../resolver/DefaultImportModelResolver.java | 69 + .../resolver/DefaultModelResolver.java | 66 + .../DefaultModelResolverExtensionPoint.java | 117 ++ .../resolver/ExtensibleModelResolver.java | 213 +++ .../sca/contribution/resolver/ModelResolver.java | 69 + .../resolver/ModelResolverExtensionPoint.java | 52 + .../contribution/resolver/ResolverExtension.java | 45 + .../contribution/resolver/ResourceReference.java | 103 ++ .../contribution/scanner/ContributionScanner.java | 65 + .../scanner/ContributionScannerExtensionPoint.java | 50 + .../DefaultContributionScannerExtensionPoint.java | 125 ++ .../service/ContributionException.java | 45 + .../contribution/service/ContributionListener.java | 58 + .../ContributionListenerExtensionPoint.java | 44 + .../service/ContributionReadException.java | 94 ++ .../service/ContributionRepository.java | 128 ++ .../service/ContributionResolveException.java | 41 + .../service/ContributionRuntimeException.java | 44 + .../contribution/service/ContributionService.java | 137 ++ .../service/ContributionWriteException.java | 61 + .../DefaultContributionListenerExtensionPoint.java | 118 ++ .../service/ExtensibleContributionListener.java | 77 + .../sca/contribution/service/TypeDescriber.java | 38 + .../service/UnrecognizedElementException.java | 48 + .../service/UnsupportedContentTypeException.java | 42 + .../service/UnsupportedPackageTypeException.java | 39 + ...he.tuscany.sca.contribution.ContributionFactory | 18 + ...any.sca.contribution.ModelFactoryExtensionPoint | 18 + ...ocessor.ContributionPostProcessorExtensionPoint | 18 + ...bution.processor.PackageProcessorExtensionPoint | 18 + ...n.processor.StAXArtifactProcessorExtensionPoint | 18 + ....processor.StAXAttributeProcessorExtensionPoint | 18 + ...on.processor.URLArtifactProcessorExtensionPoint | 18 + ...bution.processor.ValidationSchemaExtensionPoint | 18 + ...ntribution.resolver.ModelResolverExtensionPoint | 18 + ...ution.scanner.ContributionScannerExtensionPoint | 18 + ...tion.service.ContributionListenerExtensionPoint | 18 + .../contribution-validation-messages.properties | 34 + .../sca-java-1.6/modules/core-databinding/LICENSE | 205 +++ .../sca-java-1.6/modules/core-databinding/NOTICE | 6 + .../sca-java-1.6/modules/core-databinding/pom.xml | 139 ++ .../module/DataBindingModuleActivator.java | 109 ++ .../DataBindingJavaInterfaceProcessor.java | 141 ++ .../processor/WrapperJavaInterfaceProcessor.java | 128 ++ .../transformers/Array2ArrayTransformer.java | 110 ++ .../CallableReference2XMLStreamReader.java | 75 + .../transformers/CallableReferenceDataBinding.java | 42 + .../transformers/CallableReferenceTypeHelper.java | 75 + .../transformers/CallableReferenceXMLAdapter.java | 61 + .../Exception2ExceptionTransformer.java | 114 ++ .../transformers/Input2InputTransformer.java | 279 ++++ .../transformers/OMElementXMLAdapter.java | 62 + .../transformers/Output2OutputTransformer.java | 257 ++++ .../XMLStreamReader2CallableReference.java | 100 ++ .../wire/DataBindingRuntimeWireProcessor.java | 198 +++ .../wire/DataTransformationInterceptor.java | 104 ++ .../databinding/wire/PassByValueInterceptor.java | 80 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../DataBindingJavaInterfaceProcessorTestCase.java | 89 ++ .../transformers/IDLTransformerTestCaseFIXME.java | 229 +++ .../branches/sca-java-1.6/modules/core-spi/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/core-spi/NOTICE | 6 + .../branches/sca-java-1.6/modules/core-spi/pom.xml | 122 ++ .../modules/core-spi/src/doc/Context Model.emx | 673 +++++++++ .../sca/context/ComponentContextFactory.java | 38 + .../sca/context/ContextFactoryExtensionPoint.java | 50 + .../DefaultContextFactoryExtensionPoint.java | 114 ++ .../tuscany/sca/context/PropertyValueFactory.java | 40 + .../tuscany/sca/context/RequestContextFactory.java | 33 + ...faultEndpointResolverFactoryExtensionPoint.java | 180 +++ .../sca/endpointresolver/EndpointResolver.java | 55 + .../endpointresolver/EndpointResolverFactory.java | 44 + .../EndpointResolverFactoryExtensionPoint.java | 57 + .../java/org/apache/tuscany/sca/event/Event.java | 33 + .../org/apache/tuscany/sca/event/EventFilter.java | 35 + .../apache/tuscany/sca/event/EventPublisher.java | 55 + .../tuscany/sca/event/RuntimeEventListener.java | 35 + .../org/apache/tuscany/sca/event/TrueFilter.java | 37 + .../sca/invocation/DataExchangeSemantics.java | 34 + .../apache/tuscany/sca/invocation/Interceptor.java | 40 + .../tuscany/sca/invocation/InvocationChain.java | 112 ++ .../org/apache/tuscany/sca/invocation/Invoker.java | 36 + .../org/apache/tuscany/sca/invocation/Message.java | 127 ++ .../tuscany/sca/invocation/MessageFactory.java | 36 + .../org/apache/tuscany/sca/invocation/Phase.java | 69 + .../tuscany/sca/management/ManagementService.java | 39 + .../sca/provider/BindingProviderFactory.java | 60 + .../DefaultProviderFactoryExtensionPoint.java | 509 +++++++ ...efaultSCADefinitionsProviderExtensionPoint.java | 91 ++ .../sca/provider/ImplementationProvider.java | 68 + .../provider/ImplementationProviderFactory.java | 42 + .../sca/provider/OperationSelectorProvider.java | 39 + .../provider/OperationSelectorProviderFactory.java | 53 + .../tuscany/sca/provider/PolicyImplementor.java | 38 + .../tuscany/sca/provider/PolicyProvider.java | 41 + .../sca/provider/PolicyProviderFactory.java | 63 + .../tuscany/sca/provider/ProviderFactory.java | 36 + .../provider/ProviderFactoryExtensionPoint.java | 63 + .../sca/provider/ReferenceBindingProvider.java | 76 + .../sca/provider/ReferenceBindingProviderRRB.java | 35 + .../sca/provider/SCADefinitionsProvider.java | 33 + .../provider/SCADefinitionsProviderException.java | 30 + .../SCADefinitionsProviderExtensionPoint.java | 35 + .../sca/provider/ServiceBindingProvider.java | 63 + .../sca/provider/ServiceBindingProviderRRB.java | 39 + .../tuscany/sca/provider/WireFormatProvider.java | 54 + .../sca/provider/WireFormatProviderFactory.java | 53 + .../DefaultWireProcessorExtensionPoint.java | 63 + .../tuscany/sca/runtime/EndpointReference.java | 93 ++ .../tuscany/sca/runtime/ReferenceParameters.java | 69 + .../tuscany/sca/runtime/RuntimeComponent.java | 83 + .../sca/runtime/RuntimeComponentContext.java | 105 ++ .../sca/runtime/RuntimeComponentReference.java | 119 ++ .../sca/runtime/RuntimeComponentService.java | 138 ++ .../apache/tuscany/sca/runtime/RuntimeWire.java | 117 ++ .../tuscany/sca/runtime/RuntimeWireProcessor.java | 35 + .../RuntimeWireProcessorExtensionPoint.java | 53 + .../sca/store/DuplicateRecordException.java | 56 + .../apache/tuscany/sca/store/RecoveryListener.java | 46 + .../java/org/apache/tuscany/sca/store/Store.java | 96 ++ .../apache/tuscany/sca/store/StoreException.java | 57 + .../tuscany/sca/store/StoreExpirationEvent.java | 71 + .../org/apache/tuscany/sca/store/StoreMonitor.java | 71 + .../tuscany/sca/store/StoreReadException.java | 56 + .../tuscany/sca/store/StoreWriteException.java | 56 + .../tuscany/sca/work/NotificationListener.java | 67 + .../org/apache/tuscany/sca/work/WorkScheduler.java | 58 + .../tuscany/sca/work/WorkSchedulerException.java | 59 + ...uscany.sca.context.ContextFactoryExtensionPoint | 18 + ...tresolver.EndpointResolverFactoryExtensionPoint | 18 + ...cany.sca.provider.ProviderFactoryExtensionPoint | 18 + ...a.provider.SCADefinitionsProviderExtensionPoint | 19 + ....sca.runtime.RuntimeWireProcessorExtensionPoint | 18 + ...efaultContextFactoryExtensionPointTestCase.java | 208 +++ .../tuscany/sca/event/TrueFilterTestCase.java | 63 + .../branches/sca-java-1.6/modules/core/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/core/NOTICE | 6 + .../branches/sca-java-1.6/modules/core/pom.xml | 114 ++ .../sca/core/assembly/ActivationException.java | 37 + .../sca/core/assembly/CompositeActivator.java | 154 ++ .../sca/core/assembly/CompositeActivatorImpl.java | 1101 ++++++++++++++ .../sca/core/assembly/EndpointReferenceImpl.java | 186 +++ .../sca/core/assembly/EndpointWireImpl.java | 185 +++ .../core/assembly/ReferenceParameterProcessor.java | 101 ++ .../sca/core/assembly/ReferenceParametersImpl.java | 139 ++ .../sca/core/assembly/RuntimeAssemblyFactory.java | 53 + .../sca/core/assembly/RuntimeComponentImpl.java | 111 ++ .../assembly/RuntimeComponentReferenceImpl.java | 155 ++ .../core/assembly/RuntimeComponentServiceImpl.java | 163 ++ .../tuscany/sca/core/assembly/RuntimeWireImpl.java | 473 ++++++ .../sca/core/context/CallableReferenceImpl.java | 605 ++++++++ .../sca/core/context/ComponentContextHelper.java | 320 ++++ .../sca/core/context/ComponentContextImpl.java | 452 ++++++ .../context/DefaultComponentContextFactory.java | 70 + .../tuscany/sca/core/context/InstanceWrapper.java | 48 + .../sca/core/context/RequestContextImpl.java | 113 ++ .../sca/core/context/ServiceReferenceImpl.java | 133 ++ .../core/conversation/ConversationListener.java | 40 + .../sca/core/conversation/ConversationManager.java | 73 + .../core/conversation/ConversationManagerImpl.java | 225 +++ .../sca/core/conversation/ConversationState.java | 29 + .../core/conversation/ExtendedConversation.java | 66 + .../conversation/ExtendedConversationImpl.java | 265 ++++ .../tuscany/sca/core/event/BaseEventPublisher.java | 89 ++ .../tuscany/sca/core/event/ComponentStart.java | 54 + .../tuscany/sca/core/event/ComponentStop.java | 53 + .../tuscany/sca/core/event/ConversationEnd.java | 53 + .../tuscany/sca/core/event/ConversationStart.java | 52 + .../tuscany/sca/core/event/HttpSessionEnd.java | 53 + .../tuscany/sca/core/event/HttpSessionStart.java | 52 + .../apache/tuscany/sca/core/event/RequestEnd.java | 45 + .../tuscany/sca/core/event/RequestStart.java | 45 + .../sca/core/factory/ObjectCreationException.java | 47 + .../tuscany/sca/core/factory/ObjectFactory.java | 35 + .../invocation/CallableReferenceObjectFactory.java | 63 + .../invocation/CallbackInterfaceInterceptor.java | 57 + .../sca/core/invocation/CallbackReferenceImpl.java | 268 ++++ .../invocation/CallbackReferenceObjectFactory.java | 48 + .../core/invocation/CallbackWireObjectFactory.java | 47 + .../sca/core/invocation/CglibProxyFactory.java | 172 +++ .../DefaultProxyFactoryExtensionPoint.java | 74 + .../core/invocation/ExtensibleProxyFactory.java | 113 ++ .../core/invocation/ExtensibleWireProcessor.java | 44 + .../sca/core/invocation/InvocationChainImpl.java | 191 +++ .../invocation/JDKCallbackInvocationHandler.java | 124 ++ .../sca/core/invocation/JDKInvocationHandler.java | 614 ++++++++ .../sca/core/invocation/JDKProxyFactory.java | 104 ++ .../sca/core/invocation/MessageFactoryImpl.java | 36 + .../tuscany/sca/core/invocation/MessageImpl.java | 113 ++ .../invocation/NoMethodForOperationException.java | 43 + .../core/invocation/NonBlockingInterceptor.java | 202 +++ .../tuscany/sca/core/invocation/PhaseManager.java | 298 ++++ .../tuscany/sca/core/invocation/PhaseSorter.java | 236 +++ .../core/invocation/ProxyCreationException.java | 48 + .../tuscany/sca/core/invocation/ProxyFactory.java | 87 ++ .../invocation/ProxyFactoryExtensionPoint.java | 53 + .../sca/core/invocation/RuntimeWireInvoker.java | 264 ++++ .../tuscany/sca/core/invocation/SCAProxy.java | 78 + .../core/invocation/TargetInvocationException.java | 45 + .../sca/core/invocation/ThreadMessageContext.java | 80 + .../sca/core/invocation/WireObjectFactory.java | 54 + .../sca/core/scope/AbstractScopeContainer.java | 200 +++ .../sca/core/scope/CompositeScopeContainer.java | 90 ++ .../core/scope/CompositeScopeContainerFactory.java | 37 + .../core/scope/ConversationalScopeContainer.java | 290 ++++ .../scope/ConversationalScopeContainerFactory.java | 44 + .../sca/core/scope/HttpSessionScopeContainer.java | 83 + .../scope/HttpSessionScopeContainerFactory.java | 41 + .../sca/core/scope/RequestScopeContainer.java | 106 ++ .../core/scope/RequestScopeContainerFactory.java | 37 + .../org/apache/tuscany/sca/core/scope/Scope.java | 66 + .../tuscany/sca/core/scope/ScopeContainer.java | 159 ++ .../sca/core/scope/ScopeContainerFactory.java | 32 + .../tuscany/sca/core/scope/ScopeRegistry.java | 43 + .../tuscany/sca/core/scope/ScopeRegistryImpl.java | 62 + .../core/scope/ScopedImplementationProvider.java | 65 + .../sca/core/scope/ScopedRuntimeComponent.java | 40 + .../sca/core/scope/StatelessScopeContainer.java | 67 + .../core/scope/StatelessScopeContainerFactory.java | 37 + .../sca/core/scope/TargetDestructionException.java | 44 + .../core/scope/TargetInitializationException.java | 44 + .../sca/core/scope/TargetNotFoundException.java | 44 + .../sca/core/scope/TargetResolutionException.java | 44 + .../apache/tuscany/sca/core/store/MemoryStore.java | 195 +++ .../sca/core/work/DefaultWorkScheduler.java | 191 +++ .../sca/core/work/ThreadPoolWorkManager.java | 229 +++ .../org/apache/tuscany/sca/core/work/Work.java | 65 + .../apache/tuscany/sca/core/work/WorkEvent.java | 80 + .../org/apache/tuscany/sca/core/work/WorkItem.java | 167 ++ .../apache/tuscany/sca/core/work/WorkListener.java | 32 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...scany.sca.core.conversation.ConversationManager | 18 + ....sca.core.invocation.ProxyFactoryExtensionPoint | 18 + ...rg.apache.tuscany.sca.invocation.MessageFactory | 18 + .../org.apache.tuscany.sca.work.WorkScheduler | 18 + .../DefaultExtensionPointRegistryTestCase.java | 52 + .../sca/core/event/BaseEventPublisherTestCase.java | 98 ++ .../tuscany/sca/core/event/EventTestCase.java | 69 + .../sca/core/invocation/PhaseManagerTestCase.java | 51 + .../sca/core/invocation/PhaseSorterTestCase.java | 63 + .../core/scope/AbstractScopeContainerTestCase.java | 69 + .../sca/core/store/MemoryStoreTestCase.java | 165 ++ .../wire/CallbackInterfaceInterceptorTestCase.java | 62 + .../sca/core/wire/InvocationChainImplTestCase.java | 93 ++ .../core/wire/NonBlockingInterceptorTestCase.java | 74 + .../apache/tuscany/sca/core/work/FailingWork.java | 53 + .../sca/core/work/JSR237MyFailingRunnable.java | 43 + .../tuscany/sca/core/work/JSR237MyRunnable.java | 71 + .../sca/core/work/JSR237MyRunnerListener.java | 154 ++ .../sca/core/work/Jsr237WorkSchedulerTestCase.java | 240 +++ .../tuscany/sca/core/work/TestWorkListener.java | 153 ++ .../core/work/ThreadPoolWorkManagerTestCase.java | 238 +++ .../tuscany/sca/core/work/TimeDelayWork.java | 86 ++ .../apache/tuscany/sca/scope/ScopeTestCase.java | 61 + .../org.apache.tuscany.sca.invocation.PhaseTest | 24 + .../branches/sca-java-1.6/modules/data-api/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/data-api/NOTICE | 6 + .../branches/sca-java-1.6/modules/data-api/pom.xml | 58 + .../tuscany/sca/data/collection/Collection.java | 78 + .../apache/tuscany/sca/data/collection/Entry.java | 85 ++ .../apache/tuscany/sca/data/collection/Item.java | 159 ++ .../sca/data/collection/ItemCollection.java | 30 + .../sca/data/collection/LocalItemCollection.java | 28 + .../sca/data/collection/NotFoundException.java | 45 + .../implementation/data/collection/Collection.java | 31 + .../sca/implementation/data/collection/Entry.java | 29 + .../sca/implementation/data/collection/Item.java | 30 + .../data/collection/ItemCollection.java | 31 + .../data/collection/LocalItemCollection.java | 29 + .../data/collection/NotFoundException.java | 30 + .../sca-java-1.6/modules/databinding-axiom/LICENSE | 205 +++ .../sca-java-1.6/modules/databinding-axiom/NOTICE | 6 + .../sca-java-1.6/modules/databinding-axiom/pom.xml | 122 ++ .../sca/databinding/axiom/AxiomDataBinding.java | 62 + .../tuscany/sca/databinding/axiom/AxiomHelper.java | 142 ++ .../sca/databinding/axiom/Exception2OMElement.java | 95 ++ .../axiom/Externalizable2OMElement.java | 77 + .../sca/databinding/axiom/OMElement2Exception.java | 79 + .../axiom/OMElement2Externalizable.java | 69 + .../sca/databinding/axiom/OMElement2Object.java | 50 + .../sca/databinding/axiom/OMElement2String.java | 64 + .../axiom/OMElement2XMLStreamReader.java | 66 + .../databinding/axiom/OMElementWrapperHandler.java | 267 ++++ .../sca/databinding/axiom/Object2OMElement.java | 63 + .../sca/databinding/axiom/String2OMElement.java | 64 + .../axiom/XMLStreamReader2OMElement.java | 70 + .../org.apache.tuscany.sca.databinding.DataBinding | 20 + ....apache.tuscany.sca.databinding.PullTransformer | 30 + .../sca/databinding/axiom/OMElementTestCase.java | 129 ++ .../databinding-axiom/src/test/resources/ipo.xml | 51 + .../databinding-axiom/src/test/resources/ipo.xsd | 137 ++ .../src/test/resources/order.wsdl | 76 + .../modules/databinding-fastinfoset/LICENSE | 202 +++ .../modules/databinding-fastinfoset/NOTICE | 14 + .../modules/databinding-fastinfoset/pom.xml | 87 ++ .../databinding/fastinfoset/FastInfoset2Node.java | 70 + .../databinding/fastinfoset/FastInfoset2SAX.java | 71 + .../fastinfoset/FastInfoset2XMLStreamReader.java | 67 + .../databinding/fastinfoset/Node2FastInfoset.java | 71 + .../fastinfoset/XMLInputStream2FastInfoset.java | 89 ++ .../fastinfoset/XMLStreamReader2FastInfoset.java | 75 + ....apache.tuscany.sca.databinding.PullTransformer | 22 + ....apache.tuscany.sca.databinding.PushTransformer | 22 + .../FastInfosetTransformerTestCase.java | 127 ++ .../src/test/resources/ipo.xsd | 136 ++ .../modules/databinding-jaxb-axiom/LICENSE | 205 +++ .../modules/databinding-jaxb-axiom/NOTICE | 6 + .../modules/databinding-jaxb-axiom/pom.xml | 189 +++ .../sca/databinding/jaxb/axiom/AxiomHelper.java | 140 ++ .../sca/databinding/jaxb/axiom/JAXB2OMElement.java | 78 + .../databinding/jaxb/axiom/JAXBCustomBuilder.java | 116 ++ .../sca/databinding/jaxb/axiom/JAXBDataSource.java | 206 +++ .../sca/databinding/jaxb/axiom/OMElement2JAXB.java | 90 ++ ....apache.tuscany.sca.databinding.PullTransformer | 26 + .../databinding/jaxb/axiom/JAXB2OMTestCase.java | 109 ++ .../jaxb/axiom/OMElement2JAXBTestCase.java | 71 + .../src/test/resources/ipo.xsd | 136 ++ .../sca-java-1.6/modules/databinding-jaxb/LICENSE | 205 +++ .../sca-java-1.6/modules/databinding-jaxb/NOTICE | 6 + .../sca-java-1.6/modules/databinding-jaxb/pom.xml | 183 +++ .../sca/databinding/jaxb/AnyTypeXmlAdapter.java | 39 + .../sca/databinding/jaxb/DOMElementXmlAdapter.java | 57 + .../sca/databinding/jaxb/DataConverter.java | 378 +++++ .../jaxb/DefaultXMLAdapterExtensionPoint.java | 60 + .../tuscany/sca/databinding/jaxb/JAXB2Node.java | 75 + .../tuscany/sca/databinding/jaxb/JAXB2SAX.java | 70 + .../tuscany/sca/databinding/jaxb/JAXB2String.java | 77 + .../sca/databinding/jaxb/JAXBContextCache.java | 563 +++++++ .../sca/databinding/jaxb/JAXBContextHelper.java | 486 ++++++ .../sca/databinding/jaxb/JAXBDataBinding.java | 131 ++ .../databinding/jaxb/JAXBPropertyDescriptor.java | 302 ++++ .../sca/databinding/jaxb/JAXBTypeHelper.java | 245 +++ .../sca/databinding/jaxb/JAXBWrapperException.java | 56 + .../sca/databinding/jaxb/JAXBWrapperHandler.java | 153 ++ .../sca/databinding/jaxb/JAXBWrapperHelper.java | 166 ++ .../tuscany/sca/databinding/jaxb/Node2JAXB.java | 73 + .../tuscany/sca/databinding/jaxb/Reader2JAXB.java | 74 + .../tuscany/sca/databinding/jaxb/String2JAXB.java | 80 + .../databinding/jaxb/XMLAdapterExtensionPoint.java | 52 + .../sca/databinding/jaxb/XMLRootElementUtil.java | 299 ++++ .../sca/databinding/jaxb/XMLStreamReader2JAXB.java | 77 + .../org.apache.tuscany.sca.databinding.DataBinding | 19 + ....apache.tuscany.sca.databinding.PullTransformer | 32 + ...y.sca.databinding.jaxb.XMLAdapterExtensionPoint | 17 + .../java/com/example/stock/StockQuoteOffer.java | 45 + .../databinding/jaxb/BeanXMLStreamReaderImpl.java | 324 ++++ .../sca/databinding/jaxb/JAXB2XMLStreamReader.java | 84 ++ .../databinding/jaxb/JAXBContextCacheTestCase.java | 123 ++ .../databinding/jaxb/JAXBDataBindingTestCase.java | 130 ++ .../databinding/jaxb/JAXBReflectionTestCase.java | 92 ++ .../tuscany/sca/databinding/jaxb/JAXBTestCase.java | 175 +++ .../jaxb/JAXBWrapperHandlerTestCase.java | 90 ++ .../tuscany/sca/databinding/jaxb/MyBean.java | 162 ++ .../tuscany/sca/databinding/jaxb/MyInterface.java | 29 + .../sca/databinding/jaxb/MyInterfaceImpl.java | 67 + .../tuscany/sca/databinding/jaxb/MyJaxbBean.java | 64 + .../tuscany/sca/databinding/jaxb/MySubBean.java | 35 + .../tuscany/sca/databinding/jaxb/POJOTestCase.java | 268 ++++ .../databinding-jaxb/src/test/resources/ipo.xsd | 136 ++ .../sca-java-1.6/modules/databinding-json/LICENSE | 202 +++ .../sca-java-1.6/modules/databinding-json/NOTICE | 6 + .../sca-java-1.6/modules/databinding-json/pom.xml | 136 ++ .../sca/databinding/json/JSON2JavaBean.java | 73 + .../tuscany/sca/databinding/json/JSON2String.java | 61 + .../sca/databinding/json/JSON2XMLStreamReader.java | 65 + .../sca/databinding/json/JSONDataBinding.java | 74 + .../tuscany/sca/databinding/json/JSONHelper.java | 91 ++ .../sca/databinding/json/JavaBean2JSON.java | 82 + .../sca/databinding/json/JavaBean2JSONObject.java | 139 ++ .../tuscany/sca/databinding/json/String2JSON.java | 64 + .../sca/databinding/json/XMLStreamReader2JSON.java | 77 + .../sca/databinding/json/axiom/JSON2OMElement.java | 94 ++ .../json/axiom/JSONBadgerfishDataSource.java | 57 + .../sca/databinding/json/axiom/JSONDataSource.java | 176 +++ .../org.apache.tuscany.sca.databinding.DataBinding | 19 + ....apache.tuscany.sca.databinding.PullTransformer | 31 + .../databinding/json/JSONTransformerTestCase.java | 128 ++ .../databinding/json/JavaBean2JSONTestCase.java | 170 +++ .../tuscany/sca/databinding/json/MyBean.java | 158 ++ .../tuscany/sca/databinding/json/MyInterface.java | 29 + .../sca/databinding/json/MyInterfaceImpl.java | 67 + .../tuscany/sca/databinding/json/POJOTestCase.java | 87 ++ .../databinding-json/src/test/resources/ipo.xsd | 136 ++ .../sca-java-1.6/modules/databinding-saxon/LICENSE | 202 +++ .../sca-java-1.6/modules/databinding-saxon/NOTICE | 6 + .../sca-java-1.6/modules/databinding-saxon/pom.xml | 137 ++ .../saxon/DataObject2NodeInfoTransformer.java | 99 ++ .../saxon/ItemList2ObjectTransformer.java | 153 ++ .../saxon/Node2NodeInfoTransformer.java | 77 + .../saxon/NodeInfo2DataObjectTransformer.java | 91 ++ .../saxon/NodeInfo2JavaArrayTransformer.java | 76 + .../saxon/NodeInfo2NodeTransformer.java | 71 + .../databinding/saxon/Object2ValueTransformer.java | 65 + .../databinding/saxon/SaxonDataBindingHelper.java | 41 + .../databinding/saxon/SaxonNodeDataBinding.java | 54 + .../databinding/saxon/SaxonValueDataBinding.java | 53 + .../saxon/SimpleType2ValueTransformer.java | 87 ++ .../sca/databinding/saxon/Value2JavaArray.java | 74 + .../databinding/saxon/Value2ObjectTransformer.java | 66 + .../saxon/Value2SimpleTypeTransformer.java | 65 + .../sca/databinding/saxon/collection/ItemList.java | 34 + .../org.apache.tuscany.sca.databinding.DataBinding | 20 + ....apache.tuscany.sca.databinding.PullTransformer | 34 + .../modules/databinding-sdo-axiom/LICENSE | 205 +++ .../modules/databinding-sdo-axiom/NOTICE | 6 + .../modules/databinding-sdo-axiom/pom.xml | 167 ++ .../sca/databinding/sdo2om/AxiomHelper.java | 142 ++ .../databinding/sdo2om/DataObject2OMElement.java | 86 ++ .../sca/databinding/sdo2om/SDODataSource.java | 89 ++ .../databinding/sdo2om/XMLDocument2OMElement.java | 65 + ....apache.tuscany.sca.databinding.PullTransformer | 20 + .../sdo2om/DataObject2OMElementTestCase.java | 78 + .../sdo2om/SDOTransformerTestCaseBase.java | 82 + .../sdo2om/XMLDocument2OMElementTestCase.java | 63 + .../src/test/resources/ipo.xsd | 136 ++ .../src/test/resources/stock.xsd | 33 + .../sca-java-1.6/modules/databinding-sdo/LICENSE | 205 +++ .../sca-java-1.6/modules/databinding-sdo/NOTICE | 6 + .../sca-java-1.6/modules/databinding-sdo/pom.xml | 144 ++ .../sca/databinding/sdo/DataObject2Node.java | 73 + .../sca/databinding/sdo/DataObject2String.java | 64 + .../sdo/DataObject2XMLStreamReader.java | 82 + .../tuscany/sca/databinding/sdo/ImportSDO.java | 78 + .../sca/databinding/sdo/ImportSDOProcessor.java | 212 +++ .../sca/databinding/sdo/Node2DataObject.java | 69 + .../sca/databinding/sdo/SDOContextHelper.java | 218 +++ .../sca/databinding/sdo/SDODataBinding.java | 148 ++ .../sca/databinding/sdo/SDOSimpleTypeMapper.java | 68 + .../tuscany/sca/databinding/sdo/SDOTypeHelper.java | 236 +++ .../tuscany/sca/databinding/sdo/SDOTypes.java | 105 ++ .../sca/databinding/sdo/SDOWrapperHandler.java | 192 +++ .../sca/databinding/sdo/String2DataObject.java | 61 + .../sca/databinding/sdo/XMLDocument2String.java | 65 + .../sdo/XMLDocument2XMLStreamReader.java | 69 + .../sdo/XMLStreamReader2DataObject.java | 72 + .../sdo/XMLStreamReader2XMLDocument.java | 66 + .../databinding/sdo/xml/SDOTypesModelResolver.java | 246 +++ .../sca/databinding/sdo/xml/SDOTypesProcessor.java | 109 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...tuscany.sca.contribution.resolver.ModelResolver | 17 + .../org.apache.tuscany.sca.databinding.DataBinding | 19 + ....apache.tuscany.sca.databinding.PullTransformer | 27 + .../databinding-sdo-validation-messages.properties | 23 + .../sdo/fault/InvalidSymbolFault_Exception.java | 70 + .../databinding/sdo/DataObject2NodeTestCase.java | 60 + .../databinding/sdo/DataObject2StringTestCase.java | 65 + .../sdo/DataObject2XMLStreamReaderTestCase.java | 75 + .../sdo/ImportSDOProcessorTestCase.java | 89 ++ .../databinding/sdo/SDOContextHelperTestCase.java | 55 + .../databinding/sdo/SDODataBindingTestCase.java | 114 ++ .../sdo/SDOTransformerTestCaseBase.java | 82 + .../databinding/sdo/SDOWrapperHandlerTestCase.java | 83 + .../sca/databinding/sdo/TestModelResolver.java | 63 + .../sdo/XMLDocument2XMLStreamReaderTestCase.java | 62 + .../databinding-sdo/src/test/resources/ipo.xsd | 136 ++ .../databinding-sdo/src/test/resources/stock.xsd | 33 + .../databinding-sdo/src/test/resources/wrapper.xml | 27 + .../databinding-sdo/src/test/resources/wrapper.xsd | 38 + .../modules/databinding-xmlbeans/LICENSE | 202 +++ .../modules/databinding-xmlbeans/NOTICE | 6 + .../modules/databinding-xmlbeans/pom.xml | 125 ++ .../sca/databinding/xmlbeans/Node2XmlObject.java | 61 + .../databinding/xmlbeans/XMLBeansDataBinding.java | 82 + .../xmlbeans/XMLBeansWrapperHandler.java | 126 ++ .../xmlbeans/XMLStreamReader2XmlObject.java | 62 + .../sca/databinding/xmlbeans/XmlObject2Node.java | 60 + .../xmlbeans/XmlObject2XMLStreamReader.java | 55 + .../org.apache.tuscany.sca.databinding.DataBinding | 19 + ....apache.tuscany.sca.databinding.PullTransformer | 22 + .../databinding/xmlbeans/XmlObjectTestCase.java | 105 ++ .../src/test/resources/ipo.xsd | 136 ++ .../src/test/resources/ipo.xsdconfig | 21 + .../modules/databinding-xstream/LICENSE | 205 +++ .../modules/databinding-xstream/NOTICE | 6 + .../modules/databinding-xstream/pom.xml | 121 ++ .../sca/databinding/xstream/MetaObject.java | 37 + .../sca/databinding/xstream/MetaObjectImpl.java | 95 ++ .../sca/databinding/xstream/Node2XObject.java | 69 + .../sca/databinding/xstream/OMElement2XObject.java | 76 + .../tuscany/sca/databinding/xstream/Utils.java | 79 + .../tuscany/sca/databinding/xstream/XObject.java | 28 + .../sca/databinding/xstream/XObject2Node.java | 69 + .../sca/databinding/xstream/XObject2OMElement.java | 106 ++ .../databinding/xstream/XObjectDataBinding.java | 37 + .../org.apache.tuscany.sca.databinding.DataBinding | 20 + ....apache.tuscany.sca.databinding.PullTransformer | 18 + .../databinding-xstream/src/test/resources/ipo.xml | 48 + .../databinding-xstream/src/test/resources/ipo.xsd | 132 ++ .../src/test/resources/order.wsdl | 76 + .../sca-java-1.6/modules/databinding/LICENSE | 244 +++ .../sca-java-1.6/modules/databinding/NOTICE | 6 + .../sca-java-1.6/modules/databinding/pom.xml | 108 ++ .../tuscany/sca/databinding/DataBinding.java | 91 ++ .../sca/databinding/DataBindingExtensionPoint.java | 74 + .../apache/tuscany/sca/databinding/DataPipe.java | 46 + .../sca/databinding/DataPipeTransformer.java | 29 + .../DefaultDataBindingExtensionPoint.java | 262 ++++ .../DefaultTransformerExtensionPoint.java | 306 ++++ .../apache/tuscany/sca/databinding/Mediator.java | 153 ++ .../tuscany/sca/databinding/PullTransformer.java | 38 + .../tuscany/sca/databinding/PushTransformer.java | 36 + .../tuscany/sca/databinding/SimpleTypeMapper.java | 46 + .../sca/databinding/TransformationContext.java | 95 ++ .../sca/databinding/TransformationException.java | 65 + .../tuscany/sca/databinding/Transformer.java | 51 + .../sca/databinding/TransformerExtensionPoint.java | 81 + .../tuscany/sca/databinding/WrapperHandler.java | 78 + .../tuscany/sca/databinding/XMLTypeHelper.java | 68 + .../sca/databinding/annotation/DataBinding.java | 56 + .../sca/databinding/annotation/DataType.java | 43 + .../externalizable/ExternalizableDataBinding.java | 39 + .../sca/databinding/impl/BaseDataBinding.java | 111 ++ .../sca/databinding/impl/BaseTransformer.java | 52 + .../tuscany/sca/databinding/impl/DOMHelper.java | 163 ++ .../sca/databinding/impl/DirectedGraph.java | 452 ++++++ .../databinding/impl/Group2GroupTransformer.java | 94 ++ .../sca/databinding/impl/GroupDataBinding.java | 103 ++ .../impl/Java2SimpleTypeTransformer.java | 70 + .../tuscany/sca/databinding/impl/MediatorImpl.java | 587 ++++++++ .../sca/databinding/impl/PipedTransformer.java | 70 + .../impl/SimpleType2JavaTransformer.java | 89 ++ .../sca/databinding/impl/SimpleTypeMapperImpl.java | 401 +++++ .../impl/TransformationContextImpl.java | 125 ++ .../sca/databinding/impl/XSDDataTypeConverter.java | 945 ++++++++++++ .../javabeans/DOMNode2JavaBeanTransformer.java | 97 ++ .../javabeans/Java2XMLMapperException.java | 69 + .../javabeans/JavaBean2DOMNodeTransformer.java | 79 + .../JavaBean2XMLStreamReaderTransformer.java | 68 + .../javabeans/JavaBean2XMLTransformer.java | 262 ++++ .../javabeans/JavaBeansDataBinding.java | 163 ++ .../javabeans/JavaExceptionDataBinding.java | 35 + .../javabeans/SimpleJavaDataBinding.java | 79 + .../javabeans/XML2JavaBeanTransformer.java | 329 ++++ .../javabeans/XML2JavaMapperException.java | 76 + .../sca/databinding/util/DataTypeHelper.java | 168 +++ .../tuscany/sca/databinding/util/LRUCache.java | 88 ++ .../databinding/xml/BeanXMLStreamReaderImpl.java | 296 ++++ .../sca/databinding/xml/DOMDataBinding.java | 71 + .../sca/databinding/xml/DOMWrapperHandler.java | 146 ++ .../sca/databinding/xml/DOMXMLStreamReader.java | 36 + .../sca/databinding/xml/DOMXmlNodeImpl.java | 156 ++ .../xml/DelegatingNamespaceContext.java | 310 ++++ .../sca/databinding/xml/InputSource2Node.java | 67 + .../sca/databinding/xml/InputSource2SAX.java | 65 + .../sca/databinding/xml/InputStream2Node.java | 69 + .../sca/databinding/xml/InputStream2SAX.java | 64 + .../xml/NameValueArrayStreamReader.java | 403 +++++ .../databinding/xml/NameValuePairStreamReader.java | 347 +++++ .../tuscany/sca/databinding/xml/NamedProperty.java | 59 + .../databinding/xml/NilElementStreamReader.java | 279 ++++ .../sca/databinding/xml/Node2OutputStream.java | 68 + .../sca/databinding/xml/Node2SimpleJavaType.java | 45 + .../databinding/xml/Node2SourceTransformer.java | 61 + .../tuscany/sca/databinding/xml/Node2String.java | 62 + .../tuscany/sca/databinding/xml/Node2Writer.java | 67 + .../sca/databinding/xml/Node2XMLStreamReader.java | 64 + .../tuscany/sca/databinding/xml/Reader2Node.java | 67 + .../tuscany/sca/databinding/xml/Reader2SAX.java | 60 + .../tuscany/sca/databinding/xml/SAX2DOM.java | 246 +++ .../tuscany/sca/databinding/xml/SAX2DOMPipe.java | 81 + .../sca/databinding/xml/SimpleJavaType2Node.java | 71 + .../sca/databinding/xml/SimpleXmlNodeImpl.java | 112 ++ .../databinding/xml/Source2NodeTransformer.java | 69 + .../databinding/xml/Source2ResultTransformer.java | 63 + .../databinding/xml/Source2StringTransformer.java | 68 + .../sca/databinding/xml/StAX2SAXAdapter.java | 256 ++++ .../sca/databinding/xml/StAXDataBinding.java | 53 + .../tuscany/sca/databinding/xml/StAXHelper.java | 86 ++ .../sca/databinding/xml/StreamDataPipe.java | 65 + .../tuscany/sca/databinding/xml/String2Node.java | 60 + .../tuscany/sca/databinding/xml/String2SAX.java | 61 + .../databinding/xml/String2SourceTransformer.java | 62 + .../databinding/xml/String2XMLStreamReader.java | 55 + .../databinding/xml/WrappingXMLStreamReader.java | 100 ++ .../sca/databinding/xml/Writer2ReaderDataPipe.java | 63 + .../databinding/xml/XMLDocumentStreamReader.java | 482 ++++++ .../databinding/xml/XMLFragmentStreamReader.java | 53 + .../xml/XMLFragmentStreamReaderImpl.java | 857 +++++++++++ .../sca/databinding/xml/XMLGroupDataBinding.java | 57 + .../sca/databinding/xml/XMLStreamReader2Node.java | 75 + .../sca/databinding/xml/XMLStreamReader2SAX.java | 70 + .../databinding/xml/XMLStreamReader2String.java | 57 + .../sca/databinding/xml/XMLStreamSerializer.java | 287 ++++ .../tuscany/sca/databinding/xml/XMLStreamable.java | 37 + .../sca/databinding/xml/XMLStringDataBinding.java | 50 + .../tuscany/sca/databinding/xml/XmlNode.java | 69 + .../sca/databinding/xml/XmlNodeIterator.java | 355 +++++ .../databinding/xml/XmlTreeStreamReaderImpl.java | 531 +++++++ .../org.apache.tuscany.sca.databinding.DataBinding | 25 + ...scany.sca.databinding.DataBindingExtensionPoint | 18 + .../org.apache.tuscany.sca.databinding.Mediator | 17 + ....apache.tuscany.sca.databinding.PullTransformer | 40 + ....apache.tuscany.sca.databinding.PushTransformer | 26 + ...scany.sca.databinding.TransformerExtensionPoint | 18 + .../databinding/extension/DOMHelperTestCase.java | 58 + .../extension/DataBindingExtensionTestCase.java | 86 ++ .../SimpleTypeMapperExtensionTestCase.java | 124 ++ .../extension/TransformerExtensionTestCase.java | 77 + .../extension/XSDDataTypeConverterTestCase.java | 64 + .../impl/DataBindingRegistryImplTestCase.java | 97 ++ .../sca/databinding/impl/DataBindingTestCase.java | 49 + .../databinding/impl/DirectedGraphTestCase.java | 125 ++ .../sca/databinding/impl/MediatorImplTestCase.java | 122 ++ .../impl/TransformerRegistryImplTestCase.java | 109 ++ .../impl/XMLDocumentStreamReaderTestCase.java | 57 + .../xml/BeanXMLStreamReaderTestCase.java | 192 +++ .../sca/databinding/xml/DOM2StAXTestCase.java | 108 ++ .../sca/databinding/xml/DataPipeTestCase.java | 93 ++ .../xml/JavaBean2XMLStreamReaderTestCase.java | 144 ++ .../sca/databinding/xml/Node2StringTestCase.java | 39 + .../xml/PushTransformationTestCase.java | 86 ++ .../sca/databinding/xml/StAXHelperTestCase.java | 55 + .../databinding/xml/TraxTransformerTestCase.java | 101 ++ .../xml/XmlTreeStreamReaderTestCase.java | 199 +++ .../apache/tuscany/sca/databinding/impl/ipo.xsd | 136 ++ .../apache/tuscany/sca/databinding/impl/order.wsdl | 76 + .../org/apache/tuscany/sca/databinding/xml/foo.xml | 22 + .../sca-java-1.6/modules/definitions-xml/LICENSE | 205 +++ .../sca-java-1.6/modules/definitions-xml/NOTICE | 6 + .../sca-java-1.6/modules/definitions-xml/pom.xml | 82 + .../xml/SCADefinitionsDocumentProcessor.java | 197 +++ .../definitions/xml/SCADefinitionsProcessor.java | 264 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...sca.contribution.processor.URLArtifactProcessor | 19 + .../definitions-xml-validation-messages.properties | 22 + .../org/apache/tuscany/sca/definitions/Policy.java | 33 + .../sca/definitions/ReadDocumentTestCase.java | 190 +++ .../sca/definitions/TestPolicyProcessor.java | 75 + .../tuscany/sca/definitions/test_definitions.xml | 255 ++++ .../sca-java-1.6/modules/definitions/LICENSE | 205 +++ .../sca-java-1.6/modules/definitions/NOTICE | 6 + .../sca-java-1.6/modules/definitions/pom.xml | 70 + .../tuscany/sca/definitions/SCADefinitions.java | 82 + .../sca/definitions/SCADefinitionsBuilder.java | 34 + .../SCADefinitionsBuilderException.java | 43 + .../sca/definitions/SCADefinitionsBuilderImpl.java | 309 ++++ .../sca/definitions/impl/SCADefinitionsImpl.java | 71 + .../sca/definitions/util/SCADefinitionsUtil.java | 87 ++ .../sca-java-1.6/modules/domain-manager/LICENSE | 205 +++ .../sca-java-1.6/modules/domain-manager/NOTICE | 6 + .../sca-java-1.6/modules/domain-manager/pom.xml | 227 +++ .../impl/CompositeConfigurationCollectionImpl.java | 127 ++ .../impl/CompositeConfigurationServiceImpl.java | 657 ++++++++ .../impl/CompositeGeneratorServiceImpl.java | 255 ++++ .../manager/impl/ContributionCollectionImpl.java | 705 +++++++++ .../manager/impl/ContributionServiceImpl.java | 77 + .../domain/manager/impl/ContributionsReader.java | 9 + .../impl/DeployableCompositeCollectionImpl.java | 481 ++++++ .../impl/DeployableCompositeServiceImpl.java | 128 ++ .../impl/DeployedCompositeCollectionImpl.java | 417 +++++ .../manager/impl/DomainManagerConfiguration.java | 53 + .../impl/DomainManagerConfigurationImpl.java | 85 ++ .../sca/domain/manager/impl/DomainManagerUtil.java | 295 ++++ .../domain/manager/impl/FileCollectionImpl.java | 136 ++ .../sca/domain/manager/impl/FileServiceImpl.java | 210 +++ .../manager/impl/NodeConfigurationServiceImpl.java | 96 ++ .../impl/NodeProcessCollectionFacadeImpl.java | 251 +++ .../domain/manager/impl/QuickStartServiceImpl.java | 242 +++ .../tuscany/sca/domain/manager/impl/Searcher.java | 461 ++++++ .../launcher/DomainManagerLauncherBootstrap.java | 95 ++ .../src/main/resources/DomainManager.composite | 316 ++++ .../src/main/resources/cloud-gadget.html | 408 +++++ .../domain-manager/src/main/resources/cloud.html | 68 + .../src/main/resources/composite-gadget.html | 278 ++++ .../src/main/resources/composite.html | 66 + .../src/main/resources/files-gadget.html | 124 ++ .../domain-manager/src/main/resources/files.html | 64 + .../src/main/resources/home-gadget.html | 36 + .../domain-manager/src/main/resources/home.html | 62 + .../src/main/resources/icons/artifact.png | Bin 0 -> 228 bytes .../src/main/resources/icons/component.png | Bin 0 -> 226 bytes .../src/main/resources/icons/composite.png | Bin 0 -> 202 bytes .../src/main/resources/icons/feed-icon.png | Bin 0 -> 818 bytes .../domain-manager/src/main/resources/manager.css | 104 ++ .../src/main/resources/search-gadget.html | 100 ++ .../domain-manager/src/main/resources/search.html | 127 ++ .../src/main/resources/toolbar-gadget.html | 59 + .../domain-manager/src/main/resources/utils.js | 248 +++ .../src/main/resources/workspace-gadget.html | 232 +++ .../src/main/resources/workspace.html | 65 + .../domain/manager/impl/DomainManagerTestCase.java | 117 ++ .../assets/META-INF/sca-contribution.xml | 26 + .../store/META-INF/sca-contribution.xml | 24 + .../src/test/resources/workspace.xml | 21 + .../sca-java-1.6/modules/domain-search/LICENSE | 205 +++ .../sca-java-1.6/modules/domain-search/NOTICE | 6 + .../sca-java-1.6/modules/domain-search/pom.xml | 107 ++ .../tuscany/sca/domain/search/DocumentMap.java | 60 + .../sca/domain/search/DocumentProcessor.java | 64 + .../sca/domain/search/DocumentProcessorsMap.java | 106 ++ .../tuscany/sca/domain/search/DomainSearch.java | 108 ++ .../tuscany/sca/domain/search/IndexException.java | 45 + .../apache/tuscany/sca/domain/search/Result.java | 121 ++ .../tuscany/sca/domain/search/ResultFactory.java | 51 + .../tuscany/sca/domain/search/ResultProcessor.java | 50 + .../search/impl/ArtifactDocumentProcessor.java | 107 ++ .../search/impl/BindingDocumentProcessor.java | 82 + .../search/impl/ComponentDocumentProcessor.java | 200 +++ .../impl/ComponentTypeDocumentProcessor.java | 186 +++ .../search/impl/CompositeDocumentProcessor.java | 128 ++ .../search/impl/ContributionDocumentProcessor.java | 154 ++ .../sca/domain/search/impl/DefaultFileContent.java | 57 + .../search/impl/DefaultFileDocumentProcessor.java | 87 ++ .../tuscany/sca/domain/search/impl/Document.java | 113 ++ .../sca/domain/search/impl/DomainPathAnalyzer.java | 233 +++ .../domain/search/impl/DomainSearchAnalyzer.java | 36 + .../impl/DomainSearchDocumentProcessorsMap.java | 50 + .../impl/DomainSearchFileDocumentProcessor.java | 35 + .../domain/search/impl/DomainSearchFormatter.java | 68 + .../sca/domain/search/impl/DomainSearchImpl.java | 371 +++++ .../search/impl/DomainSearchResultFactory.java | 40 + .../search/impl/DomainSearchResultProcessor.java | 40 + .../sca/domain/search/impl/FileContent.java | 40 + .../search/impl/FileContentResultProcessor.java | 105 ++ .../domain/search/impl/FileDocumentProcessor.java | 108 ++ .../sca/domain/search/impl/HighlightingUtil.java | 189 +++ .../sca/domain/search/impl/NamingAnalyzer.java | 48 + .../sca/domain/search/impl/NamingTokenizer.java | 149 ++ .../sca/domain/search/impl/ParentField.java | 206 +++ .../impl/PriorityFieldListResultFactory.java | 58 + .../search/impl/PropertyDocumentProcessor.java | 88 ++ .../tuscany/sca/domain/search/impl/ResultImpl.java | 270 ++++ .../domain/search/impl/ResultProcessorList.java | 186 +++ .../sca/domain/search/impl/SearchFields.java | 73 + .../sca/domain/search/impl/SystemFileContent.java | 76 + .../sca/domain/search/impl/WrappedFileContent.java | 73 + .../domain/search/impl/ZipDocumentProcessor.java | 103 ++ .../sca/domain/search/impl/ZipFileContent.java | 321 ++++ .../search/impl/DomainPathAnalyzerTestCase.java | 60 + .../search/impl/NamingTokenizerTestCase.java | 158 ++ .../branches/sca-java-1.6/modules/endpoint/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/endpoint/NOTICE | 6 + .../branches/sca-java-1.6/modules/endpoint/pom.xml | 122 ++ .../endpoint/impl/EndpointResolverFactoryImpl.java | 49 + .../sca/endpoint/impl/EndpointResolverImpl.java | 112 ++ ...ny.sca.endpointresolver.EndpointResolverFactory | 19 + .../apache/tuscany/sca/binding/sca/definitions.xml | 26 + .../src/test/java/calculator/AddService.java | 28 + .../src/test/java/calculator/AddServiceImpl.java | 35 + .../test/java/calculator/CalculatorService.java | 35 + .../java/calculator/CalculatorServiceImpl.java | 70 + .../src/test/java/calculator/DivideService.java | 28 + .../test/java/calculator/DivideServiceImpl.java | 35 + .../src/test/java/calculator/MultiplyService.java | 28 + .../test/java/calculator/MultiplyServiceImpl.java | 35 + .../src/test/java/calculator/SubtractService.java | 28 + .../test/java/calculator/SubtractServiceImpl.java | 35 + .../tuscany/sca/binding/sca/EndpointTestCase.java | 209 +++ .../src/test/resources/Calculator.composite | 52 + .../modules/extensibility-equinox/LICENSE | 205 +++ .../modules/extensibility-equinox/NOTICE | 5 + .../modules/extensibility-equinox/pom.xml | 112 ++ .../equinox/EquinoxServiceDiscoverer.java | 281 ++++ .../equinox/EquinoxServiceDiscoveryActivator.java | 46 + .../extensibility/equinox/EquinoxHostTestCase.java | 96 ++ .../equinox/EquinoxServiceDiscovererTestCase.java | 152 ++ .../sca/extensibility/equinox/TestEquinoxHost.java | 100 ++ .../src/test/resources/test-bundle.jar | Bin 0 -> 1797 bytes .../modules/extensibility-osgi/LICENSE | 205 +++ .../sca-java-1.6/modules/extensibility-osgi/NOTICE | 5 + .../modules/extensibility-osgi/pom.xml | 73 + .../extensibility/osgi/OSGiServiceDiscoverer.java | 359 +++++ .../osgi/OSGiServiceDiscoveryActivator.java | 45 + .../osgi/OSGiServiceDiscovererTestCase.java | 123 ++ .../src/test/resources/test-bundle.jar | Bin 0 -> 1797 bytes .../sca-java-1.6/modules/extensibility/LICENSE | 205 +++ .../sca-java-1.6/modules/extensibility/NOTICE | 5 + .../sca-java-1.6/modules/extensibility/pom.xml | 50 + .../sca/core/DefaultExtensionPointRegistry.java | 184 +++ .../core/DefaultModuleActivatorExtensionPoint.java | 99 ++ .../sca/core/DefaultUtilityExtensionPoint.java | 184 +++ .../tuscany/sca/core/ExtensionPointRegistry.java | 56 + .../apache/tuscany/sca/core/ModuleActivator.java | 60 + .../sca/core/ModuleActivatorExtensionPoint.java | 53 + .../tuscany/sca/core/UtilityExtensionPoint.java | 54 + .../ClassLoaderServiceDiscoverer.java | 262 ++++ .../sca/extensibility/ServiceDeclaration.java | 68 + .../sca/extensibility/ServiceDiscoverer.java | 37 + .../sca/extensibility/ServiceDiscovery.java | 170 +++ ....tuscany.sca.core.ModuleActivatorExtensionPoint | 18 + ...g.apache.tuscany.sca.core.UtilityExtensionPoint | 18 + .../ClassLoaderServiceDiscovererTestCase.java | 72 + .../sca-java-1.6/modules/extension-helper/LICENSE | 205 +++ .../sca-java-1.6/modules/extension-helper/NOTICE | 6 + .../sca-java-1.6/modules/extension-helper/pom.xml | 95 ++ .../sca/extension/helper/BindingActivator.java | 69 + .../sca/extension/helper/ComponentLifecycle.java | 32 + .../extension/helper/ImplementationActivator.java | 64 + .../sca/extension/helper/InvokerFactory.java | 34 + .../helper/impl/BindingSCDLProcessor.java | 195 +++ .../extension/helper/impl/BindingsActivator.java | 262 ++++ .../sca/extension/helper/impl/DiscoveryUtils.java | 113 ++ .../impl/ImplementationImplementationProvider.java | 99 ++ .../helper/impl/ImplementationsActivator.java | 135 ++ .../sca/extension/helper/impl/PojoBinding.java | 40 + .../extension/helper/impl/PojoImplementation.java | 58 + .../sca/extension/helper/impl/SCDLProcessor.java | 248 +++ .../extension/helper/utils/AbstractBinding.java | 72 + .../helper/utils/AbstractImplementation.java | 153 ++ .../utils/AbstractStAXArtifactProcessor.java | 132 ++ .../utils/DefaultPropertyValueObjectFactory.java | 231 +++ .../helper/utils/DynamicImplementation.java | 96 ++ .../helper/utils/PropertyValueObjectFactory.java | 33 + .../sca/extension/helper/utils/ResourceHelper.java | 70 + .../org.apache.tuscany.sca.core.ModuleActivator | 20 + .../sca-java-1.6/modules/host-android/LICENSE | 205 +++ .../sca-java-1.6/modules/host-android/NOTICE | 6 + .../sca-java-1.6/modules/host-android/pom.xml | 132 ++ .../tuscany/sca/host/embedded/SCADomain.java | 228 +++ .../tuscany/sca/host/embedded/SCADomainBean.java | 125 ++ .../sca/host/embedded/SCATestCaseRunner.java | 291 ++++ .../host/embedded/impl/ComponentManagerImpl.java | 120 ++ .../sca/host/embedded/impl/DefaultSCADomain.java | 339 +++++ .../sca/host/embedded/impl/EmbeddedSCADomain.java | 235 +++ .../host/embedded/impl/HotUpdatableSCADomain.java | 389 +++++ .../sca/host/embedded/impl/ReallySmallRuntime.java | 390 +++++ .../embedded/impl/ReallySmallRuntimeBuilder.java | 275 ++++ .../embedded/management/ComponentListener.java | 34 + .../host/embedded/management/ComponentManager.java | 48 + .../sca/host/embedded/SCADomainBeanTestCase.java | 57 + .../sca/host/embedded/SCADomainTestCase.java | 56 + .../host/embedded/SCADomainZipsTestCaseFIXME.java | 51 + .../embedded/impl/DefaultSCADomainTestCase.java | 63 + .../embedded/impl/EmbeddedSCADomainTestCase.java | 189 +++ .../sca/host/embedded/impl/TestModelResolver.java | 104 ++ .../DefaultTestImplementationFactory.java | 47 + .../test/extension/TestImplementation.java | 44 + .../test/extension/TestImplementationFactory.java | 37 + .../host/embedded/test/extension/TestService.java | 30 + .../extension/impl/TestImplementationImpl.java | 117 ++ .../impl/TestImplementationProcessor.java | 96 ++ .../test/extension/module/TestModuleActivator.java | 65 + .../provider/TestImplementationProvider.java | 64 + .../TestImplementationProviderFactory.java | 47 + .../test/extension/provider/TestInvoker.java | 52 + .../src/test/java/sample/Helloworld.java | 29 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../host-android/src/test/resources/helloworld.jar | Bin 0 -> 4287 bytes .../host-android/src/test/resources/helloworld.zip | Bin 0 -> 4287 bytes .../host-android/src/test/resources/test.composite | 30 + .../host-android/src/test/resources/test.txt | 16 + .../sca-java-1.6/modules/host-corba-jee/LICENSE | 205 +++ .../sca-java-1.6/modules/host-corba-jee/NOTICE | 6 + .../sca-java-1.6/modules/host-corba-jee/pom.xml | 63 + .../corba/jee/CorbaRuntimeModuleActivator.java | 52 + .../tuscany/sca/host/corba/jee/JEECorbaHost.java | 162 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../corba/jee/testing/JEECorbaHostTestCase.java | 208 +++ .../sca/host/corba/jee/testing/TestContext.java | 174 +++ .../jee/testing/TestInitialContextFactory.java | 37 + .../corba/jee/testing/general/TestInterface.java | 30 + .../jee/testing/general/TestInterfaceHelper.java | 100 ++ .../jee/testing/general/TestInterfaceHolder.java | 51 + .../testing/general/TestInterfaceOperations.java | 31 + .../testing/general/_TestInterfaceImplBase.java | 74 + .../jee/testing/general/_TestInterfaceStub.java | 73 + .../jee/testing/servants/TestInterfaceServant.java | 35 + .../host-corba-jee/src/test/resources/general.idl | 45 + .../modules/host-corba-jse-tns/LICENSE | 205 +++ .../sca-java-1.6/modules/host-corba-jse-tns/NOTICE | 6 + .../modules/host-corba-jse-tns/pom.xml | 71 + .../corba/jse/tns/CorbaRuntimeModuleActivator.java | 53 + .../host/corba/jse/tns/TnsDefaultCorbaHost.java | 116 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../corba/testing/TnsDefaultCorbaHostTestCase.java | 97 ++ .../sca-java-1.6/modules/host-corba-jse/LICENSE | 205 +++ .../sca-java-1.6/modules/host-corba-jse/NOTICE | 6 + .../sca-java-1.6/modules/host-corba-jse/pom.xml | 57 + .../corba/jse/CorbaRuntimeModuleActivator.java | 48 + .../sca/host/corba/jse/DefaultCorbaHost.java | 181 +++ .../sca/host/corba/naming/NamingContextBase.java | 863 +++++++++++ .../sca/host/corba/naming/TransientNameServer.java | 133 ++ .../host/corba/naming/TransientNameService.java | 203 +++ .../host/corba/naming/TransientNamingContext.java | 440 ++++++ .../corba/naming/TransientServiceException.java | 44 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../corba/testing/DefaultCorbaHostTestCase.java | 250 +++ .../host/corba/testing/general/TestInterface.java | 30 + .../corba/testing/general/TestInterfaceHelper.java | 98 ++ .../corba/testing/general/TestInterfaceHolder.java | 51 + .../testing/general/TestInterfaceOperations.java | 31 + .../testing/general/_TestInterfaceImplBase.java | 74 + .../corba/testing/general/_TestInterfaceStub.java | 73 + .../testing/servants/TestInterfaceServant.java | 35 + .../host-corba-jse/src/test/resources/general.idl | 43 + .../sca-java-1.6/modules/host-corba/LICENSE | 205 +++ .../sca-java-1.6/modules/host-corba/NOTICE | 6 + .../sca-java-1.6/modules/host-corba/pom.xml | 57 + .../apache/tuscany/sca/host/corba/CorbaHost.java | 56 + .../tuscany/sca/host/corba/CorbaHostException.java | 47 + .../sca/host/corba/CorbaHostExtensionPoint.java | 51 + .../tuscany/sca/host/corba/CorbaHostUtils.java | 61 + .../tuscany/sca/host/corba/CorbanameURL.java | 202 +++ .../host/corba/DefaultCorbaHostExtensionPoint.java | 48 + .../sca/host/corba/ExtensibleCorbaHost.java | 55 + .../apache/tuscany/sca/host/corba/SocketUtil.java | 226 +++ ....tuscany.sca.host.corba.CorbaHostExtensionPoint | 18 + .../tuscany/sca/host/corba/UtilsTestCase.java | 145 ++ .../branches/sca-java-1.6/modules/host-ejb/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/host-ejb/NOTICE | 6 + .../branches/sca-java-1.6/modules/host-ejb/pom.xml | 57 + .../sca/host/ejb/DefaultEJBHostExtensionPoint.java | 45 + .../org/apache/tuscany/sca/host/ejb/EJBHost.java | 62 + .../sca/host/ejb/EJBHostExtensionPoint.java | 51 + .../sca/host/ejb/EJBRegistrationException.java | 44 + .../tuscany/sca/host/ejb/EJBSessionBean.java | 45 + .../tuscany/sca/host/ejb/ExtensibleEJBHost.java | 69 + ...ache.tuscany.sca.host.ejb.EJBHostExtensionPoint | 18 + .../sca-java-1.6/modules/host-embedded/LICENSE | 205 +++ .../sca-java-1.6/modules/host-embedded/NOTICE | 6 + .../sca-java-1.6/modules/host-embedded/pom.xml | 138 ++ .../tuscany/sca/host/embedded/SCADomain.java | 228 +++ .../tuscany/sca/host/embedded/SCADomainBean.java | 125 ++ .../sca/host/embedded/SCATestCaseRunner.java | 291 ++++ .../host/embedded/impl/ComponentManagerImpl.java | 120 ++ .../sca/host/embedded/impl/DefaultSCADomain.java | 360 +++++ .../sca/host/embedded/impl/EmbeddedSCADomain.java | 235 +++ .../host/embedded/impl/HotUpdatableSCADomain.java | 389 +++++ .../sca/host/embedded/impl/ReallySmallRuntime.java | 387 +++++ .../embedded/impl/ReallySmallRuntimeBuilder.java | 275 ++++ .../embedded/management/ComponentListener.java | 34 + .../host/embedded/management/ComponentManager.java | 48 + .../sca/host/embedded/SCADomainBeanTestCase.java | 57 + .../sca/host/embedded/SCADomainTestCase.java | 56 + .../host/embedded/SCADomainZipsTestCaseFIXME.java | 51 + .../embedded/impl/DefaultSCADomainTestCase.java | 63 + .../embedded/impl/EmbeddedSCADomainTestCase.java | 189 +++ .../sca/host/embedded/impl/TestModelResolver.java | 104 ++ .../DefaultTestImplementationFactory.java | 47 + .../test/extension/TestImplementation.java | 44 + .../test/extension/TestImplementationFactory.java | 37 + .../host/embedded/test/extension/TestService.java | 30 + .../extension/impl/TestImplementationImpl.java | 117 ++ .../impl/TestImplementationProcessor.java | 96 ++ .../test/extension/module/TestModuleActivator.java | 65 + .../provider/TestImplementationProvider.java | 64 + .../TestImplementationProviderFactory.java | 47 + .../test/extension/provider/TestInvoker.java | 52 + .../src/test/java/sample/Helloworld.java | 29 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../src/test/resources/helloworld.jar | Bin 0 -> 4287 bytes .../src/test/resources/helloworld.zip | Bin 0 -> 4287 bytes .../src/test/resources/test.composite | 30 + .../host-embedded/src/test/resources/test.txt | 16 + .../sca-java-1.6/modules/host-http/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/host-http/NOTICE | 6 + .../sca-java-1.6/modules/host-http/pom.xml | 65 + .../sca/host/http/DefaultResourceServlet.java | 86 ++ .../http/DefaultServletHostExtensionPoint.java | 45 + .../sca/host/http/ExtensibleServletHost.java | 133 ++ .../tuscany/sca/host/http/SecurityContext.java | 64 + .../apache/tuscany/sca/host/http/ServletHost.java | 124 ++ .../sca/host/http/ServletHostExtensionPoint.java | 51 + .../sca/host/http/ServletMappingException.java | 44 + .../apache/tuscany/sca/host/http/UserContext.java | 68 + ...tuscany.sca.host.http.ServletHostExtensionPoint | 18 + .../sca-java-1.6/modules/host-jetty/LICENSE | 205 +++ .../sca-java-1.6/modules/host-jetty/NOTICE | 6 + .../sca-java-1.6/modules/host-jetty/pom.xml | 76 + .../sca/http/jetty/JettyDefaultServlet.java | 90 ++ .../apache/tuscany/sca/http/jetty/JettyLogger.java | 87 ++ .../apache/tuscany/sca/http/jetty/JettyServer.java | 512 +++++++ .../jetty/module/JettyRuntimeModuleActivator.java | 77 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sca/http/jetty/JettyServerTestCase.java | 323 ++++ .../src/test/resources/content/test.html | 21 + .../host-jetty/src/test/resources/tuscany.keyStore | Bin 0 -> 1265 bytes .../sca-java-1.6/modules/host-jms-asf/LICENSE | 205 +++ .../sca-java-1.6/modules/host-jms-asf/NOTICE | 6 + .../sca-java-1.6/modules/host-jms-asf/pom.xml | 88 ++ .../tuscany/sca/host/jms/asf/ASFListener.java | 236 +++ .../host/jms/asf/JMSHostExtensionPointImpl.java | 42 + .../jms/asf/JMSServiceListenerFactoryImpl.java | 56 + .../tuscany/sca/host/jms/asf/ServiceInvoker.java | 98 ++ ...ache.tuscany.sca.host.jms.JMSHostExtensionPoint | 19 + .../branches/sca-java-1.6/modules/host-jms/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/host-jms/NOTICE | 6 + .../branches/sca-java-1.6/modules/host-jms/pom.xml | 77 + .../sca/host/jms/JMSHostExtensionPoint.java | 27 + .../tuscany/sca/host/jms/JMSServiceListener.java | 29 + .../sca/host/jms/JMSServiceListenerDetails.java | 40 + .../sca/host/jms/JMSServiceListenerFactory.java | 27 + .../sca-java-1.6/modules/host-openejb/LICENSE | 205 +++ .../sca-java-1.6/modules/host-openejb/NOTICE | 6 + .../sca-java-1.6/modules/host-openejb/pom.xml | 103 ++ .../openejb/OpenEJBRuntimeModuleActivator.java | 52 + .../tuscany/sca/host/openejb/OpenEJBServer.java | 145 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 19 + .../sca/host/openejb/OpenEJBServerTestCase.java | 86 ++ .../branches/sca-java-1.6/modules/host-rmi/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/host-rmi/NOTICE | 6 + .../branches/sca-java-1.6/modules/host-rmi/pom.xml | 57 + .../tuscany/sca/host/rmi/DefaultRMIHost.java | 127 ++ .../sca/host/rmi/DefaultRMIHostExtensionPoint.java | 49 + .../tuscany/sca/host/rmi/ExtensibleRMIHost.java | 73 + .../org/apache/tuscany/sca/host/rmi/RMIHost.java | 90 ++ .../tuscany/sca/host/rmi/RMIHostException.java | 45 + .../sca/host/rmi/RMIHostExtensionPoint.java | 51 + .../sca/host/rmi/RMIHostRuntimeException.java | 46 + ...ache.tuscany.sca.host.rmi.RMIHostExtensionPoint | 18 + .../tuscany/sca/host/rmi/RMIHostImplTestCase.java | 90 ++ .../sca-java-1.6/modules/host-tomcat/LICENSE | 205 +++ .../sca-java-1.6/modules/host-tomcat/NOTICE | 6 + .../sca-java-1.6/modules/host-tomcat/pom.xml | 87 ++ .../tuscany/sca/http/tomcat/ServletWrapper.java | 58 + .../sca/http/tomcat/TomcatDefaultServlet.java | 114 ++ .../sca/http/tomcat/TomcatPolicyBaseRealm.java | 95 ++ .../tuscany/sca/http/tomcat/TomcatServer.java | 692 +++++++++ .../module/TomcatRuntimeModuleActivator.java | 69 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sca/http/tomcat/TomcatServerTestCase.java | 353 +++++ .../src/test/resources/content/test.html | 21 + .../src/test/resources/tuscany.keyStore | Bin 0 -> 1265 bytes .../sca-java-1.6/modules/host-webapp/LICENSE | 241 +++ .../sca-java-1.6/modules/host-webapp/NOTICE | 12 + .../sca-java-1.6/modules/host-webapp/pom.xml | 101 ++ .../sca/host/webapp/HotUpdateContextListener.java | 57 + .../tuscany/sca/host/webapp/SCADomainHelper.java | 72 + .../sca/host/webapp/TuscanyContextListener.java | 73 + .../tuscany/sca/host/webapp/TuscanyServlet.java | 67 + .../sca/host/webapp/TuscanyServletFilter.java | 104 ++ .../sca/host/webapp/WebAppModuleActivator.java | 72 + .../sca/host/webapp/WebAppRequestDispatcher.java | 114 ++ .../tuscany/sca/host/webapp/WebAppServletHost.java | 365 +++++ .../tuscany/sca/host/webapp/WebSCADomain.java | 53 + .../tuscany/sca/host/webapp/jsp/ReferenceTEI.java | 45 + .../tuscany/sca/host/webapp/jsp/ReferenceTag.java | 118 ++ .../src/main/resources/META-INF/sca.tld | 49 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../modules/implementation-bpel-ode/LICENSE | 251 +++ .../modules/implementation-bpel-ode/NOTICE | 17 + .../modules/implementation-bpel-ode/pom.xml | 450 ++++++ .../implementation/bpel/ode/BPELODEDeployFile.java | 225 +++ .../implementation/bpel/ode/EmbeddedODEServer.java | 270 ++++ .../implementation/bpel/ode/GeronimoTxFactory.java | 48 + .../implementation/bpel/ode/ODEBindingContext.java | 79 + .../sca/implementation/bpel/ode/ODEDeployment.java | 44 + .../bpel/ode/ODEDeploymentException.java | 41 + .../bpel/ode/ODEExternalService.java | 299 ++++ .../bpel/ode/ODEInitializationException.java | 41 + .../bpel/ode/ODEMessageExchangeContext.java | 57 + .../bpel/ode/ODEShutdownException.java | 41 + .../sca/implementation/bpel/ode/TuscanyEPR.java | 54 + .../sca/implementation/bpel/ode/TuscanyPRC.java | 75 + .../bpel/ode/TuscanyProcessConfImpl.java | 434 ++++++ .../ode/provider/BPELImplementationProvider.java | 145 ++ .../BPELImplementationProviderFactory.java | 69 + .../bpel/ode/provider/BPELInvoker.java | 251 +++ ...cany.sca.provider.ImplementationProviderFactory | 19 + .../bpel/ode/EmbeddedODEServerTestCase.java | 148 ++ .../src/test/resources/helloworld/greetings.wsdl | 87 ++ .../src/test/resources/helloworld/helloworld.bpel | 66 + .../src/test/resources/helloworld/helloworld.wsdl | 82 + .../src/test/resources/log4j.properties | 36 + .../modules/implementation-bpel/LICENSE | 251 +++ .../modules/implementation-bpel/NOTICE | 17 + .../modules/implementation-bpel/pom.xml | 98 ++ .../sca/implementation/bpel/BPELFactory.java | 42 + .../implementation/bpel/BPELImplementation.java | 91 ++ .../implementation/bpel/BPELProcessDefinition.java | 109 ++ .../implementation/bpel/impl/BPELFactoryImpl.java | 45 + .../bpel/impl/BPELImplementationImpl.java | 132 ++ .../bpel/impl/BPELProcessDefinitionImpl.java | 116 ++ .../bpel/xml/BPELDocumentModelResolver.java | 84 ++ .../bpel/xml/BPELDocumentProcessor.java | 532 +++++++ .../bpel/xml/BPELImplementationProcessor.java | 518 +++++++ .../implementation/bpel/xml/BPELImportElement.java | 65 + .../bpel/xml/BPELPartnerLinkElement.java | 130 ++ .../bpel/xml/BPELPartnerLinkTypeElement.java | 112 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...sca.contribution.processor.URLArtifactProcessor | 19 + ...tuscany.sca.contribution.resolver.ModelResolver | 18 + ...che.tuscany.sca.implementation.bpel.BPELFactory | 18 + .../impl-bpel-validation-messages.properties | 34 + .../bpel/BPELDocumentProcessorTestCase.java | 59 + .../bpel/BPELImplementationProcessorTestCase.java | 111 ++ .../src/test/resources/helloworld/helloworld.bpel | 66 + .../src/test/resources/helloworld/helloworld.wsdl | 82 + .../modules/implementation-ejb/LICENSE | 205 +++ .../sca-java-1.6/modules/implementation-ejb/NOTICE | 6 + .../modules/implementation-ejb/pom.xml | 93 ++ .../sca/implementation/ejb/EJBImplementation.java | 81 + .../ejb/EJBImplementationFactory.java | 36 + .../ejb/impl/EJBImplementationFactoryImpl.java | 39 + .../ejb/impl/EJBImplementationImpl.java | 194 +++ .../ejb/xml/EJBImplementationProcessor.java | 262 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...sca.implementation.ejb.EJBImplementationFactory | 19 + .../impl-ejb-validation-messages.properties | 21 + .../sca/implementation/ejb/xml/ReadTestCase.java | 84 ++ .../sca/implementation/ejb/xml/WriteTestCase.java | 68 + .../sca/implementation/ejb/xml/TestEJB.composite | 29 + .../modules/implementation-java-runtime/LICENSE | 205 +++ .../modules/implementation-java-runtime/NOTICE | 6 + .../modules/implementation-java-runtime/pom.xml | 81 + .../java/context/InstanceFactory.java | 43 + .../java/context/InstanceFactoryProvider.java | 49 + .../java/context/ReflectiveInstanceFactory.java | 86 ++ .../java/context/ReflectiveInstanceWrapper.java | 56 + .../injection/ArrayMultiplicityObjectFactory.java | 54 + .../java/injection/ContextInjector.java | 32 + .../injection/ConversationIDObjectFactory.java | 39 + .../java/injection/FieldInjector.java | 67 + .../java/injection/InjectionRuntimeException.java | 45 + .../implementation/java/injection/Injector.java | 35 + .../java/injection/InvalidAccessorException.java | 43 + .../injection/JavaPropertyValueObjectFactory.java | 331 ++++ .../injection/ListMultiplicityObjectFactory.java | 50 + .../java/injection/MethodInjector.java | 64 + .../injection/RequestContextObjectFactory.java | 55 + .../java/injection/ResourceHost.java | 46 + .../java/injection/ResourceNotFoundException.java | 51 + .../java/injection/ResourceObjectFactory.java | 87 ++ .../injection/ResourceResolutionException.java | 43 + .../java/invocation/EventInvocationException.java | 47 + .../java/invocation/EventInvoker.java | 34 + .../InvalidConversationSequenceException.java | 46 + .../JavaCallbackRuntimeWireProcessor.java | 106 ++ .../invocation/JavaComponentContextFactory.java | 40 + .../invocation/JavaComponentContextProvider.java | 409 +++++ .../java/invocation/JavaComponentNameFactory.java | 40 + .../java/invocation/JavaImplementationInvoker.java | 248 +++ .../invocation/JavaImplementationProvider.java | 204 +++ .../JavaImplementationProviderFactory.java | 76 + .../invocation/JavaInstanceFactoryProvider.java | 183 +++ .../JavaPolicyHandlingRuntimeWireProcessor.java | 126 ++ .../java/invocation/MethodEventInvoker.java | 56 + .../NoConversationalContractException.java | 34 + .../java/invocation/PolicyHandlingInterceptor.java | 74 + .../java/module/JavaRuntimeModuleActivator.java | 106 ++ ...apache.tuscany.sca.context.PropertyValueFactory | 17 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../java/context/MultiplicityTestCase.java | 34 + .../context/ReflectiveInstanceWrapperTestCase.java | 84 ++ .../CallbackWireObjectFactoryTestCase.java | 54 + .../java/injection/FieldInjectorTestCase.java | 49 + .../JavaPropertyValueObjectFactoryTestCase.java | 449 ++++++ .../java/injection/MethodEventInvokerTestCase.java | 76 + .../java/injection/MethodInjectorTestCase.java | 80 + .../RequestContextObjectFactoryTestCase.java | 33 + .../injection/ResourceObjectFactoryTestCase.java | 89 ++ .../java/injection/SingletonObjectFactory.java | 39 + .../injection/SingletonObjectFactoryTestCase.java | 33 + .../java/injection/TestObjectFactory.java | 120 ++ .../java/injection/TestObjectFactoryTestCase.java | 77 + .../sca/implementation/java/util/Bean1.java | 50 + .../sca/implementation/java/util/Bean2.java | 51 + .../sca/implementation/java/util/Entry.java | 32 + .../java/util/JavaIntrospectionHelperTestCase.java | 185 +++ .../sca/implementation/java/util/SuperBean.java | 48 + .../modules/implementation-java-xml/LICENSE | 205 +++ .../modules/implementation-java-xml/NOTICE | 6 + .../modules/implementation-java-xml/pom.xml | 112 ++ .../java/xml/JavaImplementationConstants.java | 36 + .../java/xml/JavaImplementationProcessor.java | 351 +++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../impl-javaxml-validation-messages.properties | 23 + .../src/test/java/calculator/AddService.java | 30 + .../src/test/java/calculator/AddServiceImpl.java | 37 + .../test/java/calculator/CalculatorService.java | 36 + .../java/calculator/CalculatorServiceImpl.java | 73 + .../src/test/java/calculator/DivideService.java | 30 + .../test/java/calculator/DivideServiceImpl.java | 35 + .../src/test/java/calculator/MultiplyService.java | 30 + .../test/java/calculator/MultiplyServiceImpl.java | 35 + .../src/test/java/calculator/SubtractService.java | 30 + .../test/java/calculator/SubtractServiceImpl.java | 35 + .../sca/implementation/java/xml/ReadTestCase.java | 224 +++ .../implementation/java/xml/TestModelResolver.java | 88 ++ .../sca/implementation/java/xml/WriteTestCase.java | 66 + .../implementation/java/xml/Calculator.composite | 66 + .../sca/implementation/java/xml/definitions.xml | 100 ++ .../java/xml/definitions_with_policysets.xml | 133 ++ .../modules/implementation-java/LICENSE | 205 +++ .../modules/implementation-java/NOTICE | 6 + .../modules/implementation-java/pom.xml | 84 ++ .../java/BaseJavaImplementation.java | 59 + .../java/DefaultJavaImplementationFactory.java | 33 + .../java/IntrospectionException.java | 60 + .../implementation/java/JavaImplementation.java | 198 +++ .../java/JavaImplementationFactory.java | 75 + .../java/impl/BaseJavaImplementationImpl.java | 89 ++ .../java/impl/JavaClassIntrospectorImpl.java | 141 ++ .../java/impl/JavaConstructorImpl.java | 53 + .../implementation/java/impl/JavaElementImpl.java | 225 +++ .../java/impl/JavaImplementationActivator.java | 86 ++ .../java/impl/JavaImplementationFactoryImpl.java | 77 + .../java/impl/JavaImplementationImpl.java | 168 +++ .../java/impl/JavaParameterImpl.java | 35 + .../implementation/java/impl/JavaResourceImpl.java | 85 ++ .../implementation/java/impl/JavaScopeImpl.java | 66 + .../java/introspect/JavaClassVisitor.java | 126 ++ .../introspect/impl/AbstractPropertyProcessor.java | 192 +++ .../impl/AllowsPassByReferenceProcessor.java | 51 + .../impl/AmbiguousConstructorException.java | 40 + .../java/introspect/impl/BaseJavaClassVisitor.java | 64 + .../introspect/impl/ComponentNameProcessor.java | 80 + .../java/introspect/impl/ConstructorProcessor.java | 83 + .../java/introspect/impl/ContextProcessor.java | 82 + .../introspect/impl/ConversationIDProcessor.java | 70 + .../introspect/impl/ConversationProcessor.java | 132 ++ .../java/introspect/impl/DestroyProcessor.java | 61 + .../impl/DuplicateConstructorException.java | 41 + .../impl/DuplicateDestructorException.java | 35 + .../introspect/impl/DuplicateInitException.java | 35 + .../impl/DuplicatePropertyException.java | 34 + .../impl/DuplicateReferenceException.java | 35 + .../impl/DuplicateResourceException.java | 36 + .../java/introspect/impl/EagerInitProcessor.java | 57 + .../introspect/impl/HeuristicPojoProcessor.java | 615 ++++++++ .../impl/IllegalCallbackReferenceException.java | 40 + .../introspect/impl/IllegalContextException.java | 40 + .../impl/IllegalDestructorException.java | 40 + .../java/introspect/impl/IllegalInitException.java | 40 + .../introspect/impl/IllegalPropertyException.java | 40 + .../introspect/impl/IllegalReferenceException.java | 40 + .../introspect/impl/IllegalResourceException.java | 40 + .../impl/IllegalServiceDefinitionException.java | 35 + .../java/introspect/impl/InitProcessor.java | 61 + .../impl/InvalidConstructorException.java | 36 + .../impl/InvalidConversationalImplementation.java | 39 + .../introspect/impl/InvalidPropertyException.java | 35 + .../introspect/impl/InvalidReferenceException.java | 42 + .../introspect/impl/InvalidResourceException.java | 40 + .../java/introspect/impl/InvalidServiceType.java | 48 + .../introspect/impl/JavaIntrospectionHelper.java | 577 +++++++ .../introspect/impl/NoConstructorException.java | 37 + .../java/introspect/impl/PolicyProcessor.java | 292 ++++ .../java/introspect/impl/PropertyProcessor.java | 46 + .../java/introspect/impl/ReferenceProcessor.java | 208 +++ .../java/introspect/impl/Resource.java | 49 + .../java/introspect/impl/ResourceProcessor.java | 137 ++ .../java/introspect/impl/ScopeProcessor.java | 61 + .../java/introspect/impl/ServiceProcessor.java | 184 +++ .../impl/ServiceTypeNotFoundException.java | 35 + .../impl/UnknownContextTypeException.java | 33 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + ...a.implementation.java.JavaImplementationFactory | 18 + .../introspect/impl/AbstractProcessorTest.java | 76 + .../impl/AbstractPropertyProcessorTestCase.java | 169 +++ .../AllowsPassByReferenceProcessorTestCase.java | 71 + .../impl/ConstructorProcessorTestCase.java | 192 +++ .../impl/ConstructorPropertyTestCase.java | 157 ++ .../impl/ConstructorReferenceTestCase.java | 167 ++ .../impl/ConstructorResourceTestCase.java | 152 ++ .../introspect/impl/ContextProcessorTestCase.java | 201 +++ .../impl/ConversationIDProcessorTestCase.java | 94 ++ .../impl/ConversationProcessorTestCase.java | 144 ++ .../introspect/impl/ConvertTimeMillisTestCase.java | 117 ++ .../introspect/impl/DestroyProcessorTestCase.java | 129 ++ .../impl/EagerInitProcessorTestCase.java | 59 + .../impl/HeuristicAndPropertyTestCase.java | 71 + .../impl/HeuristicConstructorTestCase.java | 310 ++++ .../impl/HeuristicPojoProcessorTestCase.java | 562 +++++++ .../HeutisticExtensibleConstructorTestCase.java | 148 ++ .../introspect/impl/InitProcessorTestCase.java | 145 ++ .../impl/JavaClassIntrospectorImplTestCase.java | 95 ++ .../java/introspect/impl/ModelHelper.java | 99 ++ .../introspect/impl/PolicyProcessorTestCase.java | 418 +++++ .../introspect/impl/PropertyProcessorTestCase.java | 212 +++ .../impl/ReferenceProcessorTestCase.java | 221 +++ .../introspect/impl/ResourceProcessorTestCase.java | 119 ++ .../introspect/impl/ScopeProcessorTestCase.java | 113 ++ .../introspect/impl/ServiceCallbackTestCase.java | 183 +++ .../introspect/impl/ServiceProcessorTestCase.java | 158 ++ .../modules/implementation-jee/LICENSE | 205 +++ .../sca-java-1.6/modules/implementation-jee/NOTICE | 6 + .../modules/implementation-jee/pom.xml | 97 ++ .../sca/implementation/jee/JEEImplementation.java | 43 + .../jee/JEEImplementationFactory.java | 36 + .../jee/impl/JEEImplementationFactoryImpl.java | 38 + .../jee/impl/JEEImplementationImpl.java | 61 + .../jee/xml/JEEImplementationProcessor.java | 330 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 21 + ...sca.implementation.jee.JEEImplementationFactory | 21 + .../sca/implementation/jee/xml/ReadTestCase.java | 88 ++ .../sca/implementation/jee/xml/WriteTestCase.java | 68 + .../src/test/java/test/Helloworld.java | 25 + .../test/MockImplementationProviderFactory.java | 44 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../sca/implementation/jee/xml/TestJEE.composite | 32 + .../modules/implementation-node-runtime/LICENSE | 205 +++ .../modules/implementation-node-runtime/NOTICE | 6 + .../modules/implementation-node-runtime/pom.xml | 103 ++ .../NodeImplementationDaemonBootstrap.java | 85 ++ .../NodeImplementationLauncherBootstrap.java | 149 ++ .../launcher/NodeImplementationLauncherUtil.java | 51 + .../node/provider/NodeImplementationInvoker.java | 44 + .../node/provider/NodeImplementationProvider.java | 62 + .../NodeImplementationProviderFactory.java | 49 + .../node/webapp/NodeWebAppRequestDispatcher.java | 119 ++ .../node/webapp/NodeWebAppServletHost.java | 397 +++++ ...cany.sca.provider.ImplementationProviderFactory | 19 + .../node/NodeImplementationTestCase.java | 48 + .../src/test/resources/TestComposite.composite | 29 + .../src/test/resources/TestNode.composite | 30 + .../modules/implementation-node/LICENSE | 205 +++ .../modules/implementation-node/NOTICE | 6 + .../modules/implementation-node/pom.xml | 93 ++ .../node/ConfiguredNodeImplementation.java | 54 + .../implementation/node/NodeImplementation.java | 45 + .../node/NodeImplementationFactory.java | 42 + .../builder/impl/NodeCompositeBuilderImpl.java | 111 ++ .../impl/ConfiguredNodeImplementationImpl.java | 104 ++ .../node/impl/NodeImplementationFactoryImpl.java | 44 + .../node/impl/NodeImplementationImpl.java | 97 ++ .../xml/ConfiguredNodeImplementationProcessor.java | 196 +++ .../node/xml/NodeImplementationProcessor.java | 119 ++ ...ca.contribution.processor.StAXArtifactProcessor | 20 + ...a.implementation.node.NodeImplementationFactory | 19 + .../builder/impl/CalculateBindingURITestCase.java | 603 ++++++++ .../sca/implementation/node/xml/ReadTestCase.java | 81 + .../sca/implementation/node/xml/WriteTestCase.java | 65 + .../node/xml/TestComposite.composite | 29 + .../sca/implementation/node/xml/TestNode.composite | 64 + .../modules/implementation-notification/LICENSE | 205 +++ .../modules/implementation-notification/NOTICE | 6 + .../modules/implementation-notification/pom.xml | 110 ++ .../DefaultNotificationImplementationFactory.java | 33 + .../notification/ImmutableMessage.java | 105 ++ .../notification/NotificationComponentInvoker.java | 112 ++ .../NotificationImplementationFactory.java | 27 + .../NotificationImplementationImpl.java | 96 ++ .../NotificationImplementationProcessor.java | 99 ++ .../NotificationImplementationProvider.java | 67 + .../NotificationImplementationProviderFactory.java | 38 + .../notification/NotificationModuleActivator.java | 49 + .../org.apache.tuscany.sca.core.ModuleActivator | 19 + .../NotificationComponentTestCase.java | 136 ++ .../NotificationImplementationLoaderTestCase.java | 56 + ...afficAdvisoryNotificationTestCase.componentType | 30 + .../modules/implementation-openjpa/LICENSE | 205 +++ .../modules/implementation-openjpa/NOTICE | 6 + .../modules/implementation-openjpa/README | 33 + .../modules/implementation-openjpa/pom.xml | 132 ++ .../implementation/openjpa/JPAImplementation.java | 36 + .../openjpa/JPAImplementationFactory.java | 24 + .../openjpa/JPAImplementationProcessor.java | 99 ++ .../openjpa/PersistenceUnitInfoImplProcessor.java | 109 ++ .../openjpa/TuscanyBrokerFactory.java | 100 ++ .../implementation/openjpa/TuscanyBrokerImpl.java | 37 + .../openjpa/TuscanyJDBCConfigurationImpl.java | 59 + .../openjpa/TuscanyManagerRuntime.java | 51 + .../openjpa/TuscanyStoreManager.java | 49 + .../openjpa/impl/JPAImplementationFactoryImpl.java | 39 + .../openjpa/impl/JPAImplementationImpl.java | 119 ++ .../provider/JPAImplementationProvider.java | 101 ++ .../provider/JPAImplementationProviderFactory.java | 45 + .../openjpa/provider/JPAInvoker.java | 63 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...ementation.openjpa.OpenJpaImplementationFactory | 18 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../implementation/openjpa/ImplJpaTestCase.java | 69 + .../src/test/java/sample/Abc.java | 34 + .../src/test/java/sample/Message.java | 72 + .../src/test/java/sample/MyObject.java | 33 + .../src/test/resources/openjpa.composite | 44 + .../modules/implementation-openjpa/test/db.lck | Bin 0 -> 38 bytes .../implementation-openjpa/test/log/log.ctrl | Bin 0 -> 48 bytes .../implementation-openjpa/test/log/log1.dat | Bin 0 -> 1048576 bytes .../implementation-openjpa/test/log/logmirror.ctrl | Bin 0 -> 48 bytes .../implementation-openjpa/test/seg0/c10.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c101.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c111.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c121.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c130.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c141.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c150.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c161.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c171.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c180.dat | Bin 0 -> 24576 bytes .../implementation-openjpa/test/seg0/c191.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c1a1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c1b1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c1c0.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c1d1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c1e0.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c1f1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c20.dat | Bin 0 -> 20480 bytes .../implementation-openjpa/test/seg0/c200.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c211.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c221.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c230.dat | Bin 0 -> 118784 bytes .../implementation-openjpa/test/seg0/c241.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c251.dat | Bin 0 -> 12288 bytes .../implementation-openjpa/test/seg0/c260.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c271.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c281.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c290.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c2a1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c2b1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c2c1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c2d0.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c2e1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c2f0.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c300.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c31.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c311.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c320.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c331.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c41.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c51.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c60.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c71.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c81.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/c90.dat | Bin 0 -> 20480 bytes .../implementation-openjpa/test/seg0/ca1.dat | Bin 0 -> 20480 bytes .../implementation-openjpa/test/seg0/cb1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/cc0.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/cd1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/ce1.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/seg0/cf0.dat | Bin 0 -> 8192 bytes .../implementation-openjpa/test/service.properties | 22 + .../modules/implementation-osgi/LICENSE | 203 +++ .../modules/implementation-osgi/NOTICE | 6 + .../modules/implementation-osgi/pom.xml | 164 ++ .../implementation/osgi/OSGiImplementation.java | 45 + .../osgi/context/OSGiAnnotations.java | 325 ++++ .../osgi/context/OSGiPropertyInjector.java | 293 ++++ .../context/OSGiPropertyValueObjectFactory.java | 226 +++ .../osgi/impl/OSGiImplementationImpl.java | 168 +++ .../osgi/runtime/OSGiImplementationProvider.java | 1254 +++++++++++++++ .../runtime/OSGiImplementationProviderFactory.java | 109 ++ .../osgi/runtime/OSGiInstanceWrapper.java | 299 ++++ .../osgi/runtime/OSGiRemotableInvoker.java | 139 ++ .../osgi/runtime/OSGiTargetInvoker.java | 199 +++ .../osgi/xml/OSGiImplementationProcessor.java | 550 +++++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../impl-osgi-validation-messages.properties | 25 + .../osgi/runtime/OSGiPropertyTestCase.java | 49 + .../implementation/osgi/runtime/OSGiTestCase.java | 74 + .../implementation/osgi/test/OSGiTestBundles.java | 116 ++ .../sca/implementation/osgi/test/OSGiTestImpl.java | 51 + .../osgi/test/OSGiTestInterface.java | 32 + .../osgi/test/OSGiTestWithPropertyImpl.java | 66 + .../osgi/xml/OSGiReadImplTestCase.java | 132 ++ .../implementation/osgi/xml/TestModelResolver.java | 106 ++ .../test/resources/OSGiTestService.componentType | 28 + .../src/test/resources/osgiproptest.composite | 37 + .../src/test/resources/osgitest.composite | 36 + .../implementation-resource-runtime/LICENSE | 205 +++ .../modules/implementation-resource-runtime/NOTICE | 6 + .../implementation-resource-runtime/pom.xml | 86 ++ .../resource/provider/GetResourceInvoker.java | 67 + .../provider/ResourceImplementationProvider.java | 75 + .../ResourceImplementationProviderFactory.java | 47 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../resource/ResourceImplementationTestCase.java | 77 + .../src/test/resources/content/test.html | 21 + .../src/test/resources/resource.composite | 30 + .../modules/implementation-resource/LICENSE | 205 +++ .../modules/implementation-resource/NOTICE | 6 + .../modules/implementation-resource/pom.xml | 79 + .../sca/implementation/resource/Resource.java | 34 + .../resource/ResourceImplementation.java | 57 + .../resource/ResourceImplementationFactory.java | 35 + .../impl/ResourceImplementationFactoryImpl.java | 47 + .../resource/impl/ResourceImplementationImpl.java | 130 ++ .../impl/ResourceImplementationProcessor.java | 167 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...entation.resource.ResourceImplementationFactory | 19 + .../impl-resource-validation-messages.properties | 23 + .../modules/implementation-script/LICENSE | 251 +++ .../modules/implementation-script/NOTICE | 12 + .../modules/implementation-script/pom.xml | 197 +++ .../script/ScriptImplementation.java | 99 ++ .../script/ScriptImplementationActivator.java | 49 + .../sca/implementation/script/ScriptInvoker.java | 84 ++ .../script/ScriptInvokerFactory.java | 172 +++ .../script/engines/TuscanyJRubyScriptEngine.java | 697 +++++++++ ...ny.sca.extension.helper.ImplementationActivator | 18 + .../script/itests/AbstractSCATestCase.java | 54 + .../itests/dynamic/AbstractHelloWorldTestCase.java | 38 + .../script/itests/dynamic/HelloWorld.java | 31 + .../dynamic/JavaScriptDynamicRefTestCase.java | 29 + .../dynamic/JavaScriptHelloWorldTestCase.java | 34 + .../helloworld/AbstractHelloWorldTestCase.java | 38 + .../helloworld/GroovyHelloWorldTestCase.java | 29 + .../script/itests/helloworld/HelloWorld.java | 30 + .../script/itests/helloworld/HelloWorldProxy.java | 37 + .../itests/helloworld/JRubyHelloWorldTestCase.java | 29 + .../JavaScripInlineHelloWorldTestCase.java | 29 + .../helloworld/JavaScriptHelloWorldTestCase.java | 29 + .../helloworld/JythonHelloWorldTestCase.java | 29 + .../properties/AbstractHelloWorldTestCase.java | 38 + .../properties/GroovyHelloWorldTestCase.java | 29 + .../script/itests/properties/HelloWorld.java | 30 + .../script/itests/properties/HelloWorldProxy.java | 37 + .../itests/properties/JRubyHelloWorldTestCase.java | 28 + .../properties/JavaScriptHelloWorldTestCase.java | 29 + .../properties/JythonHelloWorldTestCase.java | 29 + .../itests/references/GroovyReferenceTestCase.java | 29 + .../script/itests/references/HelloWorldTarget.java | 34 + .../itests/references/JRubyReferenceTestCase.java | 29 + .../references/JavaScriptReferenceTestCase.java | 29 + .../itests/references/JythonReferenceTestCase.java | 29 + .../itests/dynamic/JavaScriptDynamicRef.composite | 35 + .../itests/dynamic/JavaScriptHelloWorld.composite | 30 + .../script/itests/dynamic/helloworld.js | 26 + .../script/itests/dynamic/helloworldProxy.js | 22 + .../itests/helloworld/GroovyHelloWorld.composite | 33 + .../itests/helloworld/JRubyHelloWorld.composite | 33 + .../helloworld/JavaScripInlineHelloWorld.composite | 34 + .../helloworld/JavaScriptHelloWorld.composite | 33 + .../itests/helloworld/JythonHelloWorld.composite | 33 + .../itests/helloworld/helloworld.componentType | 30 + .../script/itests/helloworld/helloworld.groovy | 22 + .../script/itests/helloworld/helloworld.js | 23 + .../script/itests/helloworld/helloworld.py | 20 + .../script/itests/helloworld/helloworld.rb | 21 + .../itests/properties/GroovyHelloWorld.composite | 33 + .../itests/properties/JRubyHelloWorld.composite | 33 + .../properties/JavaScriptHelloWorld.composite | 33 + .../itests/properties/JythonHelloWorld.composite | 33 + .../itests/properties/helloworld.componentType | 32 + .../script/itests/properties/helloworld.groovy | 22 + .../script/itests/properties/helloworld.js | 23 + .../script/itests/properties/helloworld.py | 20 + .../script/itests/properties/helloworld.rb | 21 + .../itests/references/GroovyReference.composite | 38 + .../itests/references/JRubyReference.composite | 38 + .../references/JavaScriptReference.composite | 38 + .../itests/references/JythonReference.composite | 38 + .../itests/references/reference.componentType | 31 + .../script/itests/references/reference.groovy | 22 + .../script/itests/references/reference.js | 22 + .../script/itests/references/reference.py | 20 + .../script/itests/references/reference.rb | 21 + .../modules/implementation-spring-old/LICENSE | 205 +++ .../modules/implementation-spring-old/NOTICE | 6 + .../modules/implementation-spring-old/pom.xml | 119 ++ .../spring/SCAApplicationContext.java | 53 + .../spring/SCANamespaceHandlerResolver.java | 53 + .../spring/SCAParentApplicationContext.java | 271 ++++ .../implementation/spring/ScaNamespaceHandler.java | 38 + .../spring/ScaPropertyBeanDefinitionParser.java | 35 + .../spring/ScaReferenceBeanDefinitionParser.java | 36 + .../spring/ScaServiceBeanDefinitionParser.java | 36 + .../spring/SpringBeanNotFoundException.java | 39 + .../spring/SpringImplementation.java | 227 +++ .../spring/SpringImplementationProcessor.java | 230 +++ .../spring/SpringImplementationProvider.java | 201 +++ .../SpringImplementationProviderFactory.java | 85 ++ .../spring/SpringInvocationException.java | 40 + .../sca/implementation/spring/SpringInvoker.java | 127 ++ .../spring/SpringOperationNotFoundException.java | 40 + .../spring/SpringPropertyValueObjectFactory.java | 45 + .../ComponentNameAnnotationProcessor.java | 151 ++ .../processor/ConstructorAnnotationProcessor.java | 119 ++ .../processor/InitDestroyAnnotationProcessor.java | 72 + .../processor/PropertyAnnotationProcessor.java | 220 +++ .../processor/ReferenceAnnotationProcessor.java | 186 +++ .../sca/implementation/spring/xml/Constants.java | 64 + .../spring/xml/SpringBeanElement.java | 76 + .../spring/xml/SpringBeanIntrospector.java | 133 ++ .../spring/xml/SpringBeanPojoProcessor.java | 656 ++++++++ .../spring/xml/SpringConstructorArgElement.java | 78 + .../spring/xml/SpringPropertyElement.java | 61 + .../spring/xml/SpringSCAPropertyElement.java | 52 + .../spring/xml/SpringSCAReferenceElement.java | 54 + .../spring/xml/SpringSCAServiceElement.java | 64 + .../spring/xml/SpringXMLComponentTypeLoader.java | 739 +++++++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../src/main/resources/META-INF/spring.handlers | 1 + .../src/main/resources/META-INF/spring.schemas | 1 + .../impl-spring-validation-messages.properties | 23 + .../org/springframework/sca/xml/spring-sca.xsd | 99 ++ .../spring/itests/AbstractSCATestCase.java | 55 + .../helloworld/AbstractHelloWorldTestCase.java | 43 + .../spring/itests/helloworld/HelloWorld.java | 35 + .../spring/itests/helloworld/HelloWorldImpl.java | 38 + .../spring/itests/helloworld/HelloWorldProxy.java | 42 + .../helloworld/SpringContextAccessTestCase.java | 35 + .../SpringExplicitHelloWorldTestCase.java | 34 + .../SpringExplicitReferenceTestCase.java | 39 + .../helloworld/SpringHelloWorldTestCase.java | 32 + .../SpringImplicitReferenceTestCase.java | 42 + .../helloworld/SpringImportHelloWorldTestCase.java | 32 + .../helloworld/SpringSCAPropertyTestCase.java | 39 + .../spring/itests/mock/TestBean.java | 31 + .../spring/itests/mock/TestBeanImpl.java | 42 + .../spring/itests/mock/TestContextAccessBean.java | 77 + .../spring/itests/mock/TestHelloWorldBean.java | 39 + .../spring/itests/mock/TestReference.java | 27 + .../spring/itests/mock/TestReferenceBean.java | 57 + .../spring/itests/mock/TestSCAPropertyBean.java | 55 + .../META-INF/sca/SpringContextAccess-context.xml | 31 + .../sca/SpringExplicitHelloWorld-context.xml | 39 + .../sca/SpringExplicitReference-context.xml | 33 + .../sca/SpringHelloWorld-Imported-context.xml | 31 + .../META-INF/sca/SpringHelloWorld-context.xml | 31 + .../sca/SpringImplicitReference-context.xml | 34 + .../sca/SpringImportHelloWorld-context.xml | 29 + .../META-INF/sca/testReferenceContext.xml | 33 + .../resources/META-INF/sca/testServiceContext.xml | 31 + .../helloworld/SpringContextAccess.composite | 35 + .../helloworld/SpringExplicitHelloWorld.composite | 33 + .../helloworld/SpringExplicitReference.composite | 32 + .../itests/helloworld/SpringHelloWorld.composite | 32 + .../helloworld/SpringImplicitReference.composite | 39 + .../helloworld/SpringImportHelloWorld.composite | 32 + .../itests/helloworld/SpringSCAProperty.composite | 39 + .../src/test/resources/spring/META-INF/MANIFEST.MF | 3 + .../META-INF/spring/SpringSCAProperty-context.xml | 38 + .../src/test/resources/test.xml | 27 + .../modules/implementation-spring-runtime/LICENSE | 205 +++ .../modules/implementation-spring-runtime/NOTICE | 6 + .../modules/implementation-spring-runtime/README | 9 + .../modules/implementation-spring-runtime/pom.xml | 90 ++ .../namespace/SCANamespaceHandlerResolver.java | 53 + .../spring/namespace/ScaNamespaceHandler.java | 38 + .../namespace/ScaPropertyBeanDefinitionParser.java | 35 + .../ScaReferenceBeanDefinitionParser.java | 36 + .../namespace/ScaServiceBeanDefinitionParser.java | 36 + .../ComponentNameAnnotationProcessor.java | 150 ++ .../spring/processor/ComponentStub.java | 54 + .../processor/ConstructorAnnotationProcessor.java | 115 ++ .../processor/InitDestroyAnnotationProcessor.java | 75 + .../processor/PropertyAnnotationProcessor.java | 161 ++ .../spring/processor/PropertyValueStub.java | 55 + .../processor/ReferenceAnnotationProcessor.java | 164 ++ .../context/SCAGenericApplicationContext.java | 29 + .../context/SCAParentApplicationContext.java | 190 +++ .../spring/runtime/context/SpringContextTie.java | 149 ++ .../runtime/context/SpringImplementationStub.java | 129 ++ .../src/main/resources/META-INF/spring.handlers | 1 + .../src/main/resources/META-INF/spring.schemas | 1 + .../org/springframework/sca/xml/spring-sca.xsd | 84 ++ .../modules/implementation-spring/LICENSE | 205 +++ .../modules/implementation-spring/NOTICE | 6 + .../modules/implementation-spring/README | 9 + .../modules/implementation-spring/pom.xml | 109 ++ .../implementation/spring/SpringBeanElement.java | 76 + .../spring/SpringConstructorArgElement.java | 78 + .../spring/SpringImplementation.java | 226 +++ .../spring/SpringImplementationConstants.java | 64 + .../spring/SpringPropertyElement.java | 61 + .../spring/SpringSCAPropertyElement.java | 52 + .../spring/SpringSCAReferenceElement.java | 54 + .../spring/SpringSCAServiceElement.java | 64 + .../spring/introspect/SpringBeanIntrospector.java | 135 ++ .../spring/introspect/SpringBeanPojoProcessor.java | 656 ++++++++ .../introspect/SpringXMLComponentTypeLoader.java | 859 +++++++++++ .../spring/invocation/ComponentTie.java | 41 + .../ConfigurationPropertiesExtensionPoint.java | 9 + ...faultConfigurationPropertiesExtensionPoint.java | 27 + .../spring/invocation/PropertyValueTie.java | 53 + .../spring/invocation/SpringContextStub.java | 138 ++ .../invocation/SpringImplementationProvider.java | 87 ++ .../SpringImplementationProviderFactory.java | 89 ++ .../spring/invocation/SpringImplementationTie.java | 147 ++ .../invocation/SpringInvocationException.java | 40 + .../spring/invocation/SpringInvoker.java | 124 ++ .../spring/xml/SpringImplementationProcessor.java | 234 +++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...on.spring.ConfigurationPropertiesExtensionPoint | 18 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../impl-spring-validation-messages.properties | 23 + .../modules/implementation-web-runtime/LICENSE | 203 +++ .../modules/implementation-web-runtime/NOTICE | 9 + .../modules/implementation-web-runtime/pom.xml | 116 ++ .../web/ComponentContextServlet.java | 156 ++ .../implementation/web/ContextScriptProcessor.java | 32 + .../web/ContextScriptProcessorExtensionPoint.java | 27 + ...efaultContextScriptProcessorExtensionPoint.java | 51 + .../implementation/web/JSONRPCScripProcessor.java | 57 + .../web/runtime/ComponentContextProxy.java | 88 ++ .../runtime/WebImplementationProviderFactory.java | 78 + ...tation.web.ContextScriptProcessorExtensionPoint | 19 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../src/main/resources/jsonrpc.js | 493 ++++++ .../modules/implementation-web/LICENSE | 205 +++ .../sca-java-1.6/modules/implementation-web/NOTICE | 6 + .../modules/implementation-web/pom.xml | 100 ++ .../sca/implementation/web/WebImplementation.java | 71 + .../web/WebImplementationFactory.java | 34 + .../web/impl/WebImplementationFactoryImpl.java | 37 + .../web/impl/WebImplementationImpl.java | 168 +++ .../web/introspect/PropertyProcessor.java | 154 ++ .../web/introspect/ReferenceProcessor.java | 181 +++ .../web/xml/WebImplementationProcessor.java | 230 +++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...sca.implementation.web.WebImplementationFactory | 19 + .../sca/implementation/web/xml/ReadTestCase.java | 81 + .../sca/implementation/web/xml/WriteTestCase.java | 66 + .../sca/implementation/web/xml/TestWeb.composite | 29 + .../implementation-widget-runtime-dojo/LICENSE | 205 +++ .../implementation-widget-runtime-dojo/NOTICE | 6 + .../implementation-widget-runtime-dojo/pom.xml | 67 + .../dojo/DojoJavaScriptComponentGeneratorImpl.java | 208 +++ ...sca.web.javascript.ComponentJavaScriptGenerator | 19 + .../implementation-widget-runtime-tuscany/LICENSE | 205 +++ .../implementation-widget-runtime-tuscany/NOTICE | 6 + .../implementation-widget-runtime-tuscany/pom.xml | 110 ++ .../TuscanyJavaScriptComponentGeneratorImpl.java | 203 +++ ...sca.web.javascript.ComponentJavaScriptGenerator | 19 + .../widget/WidgetImplementationTestCase.java | 48 + .../src/test/java/store/Catalog.java | 32 + .../src/test/java/store/CatalogImpl.java | 47 + .../src/test/java/store/ShoppingCartImpl.java | 124 ++ .../src/test/resources/content/store.html | 127 ++ .../src/test/resources/content/storeJS.html | 152 ++ .../src/test/resources/content/unitTests.html | 250 +++ .../src/test/resources/widget.composite | 54 + .../src/test/resources/widgetJS.composite | 58 + .../modules/implementation-widget-runtime/LICENSE | 205 +++ .../modules/implementation-widget-runtime/NOTICE | 6 + .../modules/implementation-widget-runtime/pom.xml | 92 ++ .../provider/WidgetComponentScriptGenerator.java | 218 +++ .../provider/WidgetComponentScriptServlet.java | 62 + .../provider/WidgetImplementationInvoker.java | 101 ++ .../provider/WidgetImplementationProvider.java | 126 ++ .../WidgetImplementationProviderFactory.java | 59 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../src/main/resources/atomModel.js | 1590 ++++++++++++++++++++ .../src/main/resources/binding-http.js | 105 ++ .../modules/implementation-widget/LICENSE | 205 +++ .../modules/implementation-widget/NOTICE | 6 + .../modules/implementation-widget/pom.xml | 79 + .../tuscany/sca/implementation/widget/Widget.java | 34 + .../widget/WidgetImplementation.java | 40 + .../widget/WidgetImplementationFactory.java | 31 + .../widget/WidgetImplementationIntrospector.java | 145 ++ .../widget/WidgetImplementationProcessor.java | 172 +++ .../impl/WidgetImplementationFactoryImpl.java | 47 + .../widget/impl/WidgetImplementationImpl.java | 135 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...plementation.widget.WidgetImplementationFactory | 19 + .../impl-widget-validation-messages.properties | 23 + .../modules/implementation-xquery/LICENSE | 202 +++ .../modules/implementation-xquery/NOTICE | 6 + .../modules/implementation-xquery/pom.xml | 105 ++ .../xquery/XQueryImplementation.java | 75 + .../xquery/XQueryImplementationFactory.java | 32 + .../xquery/XQueryImplementationProvider.java | 166 ++ .../XQueryImplementationProviderFactory.java | 51 + .../xquery/XQueryInvokationException.java | 33 + .../sca/implementation/xquery/XQueryInvoker.java | 318 ++++ .../impl/XQueryImplementationFactoryImpl.java | 35 + .../xquery/impl/XQueryImplementationImpl.java | 102 ++ .../xquery/xml/XQueryImplementationProcessor.java | 159 ++ .../xquery/xml/XQueryIntrospector.java | 328 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../impl-xquery-validation-messages.properties | 22 + .../modules/interface-java-jaxws/LICENSE | 205 +++ .../modules/interface-java-jaxws/NOTICE | 6 + .../modules/interface-java-jaxws/pom.xml | 313 ++++ .../interfacedef/java/jaxws/BaseBeanGenerator.java | 539 +++++++ .../java/jaxws/CodeGenerationHelper.java | 280 ++++ .../java/jaxws/FaultBeanGenerator.java | 147 ++ .../java/jaxws/GeneratedClassLoader.java | 69 + .../java/jaxws/GeneratedDataTypeImpl.java | 143 ++ .../java/jaxws/JAXWSFaultExceptionMapper.java | 403 +++++ .../java/jaxws/JAXWSJavaInterfaceProcessor.java | 454 ++++++ .../java/jaxws/WebServiceInterfaceProcessor.java | 49 + .../java/jaxws/WrapperBeanGenerator.java | 238 +++ ...e.tuscany.sca.interfacedef.FaultExceptionMapper | 17 + .../tuscany/sca/interfacedef/java/jaxws/Bean.java | 27 + .../tuscany/sca/interfacedef/java/jaxws/Bean1.java | 40 + .../tuscany/sca/interfacedef/java/jaxws/Bean2.java | 40 + .../java/jaxws/FaultBeanGeneratorTestCase.java | 62 + .../jaxws/JAXWSJavaInterfaceProcessorTestCase.java | 119 ++ .../java/jaxws/JavaReflectionHelperTestCase.java | 48 + .../sca/interfacedef/java/jaxws/MyException.java | 62 + .../sca/interfacedef/java/jaxws/MyServiceImpl.java | 52 + .../interfacedef/java/jaxws/TestGenericClass.java | 40 + .../sca/interfacedef/java/jaxws/TestInterface.java | 66 + .../java/jaxws/WrapperBeanGeneratorTestCase.java | 79 + .../src/test/resources/wsdl/Stock.wsdl | 142 ++ .../test/resources/wsdl/StockExceptionTest.wsdl | 149 ++ .../modules/interface-java-xml/LICENSE | 205 +++ .../sca-java-1.6/modules/interface-java-xml/NOTICE | 6 + .../modules/interface-java-xml/pom.xml | 83 + .../sca/interfacedef/java/xml/JavaConstants.java | 37 + .../java/xml/JavaInterfaceProcessor.java | 227 +++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...nterface-javaxml-validation-messages.properties | 22 + .../sca/interfacedef/java/xml/ReadTestCase.java | 100 ++ .../sca/interfacedef/java/xml/WriteTestCase.java | 83 + .../sca/interfacedef/java/xml/Calculator.composite | 53 + .../java/xml/CalculatorComponent.constrainingType | 34 + .../java/xml/CalculatorImpl.componentType | 31 + .../sca-java-1.6/modules/interface-java/LICENSE | 205 +++ .../sca-java-1.6/modules/interface-java/NOTICE | 6 + .../sca-java-1.6/modules/interface-java/pom.xml | 82 + .../java/DefaultJavaInterfaceFactory.java | 99 ++ .../sca/interfacedef/java/JavaInterface.java | 87 ++ .../interfacedef/java/JavaInterfaceContract.java | 33 + .../interfacedef/java/JavaInterfaceFactory.java | 82 + .../sca/interfacedef/java/JavaOperation.java | 57 + .../impl/ClassCachedJavaInterfaceFactoryImpl.java | 129 ++ .../java/impl/JavaInterfaceContractImpl.java | 54 + .../java/impl/JavaInterfaceFactoryImpl.java | 84 ++ .../interfacedef/java/impl/JavaInterfaceImpl.java | 139 ++ .../java/impl/JavaInterfaceIntrospectorImpl.java | 276 ++++ .../interfacedef/java/impl/JavaInterfaceUtil.java | 225 +++ .../interfacedef/java/impl/JavaOperationImpl.java | 83 + .../java/impl/PolicyJavaInterfaceVisitor.java | 159 ++ .../java/introspect/JavaInterfaceVisitor.java | 39 + ...cany.sca.interfacedef.java.JavaInterfaceFactory | 18 + ...avaInterfaceUtilDuplicateRemotableTestCase.java | 308 ++++ .../java/impl/JavaInterfaceUtilTestCase.java | 121 ++ .../impl/ConversationalIntrospectionTestCase.java | 98 ++ ...JavaInterfaceProcessorRegistryImplTestCase.java | 107 ++ .../impl/PolicyProcessorTestCase.java | 108 ++ .../modules/interface-wsdl-xml/LICENSE | 205 +++ .../sca-java-1.6/modules/interface-wsdl-xml/NOTICE | 6 + .../modules/interface-wsdl-xml/pom.xml | 95 ++ .../wsdl/xml/BPELExtensionHandler.java | 140 ++ .../wsdl/xml/BPELPartnerLinkTypeExt.java | 79 + .../sca/interfacedef/wsdl/xml/WSDLConstants.java | 40 + .../wsdl/xml/WSDLDocumentProcessor.java | 230 +++ .../wsdl/xml/WSDLInterfaceProcessor.java | 315 ++++ .../interfacedef/wsdl/xml/WSDLModelResolver.java | 600 ++++++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...sca.contribution.processor.URLArtifactProcessor | 19 + ...tuscany.sca.contribution.resolver.ModelResolver | 18 + ...nterface-wsdlxml-validation-messages.properties | 24 + .../interfacedef/wsdl/AbstractWSDLTestCase.java | 68 + .../WSDLInterfaceIntrospectorTestCase.java | 83 + .../WSDLOperationIntrospectorTestCase.java | 117 ++ ...licyAnnotatedInterfaceIntrospectorTestCase.java | 87 ++ .../introspect/WrapperStyleOperationTestCase.java | 70 + .../sca/interfacedef/wsdl/xml/ReadTestCase.java | 97 ++ .../wsdl/xml/WSDLDocumentProcessorTestCase.java | 86 ++ .../sca/interfacedef/wsdl/xml/WSDLTestCase.java | 104 ++ .../sca/interfacedef/wsdl/xml/WriteTestCase.java | 83 + .../wsdl/xml/XMLDocumentHelperTestCase.java | 53 + .../sca/interfacedef/wsdl/xml/Calculator.composite | 55 + .../wsdl/xml/CalculatorComponent.constrainingType | 36 + .../wsdl/xml/CalculatorImpl.componentType | 33 + .../tuscany/sca/interfacedef/wsdl/xml/example.wsdl | 26 + .../interfacedef/wsdl/xml/invalid-stockquote.wsdl | 58 + .../tuscany/sca/interfacedef/wsdl/xml/ipo.xsd | 136 ++ .../sca/interfacedef/wsdl/xml/stockquote.wsdl | 58 + .../tuscany/sca/interfacedef/wsdl/xml/test1.wsdl | 45 + .../tuscany/sca/interfacedef/wsdl/xml/test1.xsd | 33 + .../tuscany/sca/interfacedef/wsdl/xml/test2.wsdl | 63 + .../wsdl/xml/unwrapped-stockquote.wsdl | 76 + .../test/resources/policy/stockquote_policy.wsdl | 62 + .../test/resources/wsdl/helloworld-interface.wsdl | 67 + .../test/resources/wsdl/helloworld-service.wsdl | 49 + .../src/test/resources/xsd/greeting.xsd | 29 + .../src/test/resources/xsd/helloworld.xsd | 22 + .../src/test/resources/xsd/name.xsd | 29 + .../sca-java-1.6/modules/interface-wsdl/LICENSE | 205 +++ .../sca-java-1.6/modules/interface-wsdl/NOTICE | 6 + .../sca-java-1.6/modules/interface-wsdl/pom.xml | 103 ++ .../sca/interfacedef/wsdl/DefaultWSDLFactory.java | 35 + .../sca/interfacedef/wsdl/WSDLDefinition.java | 148 ++ .../tuscany/sca/interfacedef/wsdl/WSDLFactory.java | 70 + .../sca/interfacedef/wsdl/WSDLInterface.java | 67 + .../interfacedef/wsdl/WSDLInterfaceContract.java | 44 + .../tuscany/sca/interfacedef/wsdl/WSDLObject.java | 54 + .../sca/interfacedef/wsdl/WSDLOperation.java | 40 + .../wsdl/impl/InvalidWSDLException.java | 35 + .../interfacedef/wsdl/impl/WSDLDefinitionImpl.java | 299 ++++ .../interfacedef/wsdl/impl/WSDLFactoryImpl.java | 75 + .../wsdl/impl/WSDLInterfaceContractImpl.java | 64 + .../interfacedef/wsdl/impl/WSDLInterfaceImpl.java | 115 ++ .../wsdl/impl/WSDLInterfaceIntrospectorImpl.java | 159 ++ .../sca/interfacedef/wsdl/impl/WSDLObjectImpl.java | 61 + .../interfacedef/wsdl/impl/WSDLOperationImpl.java | 81 + .../wsdl/impl/WSDLOperationIntrospectorImpl.java | 617 ++++++++ ...pache.tuscany.sca.interfacedef.wsdl.WSDLFactory | 18 + .../sca-java-1.6/modules/interface/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/interface/NOTICE | 6 + .../sca-java-1.6/modules/interface/pom.xml | 57 + .../sca/interfacedef/ConversationSequence.java | 29 + .../apache/tuscany/sca/interfacedef/DataType.java | 119 ++ .../sca/interfacedef/FaultExceptionMapper.java | 62 + .../IncompatibleInterfaceContractException.java | 69 + .../apache/tuscany/sca/interfacedef/Interface.java | 111 ++ .../sca/interfacedef/InterfaceContract.java | 81 + .../sca/interfacedef/InterfaceContractMapper.java | 115 ++ .../sca/interfacedef/InvalidCallbackException.java | 34 + .../interfacedef/InvalidInterfaceException.java | 41 + .../interfacedef/InvalidOperationException.java | 42 + .../apache/tuscany/sca/interfacedef/Operation.java | 226 +++ .../interfacedef/OverloadedOperationException.java | 45 + .../tuscany/sca/interfacedef/ParameterMode.java | 28 + .../sca/interfacedef/impl/DataTypeImpl.java | 230 +++ .../interfacedef/impl/InterfaceContractImpl.java | 128 ++ .../impl/InterfaceContractMapperImpl.java | 302 ++++ .../sca/interfacedef/impl/InterfaceImpl.java | 331 ++++ .../sca/interfacedef/impl/OperationImpl.java | 321 ++++ .../tuscany/sca/interfacedef/util/ElementInfo.java | 114 ++ .../sca/interfacedef/util/FaultException.java | 82 + .../sca/interfacedef/util/JavaXMLMapper.java | 143 ++ .../tuscany/sca/interfacedef/util/TypeInfo.java | 100 ++ .../tuscany/sca/interfacedef/util/WrapperInfo.java | 140 ++ .../tuscany/sca/interfacedef/util/XMLType.java | 152 ++ ...uscany.sca.interfacedef.InterfaceContractMapper | 18 + .../impl/ContractCompatibilityTestCase.java | 380 +++++ .../impl/InterfaceContractTestCase.java | 71 + .../branches/sca-java-1.6/modules/monitor/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/monitor/NOTICE | 6 + .../branches/sca-java-1.6/modules/monitor/pom.xml | 57 + .../org/apache/tuscany/sca/monitor/Monitor.java | 162 ++ .../apache/tuscany/sca/monitor/MonitorFactory.java | 35 + .../sca/monitor/MonitorRuntimeException.java | 55 + .../org/apache/tuscany/sca/monitor/Problem.java | 49 + .../monitor/impl/DefaultMonitorFactoryImpl.java | 41 + .../sca/monitor/impl/DefaultMonitorImpl.java | 116 ++ .../tuscany/sca/monitor/impl/ProblemImpl.java | 132 ++ .../org.apache.tuscany.sca.monitor.MonitorFactory | 18 + .../branches/sca-java-1.6/modules/node-api/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/node-api/NOTICE | 6 + .../branches/sca-java-1.6/modules/node-api/pom.xml | 61 + .../org/apache/tuscany/sca/node/SCAClient.java | 71 + .../apache/tuscany/sca/node/SCAContribution.java | 54 + .../java/org/apache/tuscany/sca/node/SCANode.java | 42 + .../java/org/apache/tuscany/sca/node/SCANode2.java | 33 + .../apache/tuscany/sca/node/SCANode2Factory.java | 203 +++ .../apache/tuscany/sca/node/SCANodeFactory.java | 208 +++ .../sca-java-1.6/modules/node-impl/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/node-impl/NOTICE | 6 + .../sca-java-1.6/modules/node-impl/pom.xml | 154 ++ .../tuscany/sca/node/impl/Node2FactoryImpl.java | 57 + .../apache/tuscany/sca/node/impl/Node2Impl.java | 63 + .../tuscany/sca/node/impl/NodeFactoryImpl.java | 60 + .../org/apache/tuscany/sca/node/impl/NodeImpl.java | 897 +++++++++++ .../tuscany/sca/node/impl/RuntimeBootStrapper.java | 427 ++++++ .../tuscany/sca/node/impl/RuntimeBuilder.java | 256 ++++ .../org.apache.tuscany.sca.node.SCANode2Factory | 17 + .../org.apache.tuscany.sca.node.SCANodeFactory | 17 + .../node-impl/src/test/java/hello/HelloWorld.java | 30 + .../src/test/java/hello/HelloWorldImpl.java | 30 + .../tuscany/sca/node/impl/Node2ImplTestCase.java | 119 ++ .../tuscany/sca/node/impl/NodeImplTestCase.java | 119 ++ .../src/test/resources/HelloWorld.composite | 30 + .../test/resources/META-INF/sca-contribution.xml | 23 + .../modules/node-launcher-osgi/LICENSE | 205 +++ .../sca-java-1.6/modules/node-launcher-osgi/NOTICE | 6 + .../modules/node-launcher-osgi/pom.xml | 155 ++ .../sca/node/osgi/launcher/Contribution.java | 48 + .../node/osgi/launcher/DomainManagerLauncher.java | 110 ++ .../sca/node/osgi/launcher/FelixOSGiHost.java | 174 +++ .../sca/node/osgi/launcher/JarFileFinder.java | 348 +++++ .../osgi/launcher/LauncherBundleActivator.java | 475 ++++++ .../sca/node/osgi/launcher/LauncherException.java | 55 + .../sca/node/osgi/launcher/NodeDaemonLauncher.java | 100 ++ .../sca/node/osgi/launcher/NodeLauncher.java | 165 ++ .../sca/node/osgi/launcher/NodeLauncherUtil.java | 198 +++ .../tuscany/sca/node/osgi/launcher/NodeMain.java | 44 + .../sca/node/osgi/launcher/NodeServletFilter.java | 127 ++ .../tuscany/sca/node/osgi/launcher/OSGiHost.java | 30 + .../src/test/java/hello/HelloWorld.java | 30 + .../src/test/java/hello/HelloWorldImpl.java | 30 + .../node/osgi/launcher/FelixOSGiHostTestCase.java | 95 ++ .../node/osgi/launcher/NodeLauncherTestCase.java | 69 + .../src/test/resources/HelloWorld.composite | 30 + .../sca-java-1.6/modules/node-launcher/LICENSE | 205 +++ .../sca-java-1.6/modules/node-launcher/NOTICE | 6 + .../sca-java-1.6/modules/node-launcher/pom.xml | 72 + .../tuscany/sca/node/launcher/Contribution.java | 48 + .../sca/node/launcher/DomainManagerLauncher.java | 186 +++ .../sca/node/launcher/LauncherException.java | 55 + .../sca/node/launcher/NodeDaemonLauncher.java | 168 +++ .../tuscany/sca/node/launcher/NodeLauncher.java | 238 +++ .../sca/node/launcher/NodeLauncherUtil.java | 543 +++++++ .../apache/tuscany/sca/node/launcher/NodeMain.java | 44 + .../sca/node/launcher/NodeServletFilter.java | 130 ++ .../sca-java-1.6/modules/node-manager/LICENSE | 205 +++ .../sca-java-1.6/modules/node-manager/NOTICE | 6 + .../sca-java-1.6/modules/node-manager/pom.xml | 138 ++ .../node/manager/NodeManagerUtil.java | 51 + .../node/manager/NodeProcessCollectionImpl.java | 338 +++++ .../node/manager/PingServiceImpl.java | 61 + .../src/main/resources/NodeDaemon.composite | 39 + .../sca-java-1.6/modules/osgi-runtime/LICENSE | 203 +++ .../sca-java-1.6/modules/osgi-runtime/NOTICE | 6 + .../sca-java-1.6/modules/osgi-runtime/pom.xml | 70 + .../tuscany/sca/osgi/runtime/EquinoxRuntime.java | 117 ++ .../tuscany/sca/osgi/runtime/FelixRuntime.java | 253 ++++ .../sca/osgi/runtime/KnopflerfishRuntime.java | 168 +++ .../sca/osgi/runtime/OSGiBundleActivator.java | 252 ++++ .../tuscany/sca/osgi/runtime/OSGiRuntime.java | 275 ++++ .../osgi/runtime/OSGiRuntimeModuleActivator.java | 47 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sca/osgi/runtime/OSGiRuntimeTestCase.java | 78 + .../sca-java-1.6/modules/policy-logging/LICENSE | 205 +++ .../sca-java-1.6/modules/policy-logging/NOTICE | 6 + .../sca-java-1.6/modules/policy-logging/pom.xml | 77 + .../logging/LoggingPolicyDefinitionsProvider.java | 67 + .../JDKLoggingImplementationPolicyProvider.java | 90 ++ .../sca/policy/logging/jdk/JDKLoggingPolicy.java | 84 ++ .../logging/jdk/JDKLoggingPolicyInterceptor.java | 130 ++ .../logging/jdk/JDKLoggingPolicyProcessor.java | 137 ++ .../jdk/JDKLoggingPolicyProviderFactory.java | 75 + .../jdk/JDKLoggingReferencePolicyProvider.java | 89 ++ .../jdk/JDKLoggingServicePolicyProvider.java | 87 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...ache.tuscany.sca.provider.PolicyProviderFactory | 19 + ...che.tuscany.sca.provider.SCADefinitionsProvider | 19 + .../tuscany/sca/policy/logging/definitions.xml | 31 + .../sca/policy/logging/jdk/PolicyReadTestCase.java | 91 ++ .../sca/policy/logging/jdk/mock_policies.xml | 23 + .../modules/policy-reliability/LICENSE | 205 +++ .../sca-java-1.6/modules/policy-reliability/NOTICE | 6 + .../modules/policy-reliability/pom.xml | 70 + .../ReliabilityPolicyDefinitionsProvider.java | 72 + ...che.tuscany.sca.provider.SCADefinitionsProvider | 19 + .../tuscany/sca/policy/reliability/definitions.xml | 62 + .../modules/policy-security-geronimo/pom.xml | 70 + .../geronimo/GeronimoLDAPSecurityHandler.java | 143 ++ ...security.http.extensibility.LDAPSecurityHandler | 18 + .../modules/policy-security-http/LICENSE | 205 +++ .../modules/policy-security-http/NOTICE | 6 + .../modules/policy-security-http/pom.xml | 106 ++ .../AuthenticationConfigurationPolicy.java | 45 + ...AuthenticationConfigurationPolicyProcessor.java | 156 ++ .../confidentiality/ConfidentialityPolicy.java | 132 ++ .../ConfidentialityPolicyProcessor.java | 157 ++ .../LDAPRealmAuthenticationCallbackHandler.java | 71 + ...AuthenticationImplementationPolicyProvider.java | 193 +++ .../http/LDAPRealmAuthenticationInterceptor.java | 66 + .../http/LDAPRealmAuthenticationPolicy.java | 79 + .../LDAPRealmAuthenticationPolicyProcessor.java | 140 ++ ...APRealmAuthenticationPolicyProviderFactory.java | 69 + ...APRealmAuthenticationServicePolicyProvider.java | 234 +++ .../DefaultLDAPSecurityExtensionPoint.java | 133 ++ .../http/extensibility/LDAPSecurityHandler.java | 63 + .../LDAPSecurityHandlerExtensionPoint.java | 50 + .../security/http/util/HttpSecurityUtil.java | 124 ++ ...ca.contribution.processor.StAXArtifactProcessor | 21 + ...extensibility.LDAPSecurityHandlerExtensionPoint | 18 + ...ache.tuscany.sca.provider.PolicyProviderFactory | 19 + ...cy-security-http-validation-messages.properties | 22 + .../modules/policy-security-jsr250/LICENSE | 205 +++ .../modules/policy-security-jsr250/NOTICE | 6 + .../modules/policy-security-jsr250/pom.xml | 83 + .../implementation/java/impl/JSR250Activator.java | 51 + .../introspect/impl/JSR250PolicyProcessor.java | 178 +++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../impl/PolicyProcessorTestCaseFIXME.java | 418 +++++ .../sca-java-1.6/modules/policy-security/LICENSE | 205 +++ .../sca-java-1.6/modules/policy-security/NOTICE | 6 + .../sca-java-1.6/modules/policy-security/pom.xml | 74 + .../apache/tuscany/sca/policy/SecurityUtil.java | 76 + .../basic/BasicAuthenticationPolicy.java | 66 + .../basic/BasicAuthenticationPolicyProcessor.java | 123 ++ .../BasicAuthenticationPolicyProviderFactory.java | 75 + .../basic/BasicAuthenticationPrincipal.java | 80 + ...icAuthenticationReferencePolicyInterceptor.java | 95 ++ ...BasicAuthenticationReferencePolicyProvider.java | 89 ++ ...asicAuthenticationServicePolicyInterceptor.java | 92 ++ .../BasicAuthenticationServicePolicyProvider.java | 87 ++ .../authentication/token/TokenPrincipal.java | 74 + .../policy/authorization/AuthorizationPolicy.java | 84 ++ .../AuthorizationPolicyProcessor.java | 152 ++ ...ityIdentityImplementationPolicyInterceptor.java | 80 + ...curityIdentityImplementationPolicyProvider.java | 88 ++ .../policy/identity/SecurityIdentityPolicy.java | 76 + .../identity/SecurityIdentityPolicyProcessor.java | 133 ++ .../SecurityIdentityPolicyProviderFactory.java | 75 + .../SecurityPolicyDefinitionsProvider.java | 85 ++ ...AuthenticationImplementationPolicyProvider.java | 90 ++ .../jaas/JaasAuthenticationInterceptor.java | 76 + .../security/jaas/JaasAuthenticationPolicy.java | 73 + .../jaas/JaasAuthenticationPolicyHandler.java | 72 + .../jaas/JaasAuthenticationPolicyProcessor.java | 151 ++ .../JaasAuthenticationPolicyProviderFactory.java | 72 + .../JaasAuthenticationServicePolicyProvider.java | 110 ++ ...ca.contribution.processor.StAXArtifactProcessor | 27 + ...ache.tuscany.sca.provider.PolicyProviderFactory | 21 + ...che.tuscany.sca.provider.SCADefinitionsProvider | 19 + .../tuscany/sca/policy/security/definitions.xml | 65 + .../sca/policy/security/tuscany_definitions.xml | 30 + .../policy-security-validation-messages.properties | 22 + .../policy/security/PolicyProcessorTestCase.java | 88 ++ .../policy/security/mock_policy_definitions.xml | 78 + .../modules/policy-transaction/LICENSE | 205 +++ .../sca-java-1.6/modules/policy-transaction/NOTICE | 6 + .../modules/policy-transaction/pom.xml | 127 ++ .../transaction/IncompatibleIntentException.java | 44 + .../TransactionImplementationPolicyProvider.java | 61 + .../sca/policy/transaction/TransactionIntent.java | 28 + .../policy/transaction/TransactionInterceptor.java | 122 ++ .../transaction/TransactionManagerHelper.java | 243 +++ .../transaction/TransactionManagerWrapper.java | 90 ++ .../transaction/TransactionModuleActivator.java | 84 ++ .../sca/policy/transaction/TransactionPolicy.java | 46 + .../TransactionPolicyDefinitionsProvider.java | 71 + .../policy/transaction/TransactionPolicyImpl.java | 59 + .../transaction/TransactionPolicyProcessor.java | 96 ++ .../TransactionPolicyProviderFactory.java | 92 ++ .../TransactionReferencePolicyProvider.java | 61 + .../TransactionServicePolicyProvider.java | 61 + .../policy/transaction/TransactionalAction.java | 31 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + ...ache.tuscany.sca.provider.PolicyProviderFactory | 19 + ...che.tuscany.sca.provider.SCADefinitionsProvider | 19 + .../src/main/resources/log4j.properties | 29 + .../tuscany/sca/policy/transaction/definitions.xml | 66 + .../sca/policy/transaction/tuscany_definitions.xml | 54 + .../sca/policy/transaction/PolicyReadTestCase.java | 54 + .../TransactionManagerHelperTestCase.java | 194 +++ .../sca-java-1.6/modules/policy-xml-ws/LICENSE | 205 +++ .../sca-java-1.6/modules/policy-xml-ws/NOTICE | 6 + .../sca-java-1.6/modules/policy-xml-ws/pom.xml | 142 ++ .../sca/policy/xml/ws/WSPolicyProcessor.java | 162 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../tuscany/sca/policy/xml/TestModelResolver.java | 63 + .../sca/policy/xml/TestPolicyProcessor.java | 74 + .../sca/policy/xml/WSPolicyProcessorTestCase.java | 111 ++ .../tuscany/sca/policy/xml/test_definitions.xml | 106 ++ .../sca-java-1.6/modules/policy-xml/LICENSE | 205 +++ .../sca-java-1.6/modules/policy-xml/NOTICE | 6 + .../sca-java-1.6/modules/policy-xml/pom.xml | 76 + .../sca/policy/xml/BindingTypeProcessor.java | 68 + .../policy/xml/ImplementationTypeProcessor.java | 68 + .../policy/xml/IntentAttachPointTypeProcessor.java | 248 +++ .../tuscany/sca/policy/xml/PolicyConstants.java | 75 + .../sca/policy/xml/PolicyIntentProcessor.java | 417 +++++ .../tuscany/sca/policy/xml/PolicySetProcessor.java | 487 ++++++ .../sca/policy/xml/ProfileIntentProcessor.java | 45 + .../sca/policy/xml/QualifiedIntentProcessor.java | 45 + .../sca/policy/xml/SimpleIntentProcessor.java | 45 + ...ca.contribution.processor.StAXArtifactProcessor | 24 + .../policy-xml-validation-messages.properties | 44 + .../sca/policy/xml/ReadDocumentTestCase.java | 280 ++++ .../sca/policy/xml/TestPolicyProcessor.java | 74 + .../tuscany/sca/policy/xml/test_definitions.xml | 255 ++++ .../branches/sca-java-1.6/modules/policy/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/policy/NOTICE | 5 + .../branches/sca-java-1.6/modules/policy/pom.xml | 58 + .../DefaultIntentAttachPointTypeFactory.java | 29 + .../tuscany/sca/policy/DefaultPolicyFactory.java | 30 + .../java/org/apache/tuscany/sca/policy/Intent.java | 116 ++ .../tuscany/sca/policy/IntentAttachPoint.java | 52 + .../tuscany/sca/policy/IntentAttachPointType.java | 71 + .../sca/policy/IntentAttachPointTypeFactory.java | 43 + .../org/apache/tuscany/sca/policy/IntentMap.java | 89 ++ .../java/org/apache/tuscany/sca/policy/Policy.java | 33 + .../apache/tuscany/sca/policy/PolicyContext.java | 38 + .../apache/tuscany/sca/policy/PolicyFactory.java | 69 + .../org/apache/tuscany/sca/policy/PolicySet.java | 155 ++ .../tuscany/sca/policy/PolicySetAttachPoint.java | 48 + .../tuscany/sca/policy/PolicySetReference.java | 43 + .../apache/tuscany/sca/policy/ProfileIntent.java | 36 + .../apache/tuscany/sca/policy/QualifiedIntent.java | 41 + .../tuscany/sca/policy/impl/BindingTypeImpl.java | 90 ++ .../sca/policy/impl/ImplementationTypeImpl.java | 88 ++ .../impl/IntentAttachPointTypeFactoryImpl.java | 39 + .../apache/tuscany/sca/policy/impl/IntentImpl.java | 151 ++ .../tuscany/sca/policy/impl/IntentMapImpl.java | 73 + .../tuscany/sca/policy/impl/PolicyContextImpl.java | 93 ++ .../tuscany/sca/policy/impl/PolicyFactoryImpl.java | 60 + .../tuscany/sca/policy/impl/PolicySetImpl.java | 149 ++ .../sca/policy/impl/PolicySetReferenceImpl.java | 48 + .../tuscany/sca/policy/impl/ProfileIntentImpl.java | 39 + .../sca/policy/impl/QualifiedIntentImpl.java | 50 + .../sca/policy/util/PolicyComputationUtils.java | 418 +++++ .../tuscany/sca/policy/util/PolicyHandler.java | 38 + .../util/PolicyHandlerDefinitionsLoader.java | 87 ++ .../sca/policy/util/PolicyHandlerTuple.java | 91 ++ .../sca/policy/util/PolicyHandlerUtils.java | 64 + .../sca/policy/util/PolicyValidationException.java | 38 + .../sca/policy/util/PolicyValidationUtils.java | 111 ++ ...tuscany.sca.policy.IntentAttachPointTypeFactory | 18 + .../org.apache.tuscany.sca.policy.PolicyFactory | 18 + .../tuscany/sca/policy/PolicyFactoryTestCase.java | 50 + sca-java-1.x/branches/sca-java-1.6/modules/pom.xml | 246 +++ .../sca-java-1.6/modules/sca-api-extension/LICENSE | 202 +++ .../sca-java-1.6/modules/sca-api-extension/NOTICE | 6 + .../sca-java-1.6/modules/sca-api-extension/pom.xml | 62 + .../tuscany/sca/api/ComponentContextExtension.java | 55 + .../branches/sca-java-1.6/modules/sca-api/LICENSE | 243 +++ .../branches/sca-java-1.6/modules/sca-api/NOTICE | 13 + .../branches/sca-java-1.6/modules/sca-api/pom.xml | 54 + .../main/java/org/osoa/sca/CallableReference.java | 54 + .../main/java/org/osoa/sca/ComponentContext.java | 100 ++ .../src/main/java/org/osoa/sca/Constants.java | 34 + .../src/main/java/org/osoa/sca/Conversation.java | 30 + .../org/osoa/sca/ConversationEndedException.java | 56 + .../osoa/sca/NoRegisteredCallbackException.java | 57 + .../src/main/java/org/osoa/sca/RequestContext.java | 55 + .../main/java/org/osoa/sca/ServiceReference.java | 54 + .../java/org/osoa/sca/ServiceRuntimeException.java | 58 + .../org/osoa/sca/ServiceUnavailableException.java | 54 + .../sca/annotations/AllowsPassByReference.java | 28 + .../org/osoa/sca/annotations/Authentication.java | 58 + .../java/org/osoa/sca/annotations/Callback.java | 39 + .../org/osoa/sca/annotations/ComponentName.java | 25 + .../org/osoa/sca/annotations/Confidentiality.java | 58 + .../java/org/osoa/sca/annotations/Constructor.java | 25 + .../java/org/osoa/sca/annotations/Context.java | 28 + .../sca/annotations/ConversationAttributes.java | 46 + .../org/osoa/sca/annotations/ConversationID.java | 25 + .../org/osoa/sca/annotations/Conversational.java | 27 + .../java/org/osoa/sca/annotations/Destroy.java | 25 + .../java/org/osoa/sca/annotations/EagerInit.java | 25 + .../org/osoa/sca/annotations/EndsConversation.java | 24 + .../main/java/org/osoa/sca/annotations/Init.java | 26 + .../java/org/osoa/sca/annotations/Integrity.java | 58 + .../main/java/org/osoa/sca/annotations/Intent.java | 48 + .../main/java/org/osoa/sca/annotations/OneWay.java | 25 + .../java/org/osoa/sca/annotations/PolicySets.java | 35 + .../java/org/osoa/sca/annotations/Property.java | 41 + .../java/org/osoa/sca/annotations/Qualifier.java | 25 + .../java/org/osoa/sca/annotations/Reference.java | 40 + .../java/org/osoa/sca/annotations/Remotable.java | 26 + .../java/org/osoa/sca/annotations/Requires.java | 46 + .../main/java/org/osoa/sca/annotations/Scope.java | 38 + .../java/org/osoa/sca/annotations/Service.java | 37 + .../sca-java-1.6/modules/tracing-aspectj/LICENSE | 205 +++ .../sca-java-1.6/modules/tracing-aspectj/NOTICE | 6 + .../modules/tracing-aspectj/launcher.bat | 22 + .../sca-java-1.6/modules/tracing-aspectj/pom.xml | 120 ++ .../apache/tuscany/sca/aspectj/LoggingAspect.java | 105 ++ .../tuscany/sca/aspectj/SimpleTracingAspect.java | 87 ++ .../apache/tuscany/sca/aspectj/TimingAspect.java | 60 + .../apache/tuscany/sca/aspectj/TracingAspect.java | 92 ++ .../src/main/resources/META-INF/aop.xml | 43 + .../tuscany/sca/aspectj/TracingTestCase.java | 41 + .../modules/web-javascript-dojo/LICENSE | 238 +++ .../modules/web-javascript-dojo/NOTICE | 11 + .../modules/web-javascript-dojo/build-dojo.xml | 62 + .../modules/web-javascript-dojo/pom.xml | 118 ++ .../web/javascript/dojo/DojoModuleActivator.java | 84 ++ .../web/javascript/dojo/DojoResourceServlet.java | 73 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../src/main/resources/tuscany/AtomService.js | 141 ++ .../sca-java-1.6/modules/web-javascript/LICENSE | 205 +++ .../sca-java-1.6/modules/web-javascript/NOTICE | 6 + .../sca-java-1.6/modules/web-javascript/pom.xml | 67 + .../javascript/ComponentJavaScriptGenerator.java | 59 + ...ComponentJavaScriptGeneratorExtensionPoint.java | 56 + ...ComponentJavaScriptGeneratorExtensionPoint.java | 154 ++ ...efaultJavascriptProxyFactoryExtensionPoint.java | 225 +++ .../sca/web/javascript/JavascriptProxyFactory.java | 69 + .../JavascriptProxyFactoryExtensionPoint.java | 52 + ...ript.ComponentJavaScriptGeneratorExtensionPoint | 18 + ...javascript.JavascriptProxyFactoryExtensionPoint | 18 + .../web-javascript-validation-messages.properties | 21 + .../sca-java-1.6/modules/workspace-impl/LICENSE | 205 +++ .../sca-java-1.6/modules/workspace-impl/NOTICE | 6 + .../sca-java-1.6/modules/workspace-impl/pom.xml | 83 + .../impl/ContributionDependencyBuilderImpl.java | 145 ++ .../impl/ContributionContentProcessor.java | 305 ++++ .../processor/impl/ContributionInfoProcessor.java | 240 +++ .../scanner/impl/DirectoryContributionScanner.java | 107 ++ .../scanner/impl/JarContributionScanner.java | 121 ++ ...sca.contribution.processor.URLArtifactProcessor | 20 + .../workspace-validation-messages.properties | 22 + .../workspace-validation-messages_it.properties | 21 + .../ContributionDependencyBuilderTestCase.java | 100 ++ .../sca-java-1.6/modules/workspace-manager/LICENSE | 205 +++ .../sca-java-1.6/modules/workspace-manager/NOTICE | 6 + .../sca-java-1.6/modules/workspace-manager/pom.xml | 88 ++ .../sca/workspace/manager/WorkspaceManager.java | 106 ++ .../manager/impl/WorkspaceManagerImpl.java | 190 +++ .../sca-java-1.6/modules/workspace-xml/LICENSE | 205 +++ .../sca-java-1.6/modules/workspace-xml/NOTICE | 6 + .../sca-java-1.6/modules/workspace-xml/pom.xml | 70 + .../workspace/xml/WorkspaceDocumentProcessor.java | 131 ++ .../sca/workspace/xml/WorkspaceProcessor.java | 167 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../workspace-xml-validation-messages.properties | 22 + .../ContributionWorkspaceProcessorTestCase.java | 89 ++ .../sca-java-1.6/modules/workspace/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/workspace/NOTICE | 6 + .../sca-java-1.6/modules/workspace/pom.xml | 64 + .../sca/workspace/ContributionConfiguration.java | 54 + .../sca/workspace/DefaultWorkspaceFactory.java | 32 + .../apache/tuscany/sca/workspace/Workspace.java | 39 + .../tuscany/sca/workspace/WorkspaceFactory.java | 36 + .../builder/ContributionDependencyBuilder.java | 42 + .../sca/workspace/impl/WorkspaceFactoryImpl.java | 40 + .../tuscany/sca/workspace/impl/WorkspaceImpl.java | 152 ++ ...g.apache.tuscany.sca.workspace.WorkspaceFactory | 18 + .../branches/sca-java-1.6/modules/xsd-xml/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/xsd-xml/NOTICE | 6 + .../branches/sca-java-1.6/modules/xsd-xml/pom.xml | 82 + .../tuscany/sca/xsd/xml/XMLDocumentHelper.java | 184 +++ .../tuscany/sca/xsd/xml/XSDDocumentProcessor.java | 102 ++ .../tuscany/sca/xsd/xml/XSDModelResolver.java | 343 +++++ ...sca.contribution.processor.URLArtifactProcessor | 19 + ...tuscany.sca.contribution.resolver.ModelResolver | 18 + .../xsd-xml-validation-messages.properties | 23 + .../sca/xsd/xml/XMLDocumentHelperTestCase.java | 51 + .../sca/xsd/xml/XSDDocumentProcessorTestCase.java | 90 ++ .../xsd-xml/src/test/resources/xsd/greeting.xsd | 29 + .../xsd-xml/src/test/resources/xsd/name.xsd | 29 + .../branches/sca-java-1.6/modules/xsd/LICENSE | 205 +++ .../branches/sca-java-1.6/modules/xsd/NOTICE | 6 + .../branches/sca-java-1.6/modules/xsd/pom.xml | 85 ++ .../apache/tuscany/sca/xsd/DefaultXSDFactory.java | 30 + .../org/apache/tuscany/sca/xsd/XSDFactory.java | 35 + .../org/apache/tuscany/sca/xsd/XSDefinition.java | 117 ++ .../tuscany/sca/xsd/impl/XSDFactoryImpl.java | 35 + .../tuscany/sca/xsd/impl/XSDefinitionImpl.java | 232 +++ .../services/org.apache.tuscany.sca.xsd.XSDFactory | 18 + 3992 files changed, 386716 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Multiplicity.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/local.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-all.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-contributions.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-core.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-definitions.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-ejb.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-jee.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-web.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-policy.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-core.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-corba.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-gdata.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jms.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-contributions.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-widget.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/ws-addr.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/wsdli.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/BindingRRB.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConfiguredOperation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefinitionElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationSelector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/WireFormat.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/AutomaticBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DomainBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConfiguredOperationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.ExtensionFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/assembly-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/assembly-validation-messages_it.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/Collection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/MediaCollection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/NotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomTestCaseUtils.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Aggregator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Sort.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/Headline.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/ReceiptToms.gif create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/ReceiptValue.jpg create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Consumer.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Provider.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/ProviderNonCollection.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/aggregator/FeedAggregator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/news/news.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/java/org/apache/tuscany/sca/binding/atom/js/AtomBindingJavascriptProxyFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/resources/binding-atom.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/AtomBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/AtomBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/impl/AtomBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/impl/AtomBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.atom.AtomBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/CorbaException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/RequestConfigurationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaResponse.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceInstanceCreator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceMethodInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/ComponentInvocationProxy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationProxy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/AnnotationAttributes.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/NodeType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTree.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeNode.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/UnionAttributes.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ArrayTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/BooleanTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ByteTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/CharTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/DoubleTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/EnumTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/FloatTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/IntTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/LongTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ReferenceTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/SequenceTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ShortTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StringTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StructTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelpersProxy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/UnionTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/Utils.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/util/MethodFinder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/util/OperationMapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaArray.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaUnionElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaUnionElementType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/MappingTestInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/MethodFinderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/OperationMappingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/TestConstants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnion.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnionHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnionHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnion.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnionHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnionHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArrayHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArrayHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStruct.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStructHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStructHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/_ArraysUnionsTestsImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/_ArraysUnionsTestsStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/Color.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/ColorHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/ColorHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/_EnumManagerImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/_EnumManagerStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/Arguments.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/ArgumentsHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/ArgumentsHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZero.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZeroHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZeroHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupported.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupportedHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupportedHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/_CalcImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/_CalcStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStruct.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStructHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStructHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStruct.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStructHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStructHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_ArraysSetterImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_ArraysSetterStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_PrimitivesSetterImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_PrimitivesSetterStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_RemoteObjectImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_RemoteObjectStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_TestObjectImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_TestObjectStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/boolean_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/boolean_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/char_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/char_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/double_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/double_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/float_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/float_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_long_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_long_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1Helper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1Holder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2Helper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2Holder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3Helper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3Holder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/octet_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/octet_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/short_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/short_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/string_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/string_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wchar_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wchar_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wstring_listHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wstring_listHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/ArraysTestStruct.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/Calc.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/DummyObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InnerUnion.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidCorbaArray.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum1.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum2.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum3.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct1.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct2.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct3.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion1.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion2.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion3.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion4.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion5.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/NonCorbaException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/RichUnion.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/SimpleStruct.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/SomeStruct.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_DummyObjectImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_DummyObjectStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_ObjectManagerImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_ObjectManagerStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysSetterServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysUnionsServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysUnionsTuscanyServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/CalcServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/DummyObjectServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/EnumManagerServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTestObjectServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/NonCorbaServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ObjectManagerServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/PrimitivesSetterServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/TestObjectServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestDataType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestInterfaceContract.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestOperation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/arrays_unions.idl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/enums.idl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/exceptions.idl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/general_tests.idl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/references.idl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.corba.CorbaBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ClassLoadingUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/DynamicStubClassLoader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/Java2IDLUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ObjectInputStreamExt.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/StubMethodInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/UtilInitializer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/resources/binding-ejb-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/BankManagerFacade.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/Customer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/CustomerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/calculator/AddServiceRemote.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/resources/account/account.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/resources/calculator-ejb/calculator-ejb.jar create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ejb.EJBBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/binding-ejb-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/impl/ReadWriteAnyAttributeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNodeElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/AnnotatedListTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/AtomTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BinaryTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BooleanTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ByteTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/CharTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/DoubleTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/FloatTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/IntTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ListTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/LongTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ShortTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/StringTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TupleTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/meta/ErlangAtom.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/AtomTuple.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ModuleInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/SmallTuple.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/StructuredTuple.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/resources/ErlangReference.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/resources/ErlangService.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.erlang.ErlangBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ErlangBindingProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/NotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomFeedEntryUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.AtomBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.RSSBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Consumer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Provider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/NotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingListenerServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Constants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/ConsumerProviderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleBloggerServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleCalendarServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleContactsServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleWebAlbumServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Provider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/StartLocalhostServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/log4j.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleCalendar.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleContacts.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleWebAlbum.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.gdata.GdataBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBindingException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianServiceListenerServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/binding-hessian.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/FirstImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/FirstTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/IFirst.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/ISecond.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/SecondImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/SecondTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/resources/first_hessian.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/resources/second_hessian.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatReferenceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JavaToSmd.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/JSONRPCOperationSelector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/JSONRPCOperationSelectorFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/JSONRPCWireFormat.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/JSONRPCWireFormatFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelectorFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormatFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPGetListenerServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPRRBListenerServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/util/HTTPHeadersParser.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/NotModifiedException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/PreconditionFailedException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestBindingCacheImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceCacheImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/content/test.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/test.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/testCache.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBindingContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPCacheContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPHeader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.HTTPBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/JMSBindingDefinitionsProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationReferencePolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationReferencePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderReferencePolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderReferencePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/binding-jms-policy-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/test/resources/org/apache/tuscany/sca/binding/jms/policy/mock_policy_definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldClientImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/OperationSelectionTestCaseFIXME.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/resources/simple/client.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/resources/simple/service.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/BindingProperty.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefault.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/OperationSelectorJMSUserProp.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/OperationSelectorJMSUserPropProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytes.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/WireFormatJMSBytesXML.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/WireFormatJMSBytesXMLProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObjectProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/WireFormatJMSText.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/WireFormatJMSTextProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/WireFormatJMSTextXML.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/WireFormatJMSTextXMLProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorWriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/JSONRPCBindingJavascriptProxyFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/resources/binding-jsonrpc.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JavaToSmd.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/ScaDomainScriptServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/provider/jsonrpc.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoBusinessException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/impl/JSONRPCBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/impl/JSONRPCBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/DefaultNotificationBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBrokerManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManagerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBroker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBrokerEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Broker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReferenceEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerID.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerIDEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReferenceEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Brokers.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokersEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverride.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponse.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponseEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Constants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReferenceEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/DefaultEncodingRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingUtils.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumers.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumersEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducers.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducersEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddress.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddressEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequence.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequenceEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapperEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumers.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumersEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Neighbors.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborsEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBroker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAck.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAckEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponse.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponseEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponse.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponseEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponse.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponseEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferenceProperties.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferencePropertiesEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBroker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBrokerEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBroker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBrokerEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnectionEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Subscribe.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/SubscribeEnDeCoder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/IOUtils.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/NotificationServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/URIUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/AxiomTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldRmiImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldRmiService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/HelloWorldImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/HelloWorldRmiImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/RMIBindingTest.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/impl/RMIBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/impl/RMIBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rmi.RMIBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/Collection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/MediaCollection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/NotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingListenerServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Consumer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClientImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Provider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/RSSGetTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Consumer.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Provider.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/RSSBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/RSSBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/impl/RSSBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/impl/RSSBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rss.RSSBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BindingScaEndpointResolverFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BindingScaEndpointResolverImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldCallbackRemote.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackOnewayRemote.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackRemote.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceLocal.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote2.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackOnewayRemoteImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackRemoteImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientLocalImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemote2Impl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemoteImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackOnewayRemoteImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackRemoteImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceLocalImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceMultipleServicesImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceRemoteImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeA/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeA/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeB/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeB/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorldComponent.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorldComponent.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeE/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeE/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeF/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeF/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeG/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeG/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeH/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeH/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCABindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvocationProxy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/WrappedSCAException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/AMQJMSResourceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/AMQResourceFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/JMSBroker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/JMSSCABindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadWriteAnyAttributeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/resources/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/SCABindingDefinitionsProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RemoteBindingHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/test/resources/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderReferencePolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderReferencePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderServicePolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderServicePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2SOAPHeader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2SOAPHeaderString.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSSecurityPolicyHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/PolicyReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/mock_policies.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/AxisPolicyHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListenerManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/WSBindingDefinitionsProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/AxisJMSException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSConnectionFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSMessageReceiver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSOutTransportInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSSender.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/README create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingBasicAuthenticationConfigurator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingHeaderConfigurator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.4.mar create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/services/services.list create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Greeter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/GreetingCallback.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Account.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/AccountService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Bar.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/CustomerProfileData.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Echo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoComponent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Foo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldComponent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldMultiService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDLTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM2.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMComponent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldWSDLMergedTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/UriPrecedenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/AbstractHelloWorldOMTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURITestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURITestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferMTOMTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyExceptionAdapter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyExceptionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/Data.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/Data2.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/POJOWSTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/TestService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/TestServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/package-info.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/AbstractHelloWorldOMTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/ClientPWCBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/IntegrityPWCBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/ServerPWCBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityAuthenticationTestCaseFIXME.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityIntegrityTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/AbstractHelloWorldOMTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/ClientPWCBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/IntegrityPWCBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/ServerPWCBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/WSSecurityMixedTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/AbstractHelloWorldOMTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/ClientPWCBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/IntegrityPWCBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/ServerPWCBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityAuthenticationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityIntegrityTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12TestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/QuestionMarkWSDLTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDL.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdata.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdefs.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerinfo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiService.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleService.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURI.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURI.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/helloworld-om-relative-uri.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-binding.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-merged.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-porttype.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-uri.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-prec.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-prec.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransfer.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransferservice.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/test.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityAuthentication.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityConfidentiality.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityIntegrity.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/security.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/tuscanyKeys.jks create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/intent/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/WSSecurityMixed.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/security.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/tuscanyKeys.jks create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityAuthentication.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityConfidentiality.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityIntegrity.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/tuscanyKeys.jks create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import-nested.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-include.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-import.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-include.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/questionmark-wsdl.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLDefinitionGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLGenerationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/resources/wsdlgen-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/Other.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/package-info.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFault.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFaultBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaClass.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/BindingBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/resources/binding-wsxml-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadWriteAnyAttributeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator-bad-wsdlElement.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/PoliciedCalculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/addressing/EndPointReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyArtifact.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/java/org/apache/tuscany/sca/contribution/groovy/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/java/org/apache/tuscany/sca/contribution/groovy/HelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/resources/org/apache/tuscany/sca/contribution/groovy/HelloWorld.groovy create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/resources/org/apache/tuscany/sca/contribution/groovy/helloworld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/resources/contribution-impl-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/repository3/contribution.zip create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/test.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/test.ext create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassLoaderProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassloaderProviderExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassLoaderProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassloaderProviderExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassloaderProviderExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/resources/deployables/sample-calculator.jar create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/JEEDefinitionsProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEModuleHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EARContributionClassLoader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EARContributionClassLoaderProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEIntrospectorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WARContributionClassLoader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WARContributionClassLoaderProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEIntrospector create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/org/apache/tuscany/sca/contribution/jee/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBImplementationGenerated.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbModuleInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbModuleModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbReferenceInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EnvEntryInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/InjectionTarget.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEExtension.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEOptionalExtension.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JspReferenceTagInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObjectModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebImplementationGenerated.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EarContributionProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EjbArchiveProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EjbModuleInfoImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEApplicationInfoImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEArchiveProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEExtensionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/ModelObjectImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WarContributionProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebArchiveProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebImplementationGeneratedImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebImplementationGeneratedProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebModuleInfoImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEExtension create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEOptionalExtension create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/EarContributionProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/WarContributionProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/ejb-injection-sample.ear create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/ejb-injection-sample.jar create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/sample-web-app.war create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/DefaultNamespaceImportExportFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/BundleReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleContributionProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiImportExportListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiModelResolverImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceExport.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceImport.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceImportExportFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ArtifactModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportExportFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportExportListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resource.ResourceImportExportFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLFragmentStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Constants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultContributionFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultExport.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultImport.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResolverExtension.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResourceReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScannerExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedPackageTypeException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.scanner.ContributionScannerExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/contribution-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/OMElementXMLAdapter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCaseFIXME.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/doc/Context Model.emx create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/DataExchangeSemantics.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectorProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectorProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProviderRRB.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProviderRRB.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/WireFormatProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/WireFormatProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.ContextFactoryExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/test/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPointTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/test/java/org/apache/tuscany/sca/event/TrueFilterTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Work.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEvent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItem.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.conversation.ConversationManager create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.invocation.MessageFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyFailingRunnable.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnable.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnerListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Collection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Entry.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Item.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/ItemCollection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/LocalItemCollection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/NotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Collection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Entry.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Item.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/ItemCollection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/LocalItemCollection.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/NotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Exception2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Externalizable2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Exception.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Externalizable.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/ipo.xml create mode 100755 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/order.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/Node2FastInfoset.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/XMLInputStream2FastInfoset.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/XMLStreamReader2FastInfoset.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/test/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfosetTransformerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/AxiomHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXB2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBCustomBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/OMElement2JAXB.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/java/org/apache/tuscany/databinding/jaxb/axiom/JAXB2OMTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/java/org/apache/tuscany/databinding/jaxb/axiom/OMElement2JAXBTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/AnyTypeXmlAdapter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DOMElementXmlAdapter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DataConverter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DefaultXMLAdapterExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBPropertyDescriptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLAdapterExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/com/example/stock/StockQuoteOffer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/BeanXMLStreamReaderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCacheTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBReflectionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandlerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyInterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyJaxbBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MySubBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/POJOTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2JavaBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2String.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSON.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/String2JSON.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamReader2JSON.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSON2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONBadgerfishDataSource.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONDataSource.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2NodeTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Object2ValueTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonDataBindingHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonNodeDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonValueDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SimpleType2ValueTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2ObjectTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2SimpleTypeTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/collection/ItemList.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/resources/stock.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/Node2DataObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypes.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/databinding-sdo-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/stock.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/wrapper.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/wrapper.xsd create mode 100755 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/Node2XmlObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansWrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLStreamReader2XmlObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObjectTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/resources/ipo.xsd create mode 100755 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/resources/ipo.xsdconfig create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObjectImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Node2XObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/OMElement2XObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Utils.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/ipo.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/order.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/XMLTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/externalizable/ExternalizableDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReaderTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaExceptionDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXmlNodeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SourceTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleXmlNodeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2NodeTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StreamDataPipe.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SourceTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/WrappingXMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Writer2ReaderDataPipe.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReaderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2Node.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2String.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamSerializer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamable.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStringDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlNode.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlNodeIterator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBindingExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.Mediator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.TransformerExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/order.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/xml/foo.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/src/main/resources/definitions-xml-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/Policy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/ReadDocumentTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/TestPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions-xml/src/test/resources/org/apache/tuscany/sca/definitions/test_definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitions.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/impl/SCADefinitionsImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/util/SCADefinitionsUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeGeneratorServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionsReader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerConfiguration.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerConfigurationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/FileCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/FileServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeConfigurationServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/QuickStartServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/launcher/DomainManagerLauncherBootstrap.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/DomainManager.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/cloud-gadget.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/cloud.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/composite-gadget.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/composite.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/files-gadget.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/files.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/home-gadget.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/home.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/icons/artifact.png create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/icons/component.png create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/icons/composite.png create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/icons/feed-icon.png create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/manager.css create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/search-gadget.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/search.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/toolbar-gadget.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/utils.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/workspace-gadget.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/workspace.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/test/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/test/resources/contributions/assets/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/test/resources/contributions/store/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/test/resources/workspace.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/IndexException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileContent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/Document.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchAnalyzer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFileDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingAnalyzer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/calculator/AddService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/calculator/AddServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/calculator/CalculatorService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/calculator/DivideService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/calculator/DivideServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/calculator/MultiplyService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/calculator/MultiplyServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/calculator/SubtractService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/calculator/SubtractServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/endpoint/src/test/resources/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-equinox/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-equinox/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-equinox/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHostTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/TestEquinoxHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-equinox/src/test/resources/test-bundle.jar create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-osgi/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-osgi/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-osgi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoveryActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-osgi/src/test/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscovererTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility-osgi/src/test/resources/test-bundle.jar create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivatorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/UtilityExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ClassLoaderServiceDiscoverer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclaration.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscoverer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.UtilityExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ClassLoaderServiceDiscovererTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/BindingActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/ComponentLifecycle.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/ImplementationActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/InvokerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/BindingSCDLProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/BindingsActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/DiscoveryUtils.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/ImplementationImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/ImplementationsActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/PojoBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/PojoImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/SCDLProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/AbstractBinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/AbstractImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/AbstractStAXArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/DefaultPropertyValueObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/DynamicImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/PropertyValueObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/ResourceHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/extension-helper/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomainBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/SCATestCaseRunner.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ComponentManagerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/HotUpdatableSCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainZipsTestCaseFIXME.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/DefaultTestImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/module/TestModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/java/sample/Helloworld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/resources/helloworld.jar create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/resources/helloworld.zip create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/resources/test.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-android/src/test/resources/test.txt create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/main/java/org/apache/tuscany/sca/host/corba/jee/CorbaRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/main/java/org/apache/tuscany/sca/host/corba/jee/JEECorbaHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/java/org/apache/tuscany/sca/host/corba/jee/testing/JEECorbaHostTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/java/org/apache/tuscany/sca/host/corba/jee/testing/TestContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/java/org/apache/tuscany/sca/host/corba/jee/testing/TestInitialContextFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/java/org/apache/tuscany/sca/host/corba/jee/testing/general/TestInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/java/org/apache/tuscany/sca/host/corba/jee/testing/general/TestInterfaceHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/java/org/apache/tuscany/sca/host/corba/jee/testing/general/TestInterfaceHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/java/org/apache/tuscany/sca/host/corba/jee/testing/general/TestInterfaceOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/java/org/apache/tuscany/sca/host/corba/jee/testing/general/_TestInterfaceImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/java/org/apache/tuscany/sca/host/corba/jee/testing/general/_TestInterfaceStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/java/org/apache/tuscany/sca/host/corba/jee/testing/servants/TestInterfaceServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jee/src/test/resources/general.idl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse-tns/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse-tns/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse-tns/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse-tns/src/main/java/org/apache/tuscany/sca/host/corba/jse/tns/CorbaRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse-tns/src/main/java/org/apache/tuscany/sca/host/corba/jse/tns/TnsDefaultCorbaHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse-tns/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse-tns/src/test/java/org/apache/tuscany/sca/host/corba/testing/TnsDefaultCorbaHostTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/main/java/org/apache/tuscany/sca/host/corba/jse/CorbaRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/main/java/org/apache/tuscany/sca/host/corba/jse/DefaultCorbaHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/main/java/org/apache/tuscany/sca/host/corba/naming/NamingContextBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/main/java/org/apache/tuscany/sca/host/corba/naming/TransientNameServer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/main/java/org/apache/tuscany/sca/host/corba/naming/TransientNameService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/main/java/org/apache/tuscany/sca/host/corba/naming/TransientNamingContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/main/java/org/apache/tuscany/sca/host/corba/naming/TransientServiceException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/test/java/org/apache/tuscany/sca/host/corba/testing/DefaultCorbaHostTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceHolder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/TestInterfaceOperations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceImplBase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/test/java/org/apache/tuscany/sca/host/corba/testing/general/_TestInterfaceStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/test/java/org/apache/tuscany/sca/host/corba/testing/servants/TestInterfaceServant.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba-jse/src/test/resources/general.idl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHostUtils.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbanameURL.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/DefaultCorbaHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/ExtensibleCorbaHost.java create mode 100755 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/SocketUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.corba.CorbaHostExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-corba/src/test/java/org/apache/tuscany/sca/host/corba/UtilsTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-ejb/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-ejb/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-ejb/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-ejb/src/main/java/org/apache/tuscany/sca/host/ejb/DefaultEJBHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-ejb/src/main/java/org/apache/tuscany/sca/host/ejb/EJBHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-ejb/src/main/java/org/apache/tuscany/sca/host/ejb/EJBHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-ejb/src/main/java/org/apache/tuscany/sca/host/ejb/EJBRegistrationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-ejb/src/main/java/org/apache/tuscany/sca/host/ejb/EJBSessionBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-ejb/src/main/java/org/apache/tuscany/sca/host/ejb/ExtensibleEJBHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.ejb.EJBHostExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomainBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCATestCaseRunner.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ComponentManagerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/HotUpdatableSCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainZipsTestCaseFIXME.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/DefaultTestImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/module/TestModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/java/sample/Helloworld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/resources/helloworld.jar create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/resources/helloworld.zip create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/resources/test.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-embedded/src/test/resources/test.txt create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultResourceServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/SecurityContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletMappingException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/UserContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.http.ServletHostExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyDefaultServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyLogger.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/module/JettyRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/src/test/resources/content/test.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jetty/src/test/resources/tuscany.keyStore create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms-asf/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms-asf/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms-asf/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms-asf/src/main/java/org/apache/tuscany/sca/host/jms/asf/ASFListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms-asf/src/main/java/org/apache/tuscany/sca/host/jms/asf/JMSHostExtensionPointImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms-asf/src/main/java/org/apache/tuscany/sca/host/jms/asf/JMSServiceListenerFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms-asf/src/main/java/org/apache/tuscany/sca/host/jms/asf/ServiceInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms-asf/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.jms.JMSHostExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms/src/main/java/org/apache/tuscany/sca/host/jms/JMSHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms/src/main/java/org/apache/tuscany/sca/host/jms/JMSServiceListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms/src/main/java/org/apache/tuscany/sca/host/jms/JMSServiceListenerDetails.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-jms/src/main/java/org/apache/tuscany/sca/host/jms/JMSServiceListenerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-openejb/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-openejb/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-openejb/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-openejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-openejb/src/test/java/org/apache/tuscany/sca/host/openejb/OpenEJBServerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/ExtensibleRMIHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHostException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHostRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.rmi.RMIHostExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-rmi/src/test/java/org/apache/tuscany/sca/host/rmi/RMIHostImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/ServletWrapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/TomcatDefaultServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/TomcatPolicyBaseRealm.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/TomcatServer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/module/TomcatRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/src/test/java/org/apache/tuscany/sca/http/tomcat/TomcatServerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/src/test/resources/content/test.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-tomcat/src/test/resources/tuscany.keyStore create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/HotUpdateContextListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/SCADomainHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppRequestDispatcher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebSCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTEI.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/resources/META-INF/sca.tld create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/host-webapp/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/BPELODEDeployFile.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEBindingContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeployment.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeploymentException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEExternalService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEMessageExchangeContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEShutdownException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyEPR.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyPRC.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyProcessConfImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/test/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/test/resources/helloworld/greetings.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/test/resources/helloworld/helloworld.bpel create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/test/resources/helloworld/helloworld.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel-ode/src/test/resources/log4j.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.bpel.BPELFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/main/resources/impl-bpel-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/test/resources/helloworld/helloworld.bpel create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-bpel/src/test/resources/helloworld/helloworld.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/EJBImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/EJBImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/impl/EJBImplementationFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/impl/EJBImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/xml/EJBImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.ejb.EJBImplementationFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/main/resources/impl-ejb-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/test/java/org/apache/tuscany/sca/implementation/ejb/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/test/java/org/apache/tuscany/sca/implementation/ejb/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-ejb/src/test/resources/org/apache/tuscany/sca/implementation/ejb/xml/TestEJB.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactoryProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ArrayMultiplicityObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ContextInjector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ConversationIDObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/Injector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidAccessorException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceResolutionException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvocationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/InvalidConversationSequenceException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentNameFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/MethodEventInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/NoConversationalContractException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PolicyHandlingInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.PropertyValueFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/MultiplicityTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/CallbackWireObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean1.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean2.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Entry.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/SuperBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationConstants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/main/resources/impl-javaxml-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/calculator/AddService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/calculator/DivideService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/definitions_with_policysets.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/IntrospectionException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaConstructorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaElementImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaParameterImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaResourceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaScopeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaClassVisitor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AmbiguousConstructorException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/BaseJavaClassVisitor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ComponentNameProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateConstructorException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateDestructorException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateInitException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicatePropertyException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateReferenceException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateResourceException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalCallbackReferenceException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalContextException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalDestructorException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalInitException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalPropertyException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalReferenceException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalResourceException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalServiceDefinitionException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConstructorException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidPropertyException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidReferenceException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidResourceException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/NoConstructorException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/Resource.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceTypeNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/UnknownContextTypeException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.JavaImplementationFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaClassIntrospectorImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/JEEImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/JEEImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/impl/JEEImplementationFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/impl/JEEImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.jee.JEEImplementationFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/test/java/org/apache/tuscany/sca/implementation/jee/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/test/java/org/apache/tuscany/sca/implementation/jee/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/test/java/test/Helloworld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/test/java/test/MockImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/test/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-jee/src/test/resources/org/apache/tuscany/sca/implementation/jee/xml/TestJEE.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemonBootstrap.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/test/java/org/apache/tuscany/sca/implementation/node/NodeImplementationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/test/resources/TestComposite.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node-runtime/src/test/resources/TestNode.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/ConfiguredNodeImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/builder/impl/NodeCompositeBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/ConfiguredNodeImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/xml/ConfiguredNodeImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/xml/NodeImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.node.NodeImplementationFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/builder/impl/CalculateBindingURITestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestComposite.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestNode.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/DefaultNotificationImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/ImmutableMessage.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationComponentInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/test/java/org/apache/tuscany/sca/implementation/notification/NotificationComponentTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/test/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationLoaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-notification/src/test/resources/TrafficAdvisoryNotificationTestCase.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/README create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/PersistenceUnitInfoImplProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyManagerRuntime.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyStoreManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.openjpa.OpenJpaImplementationFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/test/java/org/apache/tuscany/sca/implementation/openjpa/ImplJpaTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/test/java/sample/Abc.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/test/java/sample/Message.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/test/java/sample/MyObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/src/test/resources/openjpa.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/db.lck create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/log/log.ctrl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/log/log1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/log/logmirror.ctrl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c10.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c101.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c111.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c121.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c130.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c141.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c150.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c161.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c171.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c180.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c191.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c1a1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c1b1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c1c0.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c1d1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c1e0.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c1f1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c20.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c200.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c211.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c221.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c230.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c241.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c251.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c260.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c271.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c281.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c290.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c2a1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c2b1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c2c1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c2d0.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c2e1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c2f0.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c300.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c31.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c311.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c320.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c331.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c41.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c51.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c60.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c71.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c81.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/c90.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/ca1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/cb1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/cc0.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/cd1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/ce1.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/seg0/cf0.dat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-openjpa/test/service.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyValueObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiInstanceWrapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRemotableInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/main/resources/impl-osgi-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiPropertyTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/resources/osgiproptest.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-osgi/src/test/resources/osgitest.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource-runtime/src/main/java/org/apache/tuscany/sca/implementation/resource/provider/GetResourceInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource-runtime/src/main/java/org/apache/tuscany/sca/implementation/resource/provider/ResourceImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource-runtime/src/main/java/org/apache/tuscany/sca/implementation/resource/provider/ResourceImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource-runtime/src/test/java/org/apache/tuscany/sca/implementation/resource/ResourceImplementationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource-runtime/src/test/resources/content/test.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource-runtime/src/test/resources/resource.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/Resource.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/ResourceImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/ResourceImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/impl/ResourceImplementationFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/impl/ResourceImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/impl/ResourceImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.resource.ResourceImplementationFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-resource/src/main/resources/impl-resource-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/engines/TuscanyJRubyScriptEngine.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.ImplementationActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/AbstractSCATestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/AbstractHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRefTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/AbstractHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/GroovyHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/HelloWorldProxy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JRubyHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScriptHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JythonHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/AbstractHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/GroovyHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/HelloWorldProxy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JRubyHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JavaScriptHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JythonHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/GroovyReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/HelloWorldTarget.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JRubyReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JavaScriptReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JythonReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRef.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworld.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworldProxy.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/GroovyHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JRubyHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScriptHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JythonHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.groovy create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.py create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.rb create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/GroovyHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JRubyHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JavaScriptHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JythonHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.groovy create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.py create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.rb create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/GroovyReference.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JRubyReference.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JavaScriptReference.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JythonReference.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.groovy create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.py create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.rb create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SCAApplicationContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SCANamespaceHandlerResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SCAParentApplicationContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/ScaNamespaceHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/ScaPropertyBeanDefinitionParser.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/ScaReferenceBeanDefinitionParser.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/ScaServiceBeanDefinitionParser.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringBeanNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringInvocationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringOperationNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringPropertyValueObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/InitDestroyAnnotationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/Constants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanPojoProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringConstructorArgElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAReferenceElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAServiceElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/resources/META-INF/spring.handlers create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/resources/META-INF/spring.schemas create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/resources/impl-spring-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/main/resources/org/springframework/sca/xml/spring-sca.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/AbstractSCATestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/HelloWorldImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/HelloWorldProxy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccessTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringExplicitHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringExplicitReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImplicitReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImportHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringSCAPropertyTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestBeanImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestContextAccessBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestHelloWorldBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestReferenceBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestSCAPropertyBean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/META-INF/sca/SpringContextAccess-context.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/META-INF/sca/SpringExplicitHelloWorld-context.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/META-INF/sca/SpringExplicitReference-context.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/META-INF/sca/SpringHelloWorld-Imported-context.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/META-INF/sca/SpringHelloWorld-context.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/META-INF/sca/SpringImplicitReference-context.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/META-INF/sca/SpringImportHelloWorld-context.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/META-INF/sca/testReferenceContext.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/META-INF/sca/testServiceContext.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringContextAccess.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringExplicitHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringExplicitReference.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImplicitReference.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImportHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringSCAProperty.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/spring/META-INF/MANIFEST.MF create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/spring/META-INF/spring/SpringSCAProperty-context.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-old/src/test/resources/test.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/README create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/SCANamespaceHandlerResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaNamespaceHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaPropertyBeanDefinitionParser.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaReferenceBeanDefinitionParser.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaServiceBeanDefinitionParser.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/InitDestroyAnnotationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAGenericApplicationContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/resources/META-INF/spring.handlers create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/resources/META-INF/spring.schemas create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring-runtime/src/main/resources/org/springframework/sca/xml/spring-sca.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/README create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringBeanElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringConstructorArgElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationConstants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringPropertyElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringSCAPropertyElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringSCAReferenceElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringSCAServiceElement.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanPojoProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ComponentTie.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ConfigurationPropertiesExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/DefaultConfigurationPropertiesExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/PropertyValueTie.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationTie.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringInvocationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.spring.ConfigurationPropertiesExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-spring/src/main/resources/impl-spring-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ComponentContextServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ContextScriptProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ContextScriptProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/DefaultContextScriptProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/JSONRPCScripProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/ComponentContextProxy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.web.ContextScriptProcessorExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web-runtime/src/main/resources/jsonrpc.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/WebImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/WebImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/impl/WebImplementationFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/impl/WebImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/introspect/PropertyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/introspect/ReferenceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/xml/WebImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.web.WebImplementationFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-web/src/test/resources/org/apache/tuscany/sca/implementation/web/xml/TestWeb.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-dojo/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-dojo/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-dojo/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-dojo/src/main/java/org/apache/tuscany/sca/implementation/widget/dojo/DojoJavaScriptComponentGeneratorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-dojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.ComponentJavaScriptGenerator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/main/java/org/apache/tuscany/sca/implementation/widget/tuscany/TuscanyJavaScriptComponentGeneratorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.ComponentJavaScriptGenerator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/test/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/test/java/store/Catalog.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/test/java/store/CatalogImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/test/java/store/ShoppingCartImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/test/resources/content/store.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/test/resources/content/storeJS.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/test/resources/content/unitTests.html create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/test/resources/widget.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime-tuscany/src/test/resources/widgetJS.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetComponentScriptGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetComponentScriptServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/src/main/resources/atomModel.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget-runtime/src/main/resources/binding-http.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/Widget.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.widget.WidgetImplementationFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-widget/src/main/resources/impl-widget-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryInvokationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/impl/XQueryImplementationFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/impl/XQueryImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/xml/XQueryImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/xml/XQueryIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/implementation-xquery/src/main/resources/impl-xquery-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/CodeGenerationHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedClassLoader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WebServiceInterfaceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.FaultExceptionMapper create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean1.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean2.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGeneratorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JavaReflectionHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/MyException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/MyServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/TestGenericClass.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/TestInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGeneratorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/resources/wsdl/Stock.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-jaxws/src/test/resources/wsdl/StockExceptionTest.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/src/main/resources/interface-javaxml-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorComponent.constrainingType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/ClassCachedJavaInterfaceFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilDuplicateRemotableTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/BPELExtensionHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/BPELPartnerLinkTypeExt.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLConstants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/main/resources/interface-wsdlxml-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/AbstractWSDLTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospectorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationIntrospectorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLPolicyAnnotatedInterfaceIntrospectorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/CalculatorComponent.constrainingType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/CalculatorImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/example.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/invalid-stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/test1.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/test1.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/test2.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/unwrapped-stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/policy/stockquote_policy.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/wsdl/helloworld-interface.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/wsdl/helloworld-service.wsdl create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/xsd/greeting.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/xsd/helloworld.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl-xml/src/test/resources/xsd/name.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/DefaultWSDLFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLInterface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLInterfaceContract.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLObject.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLOperation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/InvalidWSDLException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceContractImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceIntrospectorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLObjectImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLOperationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLOperationIntrospectorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface-wsdl/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ParameterMode.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/monitor/src/main/resources/META-INF/services/org.apache.tuscany.sca.monitor.MonitorFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-api/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-api/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-api/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2FactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2Impl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANodeFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/test/java/hello/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/test/java/hello/HelloWorldImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/Node2ImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/test/resources/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/Contribution.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/JarFileFinder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherBundleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeDaemonLauncher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/test/java/hello/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/test/java/hello/HelloWorldImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher-osgi/src/test/resources/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-manager/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-manager/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-manager/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-manager/src/main/java/org/apache/tuscany/sca/implementation/node/manager/NodeManagerUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-manager/src/main/java/org/apache/tuscany/sca/implementation/node/manager/NodeProcessCollectionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-manager/src/main/java/org/apache/tuscany/sca/implementation/node/manager/PingServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/node-manager/src/main/resources/NodeDaemon.composite create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/EquinoxRuntime.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntime.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/osgi-runtime/src/test/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntimeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/LoggingPolicyDefinitionsProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/main/resources/org/apache/tuscany/sca/policy/logging/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/test/java/org/apache/tuscany/sca/policy/logging/jdk/PolicyReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-logging/src/test/resources/org/apache/tuscany/sca/policy/logging/jdk/mock_policies.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-reliability/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-reliability/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-reliability/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-reliability/src/main/java/org/apache/tuscany/sca/policy/reliability/ReliabilityPolicyDefinitionsProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-reliability/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-reliability/src/main/resources/org/apache/tuscany/sca/policy/reliability/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-geronimo/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-geronimo/src/main/java/org/apache/tuscany/sca/policy/security/geronimo/GeronimoLDAPSecurityHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-geronimo/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.security.http.extensibility.LDAPSecurityHandler create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/authentication/AuthenticationConfigurationPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/authentication/AuthenticationConfigurationPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/confidentiality/ConfidentialityPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/confidentiality/ConfidentialityPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationCallbackHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationImplementationPolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationServicePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/extensibility/DefaultLDAPSecurityExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/extensibility/LDAPSecurityHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/extensibility/LDAPSecurityHandlerExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/util/HttpSecurityUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.security.http.extensibility.LDAPSecurityHandlerExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-http/src/main/resources/policy-security-http-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-jsr250/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-jsr250/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-jsr250/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-jsr250/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JSR250Activator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-jsr250/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JSR250PolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-jsr250/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security-jsr250/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCaseFIXME.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/SecurityUtil.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPrincipal.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationServicePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/token/TokenPrincipal.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/SecurityPolicyDefinitionsProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationImplementationPolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationServicePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/resources/org/apache/tuscany/sca/policy/security/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/resources/org/apache/tuscany/sca/policy/security/tuscany_definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/main/resources/policy-security-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-security/src/test/resources/org/apache/tuscany/sca/policy/security/mock_policy_definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/IncompatibleIntentException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionImplementationPolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionIntent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerWrapper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyDefinitionsProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionReferencePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionServicePolicyProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionalAction.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/resources/log4j.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/resources/org/apache/tuscany/sca/policy/transaction/definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/main/resources/org/apache/tuscany/sca/policy/transaction/tuscany_definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/test/java/org/apache/tuscany/sca/policy/transaction/PolicyReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-transaction/src/test/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml-ws/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml-ws/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml-ws/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml-ws/src/main/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/WSPolicyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml-ws/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultIntentAttachPointTypeFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointType.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointTypeFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Policy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetAttachPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ProfileIntent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/QualifiedIntent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentAttachPointTypeFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyContextImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ProfileIntentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/QualifiedIntentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandler.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerTuple.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerUtils.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/policy/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api-extension/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api-extension/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api-extension/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api-extension/src/main/java/org/apache/tuscany/sca/api/ComponentContextExtension.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/CallableReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/Constants.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/Conversation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/ConversationEndedException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/NoRegisteredCallbackException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/RequestContext.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/ServiceReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/ServiceRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/ServiceUnavailableException.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/AllowsPassByReference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Authentication.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Callback.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/ComponentName.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Confidentiality.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Constructor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Context.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationAttributes.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationID.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Conversational.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Destroy.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/EagerInit.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/EndsConversation.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Init.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Integrity.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Intent.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/OneWay.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/PolicySets.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Property.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Qualifier.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Reference.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Remotable.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Requires.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Scope.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/sca-api/src/main/java/org/osoa/sca/annotations/Service.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/tracing-aspectj/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/tracing-aspectj/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/tracing-aspectj/launcher.bat create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/tracing-aspectj/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/tracing-aspectj/src/main/java/org/apache/tuscany/sca/aspectj/LoggingAspect.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/tracing-aspectj/src/main/java/org/apache/tuscany/sca/aspectj/SimpleTracingAspect.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/tracing-aspectj/src/main/java/org/apache/tuscany/sca/aspectj/TimingAspect.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/tracing-aspectj/src/main/java/org/apache/tuscany/sca/aspectj/TracingAspect.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/tracing-aspectj/src/main/resources/META-INF/aop.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/tracing-aspectj/src/test/java/org/apache/tuscany/sca/aspectj/TracingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript-dojo/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript-dojo/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript-dojo/build-dojo.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript-dojo/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript-dojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript-dojo/src/main/resources/tuscany/AtomService.js create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/ComponentJavaScriptGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/ComponentJavaScriptGeneratorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/DefaultComponentJavaScriptGeneratorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/DefaultJavascriptProxyFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/JavascriptProxyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/JavascriptProxyFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.ComponentJavaScriptGeneratorExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactoryExtensionPoint create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/web-javascript/src/main/resources/web-javascript-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/builder/impl/ContributionDependencyBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionInfoProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/scanner/impl/DirectoryContributionScanner.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/scanner/impl/JarContributionScanner.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/src/main/resources/workspace-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/src/main/resources/workspace-validation-messages_it.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-impl/src/test/java/org/apache/tuscany/sca/workspace/builder/impl/ContributionDependencyBuilderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-manager/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-manager/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-manager/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-manager/src/main/java/org/apache/tuscany/sca/workspace/manager/WorkspaceManager.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-manager/src/main/java/org/apache/tuscany/sca/workspace/manager/impl/WorkspaceManagerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-xml/src/main/java/org/apache/tuscany/sca/workspace/xml/WorkspaceDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-xml/src/main/java/org/apache/tuscany/sca/workspace/xml/WorkspaceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-xml/src/main/resources/workspace-xml-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace-xml/src/test/java/org/apache/tuscany/sca/workspace/xml/ContributionWorkspaceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/ContributionConfiguration.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/DefaultWorkspaceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/Workspace.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/WorkspaceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/builder/ContributionDependencyBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/impl/WorkspaceFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/src/main/java/org/apache/tuscany/sca/workspace/impl/WorkspaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/workspace/src/main/resources/META-INF/services/org.apache.tuscany.sca.workspace.WorkspaceFactory create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XMLDocumentHelper.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/src/main/resources/xsd-xml-validation-messages.properties create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/src/test/java/org/apache/tuscany/sca/xsd/xml/XMLDocumentHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/src/test/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/src/test/resources/xsd/greeting.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd-xml/src/test/resources/xsd/name.xsd create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/DefaultXSDFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/XSDFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/XSDefinition.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/impl/XSDFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/impl/XSDefinitionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.6/modules/xsd/src/main/resources/META-INF/services/org.apache.tuscany.sca.xsd.XSDFactory (limited to 'sca-java-1.x/branches/sca-java-1.6/modules') diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/pom.xml new file mode 100644 index 0000000000..5cc43aacf7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/pom.xml @@ -0,0 +1,141 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-assembly-xml + Apache Tuscany SCA XML Assembly Model + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-definitions + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution-namespace + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution-java + 1.6-SNAPSHOT + + + + javax.xml.stream + stax-api + 1.0-2 + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + org.apache.tuscany.sca + tuscany-definitions-xml + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-policy-xml + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-policy-xml-ws + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-assembly-xsd + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.6-SNAPSHOT + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.assembly.xml + ${pom.name} + org.apache.tuscany.sca.assembly.xml* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java new file mode 100644 index 0000000000..b76b755dc7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java @@ -0,0 +1,915 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; +import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.dom.DOMSource; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.impl.IntentAttachPointTypeFactoryImpl; +import org.apache.tuscany.sca.policy.util.PolicyValidationException; +import org.apache.tuscany.sca.policy.util.PolicyValidationUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * A base class with utility methods for the other artifact processors in this module. + * + * @version $Rev$ $Date$ + */ +abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implements Constants { + + protected ContributionFactory contributionFactory; + protected AssemblyFactory assemblyFactory; + protected ExtensionFactory extensionFactory; + protected PolicyFactory policyFactory; + protected StAXArtifactProcessor extensionProcessor; + protected StAXAttributeProcessor extensionAttributeProcessor; + protected PolicyAttachPointProcessor policyProcessor; + private DocumentBuilderFactory documentBuilderFactory; + protected IntentAttachPointTypeFactory intentAttachPointTypeFactory; + private Monitor monitor; + + + /** + * Constructs a new BaseArtifactProcessor. + * @param contribFactory + * @param assemblyFactory + * @param extensionFactory + * @param policyFactory + * @param extensionProcessor + * @param monitor + */ + @SuppressWarnings("unchecked") + public BaseAssemblyProcessor(ContributionFactory contribFactory, + AssemblyFactory assemblyFactory, + ExtensionFactory extensionFactory, + PolicyFactory policyFactory, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + this.contributionFactory = contribFactory; + this.assemblyFactory = assemblyFactory; + this.extensionFactory = extensionFactory; + this.policyFactory = policyFactory; + this.extensionProcessor = (StAXArtifactProcessor)extensionProcessor; + this.extensionAttributeProcessor = extensionAttributeProcessor; + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.intentAttachPointTypeFactory = new IntentAttachPointTypeFactoryImpl(); + this.monitor = monitor; + } + + /** + * Constructs a new BaseArtifactProcessor. + * @param assemblyfactory + * @param extensionFactory + * @param policyFactory + * @param extensionProcessor + * @param monitor + */ + @SuppressWarnings("unchecked") + public BaseAssemblyProcessor(AssemblyFactory assemblyfactory, + ExtensionFactory extensionFactory, + PolicyFactory policyFactory, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + this.assemblyFactory = assemblyfactory; + this.extensionFactory = extensionFactory; + this.policyFactory = policyFactory; + this.extensionProcessor = (StAXArtifactProcessor)extensionProcessor; + this.extensionAttributeProcessor = extensionAttributeProcessor; + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.monitor = monitor; + } + + /** + * Marshals warnings into the monitor + * + * @param message + * @param model + * @param messageParameters + */ + protected void warning(String message, Object model, String... messageParameters) { + if (monitor != null){ + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-xml-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Marshals errors into the monitor + * + * @param problems + * @param message + * @param model + */ + protected void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Marshals exceptions into the monitor + * + * @param problems + * @param message + * @param model + */ + protected void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-xml-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + /** + * Start an element. + * @param writer + * @param name + * @param attrs + * @throws XMLStreamException + */ + protected void writeStart(XMLStreamWriter writer, String name, XAttr... attrs) throws XMLStreamException { + writeStart(writer, SCA10_NS, name, attrs); + } + + /** + * Start a document. + * @param writer + * @throws XMLStreamException + */ + protected void writeStartDocument(XMLStreamWriter writer, String name, XAttr... attrs) throws XMLStreamException { + writer.writeStartDocument(); + writer.setDefaultNamespace(SCA10_NS); + writeStart(writer, SCA10_NS, name, attrs); + writer.writeDefaultNamespace(SCA10_NS); + } + + /** + * Read list of reference targets + * @param reference + * @param reader + */ + protected void readTargets(Reference reference, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, TARGET); + ComponentService target = null; + if (value != null) { + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + target = assemblyFactory.createComponentService(); + target.setUnresolved(true); + target.setName(tokens.nextToken()); + reference.getTargets().add(target); + } + } + } + + /** + * Write a list of targets into an attribute + * @param reference + * @return + */ + protected XAttr writeTargets(Reference reference) { + List targets = new ArrayList(); + for (Service target : reference.getTargets()) { + targets.add(target.getName()); + } + return new XAttr(TARGET, targets); + } + + /** + * Read a multiplicity attribute. + * @param reference + * @param reader + */ + protected void readMultiplicity(AbstractReference reference, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, MULTIPLICITY); + if (ZERO_ONE.equals(value)) { + reference.setMultiplicity(Multiplicity.ZERO_ONE); + } else if (ONE_N.equals(value)) { + reference.setMultiplicity(Multiplicity.ONE_N); + } else if (ZERO_N.equals(value)) { + reference.setMultiplicity(Multiplicity.ZERO_N); + } else if (ONE_ONE.equals(value)) { + reference.setMultiplicity(Multiplicity.ONE_ONE); + } + } + + protected XAttr writeMultiplicity(AbstractReference reference) { + Multiplicity multiplicity = reference.getMultiplicity(); + if (multiplicity != null) { + String value = null; + if (Multiplicity.ZERO_ONE.equals(multiplicity)) { + value = ZERO_ONE; + } else if (Multiplicity.ONE_N.equals(multiplicity)) { + value = ONE_N; + } else if (Multiplicity.ZERO_N.equals(multiplicity)) { + value = ZERO_N; + } else if (Multiplicity.ONE_ONE.equals(multiplicity)) { + value = ONE_ONE; + return null; + } + return new XAttr(MULTIPLICITY, value); + } + return null; + } + + /** + * Returns the value of a constrainingType attribute. + * @param reader + * @return + */ + protected ConstrainingType readConstrainingType(XMLStreamReader reader) { + QName constrainingTypeName = getQName(reader, Constants.CONSTRAINING_TYPE); + if (constrainingTypeName != null) { + ConstrainingType constrainingType = assemblyFactory.createConstrainingType(); + constrainingType.setName(constrainingTypeName); + constrainingType.setUnresolved(true); + return constrainingType; + } else { + return null; + } + } + + /** + * Reads an abstract property element. + * @param property + * @param reader + * @throws XMLStreamException + * @throws ContributionReadException + */ + protected void readAbstractProperty(AbstractProperty property, XMLStreamReader reader) throws XMLStreamException, + ContributionReadException { + + property.setName(getString(reader, NAME)); + property.setMany(getBoolean(reader, MANY)); + property.setMustSupply(getBoolean(reader, MUST_SUPPLY)); + property.setXSDElement(getQName(reader, ELEMENT)); + property.setXSDType(getQName(reader, TYPE)); + } + + /** + * Resolve an implementation. + * @param implementation + * @param resolver + * @return + * @throws ContributionResolveException + */ + protected Implementation resolveImplementation(Implementation implementation, ModelResolver resolver) + throws ContributionResolveException, PolicyValidationException { + if (implementation != null) { + if (implementation.isUnresolved()) { + implementation = resolver.resolveModel(Implementation.class, implementation); + + // Lazily resolve implementations + if (implementation.isUnresolved()) { + extensionProcessor.resolve(implementation, resolver); + if (!implementation.isUnresolved()) { + //resolve policies + if ( implementation instanceof PolicySetAttachPoint ) { + PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation; + resolveIntents(policiedImpl.getRequiredIntents(), resolver); + PolicyValidationUtils.validateIntents(policiedImpl, policiedImpl.getType()); + + resolvePolicySets(policiedImpl.getPolicySets(), resolver); + PolicyValidationUtils.validatePolicySets(policiedImpl); + + if ( implementation instanceof OperationsConfigurator ) { + OperationsConfigurator opsConfigurator = (OperationsConfigurator)implementation; + for ( ConfiguredOperation implOp : opsConfigurator.getConfiguredOperations() ) { + resolveIntents(implOp.getRequiredIntents(), resolver); + PolicyValidationUtils.validateIntents(implOp, policiedImpl.getType()); + + resolvePolicySets(implOp.getPolicySets(), resolver); + PolicyValidationUtils.validatePolicySets(implOp, + policiedImpl.getType(), + policiedImpl.getApplicablePolicySets()); + } + } + + for ( Service service : implementation.getServices() ) { + resolveIntents(service.getRequiredIntents(), resolver); + resolvePolicySets(service.getPolicySets(), resolver); + + for ( ConfiguredOperation svcOp : service.getConfiguredOperations() ) { + resolveIntents(svcOp.getRequiredIntents(), resolver); + resolvePolicySets(svcOp.getPolicySets(), resolver); + } + } + + for ( Reference reference : implementation.getReferences() ) { + resolveIntents(reference.getRequiredIntents(), resolver); + resolvePolicySets(reference.getPolicySets(), resolver); + } + } + + resolver.addModel(implementation); + } + } + } + + if ( implementation instanceof IntentAttachPoint && + ((IntentAttachPoint)implementation).getType() != null && + ((IntentAttachPoint)implementation).getType().isUnresolved() ) { + ((IntentAttachPoint)implementation).setType( + resolver.resolveModel(IntentAttachPointType.class, + ((IntentAttachPoint)implementation).getType())); + } + } + return implementation; + } + + /** + * Resolve interface, callback interface and bindings on a list of contracts. + * @param contracts the list of contracts + * @param resolver the resolver to use to resolve models + */ + protected void resolveContracts(List contracts, ModelResolver resolver) + throws ContributionResolveException { + resolveContracts(null, contracts, resolver); + } + + + /** + * Resolve interface, callback interface and bindings on a list of contracts. + * @param parent element for the contracts + * @param contracts the list of contracts + * @param resolver the resolver to use to resolve models + */ + protected void resolveContracts(Base parent, List contracts, ModelResolver resolver) + throws ContributionResolveException { + + String parentName = (parent instanceof Composite) ? ((Composite)parent).getName().toString() : + (parent instanceof Component) ? ((Component)parent).getName() : "UNKNOWN"; + + for (Contract contract : contracts) { + try { + //resolve the intents and policysets as they need to be copied over into the + //child binding elements + resolveIntents(contract.getRequiredIntents(), resolver); + resolvePolicySets(contract.getPolicySets(), resolver); + resolvePolicySets(contract.getApplicablePolicySets(), resolver); + + // Inherit the composite / component level applicable policy sets. + if ( parent != null && parent instanceof PolicySetAttachPoint ) { + addInheritedPolicySets(((PolicySetAttachPoint)parent).getApplicablePolicySets(), contract.getApplicablePolicySets()); + } + + for ( ConfiguredOperation confOp : contract.getConfiguredOperations() ) { + resolveIntents(confOp.getRequiredIntents(), resolver); + resolvePolicySets(confOp.getPolicySets(), resolver); + resolvePolicySets(confOp.getApplicablePolicySets(), resolver); + + //inherit applicable policy sets from parent contract + addInheritedPolicySets(contract.getApplicablePolicySets(), confOp.getApplicablePolicySets()); + } + + // Resolve the interface contract + InterfaceContract interfaceContract = contract.getInterfaceContract(); + if (interfaceContract != null) { + extensionProcessor.resolve(interfaceContract, resolver); + } + + // Resolve bindings + for (int i = 0, n = contract.getBindings().size(); i < n; i++) { + Binding binding = contract.getBindings().get(i); + extensionProcessor.resolve(binding, resolver); + + if (binding instanceof IntentAttachPoint) { + IntentAttachPoint policiedBinding = (IntentAttachPoint)binding; + + if ( policiedBinding.getType() != null && policiedBinding.getType().isUnresolved() ) { + IntentAttachPointType resolved = + resolver.resolveModel(IntentAttachPointType.class, + policiedBinding.getType()); + policiedBinding.setType(resolved); + } + + resolveIntents(policiedBinding.getRequiredIntents(), resolver); + PolicyValidationUtils.validateIntents(policiedBinding, policiedBinding.getType()); + } + + if (binding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding; + resolvePolicySets(policiedBinding.getPolicySets(), resolver); + //validate if attached policysets apply to the binding + resolvePolicySets(policiedBinding.getApplicablePolicySets(), resolver); + //inherit the applicable policysets from parent contract as whatever applies to that + //applies to the binding as well + addInheritedPolicySets(contract.getApplicablePolicySets(), policiedBinding.getApplicablePolicySets()); + PolicyValidationUtils.validatePolicySets(policiedBinding); + } + + if (binding instanceof OperationsConfigurator) { + OperationsConfigurator opConfigurator = (OperationsConfigurator)binding; + for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) { + resolveIntents(confOp.getRequiredIntents(), resolver); + PolicyValidationUtils.validateIntents(confOp, ((PolicySetAttachPoint)binding).getType()); + + resolvePolicySets(confOp.getPolicySets(), resolver); + resolvePolicySets(confOp.getApplicablePolicySets(), resolver); + //inherit the applicable policysets from parent binding as whatever applies to that + //applies to the binding as well + addInheritedPolicySets(((PolicySetAttachPoint)binding).getApplicablePolicySets(), + confOp.getApplicablePolicySets()); + PolicyValidationUtils.validatePolicySets(confOp, ((PolicySetAttachPoint)binding).getType()); + } + } + } + + // Resolve callback bindings + if (contract.getCallback() != null) { + resolveIntents(contract.getCallback().getRequiredIntents(), resolver); + resolvePolicySets(contract.getCallback().getPolicySets(), resolver); + resolvePolicySets(contract.getCallback().getApplicablePolicySets(), resolver); + //inherit the contract's policy intents and policysets + addInheritedPolicySets(contract.getApplicablePolicySets(), contract.getCallback().getApplicablePolicySets()); + + for (int i = 0, n = contract.getCallback().getBindings().size(); i < n; i++) { + Binding binding = contract.getCallback().getBindings().get(i); + extensionProcessor.resolve(binding, resolver); + + if (binding instanceof IntentAttachPoint) { + IntentAttachPoint policiedBinding = (IntentAttachPoint)binding; + + if ( policiedBinding.getType().isUnresolved() ) { + IntentAttachPointType resolved = + resolver.resolveModel(IntentAttachPointType.class, + policiedBinding.getType()); + policiedBinding.setType(resolved); + } + + resolveIntents(policiedBinding.getRequiredIntents(), resolver); + PolicyValidationUtils.validateIntents(policiedBinding, policiedBinding.getType()); + } + + if (binding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding; + resolvePolicySets(policiedBinding.getPolicySets(), resolver); + //validate if attached policysets apply to the binding + resolvePolicySets(policiedBinding.getApplicablePolicySets(), resolver); + //inherit the applicable policysets from parent contract as whatever applies to that + //applies to the binding as well + addInheritedPolicySets(contract.getApplicablePolicySets(), policiedBinding.getApplicablePolicySets()); + PolicyValidationUtils.validatePolicySets(policiedBinding); + } + + if (binding instanceof OperationsConfigurator) { + OperationsConfigurator opConfigurator = (OperationsConfigurator)binding; + for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) { + resolveIntents(confOp.getRequiredIntents(), resolver); + PolicyValidationUtils.validateIntents(confOp, ((PolicySetAttachPoint)binding).getType()); + + resolvePolicySets(confOp.getPolicySets(), resolver); + resolvePolicySets(confOp.getApplicablePolicySets(), resolver); + //inherit the applicable policysets from parent binding as whatever applies to that + //applies to the binding as well + addInheritedPolicySets(((PolicySetAttachPoint)binding).getApplicablePolicySets(), + confOp.getApplicablePolicySets()); + PolicyValidationUtils.validatePolicySets(confOp, ((PolicySetAttachPoint)binding).getType()); + } + } + } + } + } catch ( PolicyValidationException e ) { + error("PolicyServiceValidationException", contract, contract.getName(), parentName, e.getMessage()); + //throw new ContributionResolveException("PolicyValidation exceptions when processing service/reference '" + //+ contract.getName() + "' in '" + parentName + "'"); + } + } + } + + /** + * Resolve interface and callback interface on a list of abstract contracts. + * @param contracts the list of contracts + * @param resolver the resolver to use to resolve models + */ + protected void resolveAbstractContracts(List contracts, ModelResolver resolver) + throws ContributionResolveException { + for (AbstractContract contract : contracts) { + + // Resolve the interface contract + InterfaceContract interfaceContract = contract.getInterfaceContract(); + if (interfaceContract != null) { + extensionProcessor.resolve(interfaceContract, resolver); + } + } + } + + /** + * Returns a constrainingType attribute. + * @param componentType + * @return + */ + protected XAttr writeConstrainingType(ComponentType componentType) { + ConstrainingType constrainingType = componentType.getConstrainingType(); + if (constrainingType != null) + return new XAttr(Constants.CONSTRAINING_TYPE, constrainingType.getName()); + else + return null; + } + + /** + * Read a property value into a DOM document. + * @param element + * @param type + * @param reader + * @return + * @throws XMLStreamException + * @throws ContributionReadException + * @throws ParserConfigurationException + */ + protected Document readPropertyValue(QName element, QName type, XMLStreamReader reader) throws XMLStreamException, + ContributionReadException { + + Document document; + try { + if (documentBuilderFactory == null) { + documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(true); + } + document = documentBuilderFactory.newDocumentBuilder().newDocument(); + } catch (ParserConfigurationException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", documentBuilderFactory, ce); + throw ce; + } + + // root element has no namespace and local name "value" + Element root = document.createElementNS(null, "value"); + if (type != null) { + org.w3c.dom.Attr xsi = document.createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi"); + xsi.setValue(W3C_XML_SCHEMA_INSTANCE_NS_URI); + root.setAttributeNodeNS(xsi); + + String prefix = type.getPrefix(); + if (prefix == null || prefix.length() == 0) { + prefix = "ns"; + } + + declareNamespace(root, prefix, type.getNamespaceURI()); + + org.w3c.dom.Attr xsiType = document.createAttributeNS(W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type"); + xsiType.setValue(prefix + ":" + type.getLocalPart()); + root.setAttributeNodeNS(xsiType); + } + document.appendChild(root); + + loadElement(reader, root); + return document; + } + + /** + * Create a DOM element + * @param document + * @param name + * @return + */ + private 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); + } + + /** + * Declare a namespace. + * @param element + * @param prefix + * @param ns + */ + private void declareNamespace(Element element, String prefix, String ns) { + if (ns == null) { + ns = ""; + } + if (prefix == null) { + prefix = ""; + } + String qname = null; + if ("".equals(prefix)) { + qname = "xmlns"; + } else { + qname = "xmlns:" + prefix; + } + Node node = element; + boolean declared = false; + while (node != null && node.getNodeType() == Node.ELEMENT_NODE) { + NamedNodeMap attrs = node.getAttributes(); + if (attrs == null) { + break; + } + Node attr = attrs.getNamedItem(qname); + if (attr != null) { + declared = ns.equals(attr.getNodeValue()); + break; + } + node = node.getParentNode(); + } + if (!declared) { + org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname); + attr.setValue(ns); + element.setAttributeNodeNS(attr); + } + } + + /** + * Load a property value specification from an StAX stream into a DOM + * Document. Only elements, text and attributes are processed; all comments + * and other whitespace are ignored. + * + * @param reader the stream to read from + * @param root the DOM node to load + * @throws javax.xml.stream.XMLStreamException + */ + private void loadElement(XMLStreamReader reader, Element root) throws XMLStreamException { + Document document = root.getOwnerDocument(); + Node current = root; + while (true) { + switch (reader.next()) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + Element child = createElement(document, name); + + // push the new element and make it the current one + current.appendChild(child); + current = child; + + int count = reader.getNamespaceCount(); + for (int i = 0; i < count; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + declareNamespace(child, prefix, ns); + } + + if (!"".equals(name.getNamespaceURI())) { + declareNamespace(child, name.getPrefix(), name.getNamespaceURI()); + } + + // add the attributes for this element + count = reader.getAttributeCount(); + for (int i = 0; i < count; i++) { + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String qname = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + if (prefix != null && prefix.length() != 0) { + qname = prefix + ":" + qname; + } + child.setAttributeNS(ns, qname, value); + if (ns != null) { + declareNamespace(child, prefix, ns); + } + } + + break; + case XMLStreamConstants.CDATA: + current.appendChild(document.createCDATASection(reader.getText())); + break; + case XMLStreamConstants.CHARACTERS: + current.appendChild(document.createTextNode(reader.getText())); + break; + case XMLStreamConstants.END_ELEMENT: + // if we are back at the root then we are done + if (current == root) { + return; + } + + // pop the element off the stack + current = current.getParentNode(); + } + } + } + + /** + * Resolve policy intents attached to a specific SCA Artifact + * @param policyIntents list of policy intents + * @param resolver + */ + protected void resolveIntents(List policyIntents, ModelResolver resolver) { + List requiredIntents = new ArrayList(); + Intent resolvedIntent = null; + for (Intent intent : policyIntents) { + resolvedIntent = resolver.resolveModel(Intent.class, intent); + requiredIntents.add(resolvedIntent); + } + policyIntents.clear(); + policyIntents.addAll(requiredIntents); + } + + /** + * Resolve policy sets attached to a specific SCA Construct + * @param policySets list of attached policy sets + * @param resolver + */ + protected void resolvePolicySets(List policySets, ModelResolver resolver) { + List resolvedPolicySets = new ArrayList(); + PolicySet resolvedPolicySet = null; + for (PolicySet policySet : policySets) { + if (policySet.isUnresolved()) { + resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet); + resolvedPolicySets.add(resolvedPolicySet); + } else { + resolvedPolicySets.add(policySet); + } + } + policySets.clear(); + policySets.addAll(resolvedPolicySets); + } + + /** + * Write the value of a property + * @param document + * @param element + * @param type + * @param writer + * @throws XMLStreamException + */ + protected void writePropertyValue(Object propertyValue, QName element, QName type, XMLStreamWriter writer) + throws XMLStreamException { + + if (propertyValue instanceof Document) { + Document document = (Document)propertyValue; + NodeList nodeList = document.getDocumentElement().getChildNodes(); + + for (int item = 0; item < nodeList.getLength(); ++item) { + Node node = nodeList.item(item); + int nodeType = node.getNodeType(); + if (nodeType == Node.ELEMENT_NODE) { + XMLStreamReader reader = + XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(node)); + + while (reader.hasNext()) { + switch (reader.next()) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + writer.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); + + int namespaces = reader.getNamespaceCount(); + for (int i = 0; i < namespaces; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + writer.writeNamespace(prefix, ns); + } + + if (!"".equals(name.getNamespaceURI())) { + writer.writeNamespace(name.getPrefix(), name.getNamespaceURI()); + } + + // add the attributes for this element + namespaces = reader.getAttributeCount(); + for (int i = 0; i < namespaces; i++) { + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String qname = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + + writer.writeAttribute(prefix, ns, qname, value); + } + + break; + case XMLStreamConstants.CDATA: + writer.writeCData(reader.getText()); + break; + case XMLStreamConstants.CHARACTERS: + writer.writeCharacters(reader.getText()); + break; + case XMLStreamConstants.END_ELEMENT: + writer.writeEndElement(); + break; + } + } + } else { + writer.writeCharacters(node.getTextContent()); + } + } + } + } + + protected void addInheritedIntents(List sourceList, List targetList) { + if (sourceList != null) { + targetList.addAll(sourceList); + } + } + + protected void addInheritedPolicySets(List sourceList, List targetList) { + if (sourceList != null) { + targetList.addAll(sourceList); + } + } + + /** + * + * @param reader + * @param elementName + * @param extensible + * @param extensionAttributeProcessor + * @throws ContributionReadException + * @throws XMLStreamException + */ + protected void readExtendedAttributes(XMLStreamReader reader, Extensible extensible) throws ContributionReadException, XMLStreamException { + super.readExtendedAttributes(reader, extensible, extensionAttributeProcessor, extensionFactory); + } + + + /*protected void validatePolicySets(PolicySetAttachPoint policySetAttachPoint) + throws ContributionResolveException { + validatePolicySets(policySetAttachPoint, policySetAttachPoint.getApplicablePolicySets()); + } + + + protected void validatePolicySets(PolicySetAttachPoint policySetAttachPoint, + List applicablePolicySets) throws ContributionResolveException { + //Since the applicablePolicySets in a policySetAttachPoint will already have the + //list of policysets that might ever be applicable to this attachPoint, just check + //if the defined policysets feature in the list of applicable policysets + IntentAttachPointType attachPointType = policySetAttachPoint.getType(); + for ( PolicySet definedPolicySet : policySetAttachPoint.getPolicySets() ) { + if ( !definedPolicySet.isUnresolved() ) { + if ( !applicablePolicySets.contains(definedPolicySet)) { + throw new ContributionResolveException("Policy Set '" + definedPolicySet.getName() + + "' does not apply to binding type " + + attachPointType.getName()); + } + } else { + throw new ContributionResolveException("Policy Set '" + definedPolicySet.getName() + + "' is not defined in this domain "); + + + } + } + }*/ +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java new file mode 100644 index 0000000000..7681115149 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; + +/** + * A componentType processor. + * + * @version $Rev$ $Date$ + */ +public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor { + private XMLInputFactory inputFactory; + + /** + * Constructs a new componentType processor. + * @param factory + * @param policyFactory + * @param registry + */ + public ComponentTypeDocumentProcessor(StAXArtifactProcessor staxProcessor, + XMLInputFactory inputFactory, + Monitor monitor) { + super(null, null, null, staxProcessor, null, monitor); + this.inputFactory = inputFactory; + } + + /** + * Constructs a new componentType processor. + * @param modelFactories + * @param staxProcessor + */ + public ComponentTypeDocumentProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor staxProcessor, + Monitor monitor) { + super(null, null, null, staxProcessor, null, monitor); + this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); + } + + public ComponentType read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + InputStream urlStream = null; + try { + + // Create a stream reader + URLConnection connection = url.openConnection(); + connection.setUseCaches(false); + urlStream = connection.getInputStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); + reader.nextTag(); + + // Reader the componentType model + ComponentType componentType = (ComponentType)extensionProcessor.read(reader); + if (componentType != null) { + componentType.setURI(uri.toString()); + } + + // For debugging purposes, write it back to XML +// if (componentType != null) { +// try { +// ByteArrayOutputStream bos = new ByteArrayOutputStream(); +// XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); +// outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); +// extensionProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos)); +// Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray())); +// OutputFormat format = new OutputFormat(); +// format.setIndenting(true); +// format.setIndent(2); +// XMLSerializer serializer = new XMLSerializer(System.out, format); +// serializer.serialize(document); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } + + return componentType; + + } catch (XMLStreamException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", inputFactory, ce); + throw ce; + } catch (IOException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", inputFactory, ce); + throw ce; + } finally { + try { + if (urlStream != null) { + urlStream.close(); + urlStream = null; + } + } catch (IOException ioe) { + //ignore + } + } + } + + public void resolve(ComponentType componentType, ModelResolver resolver) throws ContributionResolveException { + extensionProcessor.resolve(componentType, resolver); + } + + public String getArtifactType() { + return ".componentType"; + } + + public Class getModelType() { + return ComponentType.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java new file mode 100644 index 0000000000..d0d11cd02b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Model Resolver for ComponentType models. + * + * @version $Rev$ $Date$ + */ +public class ComponentTypeModelResolver implements ModelResolver { + private Contribution contribution; + private Map map = new HashMap(); + + public ComponentTypeModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + } + + public void addModel(Object resolved) { + ComponentType componentType = (ComponentType)resolved; + map.put(componentType.getURI(), componentType); + } + + public Object removeModel(Object resolved) { + return map.remove(((ComponentType)resolved).getURI()); + } + + public T resolveModel(Class modelClass, T unresolved) { + + //get componentType artifact URI + String uri = ((ComponentType)unresolved).getURI(); + if (uri == null) { + return (T)unresolved; + } + + //lookup the componentType + ComponentType resolved = (ComponentType) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } + + //If not found, delegate the resolution to the imports (in this case based on the java imports) + //compute the package name from the componentType URI + if (unresolved instanceof ComponentType) { + //FIXME The core assembly model now depends on java imports to + // resolve componentTypes of all kinds, this is not right at all!!! + int s = uri.lastIndexOf('/'); + if (s != -1) { + String packageName = uri.substring(0, uri.lastIndexOf("/")); + for (Import import_ : this.contribution.getImports()) { + if (import_ instanceof JavaImport) { + JavaImport javaImport = (JavaImport)import_; + //check the import location against the computed package name from the componentType URI + if (javaImport.getPackage().equals(packageName)) { + // Delegate the resolution to the import resolver + resolved = javaImport.getModelResolver().resolveModel(ComponentType.class, (ComponentType)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } + } + } + } + } + + return (T)unresolved; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java new file mode 100644 index 0000000000..964116a0c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java @@ -0,0 +1,390 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.w3c.dom.Document; + +/** + * A componentType processor. + * + * @version $Rev$ $Date$ + */ +public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor { + + /** + * Constructs a new componentType processor. + * @param assemblyFactory + * @param policyFactory + * @param registry + */ + public ComponentTypeProcessor(AssemblyFactory assemblyFactory, + ExtensionFactory extensionFactory, + PolicyFactory policyFactory, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + super(assemblyFactory, extensionFactory, policyFactory, extensionProcessor, extensionAttributeProcessor, monitor); + } + + /** + * Constructs a new componentType processor. + * + * @param modelFactories + * @param extensionProcessor + */ + public ComponentTypeProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + super(modelFactories.getFactory(AssemblyFactory.class), + modelFactories.getFactory(ExtensionFactory.class), + modelFactories.getFactory(PolicyFactory.class), + extensionProcessor, + extensionAttributeProcessor, + monitor); + } + + public ComponentType read(XMLStreamReader reader) throws ContributionReadException { + ComponentType componentType = null; + Service service = null; + Reference reference = null; + Contract contract = null; + Property property = null; + Callback callback = null; + QName name = null; + + try { + // Read the componentType document + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + name = reader.getName(); + + if (Constants.COMPONENT_TYPE_QNAME.equals(name)) { + + // Read a + componentType = assemblyFactory.createComponentType(); + componentType.setConstrainingType(readConstrainingType(reader)); + + } else if (Constants.SERVICE_QNAME.equals(name)) { + + // Read a + service = assemblyFactory.createService(); + contract = service; + service.setName(getString(reader, Constants.NAME)); + componentType.getServices().add(service); + policyProcessor.readPolicies(service, reader); + + } else if (Constants.REFERENCE_QNAME.equals(name)) { + + // Read a + reference = assemblyFactory.createReference(); + contract = reference; + reference.setName(getString(reader, Constants.NAME)); + reference.setWiredByImpl(getBoolean(reader, Constants.WIRED_BY_IMPL)); + readMultiplicity(reference, reader); + readTargets(reference, reader); + componentType.getReferences().add(reference); + policyProcessor.readPolicies(reference, reader); + + } else if (Constants.PROPERTY_QNAME.equals(name)) { + + // Read a + property = assemblyFactory.createProperty(); + readAbstractProperty(property, reader); + policyProcessor.readPolicies(property, reader); + + // Read the property value + Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader); + property.setValue(value); + + componentType.getProperties().add(property); + + } else if (Constants.IMPLEMENTATION_QNAME.equals(name)) { + + // Read an element + policyProcessor.readPolicies(componentType, reader); + + } else if (Constants.CALLBACK_QNAME.equals(name)) { + + // Read a + callback = assemblyFactory.createCallback(); + contract.setCallback(callback); + policyProcessor.readPolicies(callback, reader); + + } else if (OPERATION_QNAME.equals(name)) { + + // Read an + Operation operation = new OperationImpl(); + operation.setName(getString(reader, NAME)); + operation.setUnresolved(true); + if (callback != null) { + policyProcessor.readPolicies(callback, operation, reader); + } else { + policyProcessor.readPolicies(contract, operation, reader); + } + } else { + + // Read an extension element + Object extension = extensionProcessor.read(reader); + if (extension != null) { + if (extension instanceof InterfaceContract) { + + // and + contract.setInterfaceContract((InterfaceContract)extension); + + } else if (extension instanceof Binding) { + + // and + if (callback != null) { + callback.getBindings().add((Binding)extension); + } else { + contract.getBindings().add((Binding)extension); + } + } else { + + // Add the extension element to the current element + if (callback != null) { + callback.getExtensions().add(extension); + } else if (contract != null) { + contract.getExtensions().add(extension); + } else if (property != null) { + property.getExtensions().add(extension); + } else { + if (componentType instanceof Extensible) { + ((Extensible)componentType).getExtensions().add(extension); + } + } + } + } + } + break; + + case END_ELEMENT: + name = reader.getName(); + + // Clear current state when reading reaching end element + if (SERVICE_QNAME.equals(name)) { + service = null; + contract = null; + } else if (REFERENCE_QNAME.equals(name)) { + reference = null; + contract = null; + } else if (PROPERTY_QNAME.equals(name)) { + property = null; + } else if (CALLBACK_QNAME.equals(name)) { + callback = null; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return componentType; + } + + public void write(ComponentType componentType, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write element + writeStartDocument(writer, COMPONENT_TYPE, + writeConstrainingType(componentType)); + + // Write elements + for (Service service : componentType.getServices()) { + writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), + policyProcessor.writePolicies(service)); + + if (service.getInterfaceContract() != null) { + extensionProcessor.write(service.getInterfaceContract(), writer); + } + + for (Binding binding: service.getBindings()) { + extensionProcessor.write(binding, writer); + } + + if (service.getCallback() != null) { + Callback callback = service.getCallback(); + writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); + + for (Binding binding: callback.getBindings()) { + extensionProcessor.write(binding, writer); + } + for (Object extension: callback.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + for (Object extension: service.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write elements + for (Reference reference : componentType.getReferences()) { + + writeStart(writer, REFERENCE, + new XAttr(NAME, reference.getName()), + writeMultiplicity(reference), + writeTargets(reference), + policyProcessor.writePolicies(reference)); + + extensionProcessor.write(reference.getInterfaceContract(), writer); + + for (Binding binding: reference.getBindings()) { + extensionProcessor.write(binding, writer); + } + + if (reference.getCallback() != null) { + Callback callback = reference.getCallback(); + writeStart(writer, CALLBACK, + policyProcessor.writePolicies(callback)); + + for (Binding binding: callback.getBindings()) { + extensionProcessor.write(binding, writer); + } + for (Object extension: callback.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + for (Object extension: reference.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write elements + for (Property property : componentType.getProperties()) { + writeStart(writer, + PROPERTY, + new XAttr(NAME, property.getName()), + new XAttr(MUST_SUPPLY, property.isMustSupply()), + new XAttr(MANY, property.isMany()), + new XAttr(TYPE, property.getXSDType()), + new XAttr(ELEMENT, property.getXSDElement()), + policyProcessor.writePolicies(property)); + + // Write property value + writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer); + + // Write extensions + for (Object extension : property.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write extension elements + if (componentType instanceof Extensible) { + for (Object extension: ((Extensible)componentType).getExtensions()) { + extensionProcessor.write(extension, writer); + } + } + + // Write elements if the componentType has + // any intents or policySets + boolean writeImplementation = false; + if (componentType instanceof IntentAttachPoint) { + if (!((IntentAttachPoint)componentType).getRequiredIntents().isEmpty()) { + writeImplementation = true; + } + } + if (componentType instanceof PolicySetAttachPoint) { + if (!((PolicySetAttachPoint)componentType).getPolicySets().isEmpty()) { + writeImplementation = true; + } + } + if (writeImplementation) { + writeStart(writer, IMPLEMENTATION, + policyProcessor.writePolicies(componentType)); + } + + writeEndDocument(writer); + } + + public void resolve(ComponentType componentType, ModelResolver resolver) throws ContributionResolveException { + + // Resolve component type services and references + resolveContracts(componentType.getServices(), resolver); + resolveContracts(componentType.getReferences(), resolver); + if ( componentType instanceof PolicySetAttachPoint ) { + resolveIntents(((PolicySetAttachPoint)componentType).getRequiredIntents(), resolver); + resolvePolicySets(((PolicySetAttachPoint)componentType).getPolicySets(), resolver); + } + } + + public QName getArtifactType() { + return COMPONENT_TYPE_QNAME; + } + + public Class getModelType() { + return ComponentType.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java new file mode 100644 index 0000000000..6abc28adde --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java @@ -0,0 +1,266 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; +import java.util.Collection; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.util.PolicyComputationUtils; + +/** + * A composite processor. + * + * @version $Rev$ $Date$ + */ +public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor { + private XMLInputFactory inputFactory; + private DocumentBuilderFactory documentBuilderFactory; + private List scaDefnSink; + private Collection domainPolicySets = null; + private int scaDefnsCount = 0; + + /** + * Construct a new composite processor + * @param staxProcessor + * @param inputFactory + * @param scaDefnsSink + * @param monitor + */ + @Deprecated + public CompositeDocumentProcessor(StAXArtifactProcessor staxProcessor, + XMLInputFactory inputFactory, + List scaDefnsSink, + Monitor monitor) { + super(null, null, null, staxProcessor, null, monitor); + this.inputFactory = inputFactory; + this.scaDefnSink = scaDefnsSink; + } + + + /** + * Construct a new composite processor + * @param staxProcessor + * @param inputFactory + * @param documentBuilderFactory + * @param scaDefnsSink + * @param monitor + */ + public CompositeDocumentProcessor(StAXArtifactProcessor staxProcessor, + XMLInputFactory inputFactory, + DocumentBuilderFactory documentBuilderFactory, + List scaDefnsSink, + Monitor monitor) { + super(null, null, null, staxProcessor, null, monitor); + this.documentBuilderFactory = documentBuilderFactory; + this.inputFactory = inputFactory; + this.scaDefnSink = scaDefnsSink; + } + + + /** + * Construct a new composite processor + * @param modelFactories + * @param staxProcessor + * @param monitor + */ + public CompositeDocumentProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor staxProcessor, + Monitor monitor) { + super(null, null, null, staxProcessor, null, monitor); + this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); + this.documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); + } + + public Composite read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + InputStream scdlStream = null; + try { + URLConnection connection = url.openConnection(); + connection.setUseCaches(false); + try { + scdlStream = connection.getInputStream(); + } catch (IOException e) { + if (e.getClass() == IOException.class && connection instanceof HttpURLConnection + && ((HttpURLConnection)connection).getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) { + error("HttpServerError", url, ((HttpURLConnection)connection).getResponseMessage()); + } + throw e; + } + } catch (IOException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", url, e); + throw ce; + } + return read(uri, scdlStream); + } + + public Composite read(URI uri, InputStream scdlStream) throws ContributionReadException { + try { + if (scaDefnSink != null ) { + fillDomainPolicySets(scaDefnSink); + } + + Composite composite = null; + + byte[] transformedArtifactContent; + try { + if ( domainPolicySets != null ) { + transformedArtifactContent = + PolicyComputationUtils.addApplicablePolicySets(scdlStream, domainPolicySets, documentBuilderFactory); + scdlStream = new ByteArrayInputStream(transformedArtifactContent); + + // For debugging purposes, write out the XML with applicablePolicySets added +/* + try { + scdlStream.mark(0); + ByteArrayOutputStream tmpOutput = new ByteArrayOutputStream(); + while(scdlStream.available()!= 0){ + tmpOutput.write(scdlStream.read()); + } + System.out.println(tmpOutput); + scdlStream.reset(); + + } catch (Exception e){ + e.printStackTrace(); + } +*/ + } + } catch ( IOException e ) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", scdlStream, e); + throw ce; + } catch ( Exception e ) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", scdlStream, e); + //throw ce; + } + + XMLStreamReader reader = inputFactory.createXMLStreamReader(scdlStream); + + reader.nextTag(); + + // Read the composite model + composite = (Composite)extensionProcessor.read(reader); + if (composite != null) { + composite.setURI(uri.toString()); + } + + // For debugging purposes, write it back to XML +/* + if (composite != null) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); + extensionProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray())); + OutputFormat format = new OutputFormat(); + format.setIndenting(true); + format.setIndent(2); + XMLSerializer serializer = new XMLSerializer(System.out, format); + serializer.serialize(document); + } catch (Exception e) { + e.printStackTrace(); + } + } + */ + + return composite; + + } catch (XMLStreamException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", inputFactory, e); + throw ce; + } finally { + try { + if (scdlStream != null) { + scdlStream.close(); + scdlStream = null; + } + } catch (IOException ioe) { + //ignore + } + } + } + + public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException { + if (composite != null) + extensionProcessor.resolve(composite, resolver); + } + + public String getArtifactType() { + return ".composite"; + } + + public Class getModelType() { + return Composite.class; + } + + private void fillDomainPolicySets(List scaDefnsSink) { + Map domainPolicySetMap = null; + if ( scaDefnsSink.size() > scaDefnsCount ) { + //if ( !scaDefnsSink.isEmpty() ) { + domainPolicySetMap = new Hashtable(); + + if ( domainPolicySets != null ) { + for ( PolicySet policySet : domainPolicySets ) { + domainPolicySetMap.put(policySet.getName(), policySet); + } + } + + for ( Object object : scaDefnsSink ) { + if ( object instanceof SCADefinitions ) { + for ( PolicySet policySet : ((SCADefinitions)object).getPolicySets() ) { + domainPolicySetMap.put( policySet.getName(), policySet); + } + } + } + domainPolicySets = domainPolicySetMap.values(); + //scaDefnsSink.clear(); + scaDefnsCount = scaDefnsSink.size(); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java new file mode 100644 index 0000000000..72744259f6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.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.sca.assembly.xml; + +import java.util.HashMap; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Model Resolver for Composite models. + * + * @version $Rev$ $Date$ + */ +public class CompositeModelResolver implements ModelResolver { + + private Contribution contribution; + private Map map = new HashMap(); + + public CompositeModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + } + + public void addModel(Object resolved) { + Composite composite = (Composite)resolved; + map.put(composite.getName(), composite); + } + + public Object removeModel(Object resolved) { + return map.remove(((Composite)resolved).getName()); + } + + public T resolveModel(Class modelClass, T unresolved) { + + // Lookup a definition for the given namespace + QName qname = ((Composite)unresolved).getName(); + Composite resolved = (Composite) map.get(qname); + if (resolved != null) { + return modelClass.cast(resolved); + } + + // No definition found, delegate the resolution to the imports + for (Import import_ : this.contribution.getImports()) { + if (import_ instanceof NamespaceImport) { + NamespaceImport namespaceImport = (NamespaceImport)import_; + if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) { + + // Delegate the resolution to the import resolver + resolved = namespaceImport.getModelResolver().resolveModel(Composite.class, (Composite)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } + } + } + return (T)unresolved; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java new file mode 100644 index 0000000000..f34adbc581 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java @@ -0,0 +1,1243 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.assembly.impl.CompositeImpl; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ResolverExtension; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyComputationUtils; +import org.apache.tuscany.sca.policy.util.PolicyValidationException; +import org.apache.tuscany.sca.policy.util.PolicyValidationUtils; +import org.w3c.dom.Document; + +/** + * A composite processor. + * + * @version $Rev$ $Date$ + */ +public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor { + // FIXME: to be refactored + private XPathFactory xPathFactory = XPathFactory.newInstance(); + + /** + * Construct a new composite processor + * + * @param extensionPoints + * @param extensionProcessor + */ + public CompositeProcessor(ExtensionPointRegistry extensionPoints, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + + this(modelFactories(extensionPoints), + extensionProcessor, + extensionAttributeProcessor, + monitor(extensionPoints)); + + this.extensionAttributeProcessor = extensionAttributeProcessor; + } + + /** + * Constructs a new composite processor + * + * @param modelFactories + * @param extensionProcessor + * @param monitor + */ + private CompositeProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + + super(modelFactories.getFactory(ContributionFactory.class), + modelFactories.getFactory(AssemblyFactory.class), + modelFactories.getFactory(ExtensionFactory.class), + modelFactories.getFactory(PolicyFactory.class), + extensionProcessor, + extensionAttributeProcessor, + monitor); + + this.extensionAttributeProcessor = extensionAttributeProcessor; + + } + + /** + * Construct a new composite processor + * + * @param contributionFactory + * @param assemblyFactory + * @param policyFactory + * @param extensionProcessor + */ + public CompositeProcessor(ContributionFactory contributionFactory, + AssemblyFactory assemblyFactory, + ExtensionFactory extensionFactory, + PolicyFactory policyFactory, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + super(contributionFactory, assemblyFactory, extensionFactory, policyFactory, extensionProcessor, extensionAttributeProcessor, monitor); + } + + public Composite read(XMLStreamReader reader) throws ContributionReadException { + Composite composite = null; + Composite include = null; + Component component = null; + Property property = null; + ComponentService componentService = null; + ComponentReference componentReference = null; + ComponentProperty componentProperty = null; + CompositeService compositeService = null; + CompositeReference compositeReference = null; + Contract contract = null; + Wire wire = null; + Callback callback = null; + QName name = null; + + try { + // Read the composite document + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + name = reader.getName(); + + if (COMPOSITE_QNAME.equals(name)) { + + // Read a + composite = assemblyFactory.createComposite(); + + composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME))); + + if(!isSet(reader, TARGET_NAMESPACE)){ + // spec says that a composite must have a namespace + warning("NoCompositeNamespace", composite, composite.getName().toString()); + } + + if(isSet(reader, AUTOWIRE)) { + composite.setAutowire(getBoolean(reader, AUTOWIRE)); + } + + //handle extension attributes + this.readExtendedAttributes(reader, composite); + + composite.setLocal(getBoolean(reader, LOCAL)); + composite.setConstrainingType(readConstrainingType(reader)); + policyProcessor.readPolicies(composite, reader); + + } else if (INCLUDE_QNAME.equals(name)) { + + // Read an + include = assemblyFactory.createComposite(); + include.setName(getQName(reader, NAME)); + include.setURI(getString(reader, URI)); + include.setUnresolved(true); + composite.getIncludes().add(include); + + } else if (SERVICE_QNAME.equals(name)) { + if (component != null) { + + // Read a + componentService = assemblyFactory.createComponentService(); + contract = componentService; + componentService.setName(getString(reader, NAME)); + + //handle extension attributes + this.readExtendedAttributes(reader, componentService); + + component.getServices().add(componentService); + policyProcessor.readPolicies(contract, reader); + } else { + + // Read a + compositeService = assemblyFactory.createCompositeService(); + contract = compositeService; + compositeService.setName(getString(reader, NAME)); + + String promoted = getString(reader, PROMOTE); + if (promoted != null) { + String promotedComponentName; + String promotedServiceName; + int s = promoted.indexOf('/'); + if (s == -1) { + promotedComponentName = promoted; + promotedServiceName = null; + } else { + promotedComponentName = promoted.substring(0, s); + promotedServiceName = promoted.substring(s + 1); + } + + Component promotedComponent = assemblyFactory.createComponent(); + promotedComponent.setUnresolved(true); + promotedComponent.setName(promotedComponentName); + compositeService.setPromotedComponent(promotedComponent); + + ComponentService promotedService = assemblyFactory.createComponentService(); + promotedService.setUnresolved(true); + promotedService.setName(promotedServiceName); + compositeService.setPromotedService(promotedService); + } + + //handle extension attributes + this.readExtendedAttributes(reader, compositeService); + + composite.getServices().add(compositeService); + policyProcessor.readPolicies(contract, reader); + } + + } else if (REFERENCE_QNAME.equals(name)) { + if (component != null) { + // Read a + componentReference = assemblyFactory.createComponentReference(); + contract = componentReference; + componentReference.setName(getString(reader, NAME)); + readMultiplicity(componentReference, reader); + if (isSet(reader, AUTOWIRE)) { + componentReference.setAutowire(getBoolean(reader, AUTOWIRE)); + } + readTargets(componentReference, reader); + componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL)); + + //handle extension attributes + this.readExtendedAttributes(reader, componentReference); + + component.getReferences().add(componentReference); + policyProcessor.readPolicies(contract, reader); + } else { + // Read a + compositeReference = assemblyFactory.createCompositeReference(); + contract = compositeReference; + compositeReference.setName(getString(reader, NAME)); + readMultiplicity(compositeReference, reader); + readTargets(compositeReference, reader); + String promote = reader.getAttributeValue(null, Constants.PROMOTE); + if (promote != null) { + for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) { + ComponentReference promotedReference = + assemblyFactory.createComponentReference(); + promotedReference.setUnresolved(true); + promotedReference.setName(tokens.nextToken()); + compositeReference.getPromotedReferences().add(promotedReference); + } + } + compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL)); + + //handle extension attributes + this.readExtendedAttributes(reader, compositeReference); + + composite.getReferences().add(compositeReference); + policyProcessor.readPolicies(contract, reader); + } + + } else if (PROPERTY_QNAME.equals(name)) { + if (component != null) { + + // Read a + componentProperty = assemblyFactory.createComponentProperty(); + property = componentProperty; + String source = getString(reader, SOURCE); + if(source!=null) { + source = source.trim(); + } + componentProperty.setSource(source); + if (source != null) { + // $/... + if (source.charAt(0) == '$') { + int index = source.indexOf('/'); + if (index == -1) { + // Tolerating $prop + source = source + "/"; + index = source.length() - 1; + } + source = source.substring(index + 1); + if ("".equals(source)) { + source = "."; + } + } + XPath xpath = xPathFactory.newXPath(); + xpath.setNamespaceContext(reader.getNamespaceContext()); + try { + componentProperty.setSourceXPathExpression(xpath.compile(source)); + } catch (XPathExpressionException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", xpath, ce); + //throw ce; + } + } + componentProperty.setFile(getString(reader, FILE)); + + //handle extension attributes + this.readExtendedAttributes(reader, componentProperty); + + policyProcessor.readPolicies(property, reader); + readAbstractProperty(componentProperty, reader); + + // Read the property value + Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader); + property.setValue(value); + + component.getProperties().add(componentProperty); + } else { + + // Read a + property = assemblyFactory.createProperty(); + policyProcessor.readPolicies(property, reader); + readAbstractProperty(property, reader); + + // Read the property value + Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader); + property.setValue(value); + + composite.getProperties().add(property); + } + + // TUSCANY-1949 + // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue + if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) { + property = null; + componentProperty = null; + } + + } else if (COMPONENT_QNAME.equals(name)) { + + // Read a + component = assemblyFactory.createComponent(); + component.setName(getString(reader, NAME)); + if (isSet(reader, AUTOWIRE)) { + component.setAutowire(getBoolean(reader, AUTOWIRE)); + } + if (isSet(reader, URI)) { + component.setURI(getString(reader, URI)); + } + + //handle extension attributes + this.readExtendedAttributes(reader, component); + + component.setConstrainingType(readConstrainingType(reader)); + composite.getComponents().add(component); + policyProcessor.readPolicies(component, reader); + + } else if (WIRE_QNAME.equals(name)) { + + // Read a + wire = assemblyFactory.createWire(); + ComponentReference source = assemblyFactory.createComponentReference(); + source.setUnresolved(true); + source.setName(getString(reader, SOURCE)); + wire.setSource(source); + + ComponentService target = assemblyFactory.createComponentService(); + target.setUnresolved(true); + target.setName(getString(reader, TARGET)); + wire.setTarget(target); + + //handle extension attributes + this.readExtendedAttributes(reader, wire); + + composite.getWires().add(wire); + policyProcessor.readPolicies(wire, reader); + + } else if (CALLBACK_QNAME.equals(name)) { + + // Read a + callback = assemblyFactory.createCallback(); + contract.setCallback(callback); + + //handle extension attributes + this.readExtendedAttributes(reader, callback); + + policyProcessor.readPolicies(callback, reader); + + } else if (OPERATION_QNAME.equals(name)) { + + // Read an + ConfiguredOperation operation = assemblyFactory.createConfiguredOperation(); + operation.setName(getString(reader, NAME)); + operation.setUnresolved(true); + if (callback != null) { + policyProcessor.readPolicies(operation, reader); + } else { + policyProcessor.readPolicies(operation, reader); + } + + OperationsConfigurator opConfigurator = null; + if ( compositeService != null ) { + opConfigurator = compositeService; + } else if ( componentService != null ) { + opConfigurator = componentService; + } else if ( compositeReference != null ) { + opConfigurator = compositeReference; + } else if ( componentReference != null ) { + opConfigurator = componentReference; + } + + opConfigurator.getConfiguredOperations().add(operation); + } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) { + + // Read an implementation.composite + Composite implementation = assemblyFactory.createComposite(); + implementation.setName(getQName(reader, NAME)); + implementation.setUnresolved(true); + + //handle extension attributes + this.readExtendedAttributes(reader, implementation); + + component.setImplementation(implementation); + policyProcessor.readPolicies(implementation, reader); + } else { + + // Read an extension element + Object extension = extensionProcessor.read(reader); + if (extension != null) { + if (extension instanceof InterfaceContract) { + + // and + // + if (contract != null) { + contract.setInterfaceContract((InterfaceContract)extension); + } else { + if (name.getNamespaceURI().equals(SCA10_NS)) { + error("UnexpectedInterfaceElement", extension); + //throw new ContributionReadException("Unexpected element found. It should appear inside a or element"); + } else { + composite.getExtensions().add(extension); + } + } + } else if (extension instanceof Binding) { + if ( extension instanceof PolicySetAttachPoint ) { + IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType(); + bindingType.setName(name); + bindingType.setUnresolved(true); + ((PolicySetAttachPoint)extension).setType(bindingType); + } + // and + // + if (callback != null) { + callback.getBindings().add((Binding)extension); + } else { + if (contract != null) { + contract.getBindings().add((Binding)extension); + } else { + if (name.getNamespaceURI().equals(SCA10_NS)) { + error("UnexpectedBindingElement", extension); + //throw new ContributionReadException("Unexpected element found. It should appear inside a or element"); + } else { + composite.getExtensions().add(extension); + } + } + } + + } else if (extension instanceof Implementation) { + if ( extension instanceof PolicySetAttachPoint ) { + IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType(); + implType.setName(name); + implType.setUnresolved(true); + ((PolicySetAttachPoint)extension).setType(implType); + } + // + if (component != null) { + component.setImplementation((Implementation)extension); + } else { + if (name.getNamespaceURI().equals(SCA10_NS)) { + error("UnexpectedImplementationElement", extension); + //throw new ContributionReadException("Unexpected element found. It should appear inside a element"); + } else { + composite.getExtensions().add(extension); + } + } + } else { + + // Add the extension element to the current + // element + if (callback != null) { + callback.getExtensions().add(extension); + } else if (contract != null) { + contract.getExtensions().add(extension); + } else if (property != null) { + property.getExtensions().add(extension); + } else if (component != null) { + component.getExtensions().add(extension); + } else { + composite.getExtensions().add(extension); + } + } + } + } + break; + + case XMLStreamConstants.CHARACTERS: + break; + + case END_ELEMENT: + name = reader.getName(); + + // Clear current state when reading reaching end element + if (SERVICE_QNAME.equals(name)) { + componentService = null; + compositeService = null; + contract = null; + } else if (INCLUDE_QNAME.equals(name)) { + include = null; + } else if (REFERENCE_QNAME.equals(name)) { + componentReference = null; + compositeReference = null; + contract = null; + } else if (PROPERTY_QNAME.equals(name)) { + componentProperty = null; + property = null; + } else if (COMPONENT_QNAME.equals(name)) { + component = null; + } else if (WIRE_QNAME.equals(name)) { + wire = null; + } else if (CALLBACK_QNAME.equals(name)) { + callback = null; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("ContributionReadException", reader, ex); + } + + return composite; + } + + public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write element + writeStartDocument(writer, + COMPOSITE, + writeConstrainingType(composite), + new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()), + new XAttr(NAME, composite.getName().getLocalPart()), + new XAttr(LOCAL, composite.isLocal() ? Boolean.TRUE : null), + new XAttr(AUTOWIRE, composite.getAutowire()), + policyProcessor.writePolicies(composite)); + + //write extended attributes + this.writeExtendedAttributes(writer, composite, extensionAttributeProcessor); + + // Write elements + for (Composite include : composite.getIncludes()) { + String uri = include.isUnresolved()? include.getURI() : null; + writeStart(writer, + INCLUDE, + new XAttr(NAME, include.getName()), + new XAttr(URI, uri)); + + //write extended attributes + this.writeExtendedAttributes(writer, include, extensionAttributeProcessor); + + writeEnd(writer); + } + + // Write elements + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + Component promotedComponent = compositeService.getPromotedComponent(); + ComponentService promotedService = compositeService.getPromotedService(); + String promote; + if (promotedService != null) { + if (promotedService.getName() != null) { + promote = promotedComponent.getName() + '/' + promotedService.getName(); + } else { + promote = promotedComponent.getName(); + } + } else { + promote = null; + } + writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote), + policyProcessor.writePolicies(service)); + + //write extended attributes + this.writeExtendedAttributes(writer, service, extensionAttributeProcessor); + + + // Write service interface + extensionProcessor.write(service.getInterfaceContract(), writer); + + // Write bindings + for (Binding binding : service.getBindings()) { + extensionProcessor.write(binding, writer); + } + + // Write element + if (service.getCallback() != null) { + Callback callback = service.getCallback(); + writeStart(writer, CALLBACK, + policyProcessor.writePolicies(callback)); + + //write extended attributes + this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor); + + // Write callback bindings + for (Binding binding : callback.getBindings()) { + extensionProcessor.write(binding, writer); + } + + // Write extensions + for (Object extension : callback.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write extensions + for (Object extension : service.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write elements + for (Component component : composite.getComponents()) { + writeStart(writer, COMPONENT, new XAttr(NAME, component.getName()), + new XAttr(URI, component.getURI()), + new XAttr(AUTOWIRE, component.getAutowire()), + policyProcessor.writePolicies(component)); + + //write extended attributes + this.writeExtendedAttributes(writer, component, extensionAttributeProcessor); + + // Write the component implementation + Implementation implementation = component.getImplementation(); + // check that we really have CompositeImpl and treat this specially. Some + // extension extend CompositeImpl and we want these to be treated by the extension + // processor. + if ((implementation != null ) && (implementation.getClass().equals(CompositeImpl.class))) { + writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, ((Composite)implementation).getName())); + + //write extended attributes + this.writeExtendedAttributes(writer, (Composite)implementation, extensionAttributeProcessor); + + writeEnd(writer); + } else { + extensionProcessor.write(component.getImplementation(), writer); + } + + for (Object extension : component.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + // Write elements + for (ComponentService service : component.getServices()) { + if (service.isCallback() == false){ + writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), + policyProcessor.writePolicies(service)); + + //write extended attributes + this.writeExtendedAttributes(writer, service, extensionAttributeProcessor); + + // Write service interface + extensionProcessor.write(service.getInterfaceContract(), writer); + + // Write bindings + for (Binding binding : service.getBindings()) { + extensionProcessor.write(binding, writer); + } + + // Write element + if (service.getCallback() != null) { + Callback callback = service.getCallback(); + writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); + + //write extended attributes + this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor); + + // Write bindings + for (Binding binding : callback.getBindings()) { + extensionProcessor.write(binding, writer); + } + + // Write extensions + for (Object extension : callback.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write extensions + for (Object extension : service.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + } + + // Write elements + for (ComponentReference reference : component.getReferences()) { + if (reference.isCallback() == false){ + writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()), + new XAttr(AUTOWIRE, reference.getAutowire()), + writeMultiplicity(reference), + writeTargets(reference), + policyProcessor.writePolicies(reference)); + + //write extended attributes + this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor); + + // Write reference interface + extensionProcessor.write(reference.getInterfaceContract(), writer); + + // Write bindings + for (Binding binding : reference.getBindings()) { + extensionProcessor.write(binding, writer); + } + + // Write callback + if (reference.getCallback() != null) { + Callback callback = reference.getCallback(); + writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); + + //write extended attributes + this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor); + + // Write callback bindings + for (Binding binding : callback.getBindings()) { + extensionProcessor.write(binding, writer); + } + + // Write extensions + for (Object extensions : callback.getExtensions()) { + extensionProcessor.write(extensions, writer); + } + + writeEnd(writer); + } + + // Write extensions + for (Object extensions : reference.getExtensions()) { + extensionProcessor.write(extensions, writer); + } + + writeEnd(writer); + } + } + + // Write elements + for (ComponentProperty property : component.getProperties()) { + writeStart(writer, + PROPERTY, + new XAttr(NAME, property.getName()), + new XAttr(MUST_SUPPLY, property.isMustSupply()), + new XAttr(MANY, property.isMany()), + new XAttr(TYPE, property.getXSDType()), + new XAttr(ELEMENT, property.getXSDElement()), + new XAttr(SOURCE, property.getSource()), + new XAttr(FILE, property.getFile()), + policyProcessor.writePolicies(property)); + + //write extended attributes + this.writeExtendedAttributes(writer, property, extensionAttributeProcessor); + + // Write property value + writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer); + + // Write extensions + for (Object extension : property.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + writeEnd(writer); + } + + // Write elements + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + + // Write list of promoted references + List promote = new ArrayList(); + for (ComponentReference promoted: compositeReference.getPromotedReferences()) { + promote.add(promoted.getName()); + } + + // Write element + writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()), + new XAttr(PROMOTE, promote), + writeMultiplicity(reference), + policyProcessor.writePolicies(reference)); + + //write extended attributes + this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor); + + // Write reference interface + extensionProcessor.write(reference.getInterfaceContract(), writer); + + // Write bindings + for (Binding binding : reference.getBindings()) { + extensionProcessor.write(binding, writer); + } + + // Write element + if (reference.getCallback() != null) { + Callback callback = reference.getCallback(); + writeStart(writer, CALLBACK); + + //write extended attributes + this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor); + + // Write callback bindings + for (Binding binding : callback.getBindings()) { + extensionProcessor.write(binding, writer); + } + + // Write extensions + for (Object extension : callback.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write extensions + for (Object extension : reference.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write elements + for (Property property : composite.getProperties()) { + writeStart(writer, + PROPERTY, + new XAttr(NAME, property.getName()), + new XAttr(MUST_SUPPLY, property.isMustSupply()), + new XAttr(MANY, property.isMany()), + new XAttr(TYPE, property.getXSDType()), + new XAttr(ELEMENT, property.getXSDElement()), + policyProcessor.writePolicies(property)); + + //write extended attributes + this.writeExtendedAttributes(writer, property, extensionAttributeProcessor); + + // Write property value + writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer); + + // Write extensions + for (Object extension : property.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write elements + for (Wire wire : composite.getWires()) { + writeStart(writer, WIRE, new XAttr(SOURCE, wire.getSource().getName()), new XAttr(TARGET, wire + .getTarget().getName())); + + //write extended attributes + this.writeExtendedAttributes(writer, wire, extensionAttributeProcessor); + + // Write extensions + for (Object extension : wire.getExtensions()) { + extensionProcessor.write(extension, writer); + } + writeEnd(writer); + } + + for (Object extension : composite.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEndDocument(writer); + } + + public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException { + + // Resolve constraining type + ConstrainingType constrainingType = composite.getConstrainingType(); + if (constrainingType != null) { + constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType); + composite.setConstrainingType(constrainingType); + } + + // Resolve includes in the composite + for (int i = 0, n = composite.getIncludes().size(); i < n; i++) { + Composite include = composite.getIncludes().get(i); + if (include != null) { + include = resolver.resolveModel(Composite.class, include); + composite.getIncludes().set(i, include); + } + } + + // Resolve extensions + for (Object extension : composite.getExtensions()) { + if (extension != null) { + extensionProcessor.resolve(extension, resolver); + } + } + + //resolve intents and policy sets + List compositeIntents = null; + List compositePolicySets = null; + List compositeApplicablePolicySets = null; + resolveIntents(composite.getRequiredIntents(), resolver); + resolvePolicySets(composite.getPolicySets(), resolver); + resolvePolicySets(composite.getApplicablePolicySets(), resolver); + compositeIntents = composite.getRequiredIntents(); + compositePolicySets = composite.getPolicySets(); + compositeApplicablePolicySets = composite.getApplicablePolicySets(); + + //Resolve composite services and references + resolveContracts(composite, composite.getServices(), resolver); + resolveContracts(composite, composite.getReferences(), resolver); + + // Resolve component implementations, services and references + for (Component component : composite.getComponents()) { + constrainingType = component.getConstrainingType(); + if (constrainingType != null) { + constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType); + component.setConstrainingType(constrainingType); + } + + //resolve intents and policy sets + resolveIntents(component.getRequiredIntents(), resolver); + resolvePolicySets(component.getPolicySets(), resolver); + resolvePolicySets(component.getApplicablePolicySets(), resolver); + + //inherit composite intents and policysets + PolicyComputationUtils.addDefaultPolicies(compositeIntents, + compositePolicySets, + component.getRequiredIntents(), + component.getPolicySets()); + + addInheritedPolicySets(compositeApplicablePolicySets, component.getApplicablePolicySets()); + + //resolve component services and references + resolveContracts(component, component.getServices(), resolver); + resolveContracts(component, component.getReferences(), resolver); + + for (ComponentProperty componentProperty : component.getProperties()) { + if (componentProperty.getFile() != null) { + Artifact artifact = contributionFactory.createArtifact(); + artifact.setURI(componentProperty.getFile()); + artifact = resolver.resolveModel(Artifact.class, artifact); + if (artifact.getLocation() != null) { + componentProperty.setFile(artifact.getLocation()); + } + } + } + + //resolve component implementation + Implementation implementation = component.getImplementation(); + if (implementation != null) { + try { + //resolve intents and policysets specified on this implementation + //before copying them over to the component. Before that, from the component + //copy over the applicablePolicySets alone as it might have to be + //used to validate the policysets specified on the implementation + + resolveImplIntentsAndPolicySets(implementation, + component.getApplicablePolicySets(), + resolver); + + copyPoliciesToComponent(component, implementation, resolver, true); + + //now resolve the implementation so that even if there is a shared instance + //for this that is resolved, the specified intents and policysets are safe in the + //component and not lost + implementation = resolveImplementation(implementation, resolver); + + //resolved implementation may contain intents and policysets specified at + //componentType (either in the componentType side file or in annotations if its a + //java implementation). This has to be consolidated in to the component. + copyPoliciesToComponent(component, implementation, resolver, false); + + component.setImplementation(implementation); + } catch ( PolicyValidationException e ) { + error("PolicyImplValidationException", resolver, component.getName(), e.getMessage()); + //throw new ContributionResolveException("PolicyValidation exception when processing implementation of component '" + //+ component.getName() + "' due to " + e.getMessage(), e); + } + + } + + //add model resolver to component + if (component instanceof ResolverExtension) { + ((ResolverExtension)component).setModelResolver(resolver); + } + } + + // Add model resolver to promoted components + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + Component promotedComponent = compositeService.getPromotedComponent(); + if (promotedComponent instanceof ResolverExtension) { + ((ResolverExtension)promotedComponent).setModelResolver(resolver); + } + } + } + + private void resolveImplIntentsAndPolicySets(Implementation implementation, + List inheritedApplicablePolicySets, + ModelResolver resolver) throws ContributionResolveException, + PolicyValidationException + { + if ( implementation instanceof PolicySetAttachPoint ) { + PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation; + + policiedImpl.getApplicablePolicySets().addAll(inheritedApplicablePolicySets); + + resolveIntents(policiedImpl.getRequiredIntents(), resolver); + PolicyValidationUtils.validateIntents(policiedImpl, policiedImpl.getType()); + + resolvePolicySets(policiedImpl.getPolicySets(), resolver); + resolvePolicySets(policiedImpl.getApplicablePolicySets(), resolver); + + PolicyValidationUtils.validatePolicySets(policiedImpl); + + if ( implementation instanceof OperationsConfigurator ) { + for ( ConfiguredOperation implConfOp : ((OperationsConfigurator)implementation).getConfiguredOperations() ) { + resolveIntents(implConfOp.getRequiredIntents(), resolver); + PolicyValidationUtils.validateIntents(implConfOp, policiedImpl.getType()); + + resolvePolicySets(implConfOp.getPolicySets(), resolver); + resolvePolicySets(implConfOp.getApplicablePolicySets(), resolver); + //add the inherited applicablePolicysets + addInheritedPolicySets(policiedImpl.getApplicablePolicySets(), implConfOp.getApplicablePolicySets()); + + PolicyValidationUtils.validatePolicySets(implConfOp, policiedImpl.getType()); + + PolicyComputationUtils.addDefaultPolicies( + ((PolicySetAttachPoint)implementation).getRequiredIntents(), + ((PolicySetAttachPoint)implementation).getPolicySets(), + implConfOp.getRequiredIntents(), + implConfOp.getPolicySets()); + } + } + } + } + + private void copyPoliciesToComponent(Component component, + Implementation implementation, + ModelResolver resolver, + boolean clearImplSettings) throws ContributionResolveException { + if (implementation instanceof PolicySetAttachPoint) { + // Add implementation policies into component, since implementation instances are + // reused and it's likely that this implementation instance will not hold after its resolution. + // On the first call to this method (clearImplSettings=true), we are moving policies from the + // implementation XML element up to the component. In this case if there are mutually exclusive + // policies we must clear the component policy so that the implementation policy "wins". + // On the second call to this method (clearImplSettings=false), we are moving policies from the + // componentType implementation up to the component. In this case if there are mutually + // exclusive policies it is an error. This error will be detected later in the PolicyComputer. + if (clearImplSettings) { + for (Intent intent : ((PolicySetAttachPoint)implementation).getRequiredIntents()) { + for (Intent excluded : intent.getExcludedIntents()) { + if (component.getRequiredIntents().contains(excluded)) { + component.getRequiredIntents().remove(excluded); + } + for (Iterator i = component.getPolicySets().iterator(); i.hasNext(); ) { + PolicySet cmpPolicySet = (PolicySet) i.next(); + if (cmpPolicySet.getProvidedIntents().contains(excluded)) { + i.remove(); + } + } + } + } + for (PolicySet policySet : ((PolicySetAttachPoint)implementation).getPolicySets()) { + for (Intent intent : policySet.getProvidedIntents()) { + for (Intent excluded : intent.getExcludedIntents()) { + if (component.getRequiredIntents().contains(excluded)) { + component.getRequiredIntents().remove(excluded); + } + for (Iterator i = component.getPolicySets().iterator(); i.hasNext(); ) { + PolicySet cmpPolicySet = (PolicySet) i.next(); + if (cmpPolicySet.getProvidedIntents().contains(excluded)) { + i.remove(); + } + } + } + } + } + } + component.getRequiredIntents().addAll(((PolicySetAttachPoint)implementation).getRequiredIntents()); + component.getPolicySets().addAll(((PolicySetAttachPoint)implementation).getPolicySets()); + component.getApplicablePolicySets().addAll(((PolicySetAttachPoint)implementation).getApplicablePolicySets()); + + if ( implementation instanceof OperationsConfigurator ) { + boolean notFound; + List opsFromImplementation = new ArrayList(); + List implConfOperations = + new ArrayList(((OperationsConfigurator)implementation).getConfiguredOperations()); + for ( ConfiguredOperation implConfOp : implConfOperations ) { + notFound = true; + for ( ConfiguredOperation compConfOp : ((OperationsConfigurator)component).getConfiguredOperations() ) { + if ( implConfOp.getName().equals(compConfOp.getName()) ) { + notFound = false; + + if (clearImplSettings) { + for (Intent intent : implConfOp.getRequiredIntents()) { + for (Intent excluded : intent.getExcludedIntents()) { + if (compConfOp.getRequiredIntents().contains(excluded)) { + compConfOp.getRequiredIntents().remove(excluded); + } + } + } + for (PolicySet policySet : implConfOp.getPolicySets()) { + for (Intent intent : policySet.getProvidedIntents()) { + for (Intent excluded : intent.getExcludedIntents()) { + if (compConfOp.getRequiredIntents().contains(excluded)) { + compConfOp.getRequiredIntents().remove(excluded); + } + for (Iterator i = compConfOp.getPolicySets().iterator(); i.hasNext(); ) { + PolicySet cmpPolicySet = (PolicySet) i.next(); + if (cmpPolicySet.getProvidedIntents().contains(excluded)) { + i.remove(); + } + } + } + } + } + } + + addInheritedIntents(implConfOp.getRequiredIntents(), compConfOp.getRequiredIntents()); + addInheritedPolicySets(implConfOp.getPolicySets(), compConfOp.getPolicySets()); + addInheritedPolicySets(implConfOp.getApplicablePolicySets(), compConfOp.getApplicablePolicySets()); + } + } + + if ( notFound ) { + opsFromImplementation.add(implConfOp); + } + + if ( clearImplSettings ) { + ((OperationsConfigurator)implementation).getConfiguredOperations().remove(implConfOp); + } + } + ((OperationsConfigurator)component).getConfiguredOperations().addAll(opsFromImplementation); + } + + if ( clearImplSettings ) { + ((PolicySetAttachPoint)implementation).getRequiredIntents().clear(); + ((PolicySetAttachPoint)implementation).getPolicySets().clear(); + } + } + } + + + public QName getArtifactType() { + return COMPOSITE_QNAME; + } + + public Class getModelType() { + return Composite.class; + } + + /** + * Returns the model factory extension point to use. + * + * @param extensionPoints + * @return + */ + private static ModelFactoryExtensionPoint modelFactories(ExtensionPointRegistry extensionPoints) { + return extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + } + + /** + * Returns the monitor to use. + * + * @param extensionPoints + * @return + */ + private static Monitor monitor(ExtensionPointRegistry extensionPoints) { + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + if (utilities != null) { + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + if (monitorFactory != null) { + return monitorFactory.createMonitor(); + } + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java new file mode 100644 index 0000000000..0f062dbda5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Processor for dealing with 'operation' elements from composite definitions + * + * @version $Rev$ $Date$ + */ +public class ConfiguredOperationProcessor implements StAXArtifactProcessor, Constants{ + + private AssemblyFactory assemblyFactory; + private PolicyAttachPointProcessor policyProcessor; + private PolicyFactory policyFactory; + private Monitor monitor; + + public ConfiguredOperationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.monitor = monitor; + } + + public ConfiguredOperation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + ConfiguredOperation configuredOp = assemblyFactory.createConfiguredOperation(); + + //Read an + configuredOp.setName(reader.getAttributeValue(null, NAME)); + configuredOp.setContractName(reader.getAttributeValue(null, SERVICE)); + configuredOp.setUnresolved(true); + + // Read policies + policyProcessor.readPolicies(configuredOp, reader); + + //Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && OPERATION_QNAME.equals(reader.getName())) { + break; + } + } + + return configuredOp; + } + + public void write(ConfiguredOperation configuredOperation, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + + // Write an + writer.writeStartElement(Constants.SCA10_NS, OPERATION); + policyProcessor.writePolicyAttributes(configuredOperation, writer); + + writer.writeAttribute(NAME, configuredOperation.getName()); + if ( configuredOperation.getContractName() != null ) { + writer.writeAttribute(SERVICE, configuredOperation.getContractName()); + } + writer.writeEndElement(); + } + + public void resolve(ConfiguredOperation configuredOperation, ModelResolver resolver) + throws ContributionResolveException { + } + + public QName getArtifactType() { + return OPERATION_QNAME; + } + + public Class getModelType() { + return ConfiguredOperation.class; + } + +} + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java new file mode 100644 index 0000000000..3bf5a1173b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import javax.xml.namespace.QName; + +/** + * Constants used in SCA assembly XML files. + * + * @version $Rev$ $Date$ + */ +public interface Constants { + String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.0"; + + String COMPONENT_TYPE = "componentType"; + QName COMPONENT_TYPE_QNAME = new QName(SCA10_NS, COMPONENT_TYPE); + + String SERVICE = "service"; + QName SERVICE_QNAME = new QName(SCA10_NS, SERVICE); + + String REFERENCE = "reference"; + QName REFERENCE_QNAME = new QName(SCA10_NS, REFERENCE); + + String PROPERTY = "property"; + QName PROPERTY_QNAME = new QName(SCA10_NS, PROPERTY); + + String CONSTRAINING_TYPE = "constrainingType"; + QName CONSTRAINING_TYPE_QNAME = new QName(SCA10_NS, CONSTRAINING_TYPE); + + String COMPOSITE = "composite"; + QName COMPOSITE_QNAME = new QName(SCA10_NS, COMPOSITE); + + String INCLUDE = "include"; + QName INCLUDE_QNAME = new QName(SCA10_NS, INCLUDE); + + String COMPONENT = "component"; + QName COMPONENT_QNAME = new QName(SCA10_NS, COMPONENT); + + String WIRE = "wire"; + QName WIRE_QNAME = new QName(SCA10_NS, WIRE); + + String OPERATION = "operation"; + QName OPERATION_QNAME = new QName(SCA10_NS, OPERATION); + + String CALLBACK = "callback"; + QName CALLBACK_QNAME = new QName(SCA10_NS, CALLBACK); + + String IMPLEMENTATION_COMPOSITE = "implementation.composite"; + QName IMPLEMENTATION_COMPOSITE_QNAME = new QName(SCA10_NS, IMPLEMENTATION_COMPOSITE); + + String IMPLEMENTATION = "implementation"; + QName IMPLEMENTATION_QNAME = new QName(SCA10_NS, IMPLEMENTATION); + + String BINDING_SCA = "binding.sca"; + QName BINDING_SCA_QNAME = new QName(Constants.SCA10_NS, BINDING_SCA); + + String NAME = "name"; + String TARGET_NAMESPACE = "targetNamespace"; + String LOCAL = "local"; + String AUTOWIRE = "autowire"; + String REQUIRES = "requires"; + String POLICY_SETS = "policySets"; + String APPLICABLE_POLICY_SETS = "applicablePolicySets"; + String PROMOTE = "promote"; + String TARGET = "target"; + String WIRED_BY_IMPL = "wiredByImpl"; + String MULTIPLICITY = "multiplicity"; + String TYPE = "type"; + String ELEMENT = "element"; + String MANY = "many"; + String MUST_SUPPLY = "mustSupply"; + String SOURCE = "source"; + String FILE = "file"; + String URI = "uri"; + String ZERO_ONE = "0..1"; + String ZERO_N = "0..n"; + String ONE_ONE = "1..1"; + String ONE_N = "1..n"; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java new file mode 100644 index 0000000000..9758d788f4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A contrainingType content handler. + * + * @version $Rev$ $Date$ + */ +public class ConstrainingTypeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor { + private XMLInputFactory inputFactory; + + + /** + * Construct a new constrainingType processor. + * + * @param staxProcessor + * @param inputFactory + * @param monitor + */ + public ConstrainingTypeDocumentProcessor(StAXArtifactProcessor staxProcessor, + XMLInputFactory inputFactory, + Monitor monitor) { + super(null, null, null, staxProcessor, null, monitor); + this.inputFactory = inputFactory; + } + + + /** + * Constructs a new constrainingType processor. + * @param modelFactories + * @param staxProcessor + * @param monitor + */ + public ConstrainingTypeDocumentProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor staxProcessor, + Monitor monitor) { + super(null, null, null, staxProcessor, null, monitor); + this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); + } + + public ConstrainingType read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + InputStream urlStream = null; + try { + + // Create a stream reader + URLConnection connection = url.openConnection(); + connection.setUseCaches(false); + urlStream = connection.getInputStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream); + reader.nextTag(); + + // Read the constrainingType model + ConstrainingType constrainingType = (ConstrainingType)extensionProcessor.read(reader); + + // For debugging purposes, write it back to XML +// if (constrainingType != null) { +// try { +// ByteArrayOutputStream bos = new ByteArrayOutputStream(); +// XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); +// outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); +// extensionProcessor.write(constrainingType, outputFactory.createXMLStreamWriter(bos)); +// Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray())); +// OutputFormat format = new OutputFormat(); +// format.setIndenting(true); +// format.setIndent(2); +// XMLSerializer serializer = new XMLSerializer(System.out, format); +// serializer.serialize(document); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } + + return constrainingType; + + } catch (XMLStreamException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", inputFactory, ce); + throw ce; + } catch (IOException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", inputFactory, ce); + throw ce; + } finally { + try { + if (urlStream != null) { + urlStream.close(); + urlStream = null; + } + } catch (IOException ioe) { + //ignore + } + } + } + + public void resolve(ConstrainingType constrainingType, ModelResolver resolver) throws ContributionResolveException { + extensionProcessor.resolve(constrainingType, resolver); + } + + public String getArtifactType() { + return ".constrainingType"; + } + + public Class getModelType() { + return ConstrainingType.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java new file mode 100644 index 0000000000..7dd95e3944 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.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.sca.assembly.xml; + +import java.util.HashMap; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Model Resolver for ConstrainingType models. + * + * @version $Rev$ $Date$ + */ +public class ConstrainingTypeModelResolver implements ModelResolver { + + private Contribution contribution; + private Map map = new HashMap(); + + public ConstrainingTypeModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + } + + public void addModel(Object resolved) { + ConstrainingType composite = (ConstrainingType)resolved; + map.put(composite.getName(), composite); + } + + public Object removeModel(Object resolved) { + return map.remove(((ConstrainingType)resolved).getName()); + } + + public T resolveModel(Class modelClass, T unresolved) { + + // Lookup a definition for the given namespace + QName qname = ((ConstrainingType)unresolved).getName(); + ConstrainingType resolved = (ConstrainingType) map.get(qname); + if (resolved != null) { + return modelClass.cast(resolved); + } + + // No definition found, delegate the resolution to the imports + for (Import import_ : this.contribution.getImports()) { + if (import_ instanceof NamespaceImport) { + NamespaceImport namespaceImport = (NamespaceImport)import_; + if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) { + + // Delegate the resolution to the import resolver + resolved = namespaceImport.getModelResolver().resolveModel(ConstrainingType.class, (ConstrainingType)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } + } + } + return (T)unresolved; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java new file mode 100644 index 0000000000..525ffd02e3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java @@ -0,0 +1,292 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.AbstractService; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.w3c.dom.Document; + +/** + * A constrainingType processor. + * + * @version $Rev$ $Date$ + */ +public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor { + + /** + * Construct a new constrainingType processor. + * @param assemblyFactory + * @param policyFactory + * @param extensionProcessor + */ + public ConstrainingTypeProcessor(AssemblyFactory assemblyFactory, + ExtensionFactory extensionFactory, + PolicyFactory policyFactory, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + super(assemblyFactory, extensionFactory, policyFactory, extensionProcessor, extensionAttributeProcessor, monitor); + } + + /** + * Constructs a new constrainingType processor. + * + * @param modelFactories + * @param extensionProcessor + */ + public ConstrainingTypeProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + super(modelFactories.getFactory(AssemblyFactory.class), + modelFactories.getFactory(ExtensionFactory.class), + modelFactories.getFactory(PolicyFactory.class), + extensionProcessor, + extensionAttributeProcessor, + monitor); + } + + public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException { + ConstrainingType constrainingType = null; + AbstractService abstractService = null; + AbstractReference abstractReference = null; + AbstractProperty abstractProperty = null; + AbstractContract abstractContract = null; + QName name = null; + + try { + // Read the constrainingType document + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + + case START_ELEMENT: + name = reader.getName(); + + // Read a + if (Constants.CONSTRAINING_TYPE_QNAME.equals(name)) { + constrainingType = assemblyFactory.createConstrainingType(); + constrainingType.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME))); + policyProcessor.readPolicies(constrainingType, reader); + + } else if (Constants.SERVICE_QNAME.equals(name)) { + + // Read a + abstractService = assemblyFactory.createAbstractService(); + abstractContract = abstractService; + abstractService.setName(getString(reader, Constants.NAME)); + constrainingType.getServices().add(abstractService); + policyProcessor.readPolicies(abstractService, reader); + + } else if (Constants.REFERENCE_QNAME.equals(name)) { + + // Read a + abstractReference = assemblyFactory.createAbstractReference(); + abstractContract = abstractReference; + abstractReference.setName(getString(reader, Constants.NAME)); + readMultiplicity(abstractReference, reader); + constrainingType.getReferences().add(abstractReference); + policyProcessor.readPolicies(abstractReference, reader); + + } else if (Constants.PROPERTY_QNAME.equals(name)) { + + // Read a + abstractProperty = assemblyFactory.createAbstractProperty(); + readAbstractProperty(abstractProperty, reader); + + // Read the property value + Document value = readPropertyValue(abstractProperty.getXSDElement(), abstractProperty.getXSDType(), reader); + abstractProperty.setValue(value); + + constrainingType.getProperties().add(abstractProperty); + policyProcessor.readPolicies(abstractProperty, reader); + + } else if (OPERATION_QNAME.equals(name)) { + + // Read an + Operation operation = new OperationImpl(); + operation.setName(getString(reader, NAME)); + operation.setUnresolved(true); + policyProcessor.readPolicies(abstractContract, operation, reader); + + } else { + + // Read an extension element + Object extension = extensionProcessor.read(reader); + if (extension instanceof InterfaceContract) { + + // and + abstractContract.setInterfaceContract((InterfaceContract)extension); + } else { + + // Add the extension element to the current element + if (abstractContract != null) { + abstractContract.getExtensions().add(extension); + } else { + constrainingType.getExtensions().add(extension); + } + + } + } + break; + + case END_ELEMENT: + name = reader.getName(); + + // Clear current state when reading reaching end element + if (SERVICE_QNAME.equals(name)) { + abstractService = null; + abstractContract = null; + } else if (REFERENCE_QNAME.equals(name)) { + abstractReference = null; + abstractContract = null; + } else if (PROPERTY_QNAME.equals(name)) { + abstractProperty = null; + } + break; + } + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return constrainingType; + } + + public void write(ConstrainingType constrainingType, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write element + writeStartDocument(writer, CONSTRAINING_TYPE, + new XAttr(TARGET_NAMESPACE, constrainingType.getName().getNamespaceURI()), + new XAttr(NAME, constrainingType.getName().getLocalPart()), + policyProcessor.writePolicies(constrainingType)); + + // Write elements + for (AbstractService service : constrainingType.getServices()) { + writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), + policyProcessor.writePolicies(service)); + + extensionProcessor.write(service.getInterfaceContract(), writer); + + for (Object extension: service.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write elements + for (AbstractReference reference : constrainingType.getReferences()) { + writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()), + writeMultiplicity(reference), + policyProcessor.writePolicies(reference)); + + extensionProcessor.write(reference.getInterfaceContract(), writer); + + for (Object extension: reference.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write elements + for (AbstractProperty abstractProperty : constrainingType.getProperties()) { + writeStart(writer, + PROPERTY, + new XAttr(NAME, abstractProperty.getName()), + new XAttr(MUST_SUPPLY, abstractProperty.isMustSupply()), + new XAttr(MANY, abstractProperty.isMany()), + new XAttr(TYPE, abstractProperty.getXSDType()), + new XAttr(ELEMENT, abstractProperty.getXSDElement()), + policyProcessor.writePolicies(abstractProperty)); + + // Write property value + writePropertyValue(abstractProperty.getValue(), abstractProperty.getXSDElement(), abstractProperty.getXSDType(), writer); + + // Write extensions + for (Object extension : abstractProperty.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write extension elements + for (Object extension: constrainingType.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEndDocument(writer); + } + + public void resolve(ConstrainingType constrainingType, ModelResolver resolver) throws ContributionResolveException { + // Resolve component type services and references + resolveAbstractContracts(constrainingType.getServices(), resolver); + resolveAbstractContracts(constrainingType.getReferences(), resolver); + + resolveIntents(constrainingType.getRequiredIntents(), resolver); + for ( AbstractService service : constrainingType.getServices() ) { + resolveIntents(service.getRequiredIntents(), resolver); + } + + for ( AbstractReference reference : constrainingType.getReferences() ) { + resolveIntents(reference.getRequiredIntents(), resolver); + } + } + + public QName getArtifactType() { + return CONSTRAINING_TYPE_QNAME; + } + + public Class getModelType() { + return ConstrainingType.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java new file mode 100644 index 0000000000..467ed37638 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java @@ -0,0 +1,258 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Default Model Processor for beans. + * + * @version $Rev$ $Date$ + */ +public class DefaultBeanModelProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor { + + private QName artifactType; + private Class modelClass; + private Object modelFactory; + private Method factoryMethod; + private Map setterMethods = new HashMap(); + private Map getterMethods = new HashMap(); + + public DefaultBeanModelProcessor(AssemblyFactory assemblyFactory, + ExtensionFactory extensionFactory, + PolicyFactory policyFactory, + QName artifactType, + Class modelClass, + Object modelFactory, + Monitor monitor) { + super(assemblyFactory, extensionFactory, policyFactory, null, null, monitor); + this.artifactType = artifactType; + this.modelClass = modelClass; + this.modelFactory = modelFactory; + + // Introspect the factory class and bean model class + if (modelFactory != null) { + + // Find the model create method + for (Method method: modelFactory.getClass().getMethods()) { + if (method.getName().startsWith("create") && method.getReturnType() == modelClass) { + factoryMethod = method; + break; + } + } + } + + // Index the bean's setter methods + for (Method method: modelClass.getMethods()) { + Method getter; + String name = method.getName(); + if (name.startsWith("set") && name.length() > 3) { + + // Get the corresponding getter method + try { + getter = modelClass.getMethod("get" + name.substring(3)); + } catch (Exception e) { + getter = null; + continue; + } + + // Get the property name + name = name.substring(3); + if (name.length() > 1) { + if (!name.toUpperCase().equals(name)) { + name = name.substring(0, 1).toLowerCase() + name.substring(1); + } + } + } else { + continue; + } + + // Map an uppercase property name to a lowercase attribute name + if (name.toUpperCase().equals(name)) { + name = name.toLowerCase(); + } + + // Trim trailing _ from property names + if (name.endsWith("_")) { + name = name.substring(0, name.length()-1); + } + setterMethods.put(name, method); + getterMethods.put(name, getter); + } + } + + public T read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + + // Read an element + try { + + // Create a new instance of the model + Object model; + if (modelFactory != null) { + // Invoke the factory create method + model = factoryMethod.invoke(modelFactory); + } else { + // Invoke the model bean class default constructor + model = modelClass.newInstance(); + } + + // Initialize the bean properties with the attributes found in the + // XML element + for (int i = 0, n = reader.getAttributeCount(); i < n; i++) { + String attributeName = reader.getAttributeLocalName(i); + Method setter = setterMethods.get(attributeName); + if (setter != null) { + String value = reader.getAttributeValue(i); + setter.invoke(model, value); + } + } + + // Read policies + policyProcessor.readPolicies(model, reader); + + // FIXME read extension elements + + // By default mark the model object unresolved + if (model instanceof Base) { + ((Base)model).setUnresolved(true); + } + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && artifactType.equals(reader.getName())) { + break; + } + } + return (T) model; + + } catch (Exception e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", reader, ce); + throw ce; + } + } + + public void write(T bean, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + try { + // Write the bean properties as attributes + List attrs = new ArrayList(); + for (Map.Entry entry: getterMethods.entrySet()) { + if (entry.getValue().getReturnType() == String.class) { + String value = (String)entry.getValue().invoke(bean); + attrs.add(new XAttr(entry.getKey(), value)); + } + } + + // Write element + writeStart(writer, artifactType.getNamespaceURI(), artifactType.getLocalPart(), + policyProcessor.writePolicies(bean), new XAttr(null, attrs)); + + writeEnd(writer); + + } catch (Exception e) { + ContributionWriteException ce = new ContributionWriteException(e); + error("ContributionWriteException", writer, ce); + throw ce; + } + } + + public void resolve(T bean, ModelResolver resolver) throws ContributionResolveException { + + // Resolve and merge the component type associated with an + // implementation model + if (bean instanceof Implementation) { + Implementation implementation = (Implementation)bean; + String uri = implementation.getURI(); + if (uri != null) { + int d = uri.lastIndexOf('.'); + if (d != -1) { + uri = uri.substring(0, d) + ".componentType"; + + // Resolve the component type + ComponentType componentType = assemblyFactory.createComponentType(); + componentType.setURI(uri); + componentType.setUnresolved(true); + + componentType = resolver.resolveModel(ComponentType.class, componentType); + if (componentType != null && !componentType.isUnresolved()) { + + // We found a component type, merge it into the implementation model + implementation.getServices().addAll(componentType.getServices()); + implementation.getReferences().addAll(componentType.getReferences()); + implementation.getProperties().addAll(componentType.getProperties()); + implementation.setConstrainingType(componentType.getConstrainingType()); + + if (implementation instanceof PolicySetAttachPoint && + componentType instanceof PolicySetAttachPoint ) { + PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation; + PolicySetAttachPoint policiedCompType = (PolicySetAttachPoint)componentType; + + if ( policiedImpl.getPolicySets() != null) { + policiedImpl.getPolicySets().addAll(policiedCompType.getPolicySets()); + } + if (policiedImpl.getRequiredIntents() != null) { + policiedImpl.getRequiredIntents().addAll(policiedCompType.getRequiredIntents()); + } + } + } + } + } + } + + // Mark the model resolved + if (bean instanceof Base) { + ((Base)bean).setUnresolved(false); + } + } + + public QName getArtifactType() { + return artifactType; + } + + public Class getModelType() { + return modelClass; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java new file mode 100644 index 0000000000..44be1b6de1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java @@ -0,0 +1,257 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * A Policy Attach Point processor. + * + * @version $Rev$ $Date$ + */ +public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implements Constants { + + private PolicyFactory policyFactory; + + public PolicyAttachPointProcessor(PolicyFactory policyFactory) { + this.policyFactory = policyFactory; + } + + /** + * Read policy intents associated with an operation. + * @param attachPoint + * @param operation + * @param reader + */ + private void readIntents(Object attachPoint, Operation operation, XMLStreamReader reader) { + if (!(attachPoint instanceof IntentAttachPoint)) + return; + IntentAttachPoint intentAttachPoint = (IntentAttachPoint)attachPoint; + String value = reader.getAttributeValue(null, REQUIRES); + if (value != null) { + List requiredIntents = intentAttachPoint.getRequiredIntents(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + Intent intent = policyFactory.createIntent(); + intent.setName(qname); + if (operation != null) { + //FIXME Don't we need to handle intent specification + // on an operation basis? + //intent.getOperations().add(operation); + } + requiredIntents.add(intent); + } + } + } + + /** + * Reads policy intents and policy sets associated with an operation. + * @param attachPoint + * @param operation + * @param reader + */ + public void readPolicies(Object attachPoint, Operation operation, XMLStreamReader reader) { + readIntents(attachPoint, operation, reader); + readPolicySets(attachPoint, operation, reader); + } + + /** + * Reads policy intents and policy sets. + * @param attachPoint + * @param reader + */ + public void readPolicies(Object attachPoint, XMLStreamReader reader) { + readPolicies(attachPoint, null, reader); + } + + /** + * Reads policy sets associated with an operation. + * @param attachPoint + * @param operation + * @param reader + */ + private void readPolicySets(Object attachPoint, Operation operation, XMLStreamReader reader) { + if (!(attachPoint instanceof PolicySetAttachPoint)) { + return; + } + PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint; + String value = reader.getAttributeValue(null, POLICY_SETS); + if (value != null) { + List policySets = policySetAttachPoint.getPolicySets(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + PolicySet policySet = policyFactory.createPolicySet(); + policySet.setName(qname); + if (operation != null) { + //FIXME Don't we need to handle policySet specification + // on an operation basis? + //policySet.getOperations().add(operation); + } + policySets.add(policySet); + } + } + + value = reader.getAttributeValue(SCA10_TUSCANY_NS, APPLICABLE_POLICY_SETS); + if (value != null) { + List applicablePolicySets = policySetAttachPoint.getApplicablePolicySets(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + PolicySet policySet = policyFactory.createPolicySet(); + policySet.setName(qname); + if (operation != null) { + //FIXME Don't we need to handle policySet specification + // on an operation basis? + //policySet.getOperations().add(operation); + } + applicablePolicySets.add(policySet); + } + } + } + + /** + * Write policies + * @param attachPoint + * @return + */ + XAttr writePolicies(Object attachPoint) throws XMLStreamException { + return writePolicies(attachPoint, (Operation)null); + } + + /** + * Write policies + * @param attachPoint + * @return + */ + public void writePolicyAttributes(Object attachPoint, XMLStreamWriter writer) throws XMLStreamException { + writePolicyAttributes(attachPoint, (Operation)null, writer); + } + + /** + * Write policies associated with an operation + * @param attachPoint + * @param operation + * @return + */ + XAttr writePolicies(Object attachPoint, Operation operation) { + List attrs =new ArrayList(); + attrs.add(writeIntents(attachPoint, operation)); + attrs.add(writePolicySets(attachPoint, operation)); + return new XAttr(null, attrs); + } + + /** + * Write policies + * @param attachPoint + * @return + */ + public void writePolicyAttributes(Object attachPoint, Operation operation, XMLStreamWriter writer) throws XMLStreamException { + XAttr attr = writePolicies(attachPoint, operation); + attr.write(writer); + } + + /** + * Write policies + * @param attachPoint + * @return + */ + public void writePolicyPrefixes(Object attachPoint, Operation operation, XMLStreamWriter writer) throws XMLStreamException { + XAttr attr = writePolicies(attachPoint, operation); + attr.writePrefix(writer); + } + + /** + * Write policy intents associated with an operation. + * @param attachPoint + * @param operation + */ + private XAttr writeIntents(Object attachPoint, Operation operation) { + if (!(attachPoint instanceof IntentAttachPoint)) { + return null; + } + IntentAttachPoint intentAttachPoint = (IntentAttachPoint)attachPoint; + List qnames = new ArrayList(); + for (Intent intent: intentAttachPoint.getRequiredIntents()) { + qnames.add(intent.getName()); + } + return new XAttr(Constants.REQUIRES, qnames); + } + + /** + * Write policy sets associated with an operation. + * @param attachPoint + * @param operation + */ + private XAttr writePolicySets(Object attachPoint, Operation operation) { + if (!(attachPoint instanceof PolicySetAttachPoint)) { + return null; + } + PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint; + List qnames = new ArrayList(); + for (PolicySet policySet: policySetAttachPoint.getPolicySets()) { + qnames.add(policySet.getName()); + } + return new XAttr(Constants.POLICY_SETS, qnames); + } + + public void resolvePolicies(Object attachPoint, ModelResolver resolver) { + if ( attachPoint instanceof PolicySetAttachPoint ) { + PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint; + + List requiredIntents = new ArrayList(); + Intent resolvedIntent = null; + + if ( policySetAttachPoint.getRequiredIntents() != null && policySetAttachPoint.getRequiredIntents().size() > 0 ) { + for ( Intent intent : policySetAttachPoint.getRequiredIntents() ) { + resolvedIntent = resolver.resolveModel(Intent.class, intent); + requiredIntents.add(resolvedIntent); + } + policySetAttachPoint.getRequiredIntents().clear(); + policySetAttachPoint.getRequiredIntents().addAll(requiredIntents); + } + + if ( policySetAttachPoint.getPolicySets() != null && policySetAttachPoint.getPolicySets().size() > 0 ) { + List resolvedPolicySets = new ArrayList(); + PolicySet resolvedPolicySet = null; + for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) { + resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet); + resolvedPolicySets.add(resolvedPolicySet); + } + policySetAttachPoint.getPolicySets().clear(); + policySetAttachPoint.getPolicySets().addAll(resolvedPolicySets); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..7a190dea9c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#componentType,model=org.apache.tuscany.sca.assembly.ComponentType +org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#constrainingType,model=org.apache.tuscany.sca.assembly.ConstrainingType +org.apache.tuscany.sca.assembly.xml.CompositeProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#composite,model=org.apache.tuscany.sca.assembly.Composite diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor new file mode 100644 index 0000000000..403c049b48 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.ComponentTypeDocumentProcessor;type=.componentType,model=org.apache.tuscany.sca.assembly.ComponentType +org.apache.tuscany.sca.assembly.xml.ConstrainingTypeDocumentProcessor;type=.constrainingType,model=org.apache.tuscany.sca.assembly.ConstrainingType +org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;type=.composite,model=org.apache.tuscany.sca.assembly.Composite diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..ecc34942f1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.assembly.xml.CompositeModelResolver;model=org.apache.tuscany.sca.assembly.Composite +org.apache.tuscany.sca.assembly.xml.ConstrainingTypeModelResolver;model=org.apache.tuscany.sca.assembly.ConstrainingType +org.apache.tuscany.sca.assembly.xml.ComponentTypeModelResolver;model=org.apache.tuscany.sca.assembly.ComponentType diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties new file mode 100644 index 0000000000..6fd524716c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties @@ -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. +# +# +NoCompositeNamespace = No namespace found: Composite = {0} +UnexpectedInterfaceElement = Unexpected element found. It should appear inside a or element. +UnexpectedBindingElement = Unexpected element found. It should appear inside a or element. +UnexpectedImplementationElement = Unexpected element found. It should appear inside a element. +PolicyImplValidationException = PolicyValidation exception when processing implementation of component {0} due to {1}. +PolicyServiceValidationException = PolicyValidation exceptions when processing service/reference {0} in {1}. Error is {2} +ContributionReadException = ContributionReadException occured due to : {0} +ContributionWriteException = ContributionWriteException occured due to : {0} +XMLStreamException = XMLStreamException occured due to : {0} +HttpServerError = HTTP Server Error : {0} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java new file mode 100644 index 0000000000..5f8f976b84 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.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.sca.assembly.xml; + +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; + +/** + * Test reading SCA XML assembly documents. + * + * @version $Rev: 561254 $ $Date: 2007-07-31 13:16:27 +0530 (Tue, 31 Jul 2007) $ + */ +public class BuildPolicyTestCase extends TestCase { + private URLArtifactProcessor documentProcessor; + private URLArtifactProcessor policyDefinitionsProcessor; + private ModelResolver resolver; + private CompositeBuilder compositeBuilder; + private Composite composite; + private Monitor monitor; + + @Override + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl(); + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + List policyDefinitions = new ArrayList(); + resolver = new DefaultModelResolver(); + + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + monitor = monitorFactory.createMonitor(); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + + compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, monitor); + URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint(extensionPoints); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + policyDefinitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessors.addArtifactProcessor(new TestPolicyProcessor()); + + URL url = getClass().getResource("CalculatorComponent.constrainingType"); + URI uri = URI.create("CalculatorComponent.constrainingType"); + ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + url = getClass().getResource("TestAllPolicyCalculator.composite"); + uri = URI.create("TestAllCalculator.constrainingType"); + composite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(composite); + + url = getClass().getResource("another_test_definitions.xml"); + uri = URI.create("another_test_definitions.xml"); + SCADefinitions definitions = (SCADefinitions)policyDefinitionsProcessor.read(null, uri, url); + assertNotNull(definitions); + policyDefinitions.add(definitions); + + documentProcessor.resolve(definitions, resolver); + documentProcessor.resolve(composite, resolver); + + compositeBuilder.build(composite); + } + + public void testPolicyIntentInheritance() throws Exception { + String namespaceUri = "http://test"; + + IntentAttachPoint policiedComposite = (IntentAttachPoint)composite; + assertEquals(policiedComposite.getRequiredIntents().size(), 1); + assertEquals(policiedComposite.getRequiredIntents().get(0).getName(), new QName(namespaceUri, "tuscanyIntent_1")); + + //1 defined for composite, 2 defined for the service, 1 defined and 3 inherited for the promoted service (4) + assertEquals(composite.getServices().get(0).getRequiredIntents().size(), 7); + //1 from the operation defined in this service and 2 from the operation defined in the promoted service + assertEquals(composite.getServices().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 5); + assertEquals(composite.getServices().get(0).getRequiredIntents().get(3).getName(), new QName(namespaceUri, "tuscanyIntent_3")); + //bindings will have only 2 intents since duplications will be cut out + assertEquals(((IntentAttachPoint)composite.getServices().get(0).getBindings().get(0)).getRequiredIntents().size(), 3); + assertEquals(((OperationsConfigurator)composite.getServices().get(0).getBindings().get(0)).getConfiguredOperations().size(), 1); + assertEquals(((OperationsConfigurator)composite.getServices().get(0).getBindings().get(0)).getConfiguredOperations().get(0).getRequiredIntents().size(), 5); + + assertEquals(composite.getReferences().get(0).getRequiredIntents().size(), 5); + assertEquals(composite.getReferences().get(0).getConfiguredOperations().size(), 1); + assertEquals(composite.getReferences().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 4); + assertEquals(composite.getReferences().get(0).getRequiredIntents().get(1).getName(), new QName(namespaceUri, "tuscanyIntent_1")); + assertEquals(((IntentAttachPoint)composite.getReferences().get(0).getBindings().get(0)).getRequiredIntents().size(), 3); + + assertEquals(composite.getComponents().get(0).getRequiredIntents().size(), 3); + assertEquals(composite.getComponents().get(0).getRequiredIntents().get(2).getName(), new QName(namespaceUri, "tuscanyIntent_1")); + assertEquals(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().size(), 4); + assertEquals(composite.getComponents().get(0).getServices().get(0).getCallback().getRequiredIntents().size(), 4); + assertEquals(composite.getComponents().get(0).getServices().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 5); + assertEquals(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().size(), 5); + assertEquals(composite.getComponents().get(0).getReferences().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 5); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java new file mode 100644 index 0000000000..f34ff1f8bc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static junit.framework.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.junit.Before; +import org.junit.Test; + +/** + * Test writing SCA XML assemblies. + * + * TUSCANY-2662 + * + * @version $Rev$ $Date$ + */ +public class MultiplicityReadWriteTestCase { + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + + @Before + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + } + + + @Test + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Multiplicity.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + + verifyComposite(composite); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + bos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + composite = staxProcessor.read(bis, Composite.class); + + verifyComposite(composite); + + } + + + private void verifyComposite(Composite composite) { + assertEquals(composite.getComponents().get(0).getReferences().get(0).getMultiplicity(), Multiplicity.ZERO_N); + assertEquals(composite.getReferences().get(0).getMultiplicity(), Multiplicity.ONE_N); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java new file mode 100644 index 0000000000..e2aeb85d32 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.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.sca.assembly.xml; + +import java.io.InputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadAllTestCase extends TestCase { + private StAXArtifactProcessor staxProcessor; + private XMLInputFactory inputFactory; + + @Override + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + inputFactory = XMLInputFactory.newInstance(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + assertNotNull(composite); + assertEquals(composite.getName(), new QName("http://calc", "TestAllCalculator")); + assertEquals(composite.getConstrainingType().getName(), new QName("http://calc", "CalculatorComponent")); + assertTrue(composite.isLocal()); + assertFalse(composite.getAutowire() == Boolean.TRUE); + assertEquals(((PolicySetAttachPoint)composite).getRequiredIntents().get(0).getName(), new QName("http://test", + "confidentiality")); + assertEquals(((PolicySetAttachPoint)composite).getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + + Composite include = composite.getIncludes().get(0); + assertEquals(include.getName(), new QName("http://calc", "TestAllDivide")); + + CompositeService calcCompositeService = (CompositeService)composite.getServices().get(0); + assertEquals(calcCompositeService.getName(), "CalculatorService"); + assertTrue(calcCompositeService.getPromotedService().isUnresolved()); + assertEquals(calcCompositeService.getPromotedService().getName(), + "CalculatorService"); + assertEquals(calcCompositeService.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcCompositeService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + // TODO test operations + Callback calcServiceCallback = calcCompositeService.getCallback(); + assertNotNull(calcServiceCallback); + assertEquals(calcServiceCallback.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcServiceCallback.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + // TODO test operations + + Component calcComponent = composite.getComponents().get(0); + assertEquals(calcComponent.getName(), "CalculatorServiceComponent"); + assertEquals(calcComponent.getAutowire(), Boolean.FALSE); + assertEquals(calcComponent.getConstrainingType().getName(), new QName("http://calc", + "CalculatorComponent")); + assertEquals(calcComponent.getRequiredIntents().get(0).getName(), new QName("http://test", + "confidentiality")); + assertEquals(calcComponent.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + + ComponentService calcComponentService = calcComponent.getServices().get(0); + assertEquals(calcComponentService.getName(), "CalculatorService"); + assertEquals(calcComponentService.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcComponentService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + // TODO test operations + + ComponentReference calcComponentReference = calcComponent.getReferences().get(0); + assertEquals(calcComponentReference.getName(), "addService"); + assertEquals(calcComponentReference.getAutowire(), Boolean.FALSE); + assertEquals(calcComponentReference.isWiredByImpl(), false); + assertEquals(calcComponentReference.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcComponentReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + // TODO test operations + + Property property = calcComponent.getProperties().get(0); + assertEquals(property.getName(), "round"); + Document doc = (Document) property.getValue(); + Element element = doc.getDocumentElement(); + String value = element.getTextContent(); + assertEquals(value, "true"); + assertEquals(property.getXSDType(), new QName("http://www.w3.org/2001/XMLSchema", "boolean")); + assertEquals(property.isMany(), false); + + CompositeReference calcCompositeReference = (CompositeReference)composite.getReferences().get(0); + assertEquals(calcCompositeReference.getName(), "MultiplyService"); + assertTrue(calcCompositeReference.getPromotedReferences().get(0).isUnresolved()); + assertEquals(calcCompositeReference.getPromotedReferences().get(0).getName(), + "CalculatorServiceComponent/multiplyService"); + assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + // TODO test operations + Callback calcCallback = calcCompositeReference.getCallback(); + assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + assertNotNull(calcCallback); + // TODO test operations + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java new file mode 100644 index 0000000000..b3760789c8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java @@ -0,0 +1,207 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.net.URI; +import java.net.URL; + +import javax.xml.XMLConstants; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.stream.XMLInputFactory; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.ValidatorHandler; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; + +/** + * Test reading SCA XML assembly documents. + * + * @version $Rev$ $Date$ + */ +public class ReadDocumentTestCase extends TestCase { + + private URLArtifactProcessor documentProcessor; + private ModelResolver resolver; + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + + @Override + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + inputFactory = XMLInputFactory.newInstance(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + + resolver = new DefaultModelResolver(); + } + + public void testValidateAssembly() throws Exception { + + SchemaFactory schemaFactory; + try { + schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + } catch (Error e) { + // Some old JDKs don't support XMLSchema validation + return; + } catch (Exception e) { + // Some old JDKs don't support XMLSchema validation + return; + } + Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd")); + ValidatorHandler handler = schema.newValidatorHandler(); + + SAXParserFactory parserFactory = SAXParserFactory.newInstance(); + URL url = getClass().getResource("Calculator.composite"); + XMLReader reader = parserFactory.newSAXParser().getXMLReader(); + reader.setFeature("http://xml.org/sax/features/namespaces", true); + reader.setContentHandler(handler); + reader.parse(new InputSource(url.openStream())); + + } + + public void testValidateImplementation() throws Exception { + + SchemaFactory schemaFactory; + try { + schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + } catch (Error e) { + // Some old JDKs don't support XMLSchema validation + return; + } catch (Exception e) { + // Some old JDKs don't support XMLSchema validation + return; + } + Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd")); + ValidatorHandler handler = schema.newValidatorHandler(); + + SAXParserFactory parserFactory = SAXParserFactory.newInstance(); + URL url = getClass().getResource("JavaScriptReference.composite"); + XMLReader reader = parserFactory.newSAXParser().getXMLReader(); + reader.setFeature("http://xml.org/sax/features/namespaces", true); + reader.setContentHandler(handler); + reader.parse(new InputSource(url.openStream())); + } + + public void testReadImplementation() throws Exception { + + ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint(); + schemas.addSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd").toString()); + XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null); + CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(staxProcessor, validatingInputFactory, null, null); + + URL url = getClass().getResource("JavaScriptReference.composite"); + URI uri = URI.create("JavaScriptReference.composite"); + Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url); + assertNotNull(composite); + } + + public void testValidateBinding() throws Exception { + + SchemaFactory schemaFactory; + try { + schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + } catch (Error e) { + // Some old JDKs don't support XMLSchema validation + return; + } catch (Exception e) { + // Some old JDKs don't support XMLSchema validation + return; + } + Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd")); + ValidatorHandler handler = schema.newValidatorHandler(); + + SAXParserFactory parserFactory = SAXParserFactory.newInstance(); + URL url = getClass().getResource("RMIBindingTest.composite"); + XMLReader reader = parserFactory.newSAXParser().getXMLReader(); + reader.setFeature("http://xml.org/sax/features/namespaces", true); + reader.setContentHandler(handler); + reader.parse(new InputSource(url.openStream())); + } + + public void testReadBinding() throws Exception { + + ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint(); + schemas.addSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd").toString()); + XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null); + CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(staxProcessor, validatingInputFactory, null, null); + + URL url = getClass().getResource("RMIBindingTest.composite"); + URI uri = URI.create("RMIBindingTest.composite"); + Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url); + assertNotNull(composite); + } + + public void testResolveConstrainingType() throws Exception { + + URL url = getClass().getResource("CalculatorComponent.constrainingType"); + URI uri = URI.create("CalculatorComponent.constrainingType"); + ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + url = getClass().getResource("TestAllCalculator.composite"); + uri = URI.create("TestAllCalculator.constrainingType"); + Composite composite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(composite); + + documentProcessor.resolve(composite, resolver); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + public void testResolveComposite() throws Exception { + URL url = getClass().getResource("Calculator.composite"); + URI uri = URI.create("Calculator.composite"); + Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + url = getClass().getResource("TestAllCalculator.composite"); + uri = URI.create("TestAllCalculator.composite"); + Composite composite = (Composite)documentProcessor.read(null, uri, url); + + documentProcessor.resolve(composite, resolver); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java new file mode 100644 index 0000000000..1aede413a5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + + @Override + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + @Override + public void tearDown() throws Exception { + } + + public void testReadComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(staxProcessor.read(reader)); + is.close(); + } + + public void testReadConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(staxProcessor.read(reader)); + is.close(); + + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(staxProcessor.read(reader)); + is.close(); + + } + + public void testReadCompositeAndWireIt() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(staxProcessor.read(reader)); + is.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java new file mode 100644 index 0000000000..200b7061c6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.Test; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadWriteAnyAttributeTestCase { + + private static final QName EXTENDED_ATTRIBUTE = new QName("http://test", "customAttribute"); + + private static final String XML = ""+ + ""+ + ""+ + ""+ + ""+ + ""; + + private static final String XML_WITH_EXTENDED_ATTRIBUTES_IN_BINDINGS = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + + /** + * Initialize the test environment + * This takes care to register attribute processors when provided + * + * @param attributeProcessor + * @throws Exception + */ + private void init(StAXAttributeProcessor attributeProcessor) throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + + if(attributeProcessor != null) { + StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + staxAttributeProcessors.addArtifactProcessor(attributeProcessor); + } + + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + /** + * Read and Write a composite that has a extended attribute + * and a particular attribute processor + * @throws Exception + */ + @Test + public void testReadWriteCompositeWithAttributeProcessor() throws Exception { + init(new TestAttributeProcessor()); + + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML); + // System.out.println(bos.toString()); + + assertEquals(XML, bos.toString()); + } + + /** + * Read and Write a composite that has a extended attribute + * but no particular processor for it + * @throws Exception + */ + @Test + public void testDefaultReadWriteComposite() throws Exception { + init(null); + + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML); + // System.out.println(bos.toString()); + + assertEquals(XML, bos.toString()); + } + + + @Test + public void testReadWriteCompositeWithBindings() throws Exception { + init(null); + + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_WITH_EXTENDED_ATTRIBUTES_IN_BINDINGS)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_WITH_EXTENDED_ATTRIBUTES_IN_BINDINGS); + // System.out.println(bos.toString()); + + assertEquals(XML_WITH_EXTENDED_ATTRIBUTES_IN_BINDINGS, bos.toString()); + bos.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java new file mode 100644 index 0000000000..e99f760e58 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.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.sca.assembly.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +public class ReadWriteAnyElementTestCase { + private static final String XML_RECURSIVE_EXTENDED_ELEMENT = + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String XML_UNKNOWN_IMPL = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, XMLOutputFactory.newInstance(), null); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testReadWriteExtendedRecursiveElement() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_RECURSIVE_EXTENDED_ELEMENT)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT); + // System.out.println(bos.toString()); + + assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, bos.toString()); + bos.close(); + } + + @Test + public void testReadWriteUnknwonImpl() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_UNKNOWN_IMPL); + // System.out.println(bos.toString()); + + assertEquals(XML_UNKNOWN_IMPL, bos.toString()); + bos.close(); + } + + // @Test + @Ignore() + public void testReadWriteInvalidAttribute() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_UNKNOWN_IMPL); + // System.out.println(bos.toString()); + + assertEquals(XML_UNKNOWN_IMPL, bos.toString()); + bos.close(); + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java new file mode 100644 index 0000000000..312b5c8fab --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev: 711584 $ $Date: 2008-11-05 15:07:03 +0000 (Wed, 05 Nov 2008) $ + */ +public class ReadWriteLocalCompositeTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + private static final String LOCAL_COMPOSITE_XML = ""+ + ""+ + ""; + + @Override + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + + StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + staxAttributeProcessors.addArtifactProcessor(new TestAttributeProcessor()); + + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + @Override + public void tearDown() throws Exception { + + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("local.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + assertTrue(composite.isLocal()); + is.close(); + } + + public void testWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("local.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + assertTrue(composite.isLocal()); + is.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + System.out.println(bos.toString()); + + assertEquals(LOCAL_COMPOSITE_XML, bos.toString()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java new file mode 100644 index 0000000000..32a2d94220 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.net.URI; +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Test reading SCA XML assembly documents. + * + * @version $Rev: 561254 $ $Date: 2007-07-31 13:16:27 +0530 (Tue, 31 Jul 2007) $ + */ +public class ResolvePolicyTestCase extends TestCase { + + private URLArtifactProcessor documentProcessor; + private ModelResolver resolver; + private URLArtifactProcessor policyDefinitionsProcessor; + + @Override + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + resolver = new DefaultModelResolver(); + + URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + policyDefinitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class); + + // Create StAX processors + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessors.addArtifactProcessor(new TestPolicyProcessor()); + } + + public void testResolveConstrainingType() throws Exception { + + URL url = getClass().getResource("CalculatorComponent.constrainingType"); + URI uri = URI.create("CalculatorComponent.constrainingType"); + ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + url = getClass().getResource("TestAllCalculator.composite"); + uri = URI.create("TestAllCalculator.constrainingType"); + Composite composite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(composite); + + url = getClass().getResource("test_definitions.xml"); + uri = URI.create("test_definitions.xml"); + SCADefinitions scaDefns = (SCADefinitions)policyDefinitionsProcessor.read(null, uri, url); + assertNotNull(scaDefns); + + preResolvePolicyTests(composite); + documentProcessor.resolve(scaDefns, resolver); + documentProcessor.resolve(composite, resolver); + postResolvePolicyTests(composite); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + private void preResolvePolicyTests(Composite composite) { + assertNull(((PolicySetAttachPoint)composite).getRequiredIntents().get(0).getDescription()); + assertTrue(((PolicySetAttachPoint)composite).getPolicySets().get(0).getProvidedIntents().isEmpty()); + + assertNull(composite.getServices().get(0).getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNull(composite.getServices().get(0).getCallback().getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty()); + + assertNull(composite.getComponents().get(0).getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNull(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNull(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + + assertNull(composite.getReferences().get(0).getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNull(composite.getReferences().get(0).getCallback().getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty()); + } + + private void postResolvePolicyTests(Composite composite) { + assertNotNull(((PolicySetAttachPoint)composite).getRequiredIntents().get(0).getDescription()); + assertFalse(((PolicySetAttachPoint)composite).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(((PolicySetAttachPoint)composite).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + + assertNotNull(composite.getServices().get(0).getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + assertNotNull(composite.getServices().get(0).getCallback().getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + + assertNotNull(composite.getComponents().get(0).getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + assertNotNull(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + assertNotNull(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + + assertNotNull(composite.getReferences().get(0).getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + assertNotNull(composite.getReferences().get(0).getCallback().getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + + + } + + public void testResolveComposite() throws Exception { + URL url = getClass().getResource("Calculator.composite"); + URI uri = URI.create("Calculator.composite"); + Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + url = getClass().getResource("TestAllCalculator.composite"); + uri = URI.create("TestAllCalculator.composite"); + Composite composite = (Composite)documentProcessor.read(null, uri, url); + + documentProcessor.resolve(composite, resolver); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java new file mode 100644 index 0000000000..df09a56c38 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; + +/** + * Test resolving SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ResolveTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private StAXArtifactProcessorExtensionPoint staxProcessors; + private ModelResolver resolver; + + @Override + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + resolver = new DefaultModelResolver(); + } + + public void testResolveConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + StAXArtifactProcessor constrainingTypeReader = staxProcessors.getProcessor(ConstrainingType.class); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ConstrainingType constrainingType = constrainingTypeReader.read(reader); + is.close(); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + StAXArtifactProcessor compositeReader = staxProcessors.getProcessor(Composite.class); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + is.close(); + assertNotNull(composite); + + compositeReader.resolve(composite, resolver); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + public void testResolveComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + StAXArtifactProcessor compositeReader = staxProcessors.getProcessor(Composite.class); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite nestedComposite = compositeReader.read(reader); + is.close(); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + is.close(); + + compositeReader.resolve(composite, resolver); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java new file mode 100644 index 0000000000..c34e9e3d22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.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.sca.assembly.xml; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + +/** + * A Attribute Processor used for testing. + * + * @version $Rev$ $Date$ + */ +public class TestAttributeProcessor extends BaseStAXArtifactProcessor implements StAXAttributeProcessor { + private static final QName ATTRIBUTE = new QName("http://test", "customAttribute", "test"); + + public QName getArtifactType() { + return ATTRIBUTE; + } + + public String read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + return reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart()); + } + + public void write(String value, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + writer.writeAttribute(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI(),ATTRIBUTE.getLocalPart(), value); + } + + public Class getModelType() { + return null; + } + + public void resolve(String arg0, ModelResolver arg1) throws ContributionResolveException { + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java new file mode 100644 index 0000000000..16cefc58cf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.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.sca.assembly.xml; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.policy.Policy; + +/** + * A Policy Processor used for testing. + * + * @version $Rev$ $Date$ + */ +public class TestPolicyProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment"); + } + + public Policy read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException { + return new MockPolicyImplOne(); + } + + public void write(Policy arg0, XMLStreamWriter arg1) throws ContributionWriteException, + XMLStreamException { + } + + public Class getModelType() { + return Policy.class; + } + + public void resolve(Policy arg0, ModelResolver arg1) throws ContributionResolveException { + } + + + public class MockPolicyImplOne implements Policy { + public QName getSchemaName() { + return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment"); + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java new file mode 100644 index 0000000000..c423df6f7d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.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.sca.assembly.xml; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; + +/** + * A factory for the SCA binding model. + * + * @version $Rev$ $Date$ + */ +public class TestSCABindingFactoryImpl implements SCABindingFactory { + public SCABinding createSCABinding() { + return new TestSCABindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java new file mode 100644 index 0000000000..3046f2e630 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java @@ -0,0 +1,214 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.xml; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * A test cheel for the SCA binding. + * + * @version $Rev$ $Date$ + */ +public class TestSCABindingImpl extends ExtensibleImpl implements SCABinding, OptimizableBinding, PolicySetAttachPoint, OperationsConfigurator { + private String name; + private String uri; + private List extensions = new ArrayList(); + + private Component targetComponent; + private ComponentService targetComponentService; + private Binding targetBinding; + + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType bindingType = new TestSCABindingType(); + private List configuredOperations = new ArrayList(); + private List applicablePolicySets = new ArrayList(); + + /** + * Constructs a new SCA binding. + */ + protected TestSCABindingImpl() { + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public List getExtensions() { + return extensions; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + /** + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + /** + * @return the targetComponent + */ + public Component getTargetComponent() { + return targetComponent; + } + + /** + * @param targetComponent the targetComponent to set + */ + public void setTargetComponent(Component targetComponent) { + this.targetComponent = targetComponent; + } + + /** + * @return the targetComponentService + */ + public ComponentService getTargetComponentService() { + return targetComponentService; + } + + /** + * @param targetComponentService the targetComponentService to set + */ + public void setTargetComponentService(ComponentService targetComponentService) { + this.targetComponentService = targetComponentService; + } + + /** + * @return the targetBinding + */ + public Binding getTargetBinding() { + return targetBinding; + } + + /** + * @param targetBinding the targetBinding to set + */ + public void setTargetBinding(Binding targetBinding) { + this.targetBinding = targetBinding; + } + + public List getPolicySets() { + // TODO Auto-generated method stub + return policySets; + } + + public List getRequiredIntents() { + // TODO Auto-generated method stub + return requiredIntents; + } + + public IntentAttachPointType getType() { + // TODO Auto-generated method stub + return bindingType; + } + + public void setType(IntentAttachPointType type) { + this.bindingType = type; + } + + private class TestSCABindingType implements IntentAttachPointType { + private QName name = new QName("http://www.osoa.org/xmlns/sca/1.0","binding"); + + public List getAlwaysProvidedIntents() { + // TODO Auto-generated method stub + return null; + } + + public List getMayProvideIntents() { + // TODO Auto-generated method stub + return null; + } + + public QName getName() { + return name; + } + + public boolean isUnresolved() { + // TODO Auto-generated method stub + return false; + } + + public void setName(QName type) { + // TODO Auto-generated method stub + + } + + public void setUnresolved(boolean unresolved) { + // TODO Auto-generated method stub + + } + + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public List getConfiguredOperations() { + return configuredOperations; + } + + public void setConfiguredOperations(List configuredOperations) { + this.configuredOperations = configuredOperations; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java new file mode 100644 index 0000000000..76361d4b70 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; + +/** + * Test the wiring of SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class WireTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private ModelResolver resolver; + private URLArtifactProcessor policyDefinitionsProcessor; + private CompositeBuilder compositeBuilder; + private Monitor monitor; + + @Override + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + resolver = new DefaultModelResolver(); + + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + monitor = monitorFactory.createMonitor(); + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl(); + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, monitor); + + URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + policyDefinitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class); + } + + public void testResolveConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(reader); + is.close(); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader); + is.close(); + assertNotNull(composite); + + URL url = getClass().getResource("test_definitions.xml"); + URI uri = URI.create("test_definitions.xml"); + SCADefinitions scaDefns = (SCADefinitions)policyDefinitionsProcessor.read(null, uri, url); + assertNotNull(scaDefns); + + policyDefinitionsProcessor.resolve(scaDefns, resolver); + + staxProcessor.resolve(composite, resolver); + compositeBuilder.build(composite); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + public void testResolveComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite nestedComposite = (Composite)staxProcessor.read(reader); + is.close(); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader); + is.close(); + + URL url = getClass().getResource("test_definitions.xml"); + URI uri = URI.create("test_definitions.xml"); + SCADefinitions scaDefns = (SCADefinitions)policyDefinitionsProcessor.read(null, uri, url); + assertNotNull(scaDefns); + + policyDefinitionsProcessor.resolve(scaDefns, resolver); + + staxProcessor.resolve(composite, resolver); + compositeBuilder.build(composite); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java new file mode 100644 index 0000000000..b859779437 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; + +/** + * Test writing SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class WriteAllTestCase extends TestCase { + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + private ModelResolver resolver; + private CompositeBuilder compositeBuilder; + private URLArtifactProcessor policyDefinitionsProcessor; + private Monitor monitor; + + @Override + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + resolver = new DefaultModelResolver(); + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl(); + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + monitor = monitorFactory.createMonitor(); + + compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, monitor); + + URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + policyDefinitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class); + } + + @Override + public void tearDown() throws Exception { + } + + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + + verifyComposite(composite); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + bos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + composite = staxProcessor.read(bis, Composite.class); + + verifyComposite(composite); + + } + + public void testReadWireWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + + URL url = getClass().getResource("test_definitions.xml"); + URI uri = URI.create("test_definitions.xml"); + SCADefinitions scaDefns = (SCADefinitions)policyDefinitionsProcessor.read(null, uri, url); + assertNotNull(scaDefns); + policyDefinitionsProcessor.resolve(scaDefns, resolver); + + staxProcessor.resolve(composite, resolver); + compositeBuilder.build(composite); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + } + + public void testReadWriteComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + ComponentType componentType = staxProcessor.read(is, ComponentType.class); + staxProcessor.resolve(componentType, resolver); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(componentType, bos); + } + + public void testReadWriteConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + ConstrainingType constrainingType = staxProcessor.read(is, ConstrainingType.class); + staxProcessor.resolve(constrainingType, resolver); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(constrainingType, bos); + } + + private void verifyComposite(Composite composite) { + assertEquals(composite.getProperties().get(0).getName(),"prop1"); + assertEquals(composite.getProperties().get(0).isMany(), true); + assertEquals(composite.getProperties().get(1).getName(),"prop2"); + assertEquals(composite.getProperties().get(1).isMustSupply(), true); + assertEquals(composite.getProperties().get(0).getXSDType(), new QName("http://foo", "MyComplexType")); + assertEquals(composite.getProperties().get(1).getXSDElement(), new QName("http://www.osoa.org/xmlns/sca/1.0", "MyComplexPropertyValue1")); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java new file mode 100644 index 0000000000..5188b1c91a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * Test writing SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class WriteNamespacesTestCase extends TestCase { + private StAXArtifactProcessor compositeProcessor; + private XMLOutputFactory outputFactory; + private XMLInputFactory inputFactory; + + @Override + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + //outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); + inputFactory = modelFactories.getFactory(XMLInputFactory.class); + + StAXArtifactProcessorExtensionPoint artifactProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + compositeProcessor = artifactProcessors.getProcessor(Composite.class); + } + + public void testReadWriteComposite() throws Exception { + + // Read + InputStream is = getClass().getResourceAsStream("NestedCalculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeProcessor.read(reader); + Component component = composite.getComponents().get(0); + Composite implementation = (Composite)component.getImplementation(); + QName qname = implementation.getName(); + + // Write + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bos); + compositeProcessor.write(composite, writer); + System.out.println(bos); + + // Read again + is = new ByteArrayInputStream(bos.toByteArray()); + reader = inputFactory.createXMLStreamReader(is); + composite = compositeProcessor.read(reader); + + // Compare + component = composite.getComponents().get(0); + implementation = (Composite)component.getImplementation(); + assertEquals(qname, implementation.getName()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite new file mode 100644 index 0000000000..602d42a06a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType new file mode 100644 index 0000000000..d6ec9b0ff0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType new file mode 100644 index 0000000000..299eb8c197 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite new file mode 100644 index 0000000000..a313dd1e6d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Multiplicity.composite b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Multiplicity.composite new file mode 100644 index 0000000000..a221c23eec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Multiplicity.composite @@ -0,0 +1,30 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite new file mode 100644 index 0000000000..2719ee9162 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite new file mode 100644 index 0000000000..d29fe85586 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite new file mode 100644 index 0000000000..5091ff700b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AValue + InterestingURI + + + BValue + BoringURI + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite new file mode 100644 index 0000000000..d59e69209d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite new file mode 100644 index 0000000000..7bc7ccdb83 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AValue + InterestingURI + + + BValue + BoringURI + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml new file mode 100644 index 0000000000..bcc8c54dc8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml @@ -0,0 +1,97 @@ + + + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/local.composite b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/local.composite new file mode 100644 index 0000000000..3bda9ac31c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/local.composite @@ -0,0 +1,27 @@ + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml new file mode 100644 index 0000000000..b79cb6b7b7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + ... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ... + + + + ... + + + + + + + + + Protect messages from unauthorized reading or modification + + + + + + Protect messages from unauthorized reading or modification + + + + + + + Communitcation thro this binding must prevent + unauthorized users from reading the messages. + + + + + + Communitcation thro this binding must prevent + unauthorized modification of the messages. + + + + + + Communitcation thro this binding required + Authentication. + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/LICENSE new file mode 100644 index 0000000000..646cd58e09 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/LICENSE @@ -0,0 +1,281 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + +=============================================================================== + +Apache Tuscany SCA for Java Subcomponents +=========================================: + +The Tuscany SCA for Java release includes a number of subcomponents with +separate copyright notices and license terms. Your use of the source +code for the these subcomponents is subject to the terms and +conditions of the following licenses. + +=============================================================================== + +This module includes XSD files under the following SCA Collaboration license: + +License for the Service Component Architecture JavaDoc, Interface Definition files and XSD files. + +Permission to copy, make derivative works of, and distribute the Service Component Architecture +JavaDoc, Interface Definition Files and XSD files in any medium without fee or royalty as part +of a compliant implementation of the Service Component Architecture Specification is hereby granted. +The Service Components Architecture Specification may be found at the following location: + + http://www.osoa.org/download/attachments/35/SCA_AssemblyModel_V100.pdf + +THE SERVICE COMPONENT ARCHITECTURE SPECIFICATION AND THE JAVADOC, INTERFACE DEFINITION FILES AND XSD FILES +ARE PROVIDED "AS IS," AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS +SPECIFICATION OR THE JAVADOC, INTERFACE DEFINITION FILES AND XSD FILES AND THE IMPLEMENTATION OF THEIR CONTENTS, +INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, +NON-INFRINGEMENT OR TITLE. THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, +INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO ANY USE OR DISTRIBUTION OF THE +SERVICE COMPONENT ARCHITECTURE SPECIFICATION OR THE JAVADOC, INTERFACE DEFINTION FILES OR XSD FILES. + +The name and trademarks of the Authors may NOT be used in any manner, including advertising or +publicity pertaining to the Service Component Architecture Specification or its contents without specific, +written prior permission. Title to copyright in the Service Component Architecture Specification and the +JavaDoc, Interface Definition Files and XSD Files will at all times remain with the Authors. + +No other rights are granted by implication, estoppel or otherwise. + +=============================================================================== + +This module includes XSD files under the following W3C(r) Software License: + +W3C(r) SOFTWARE NOTICE AND LICENSE +http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 + +This work (and included software, documentation such as READMEs, or other related items) +is being provided by the copyright holders under the following license. By obtaining, +using and/or copying this work, you (the licensee) agree that you have read, understood, +and will comply with the following terms and conditions. + +Permission to copy, modify, and distribute this software and its documentation, with or +without modification, for any purpose and without fee or royalty is hereby granted, provided +that you include the following on ALL copies of the software and documentation or portions +thereof, including modifications: + + 1. The full text of this NOTICE in a location viewable to users of the redistributed or + derivative work. + 2. Any pre-existing intellectual property disclaimers, notices, or terms and conditions. + If none exist, the W3C Software Short Notice should be included (hypertext is preferred, + text is permitted) within the body of any redistributed or derivative code. + 3. Notice of any changes or modifications to the files, including the date changes were + made. (We recommend you provide URIs to the location from which the code is derived.) + +THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO +REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES +OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR +DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER +RIGHTS. + +COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL +DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION. + +The name and trademarks of copyright holders may NOT be used in advertising or publicity +pertaining to the software without specific, written prior permission. Title to copyright +in this software and any associated documentation will at all times remain with copyright +holders. diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/NOTICE new file mode 100644 index 0000000000..91c3b75575 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/NOTICE @@ -0,0 +1,23 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + +This product also includes software under the SCA Collaboration license +(see the LICENSE file contained in this distribution), with the following +copyright: + +(c) Copyright SCA Collaboration 2006, 2007 + +This product also includes software under the W3C(r) Software License +(see the LICENSE file contained in this distribution), with the following +copyright: + +Copyright (c) 2004 World Wide Web Consortium (Massachusetts Institute of Technology, +European Research Consortium for Informatics and Mathematics, Keio University). +All Rights Reserved. This work is distributed under the W3C(r) Software License [1] +in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied +warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/pom.xml new file mode 100644 index 0000000000..bfa6356ec1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-assembly-xsd + Apache Tuscany SCA Assembly Model XML Schemas + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.assembly.xsd + ${pom.name} + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema new file mode 100644 index 0000000000..69b2701e30 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +tuscany-sca.xsd \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-all.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-all.xsd new file mode 100644 index 0000000000..63e83884e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-all.xsd @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd new file mode 100644 index 0000000000..b6112f9750 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd new file mode 100644 index 0000000000..dc8c4c5bd6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd new file mode 100644 index 0000000000..02703402ef --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd new file mode 100644 index 0000000000..53e40f74b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-contributions.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-contributions.xsd new file mode 100644 index 0000000000..2da2fedb1f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-contributions.xsd @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-core.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-core.xsd new file mode 100644 index 0000000000..f03d0eab01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-core.xsd @@ -0,0 +1,348 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-definitions.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-definitions.xsd new file mode 100644 index 0000000000..0249882a92 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-definitions.xsd @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd new file mode 100644 index 0000000000..87b443fb36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd new file mode 100644 index 0000000000..99669bc672 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd new file mode 100644 index 0000000000..6f1cf14a4b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-ejb.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-ejb.xsd new file mode 100644 index 0000000000..a7e781b18f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-ejb.xsd @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd new file mode 100644 index 0000000000..f9d8171b8e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-jee.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-jee.xsd new file mode 100644 index 0000000000..a5a6220d83 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-jee.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd new file mode 100644 index 0000000000..1cf9fb3ea9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-web.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-web.xsd new file mode 100644 index 0000000000..a1adf10fd9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-implementation-web.xsd @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd new file mode 100644 index 0000000000..44f14e5ed5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd new file mode 100644 index 0000000000..81f939bdb4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd new file mode 100644 index 0000000000..c1fdfd8f3c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-policy.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-policy.xsd new file mode 100644 index 0000000000..2c4875f36c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca-policy.xsd @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca.xsd new file mode 100644 index 0000000000..b4eae28bfe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/sca.xsd @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-core.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-core.xsd new file mode 100644 index 0000000000..325c0c8a59 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-core.xsd @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd new file mode 100644 index 0000000000..d400810835 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-corba.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-corba.xsd new file mode 100644 index 0000000000..0baa364f42 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-corba.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd new file mode 100644 index 0000000000..788571de7b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-gdata.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-gdata.xsd new file mode 100644 index 0000000000..2096a014aa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-gdata.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd new file mode 100644 index 0000000000..b5a0d136be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jms.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jms.xsd new file mode 100644 index 0000000000..e5530105e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jms.xsd @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd new file mode 100644 index 0000000000..bacfdda781 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd new file mode 100644 index 0000000000..6d5468b2f9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd new file mode 100644 index 0000000000..dbef8fbed6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd new file mode 100644 index 0000000000..5af65aced2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-contributions.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-contributions.xsd new file mode 100644 index 0000000000..20385e7f2c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-contributions.xsd @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd new file mode 100644 index 0000000000..1b5c8aece2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd new file mode 100644 index 0000000000..f8d437310e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd new file mode 100644 index 0000000000..f8ece54a07 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd new file mode 100644 index 0000000000..dd596821ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd new file mode 100644 index 0000000000..e1723d65f0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-widget.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-widget.xsd new file mode 100644 index 0000000000..0c0998595f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-widget.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd new file mode 100644 index 0000000000..cdabb697aa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd new file mode 100644 index 0000000000..ba1d8811cc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/ws-addr.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/ws-addr.xsd new file mode 100644 index 0000000000..47362edbe2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/ws-addr.xsd @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/wsdli.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/wsdli.xsd new file mode 100644 index 0000000000..79af5e9363 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly-xsd/src/main/resources/wsdli.xsd @@ -0,0 +1,34 @@ + + + + + + + + + + This attribute can be used to provide some hints on where + additional WSDL information for a given namespace can be + found in order to help with QName resolution + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/pom.xml new file mode 100644 index 0000000000..ee630cd5d5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-assembly + Apache Tuscany SCA Assembly Model + + + + org.apache.tuscany.sca + tuscany-policy + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-definitions + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-monitor + 1.6-SNAPSHOT + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.assembly + ${pom.name} + org.apache.tuscany.sca.assembly* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java new file mode 100644 index 0000000000..b8487d95c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.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.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.policy.IntentAttachPoint; + +/** + * Interface contracts define one or more business functions. These business + * functions are provided by services and are used by references. + * + * @version $Rev$ $Date$ + */ +public interface AbstractContract extends Base, Extensible, IntentAttachPoint, OperationsConfigurator { + + /** + * Returns the name of the contract. + * + * @return the name of the contract + */ + String getName(); + + /** + * Sets the name of the contract. + * + * @param name the name of the contract + */ + void setName(String name); + + /** + * Returns the interface contract defining the interface and callback + * interface for the contract. + * + * @return the interface contract + */ + InterfaceContract getInterfaceContract(); + + /** + * Sets the interface contract defining the interface and callback + * interface for the contract. + * + * @param interfaceContract the interface contract + */ + void setInterfaceContract(InterfaceContract interfaceContract); + + /** + * Returns true if this contract is a reference or service created internally + * to handle a callback interface of another contract, false otherwise. + * + * @return true for a callback contract, false otherwise + */ + boolean isCallback(); + + /** + * Sets a flag indicating whether this is a callback contract. + * + * @param isCallback true for a callback contract, false otherwise + */ + void setIsCallback(boolean isCallback); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java new file mode 100644 index 0000000000..05f0e60981 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.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.sca.assembly; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; + +/** + * A property allows for the configuration of an implementation with externally + * set data values. An implementation can have zero or more properties. Each + * property has a data type, which may be either simple or complex. An + * implementation may also define a default value for a property. + * + * @version $Rev$ $Date$ + */ +public interface AbstractProperty extends Base, Extensible, IntentAttachPoint { + + /** + * Returns the property name. + * + * @return the property name + */ + String getName(); + + /** + * Sets the property name. + * + * @param name the property name + */ + void setName(String name); + + /** + * Returns the default value of the property. + * + * @return the default value of this property + */ + Object getValue(); + + /** + * Sets the default value of the property. + * + * @param defaultValue the default value of this property + */ + void setValue(Object defaultValue); + + /** + * Returns true if the property allows multiple values. + * + * @return true if the property allows multiple values + */ + boolean isMany(); + + /** + * Sets whether or not the property allows multiple values. + * + * @param many true if the property should allow multiple values + */ + void setMany(boolean many); + + /** + * Returns true if a value must be supplied for the property. + * + * @return true is a value must be supplied for the property + */ + boolean isMustSupply(); + + /** + * Sets whether a value must be supplied for the property. + * + * @param mustSupply set to true to require that a value be supplied for + * uses of this property + */ + void setMustSupply(boolean mustSupply); + + /** + * Returns the data type of this property. This is the qualified name of an + * XML schema type. + * + * @return the type of this property + */ + QName getXSDType(); + + /** + * Sets the data type of this property. This is the qualified name of an XML + * schema type. + * + * @param type the type of this property + */ + void setXSDType(QName type); + + /** + * Returns the element defining the data type of this property. This is the + * qualified name of an XML schema element. + * + * @return the element defining the type of this property + */ + QName getXSDElement(); + + /** + * Sets the element defining the data type of this property. This is the + * qualified name of an XML schema element. + * + * @param element the element defining the type of this property + */ + void setXSDElement(QName element); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java new file mode 100644 index 0000000000..a9ef26bbb9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.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.sca.assembly; + +/** + * Represents a reference contract. + * + * @version $Rev$ $Date$ + */ +public interface AbstractReference extends AbstractContract { + + /** + * Returns the multiplicity allowed for wires connected to this reference. + * + * @return the multiplicity allowed for wires connected to this reference + */ + Multiplicity getMultiplicity(); + + /** + * Sets the multiplicity allowed for wires connected to this reference. + * + * @param multiplicity the multiplicity allowed for wires connected to this + * reference + */ + void setMultiplicity(Multiplicity multiplicity); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java new file mode 100644 index 0000000000..9ae511c07b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.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.sca.assembly; + +/** + * Represents a service contract. + * + * @version $Rev$ $Date$ + */ +public interface AbstractService extends AbstractContract { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java new file mode 100644 index 0000000000..8a4fc6dfda --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + + +/** + * A factory for the assembly model + * + * @version $Rev$ $Date$ + */ +public interface AssemblyFactory { + + /** + * Create a new abstract property. + * + * @return a new abstract property + */ + AbstractProperty createAbstractProperty(); + + /** + * Create a new abstract reference. + * + * @return a new abstract reference + */ + AbstractReference createAbstractReference(); + + /** + * Create a new abstract service. + * + * @return a new abstract service + */ + AbstractService createAbstractService(); + + /** + * Create a new callback. + * + * @return + */ + Callback createCallback(); + + /** + * Create a new component. + * + * @return a new component + */ + Component createComponent(); + + /** + * Create a new component property. + * + * @return a new component property + */ + ComponentProperty createComponentProperty(); + + /** + * Create a new component reference. + * + * @return a new component reference + */ + ComponentReference createComponentReference(); + + /** + * Create a new component service. + * + * @return a new component service + */ + ComponentService createComponentService(); + + /** + * Create a new component type + * + * @return a new component type + */ + ComponentType createComponentType(); + + /** + * Create a new composite. + * + * @return a new composite + */ + Composite createComposite(); + + /** + * Create a new composite reference. + * + * @return a new composite reference + */ + CompositeReference createCompositeReference(); + + /** + * Create a new composite service. + * + * @return a new composite service + */ + CompositeService createCompositeService(); + + /** + * Create a new constraining type. + * + * @return a new constraining type + */ + ConstrainingType createConstrainingType(); + + /** + * Create a new property. + * + * @return a new property + */ + Property createProperty(); + + /** + * Create a new reference. + * + * @return a new reference + */ + Reference createReference(); + + /** + * Create a new service. + * + * @return a new service + */ + Service createService(); + + /** + * Create a new wire. + * + * @return a new wire + */ + Wire createWire(); + + /** + * Create a new configured operation. + * + * @return a new ConfiguredOperation + */ + ConfiguredOperation createConfiguredOperation(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java new file mode 100644 index 0000000000..76511d351d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.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.sca.assembly; + + +/** + * Base interface for all assembly model objects. + * + * @version $Rev$ $Date$ + */ +public interface Base { + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java new file mode 100644 index 0000000000..f8b7d4d236 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.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.sca.assembly; + + +/** + * Represents a binding. + * + * @version $Rev$ $Date$ + */ +public interface Binding extends Base, Cloneable { + + /** + * Returns the binding URI. + * + * @return the binding URI + */ + String getURI(); + + /** + * Sets the binding URI. + * + * @param uri the binding URI + */ + void setURI(String uri); + + /** + * Returns the binding name. + * + * @return the binding name + */ + String getName(); + + /** + * Sets the binding name. + * + * @param name the binding name + */ + void setName(String name); + + /** + * Clone the binding + * + * @return + */ + Object clone() throws CloneNotSupportedException; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/BindingRRB.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/BindingRRB.java new file mode 100644 index 0000000000..31ff43b5ed --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/BindingRRB.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.sca.assembly; + + +/** + * Represents a binding implemented using Request/Response binding chains + * + * @version $Rev$ $Date$ + */ +public interface BindingRRB extends Binding { + + public WireFormat getRequestWireFormat(); + + public void setRequestWireFormat(WireFormat wireFormat); + + public WireFormat getResponseWireFormat(); + + public void setResponseWireFormat(WireFormat wireFormat); + + public OperationSelector getOperationSelector(); + + public void setOperationSelector(OperationSelector operationSelector); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java new file mode 100644 index 0000000000..f49a653aa9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.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.sca.assembly; + +import java.util.List; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents a callback object describing the bindings to use for callbacks. + * + * @version $Rev$ $Date$ + */ +public interface Callback extends Base, Extensible, IntentAttachPoint, PolicySetAttachPoint, OperationsConfigurator { + + /** + * Returns the bindings supported for callbacks. + * + * @return the bindings supported for callbacks + */ + List getBindings(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java new file mode 100644 index 0000000000..8e1943224c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.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.sca.assembly; + +import java.util.List; + +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents a component. A component is a configured instance of an + * implementation. + * + * @version $Rev$ $Date$ + */ +public interface Component extends Base, Extensible, PolicySetAttachPoint, Cloneable { + + /** + * Returns the URI of the component. + * + * @return the URI of the component + */ + String getURI(); + + /** + * Sets the URI of the component. + * + * @param uri the URI of the component + */ + void setURI(String uri); + + /** + * Returns the name of the component. + * + * @return the name of the component + */ + String getName(); + + /** + * Sets the name of the component. + * + * @param name the name of the component + */ + void setName(String name); + + /** + * Returns the component implementation. + * + * @return the component implementation + */ + Implementation getImplementation(); + + /** + * Sets the component implementation + * + * @param implementation the component implementation + */ + void setImplementation(Implementation implementation); + + /** + * Returns a list of references used by the component. + * + * @return a list of references used by the component + */ + List getReferences(); + + /** + * Returns a list of services exposed by the component. + * + * @return a list of services exposed by the component + */ + List getServices(); + + /** + * Returns a list of properties for the component. + * + * @return a list of properties + */ + List getProperties(); + + /** + * Returns a constraining type defining the shape of the component. + * + * @return a constraining type + */ + ConstrainingType getConstrainingType(); + + /** + * Sets a constraining type defining the shape of the component. + * + * @param constrainingType the constraining type + */ + void setConstrainingType(ConstrainingType constrainingType); + + /** + * Return the Boolean value of autowire + * @return null/TRUE/FALSE + */ + Boolean getAutowire(); + + /** + * Sets whether component references should be autowired. + * + * @param autowire whether component references should be autowired + */ + void setAutowire(Boolean autowire); + + + /** + * Returns a clone of the component. + * + * @return a clone of the component + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java new file mode 100644 index 0000000000..13d19b1757 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import javax.xml.xpath.XPathExpression; + +/** + * Represents a configured property of a component. + * + * @version $Rev$ $Date$ + */ +public interface ComponentProperty extends Property { + + /** + * Returns the property defined by the component implementation. + * + * @return the property defined by the component implementation + */ + Property getProperty(); + + /** + * Sets the property defined by this component implementation. + * + * @param property the property defined by this component implementation + */ + void setProperty(Property property); + + /** + * Returns an XPath expression referencing a property of the enclosing + * composite. + * + * @return an XPath expression referencing a property of the enclosing + * composite + */ + String getSource(); + + /** + * Sets an XPath expression referencing a property of the enclosing + * composite. + * + * @param source an XPath expression referencing a property of the enclosing + * composite + */ + void setSource(String source); + + /** + * Get the XPath expression for the source attribute + * @return the XPath expression for the source attribute + */ + XPathExpression getSourceXPathExpression(); + + /** + * Set the XPath expression for the source attribute + * @param sourceXPathExpression the XPath expression for the source attribute + */ + void setSourceXPathExpression(XPathExpression sourceXPathExpression); + + /** + * Returns a URI to a file containing the property value. + * + * @return a URI to a file containing the property value + */ + String getFile(); + + /** + * Sets a URI to a file containing the property value. + * + * @param file a URI to a file containing the property value + */ + void setFile(String file); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java new file mode 100644 index 0000000000..ce40bc089b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.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.sca.assembly; + +import java.util.List; + + + +/** + * An instance of a reference associated with a particular component. + * + * @version $Rev$ $Date$ + */ +public interface ComponentReference extends Reference { + + /** + * Returns the reference defined by the implementation for this reference. + * + * @return the implementation reference + */ + Reference getReference(); + + /** + * Sets the reference defined by the implementation for this reference. + * + * @param reference the implementation reference + */ + void setReference(Reference reference); + + /** + * Return the Boolean value of autowire + * @return null/TRUE/FALSE + */ + Boolean getAutowire(); + + /** + * Sets whether component references should be autowired. + * + * @param autowire whether component references should be autowired + */ + void setAutowire(Boolean autowire); + + + /** + * Returns the callback service created internally as a target endpoint + * for callbacks to this reference. + * + * @return the callback service + */ + ComponentService getCallbackService(); + + /** + * Sets the callback service created internally as a target endpoint + * for callbacks to this reference. + * + * @param callbackService the callback service + */ + void setCallbackService(ComponentService callbackService); + + /** + * Returns the endpoints implied by this reference. + * + * @return the endpoints implied by this reference + */ + List getEndpoints(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java new file mode 100644 index 0000000000..65945692f1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.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.sca.assembly; + + +/** + * An addressable instance of a service associated with a particular component. + * + * @version $Rev$ $Date$ + */ +public interface ComponentService extends Service { + + /** + * Returns the service defined by the implementation for this service. + * + * @return + */ + Service getService(); + + /** + * Sets the service defined by the implementation for this service. + * + * @param service + */ + void setService(Service service); + + /** + * Returns the callback reference created internally as a source endpoint + * for callbacks from this service. + * + * @return the callback reference + */ + ComponentReference getCallbackReference(); + + /** + * Sets the callback reference created internally as a source endpoint + * for callbacks from this service. + * + * @param callbackReference the callback reference + */ + void setCallbackReference(ComponentReference callbackReference); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java new file mode 100644 index 0000000000..e1ea65ea39 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.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.sca.assembly; + +import java.util.List; + +/** + * Describes an implementation and represents its configurable aspects. + * + * @version $Rev$ $Date$ + */ +public interface ComponentType extends Base { + + /** + * Returns the URI of this component type. + * @return the URI of the component type + */ + String getURI(); + + /** + * Sets the URI of this component type. + * @param uri the URI of the component type + */ + void setURI(String uri); + + /** + * Returns a list of services that are offered. + * + * @return a list of services that are offered + */ + List getServices(); + + /** + * Returns the list of reference types that are used. + * + * @return the list of reference types that are used + */ + List getReferences(); + + /** + * Returns the list of properties that can be set. + * + * @return the list of properties that can be set + */ + List getProperties(); + + /** + * Returns a constraining type defining the shape of the implementation. + * + * @return a constraining type + */ + ConstrainingType getConstrainingType(); + + /** + * Sets a constraining type defining the shape of the implementation. + * + * @param constrainingType the constraining type to set + */ + void setConstrainingType(ConstrainingType constrainingType); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java new file mode 100644 index 0000000000..2c7b7c6b9e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.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.sca.assembly; + +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + + +/** + * Represents a composite. + * + * @version $Rev$ $Date$ + */ +public interface Composite extends Implementation, Extensible, Cloneable, PolicySetAttachPoint { + + /** + * Returns the name of the composite. + * + * @return the name of the composite + */ + QName getName(); + + /** + * Sets the name of the composite. + * + * @param name the name of the composite + */ + void setName(QName name); + + /** + * Returns a list of composites included in this composite. + * + * @return a list of composites included in this composite. + */ + List getIncludes(); + + /** + * Returns a list of components contained in this composite. + * + * @return a list of components contained in this composite + */ + List getComponents(); + + /** + * Returns a list of wires contained in this composite. + * + * @return a list of wires contained in this composite + */ + List getWires(); + + /** + * Returns true if all the components within the composite must run in the + * same process. + * + * @return true if all the components within the composite must run in the + * same process + */ + boolean isLocal(); + + /** + * Sets whether all the components within the composite must run in the same + * process. + * + * @param local whether all the components within the composite must run in + * the same process + */ + void setLocal(boolean local); + + /** + * Return the Boolean value of autowire + * @return null/TRUE/FALSE + */ + Boolean getAutowire(); + + /** + * Sets whether component references should be autowired. + * + * @param autowire whether component references should be autowired + */ + void setAutowire(Boolean autowire); + + + /** + * Returns a clone of the component type. + * + * @return a clone of the component type + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java new file mode 100644 index 0000000000..d3fa80ba74 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.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.sca.assembly; + +import java.util.List; + +/** + * Represents composite reference. + * + * @version $Rev$ $Date$ + */ +public interface CompositeReference extends Reference { + + /** + * Returns the promoted composite references. + * + * @return the promoted composite references + */ + List getPromotedReferences(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java new file mode 100644 index 0000000000..7143f571f9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.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.sca.assembly; + +/** + * Represents a composite service. + * + * @version $Rev$ $Date$ + */ +public interface CompositeService extends Service { + + /** + * Returns the promoted component. + * + * @return the promoted component. + */ + Component getPromotedComponent(); + + /** + * Sets the promoted component + * + * @param promotedComponent the promoted component. + */ + void setPromotedComponent(Component promotedComponent); + + /** + * Returns the promoted component service . + * + * @return the promoted component service. + */ + ComponentService getPromotedService(); + + /** + * Sets the promoted component service + * + * @param promotedService the promoted component service. + */ + void setPromotedService(ComponentService promotedService); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConfiguredOperation.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConfiguredOperation.java new file mode 100644 index 0000000000..70e873ecf0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConfiguredOperation.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents an Operation. Typically Operation elements are used when there is a + * need to apply certain facets such as intents and policysets only to a specific + * operation provided by a service or reference. + * + * @version $Rev$ $Date$ + */ +public interface ConfiguredOperation extends Base, Cloneable, PolicySetAttachPoint { + /** + * Returns the name of the operation. + * + * @return the name of the operation + */ + String getName(); + + /** + * Sets the name of the operation. + * + * @param name the name of the operation + */ + void setName(String name); + + /** + * Returns the name of the service or reference to which this operation belongs. + * This method is particularly useful when operation elements are specified under implementation + * elements and it is necessary to identify which of the various services provided by the + * implementation is referred to by the operation element in question + * + * @return the name of the contract to which this operation belongs + */ + String getContractName(); + + /** + * Sets the name of the service or reference to which this operation belongs. + * + * @param contractName the name of the contract to which this operation belongs + */ + void setContractName(String contractName); + + /** + * Sets a list of policy sets. + * + * @param policySets + */ + public void setPolicySets(List policySets); + + /** + * Sets a list of required intents. + * + * @param intents + */ + public void setRequiredIntents(List intents); + + /** + * Clone the ConfiguredOperation + * + * @return + */ + Object clone() throws CloneNotSupportedException; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java new file mode 100644 index 0000000000..9890bfed68 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.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.sca.assembly; + +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; + +/** + * A constrainingType provides the "shape" for a component and its + * implementation. Any component configuration that points to a constrainingType + * is constrained by this shape. The constrainingType specifies the services, + * references and properties that must be implemented. + * + * @version $Rev$ $Date$ + */ +public interface ConstrainingType extends Base, Extensible, IntentAttachPoint { + + /** + * Returns the name of the constrainingType. + * + * @return the name of the constrainingType + */ + QName getName(); + + /** + * Sets the name of the constrainingType. + * + * @param name the name of the constrainingType + */ + void setName(QName name); + + /** + * Returns a list of services that are offered. + * + * @return a list of services that are offered + */ + List getServices(); + + /** + * Returns the list of references that are used. + * + * @return the list of references that are used + */ + List getReferences(); + + /** + * Returns the list of properties that can be set. + * + * @return the list of properties that can be set + */ + List getProperties(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java new file mode 100644 index 0000000000..f9a62774e6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents a contract. A contract can be either a service or a reference. + * + * @version $Rev$ $Date$ + */ +public interface Contract extends AbstractContract, PolicySetAttachPoint, Cloneable { + + /** + * Returns the bindings supported by this contract. + * + * @return the bindings supported by this contract + */ + List getBindings(); + + /** + * Returns a binding of the specified type or null if there is no such + * binding configured on this contract. + * + * @param the binding type + * @param bindingClass the binding type class + * @return the binding or null if there is no binding of the specified type + */ + B getBinding(Class bindingClass); + + /** + * Returns a callback binding of the specified type or null if there is no such + * callback binding configured on this contract. + * + * @param the callback binding type + * @param bindingClass the callback binding type class + * @return the callback binding or null if there is no callback binding of the specified type + */ + B getCallbackBinding(Class bindingClass); + + /** + * Returns a callback definition of the bindings to use for callbacks. + * + * @return a definition of the bindings to use for callbacks + */ + Callback getCallback(); + + /** + * Sets a callback definition of the bindings to use for callbacks + * + * @param callback a definition of the bindings to use for callbacks + */ + void setCallback(Callback callback); + + /** + * Returns a clone of the contract. + * + * @return a clone of the reference + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + + /** + * Returns the interface contract given a binding. Important in the case where + * a reference with multiplicity > 1 has been promoted and has it's list of + * resolved bindings extended by a promoting reference. Here the binding + * from the promoting reference may need the interface contract from the + * promoting reference and not the promoted reference. + * TODO - remove this wrinkle with better endpoint support. + * + * @param binding the binding for which the interface contract is required + * @return the interface contract + */ + InterfaceContract getInterfaceContract(Binding binding); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java new file mode 100644 index 0000000000..5dd256e3c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.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.sca.assembly; + +import org.apache.tuscany.sca.assembly.impl.AssemblyFactoryImpl; + +/** + * A factory for the assembly model. + * + * @version $Rev$ $Date$ + */ +public class DefaultAssemblyFactory extends AssemblyFactoryImpl implements AssemblyFactory { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.java new file mode 100644 index 0000000000..6b0c076ee5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.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.sca.assembly; + + +import org.apache.tuscany.sca.assembly.impl.EndpointFactoryImpl; + +/** + * A default factory for the Endpoint model. + * + * @version $Rev$ $Date$ + */ +public class DefaultEndpointFactory extends EndpointFactoryImpl { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.java new file mode 100644 index 0000000000..2ed02e214b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultExtensionFactory.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.sca.assembly; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.ExtensionImpl; + +public class DefaultExtensionFactory implements ExtensionFactory { + + public Extension createExtension() { + return new ExtensionImpl(); + } + + public Extension createExtension(QName name, Object value, boolean isAttribute) { + return new ExtensionImpl(name, value, isAttribute); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefinitionElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefinitionElement.java new file mode 100644 index 0000000000..366a736ad8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefinitionElement.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.sca.assembly; + +/** + * Contains information inherited from an SCA definitions document. + * + * @version $Rev$ $Date$ + */ +public interface DefinitionElement { + /** + * Returns the target namespace inherited from an SCA definition document + * @return the namespace + */ + String getTargetNamespace(); + + /** + * Sets the target namespace inherited from an SCA definition document + * + * @param ns the target namespace for this SCA Definition + */ + void setTargetNamespace(String ns); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java new file mode 100644 index 0000000000..ee63497fbe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +/** + * Represents an endpoint (primarily a combination of a target service name and a set of + * candidate bindings) + * + * @version $Rev$ $Date$ + */ +public interface Endpoint extends Base, Cloneable { + + /** + * Get the name of the target service that this endpoint refers to + * + * @return target service name + */ + String getTargetName(); + + /** + * Set the name of the target service that this endpoint refers to + * + * @param targetName + */ + void setTargetName(String targetName); + + /** + * Get the source component model object + * + * @return source component + */ + Component getSourceComponent(); + + /** + * Set the source component model object + * + * @param component the source component for the endpoint + */ + void setSourceComponent(Component component); + + /** + * Get the source component reference model object + * + * @return reference the source component reference for the endpoint + */ + ComponentReference getSourceComponentReference(); + + /** + * Set the source component reference model object + * + * @param reference + */ + void setSourceComponentReference(ComponentReference reference); + + /** + * Get the resolved source binding + * + * @return binding the resolved source binding + */ + Binding getSourceBinding(); + + /** + * Set the resolved source binding + * + * @param binding the resolved source binding + */ + void setSourceBinding(Binding binding); + + /** + * Get the resolved source callback binding + * + * @return binding the resolved source callback binding + */ + Binding getSourceCallbackBinding(); + + /** + * Set the resolved source callback binding + * + * @param binding the resolved source callback binding + */ + void setSourceCallbackBinding(Binding binding); + + /** + * Get the list of candidate bindings that could be used to + * communication with the target service + * + * @return list of candidate bindings + */ + List getCandidateBindings(); + + + /** + * Get the target component model object + * + * @return target component + */ + Component getTargetComponent(); + + /** + * Set the target component model object + * + * @param component target component + */ + void setTargetComponent(Component component); + + /** + * Get the target component service model object + * + * @return target component service + */ + ComponentService getTargetComponentService(); + + /** + * Set the target component service model object + * + * @param service + */ + void setTargetComponentService(ComponentService service); + + /** + * Get the resolved target binding + * + * @return target binding + */ + Binding getTargetBinding(); + + /** + * Set the resolved target binding + * + * @param binding target binding + */ + void setTargetBinding(Binding binding); + + /** + * Returns the interface contract defining the interface + * + * @return the interface contract + */ + InterfaceContract getInterfaceContract(); + + /** + * Sets the interface contract defining the interface + * + * @param interfaceContract the interface contract + */ + void setInterfaceContract(InterfaceContract interfaceContract); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.java new file mode 100644 index 0000000000..93e6c4d630 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.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.sca.assembly; + + + +/** + * A factory for the endpoint model + * + * @version $Rev$ $Date$ + */ +public interface EndpointFactory { + + /** + * Create a new endpoint model object + * + * @return a new endpoint + */ + Endpoint createEndpoint(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java new file mode 100644 index 0000000000..593b7de88b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.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.sca.assembly; + +import java.util.List; + +/** + * Base interface for extensible assembly model objects. + * + * @version $Rev$ $Date$ + */ +public interface Extensible { + + /** + * Returns a list of extension objects contained in this model object. + * + * @return a list of extension objects container in this model object + */ + List getExtensions(); + + /** + * Returns a list of attribute extensions contained in this model object + * + * @return a list of attribute extensions contained in this model object + */ + List getAttributeExtensions(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.java new file mode 100644 index 0000000000..499c97c278 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extension.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.sca.assembly; + +import javax.xml.namespace.QName; + +/** + * Base interface for storing contents of extensible assembly model objects. + * + * @version $Rev$ $Date$ + */ +public interface Extension { + + /** + * Return QName for the extension + * @return the extension QName + */ + QName getQName(); + + /** + * Set QName for the extension + * @param qName the extension QName + */ + void setQName(QName qName); + + /** + * Return the original extension value + * @return the extension value + */ + Object getValue(); + + /** + * Set the original extension value + * @param value the extension value + */ + void setValue(Object value); + + /** + * Return whether or not the extension is an attribute + * @return + */ + boolean isAttribute(); + + /** + * Set whether or not the extension is an attribute + * @param value + */ + void setIsAttribute(boolean isAttribute); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.java new file mode 100644 index 0000000000..214cf59748 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ExtensionFactory.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.sca.assembly; + +import javax.xml.namespace.QName; + +public interface ExtensionFactory { + + Extension createExtension(); + + Extension createExtension(QName qName, Object value, boolean isAttribute); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java new file mode 100644 index 0000000000..720a6801a2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.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.sca.assembly; + +/** + * Represents a component implementation. + * + * @version $Rev$ $Date$ + */ +public interface Implementation extends ComponentType { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java new file mode 100644 index 0000000000..5d15ce9938 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.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.sca.assembly; + +/** + * Enumeration for multiplicity. Defines the number of wires that can connect a + * reference to target services. + * + * @version $Rev$ $Date$ + */ +public enum Multiplicity { + + /** + * Zero or one wire can have the reference as a source. + */ + ZERO_ONE, + + /** + * The default setting, one wire can have the reference as a source. + */ + ONE_ONE, + + /** + * Zero or more wires can have the reference as a source. + */ + ZERO_N, + + /** + * One or more wires can have the reference as a source. + */ + ONE_N + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationSelector.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationSelector.java new file mode 100644 index 0000000000..6770e87ee1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationSelector.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.sca.assembly; + + +/** + * Represents an operationSelector + * + * @version $Rev$ $Date$ + */ +public interface OperationSelector extends Base, Cloneable { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java new file mode 100644 index 0000000000..947fcd4c7c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.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.sca.assembly; + +import java.util.List; + +/** + * Interface to be implemented by SCA artifacts that support configuration of 'operation' child + * elements for policies etc. + * + * @version $Rev$ $Date$ + */ + +public interface OperationsConfigurator { + List getConfiguredOperations(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.java new file mode 100644 index 0000000000..98ff92f15b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.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.sca.assembly; + +/** + * Represent a reference binding that supports optimized SCA local wiring between component + * references and services + * + * @version $Rev$ $Date$ + * + */ +public interface OptimizableBinding extends Binding, Cloneable { + + /** + * @param component + */ + void setTargetComponent(Component component); + + /** + * @param service + */ + void setTargetComponentService(ComponentService service); + + /** + * @param binding + */ + void setTargetBinding(Binding binding); + + /** + * @return + */ + Binding getTargetBinding(); + + /** + * @return + */ + Component getTargetComponent(); + + /** + * @return + */ + ComponentService getTargetComponentService(); + + /** + * Clone the binding + * @return + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java new file mode 100644 index 0000000000..683920da58 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.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.sca.assembly; + +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * A property allows for the configuration of an implementation with externally + * set data values. An implementation can have zero or more properties. Each + * property has a data type, which may be either simple or complex. An + * implementation may also define a default value for a property. + * + * @version $Rev$ $Date$ + */ +public interface Property extends AbstractProperty, PolicySetAttachPoint, Cloneable { + + /** + * Returns a clone of the property. + * + * @return a clone of the property + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java new file mode 100644 index 0000000000..2eb1bf21b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.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.sca.assembly; + +import java.util.List; + +/** + * Represents a reference. References within an implementation represent links + * to services that the implementation uses that must be provided by other + * components. + * + * @version $Rev$ $Date$ + */ +public interface Reference extends AbstractReference, Contract { + + /** + * Returns a boolean value, "false" by default, which indicates that the + * implementation wires this reference dynamically. + * + * @return true if the implementation wires this reference dynamically + */ + boolean isWiredByImpl(); + + /** + * Sets a boolean value, "false" by default, which indicates that the + * implementation wires this reference dynamically. + * + * @param wiredByImpl whether the implementation wires this reference + * dynamically + */ + void setWiredByImpl(boolean wiredByImpl); + + /** + * Returns a boolean value, "false" by default, which indicates whether + * the configuration of this reference is a promotion override for + * another more deeply nested reference. + * + * @return true if the reference is a promotion override + */ + boolean isPromotionOverride(); + + /** + * Sets a boolean value, "false" by default, which indicates whether + * the configuration of this reference is a promotion override for + * another more deeply nested reference. + * + * @param promotionOverride whether the reference is a promotion override + */ + void setPromotionOverride(boolean promotionOverride); + + /** + * Returns the targets of this reference. + * + * @return the targets of this reference. + */ + List getTargets(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java new file mode 100644 index 0000000000..5afafcbae0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.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.sca.assembly; + +/** + * Represents an SCA binding. + * + * @version $Rev$ $Date$ + */ +public interface SCABinding extends Binding, Extensible { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java new file mode 100644 index 0000000000..0abfd13d10 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.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.sca.assembly; + + +/** + * A factory for the SCA binding model + * + * @version $Rev$ $Date$ + */ +public interface SCABindingFactory { + + /** + * Create a new SCA binding. + * + * @return a new SCA binding + */ + SCABinding createSCABinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java new file mode 100644 index 0000000000..020870cd34 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.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.sca.assembly; + +/** + * Represents a service. Services are used to publish services provided by + * implementations, so that they are addressable by other components. + * + * @version $Rev$ $Date$ + */ +public interface Service extends AbstractService, Contract { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java new file mode 100644 index 0000000000..ee65e5746e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.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.sca.assembly; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents a wire. + * + * @version $Rev$ $Date$ + */ +public interface Wire extends Base, Extensible, IntentAttachPoint, PolicySetAttachPoint, Cloneable { + + /** + * Returns the source of the wire. + * + * @return the source of the wire + */ + ComponentReference getSource(); + + /** + * Sets the source of the wire. + * + * @param source the source of the wire + */ + void setSource(ComponentReference source); + + /** + * Returns the target of the wire. + * + * @return the target of the wire + */ + ComponentService getTarget(); + + /** + * Sets the target of the wire. + * + * @param target the target of the wire + */ + void setTarget(ComponentService target); + + /** + * Returns a clone of the wire. + * + * @return a clone of the wire + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/WireFormat.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/WireFormat.java new file mode 100644 index 0000000000..d8c530585e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/WireFormat.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.sca.assembly; + + +/** + * Represents a wireFormat. + * + * @version $Rev$ $Date$ + */ +public interface WireFormat extends Base, Cloneable { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/AutomaticBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/AutomaticBinding.java new file mode 100644 index 0000000000..97708f9ef5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/AutomaticBinding.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.sca.assembly.builder; + +/** + * Represent a binding that has been added automatically to the model rather + * than being specified by the user through the composite file + * + * @version $Rev$ $Date$ + * + */ +public interface AutomaticBinding extends Cloneable { + + /** + * @param isAutomatic + */ + void setIsAutomatic(boolean isAutomatic); + + /** + * @return isAutomatic + */ + boolean getIsAutomatic(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java new file mode 100644 index 0000000000..7bac630d5b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.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.sca.assembly.builder; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A builder that handles any build-time configuration needed by bindings. + * + * @version $Rev$ $Date$ + */ +public interface BindingBuilder { + + /** + * Configure a binding. + * + * @param component The component for the binding's service or reference + * @param contract The binding's service or reference + */ + void build(Component component, AbstractContract contract, Binding binding, Monitor monitor); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.java new file mode 100644 index 0000000000..37ad8af0b3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.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.sca.assembly.builder; + +/** + * An extension that can be implemented by bindings to provide a binding builder. + * + * @version $Rev$ $Date$ + */ +public interface BindingBuilderExtension { + + /** + * Returns the binding builder. + * + * @return the binding builder + */ + BindingBuilder getBuilder(); + + /** + * Sets the binding builder. + * + * @param builder the binding builder + */ + void setBuilder(BindingBuilder builder); + +} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java new file mode 100644 index 0000000000..d2fae4d24a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.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.sca.assembly.builder; + +import org.apache.tuscany.sca.assembly.Component; + +/** + * Interface for Component Pre Processors. + * + * @version $Rev$ $Date$ + */ +public interface ComponentPreProcessor { + + void preProcess(Component component); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java new file mode 100644 index 0000000000..cf38894702 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.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.sca.assembly.builder; + +import org.apache.tuscany.sca.assembly.Composite; + +/** + * A builder that handles the configuration of the components inside a + * composite and the wiring of component references to component services. + * + * @version $Rev$ $Date$ + */ +public interface CompositeBuilder { + + /** + * Build a composite. + * + * @param composite + * @throws CompositeBuilderException + */ + void build(Composite composite) throws CompositeBuilderException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java new file mode 100644 index 0000000000..5a2015f55e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.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.sca.assembly.builder; + +/** + * Reports a composite builder exception. + * + * @version $Rev$ $Date$ + */ +public class CompositeBuilderException extends Exception { + private static final long serialVersionUID = -8916323176803443856L; + + public CompositeBuilderException() { + } + + public CompositeBuilderException(String message) { + super(message); + } + + public CompositeBuilderException(Throwable cause) { + super(cause); + } + + public CompositeBuilderException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.java new file mode 100644 index 0000000000..13bfbbbeff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.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.sca.assembly.builder; + +import java.util.Map; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.builder.impl.EndpointBuilderImpl; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A default builder. + * + * @version $Rev$ $Date$ + */ +public class DefaultEndpointBuilder extends EndpointBuilderImpl { + public DefaultEndpointBuilder (Monitor monitor, Map bindingMap){ + super(monitor, bindingMap); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DomainBuilder.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DomainBuilder.java new file mode 100644 index 0000000000..20a17e1bd0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DomainBuilder.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.sca.assembly.builder; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Service; + +/** + * A builder that handles the configuration of the components inside a + * composite and the wiring of component references to component services. + * + * @version $Rev: 563358 $ $Date: 2007-08-07 01:26:27 +0100 (Tue, 07 Aug 2007) $ + */ +public interface DomainBuilder { + + /** + * Wire up the references and service in a domain returning a list + * of the composites that have changed + * + * @param domainLevelCompsite + * @return a list of change composites + * @throws CompositeBuilderException + */ + List wireDomain(Composite domainLevelComposite); + + /** + * Locates the referenced service and updates the URI on the identified binding + * + * @param domainLevelComposite + * @param referenceName + * @param bindingClassName + * @param URI + */ + void updateDomainLevelServiceURI(Composite domainLevelComposite, String referenceName, String bindingClassName, String URI); + + /** + * Get the component name out of the reference name that might look like Component/Service + * + * @param referenceName + * @return + */ + String getComponentNameFromReference(String referenceName); + + /** + * Get the service name out of the reference name that might look like Component/Service + * + * @param referenceName + * @return + */ + String getServiceNameFromReference(String referenceName); + + /** + * Find the service object given a reference name + * + * @param composite + * @param referenceName + * @return + */ + Service findServiceForReference(Composite composite, String referenceName); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.java new file mode 100644 index 0000000000..eb2977d87a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.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.sca.assembly.builder; + +import org.apache.tuscany.sca.assembly.Endpoint; + +/** + * A builder that handles the configuration of reference endpoints + * It collects together the logic so that it can be used at build time + * or later on during late binding scenarios + * + * @version $Rev$ $Date$ + */ +public interface EndpointBuilder { + + /** + * Build an endpoint. + * + * @param endpoint + */ + void build(Endpoint endpoint); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java new file mode 100644 index 0000000000..5e984c3126 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java @@ -0,0 +1,1515 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.AutomaticBinding; +import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.IntentAttachPointType; + +/** + * Base class for Builder implementations that handles configuration. + * + * @version $Rev$ $Date$ + */ +public abstract class BaseConfigurationBuilderImpl { + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + private static final String BINDING_SCA = "binding.sca"; + private static final QName BINDING_SCA_QNAME = new QName(SCA10_NS, BINDING_SCA); + + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private Monitor monitor; + private InterfaceContractMapper interfaceContractMapper; + private SCADefinitions policyDefinitions; + private DocumentBuilderFactory documentBuilderFactory; + private TransformerFactory transformerFactory; + private Map bindingMap; + + protected BaseConfigurationBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + this(assemblyFactory, scaBindingFactory, documentBuilderFactory, + transformerFactory, interfaceContractMapper, policyDefinitions, monitor, null); + } + + protected BaseConfigurationBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor, + Map bindingMap) { + this.assemblyFactory = assemblyFactory; + this.scaBindingFactory = scaBindingFactory; + this.documentBuilderFactory = documentBuilderFactory; + this.transformerFactory = transformerFactory; + this.interfaceContractMapper = interfaceContractMapper; + this.policyDefinitions = policyDefinitions; + this.monitor = monitor; + this.bindingMap = bindingMap; + } + + /** + * Configure components in the composite. + * + * @param composite + * @param problems + */ + protected void configureComponents(Composite composite) throws CompositeBuilderException { + configureComponents(composite, null); + configureSourcedProperties(composite, null); + //configureBindingURIs(composite, null, null); + } + + /** + * Configure components in the composite. + * + * @param composite + * @param uri + * @param problems + */ + private void configureComponents(Composite composite, String uri) { + String parentURI = uri; + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + + // Initialize component URI + String componentURI; + if (parentURI == null) { + componentURI = component.getName(); + } else { + componentURI = URI.create(parentURI + '/').resolve(component.getName()).toString(); + } + component.setURI(componentURI); + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // Process nested composite + configureComponents((Composite)implementation, componentURI); + } + } + + // Initialize service bindings + List compositeServices = composite.getServices(); + for (Service service : compositeServices) { + // Set default binding names + + // Create default SCA binding + if (service.getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + service.getBindings().add(scaBinding); + } +/* + // Initialize binding names and URIs + for (Binding binding : service.getBindings()) { + + // Binding name defaults to the service name + if (binding.getName() == null) { + binding.setName(service.getName()); + } + } + + if (service.getCallback() != null) { + for (Binding binding : service.getCallback().getBindings()) { + if (binding.getName() == null) { + binding.setName(service.getName()); + } + } + } +*/ + } + + // Initialize reference bindings + for (Reference reference : composite.getReferences()) { + // Create default SCA binding + if (reference.getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + reference.getBindings().add(scaBinding); + } +/* + // Set binding names + for (Binding binding : reference.getBindings()) { + if (binding.getName() == null) { + binding.setName(reference.getName()); + } + } + + if (reference.getCallback() != null) { + for (Binding binding : reference.getCallback().getBindings()) { + if (binding.getName() == null) { + binding.setName(reference.getName()); + } + } + } +*/ + } + + // Initialize all component services and references + Map components = new HashMap(); + for (Component component : composite.getComponents()) { + + // Index all components and check for duplicates + if (components.containsKey(component.getName())) { + error("DuplicateComponentName", component, composite.getName().toString(), component.getName()); + } else { + components.put(component.getName(), component); + } + + // Propagate the autowire flag from the composite to components + if (component.getAutowire() == null) { + component.setAutowire(composite.getAutowire()); + } + + if (component.getImplementation() instanceof ComponentPreProcessor) { + ((ComponentPreProcessor)component.getImplementation()).preProcess(component); + } + + // Index properties, services and references + Map services = new HashMap(); + Map references = new HashMap(); + Map properties = new HashMap(); + indexImplementationPropertiesServicesAndReferences(component, + services, + references, + properties); + + // Index component services, references and properties + // Also check for duplicates + Map componentServices = + new HashMap(); + Map componentReferences = + new HashMap(); + Map componentProperties = + new HashMap(); + indexComponentPropertiesServicesAndReferences(component, + componentServices, + componentReferences, + componentProperties); + + // Reconcile component services/references/properties and + // implementation services/references and create component + // services/references/properties for the services/references + // declared by the implementation + reconcileServices(component, services, componentServices); + reconcileReferences(component, references, componentReferences); + reconcileProperties(component, properties, componentProperties); + + // Configure or create callback services for component's references + // with callbacks + configureCallbackServices(component, componentServices); + + // Configure or create callback references for component's services + // with callbacks + configureCallbackReferences(component, componentReferences); + + // Create self references to the component's services +// if (!(component.getImplementation() instanceof Composite)) { +// createSelfReferences(component); +// } + + // Initialize service bindings + for (ComponentService componentService : component.getServices()) { + + // Create default SCA binding + if (componentService.getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + componentService.getBindings().add(scaBinding); + } +/* + // Set binding names + for (Binding binding : componentService.getBindings()) { + + // Binding name defaults to the service name + if (binding.getName() == null) { + binding.setName(componentService.getName()); + } + } + if (componentService.getCallback() != null) { + for (Binding binding : componentService.getCallback().getBindings()) { + if (binding.getName() == null) { + binding.setName(componentService.getName()); + } + } + } +*/ + } + + // Initialize reference bindings + for (ComponentReference componentReference : component.getReferences()) { + + // Create default SCA binding + if (componentReference.getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + componentReference.getBindings().add(scaBinding); + } +/* + // Set binding names + for (Binding binding : componentReference.getBindings()) { + if (binding.getName() == null) { + binding.setName(componentReference.getName()); + } + } + if (componentReference.getCallback() != null) { + for (Binding binding : componentReference.getCallback().getBindings()) { + if (binding.getName() == null) { + binding.setName(componentReference.getName()); + } + } + } +*/ + } + } + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void warning(String message, Object model, String... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, String... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Reconcile component properties and the properties defined by the + * component type. + * + * @param component + * @param properties + * @param componentProperties + * @param problems + */ + private void reconcileProperties(Component component, + Map properties, + Map componentProperties) { + + // Connect component properties to their properties + for (ComponentProperty componentProperty : component.getProperties()) { + Property property = properties.get(componentProperty.getName()); + if (property != null) { + componentProperty.setProperty(property); + } else { + warning("PropertyNotFound", component, component.getName(), componentProperty.getName()); + } + } + + // Create component properties for all properties + if (component.getImplementation() != null) { + for (Property property : component.getImplementation().getProperties()) { + if (!componentProperties.containsKey(property.getName())) { + ComponentProperty componentProperty = assemblyFactory.createComponentProperty(); + componentProperty.setName(property.getName()); + componentProperty.setMany(property.isMany()); + componentProperty.setXSDElement(property.getXSDElement()); + componentProperty.setXSDType(property.getXSDType()); + componentProperty.setProperty(property); + component.getProperties().add(componentProperty); + } + } + } + + // Reconcile component properties and their properties + for (ComponentProperty componentProperty : component.getProperties()) { + Property property = componentProperty.getProperty(); + if (property != null) { + + // Check that a component property does not override the + // mustSupply attribute + if (!property.isMustSupply() && componentProperty.isMustSupply()) { + warning("PropertyMustSupplyIncompatible", component, component.getName(), componentProperty.getName()); + } + + // Default to the mustSupply attribute specified on the property + if (!componentProperty.isMustSupply()) + componentProperty.setMustSupply(property.isMustSupply()); + + // Default to the value specified on the property + if (componentProperty.getValue() == null) { + componentProperty.setValue(property.getValue()); + } + + // Override the property value for the composite + if(component.getImplementation() instanceof Composite) { + property.setValue(componentProperty.getValue()); + } + + // Check that a value is supplied + if (componentProperty.getValue() == null && property.isMustSupply()) { + warning("PropertyMustSupplyNull", component, component.getName(), componentProperty.getName()); + } + + // Check that a a component property does not override the + // many attribute + if (!property.isMany() && componentProperty.isMany()) { + + warning("PropertyOverrideManyAttribute", component, component.getName(), componentProperty.getName()); + } + + // Default to the many attribute defined on the property + componentProperty.setMany(property.isMany()); + + // Default to the type and element defined on the property + if (componentProperty.getXSDType() == null) { + componentProperty.setXSDType(property.getXSDType()); + } + if (componentProperty.getXSDElement() == null) { + componentProperty.setXSDElement(property.getXSDElement()); + } + + // Check that a type or element are specified + if (componentProperty.getXSDElement() == null && componentProperty.getXSDType() == null) { + warning("NoTypeForComponentProperty", component, component.getName(), componentProperty.getName()); + } + } + } + } + + /** + * Reconcile component references with the references defined on the + * component type. + * + * @param component + * @param references + * @param componentReferences + * @param problems + */ + private void reconcileReferences(Component component, + Map references, + Map componentReferences) { + + // Connect each component reference to the corresponding reference + for (ComponentReference componentReference : component.getReferences()) { + if (componentReference.getReference() != null || componentReference.isCallback()) { + continue; + } + Reference reference = references.get(componentReference.getName()); + if (reference != null) { + componentReference.setReference(reference); + } else { + if (!componentReference.getName().startsWith("$self$.")) { + error("ReferenceNotFound", component, component.getName(), componentReference.getName()); + } + } + } + + // Create a component reference for each reference + if (component.getImplementation() != null) { + for (Reference reference : component.getImplementation().getReferences()) { + if (!componentReferences.containsKey(reference.getName())) { + ComponentReference componentReference = + assemblyFactory.createComponentReference(); + componentReference.setIsCallback(reference.isCallback()); + componentReference.setName(reference.getName()); + componentReference.setReference(reference); + component.getReferences().add(componentReference); + } + } + } + + // Reconcile each component reference with its reference + for (ComponentReference componentReference : component.getReferences()) { + Reference reference = componentReference.getReference(); + if (reference != null) { + // Reconcile multiplicity + if (componentReference.getMultiplicity() != null) { + if (!ReferenceConfigurationUtil.isValidMultiplicityOverride(reference.getMultiplicity(), + componentReference + .getMultiplicity())) { + warning("ReferenceIncompatibleMultiplicity", component, component.getName(), componentReference.getName()); + } + } else { + componentReference.setMultiplicity(reference.getMultiplicity()); + } + + // Reconcile interface + InterfaceContract interfaceContract = reference.getInterfaceContract(); + if (componentReference.getInterfaceContract() != null) { + if (interfaceContract != null && !componentReference.getInterfaceContract().equals(reference + .getInterfaceContract())) { + if (!interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), + interfaceContract)) { + warning("ReferenceIncompatibleComponentInterface", component, component.getName(), componentReference.getName()); + } + } + } else { + componentReference.setInterfaceContract(interfaceContract); + } + + // Reconcile bindings + if (componentReference.getBindings().isEmpty()) { + componentReference.getBindings().addAll(reference.getBindings()); + } + + // Reconcile callback bindings + if (componentReference.getCallback() == null) { + componentReference.setCallback(reference.getCallback()); + if (componentReference.getCallback() == null) { + // Create an empty callback to avoid null check + componentReference.setCallback(assemblyFactory.createCallback()); + } + + } else if (componentReference.getCallback().getBindings().isEmpty() && reference + .getCallback() != null) { + componentReference.getCallback().getBindings().addAll(reference.getCallback() + .getBindings()); + } + + // Propagate autowire setting from the component + if (componentReference.getAutowire() == null) { + componentReference.setAutowire(component.getAutowire()); + } + + // Reconcile targets + if (componentReference.getTargets().isEmpty()) { + componentReference.getTargets().addAll(reference.getTargets()); + } + } + } + } + + /** + * Reconcile component services and services defined on the component type. + * + * @param component + * @param services + * @param componentServices + * @param problems + */ + private void reconcileServices(Component component, + Map services, + Map componentServices) { + + // Connect each component service to the corresponding service + for (ComponentService componentService : component.getServices()) { + if (componentService.getService() != null || componentService.isCallback()) { + continue; + } + Service service = services.get(componentService.getName()); + if (service != null) { + componentService.setService(service); + } else { + warning("ServiceNotFoundForComponentService", component, component.getName(), componentService.getName()); + } + } + + // Create a component service for each service + if (component.getImplementation() != null) { + for (Service service : component.getImplementation().getServices()) { + if (!componentServices.containsKey(service.getName())) { + ComponentService componentService = assemblyFactory.createComponentService(); + componentService.setIsCallback(service.isCallback()); + String name = service.getName(); + componentService.setName(name); + componentService.setService(service); + component.getServices().add(componentService); + componentServices.put(name, componentService); + } + } + } + + //Reconcile each component service with its service + for (ComponentService componentService : component.getServices()) { + Service service = componentService.getService(); + if (service != null) { + // Reconcile interface + InterfaceContract interfaceContract = service.getInterfaceContract(); + if (componentService.getInterfaceContract() != null) { + if (interfaceContract != null && !componentService.getInterfaceContract().equals(interfaceContract)) { + if (!interfaceContractMapper.isCompatible(componentService.getInterfaceContract(), + interfaceContract)) { + warning("ServiceIncompatibleComponentInterface", component, component.getName(), componentService.getName()); + } + } + } else { + componentService.setInterfaceContract(interfaceContract); + } + + // Reconcile bindings + if (componentService.getBindings().isEmpty()) { + componentService.getBindings().addAll(service.getBindings()); + } + + // Reconcile callback bindings + if (componentService.getCallback() == null) { + componentService.setCallback(service.getCallback()); + if (componentService.getCallback() == null) { + // Create an empty callback to avoid null check + componentService.setCallback(assemblyFactory.createCallback()); + } + } else if (componentService.getCallback().getBindings().isEmpty() && service + .getCallback() != null) { + componentService.getCallback().getBindings().addAll(service.getCallback() + .getBindings()); + } + } + } + } + + private void indexComponentPropertiesServicesAndReferences(Component component, + Map componentServices, + Map componentReferences, + Map componentProperties) { + for (ComponentService componentService : component.getServices()) { + if (componentServices.containsKey(componentService.getName())) { + warning("DuplicateComponentServiceName", component, component.getName(), componentService.getName()); + } else { + componentServices.put(componentService.getName(), componentService); + } + } + for (ComponentReference componentReference : component.getReferences()) { + if (componentReferences.containsKey(componentReference.getName())) { + error("DuplicateComponentReferenceName", component, component.getName(), componentReference.getName()); + } else { + componentReferences.put(componentReference.getName(), componentReference); + } + } + for (ComponentProperty componentProperty : component.getProperties()) { + if (componentProperties.containsKey(componentProperty.getName())) { + warning("DuplicateComponentPropertyName", component, component.getName(), componentProperty.getName()); + } else { + componentProperties.put(componentProperty.getName(), componentProperty); + } + } + + } + + private void indexImplementationPropertiesServicesAndReferences(Component component, + Map services, + Map references, + Map properties) { + // First check that the component has a resolved implementation + Implementation implementation = component.getImplementation(); + if (implementation == null) { + // A component must have an implementation + warning("NoComponentImplementation", component, component.getName()); + + } else if (implementation.isUnresolved()) { + + // The implementation must be fully resolved + warning("UnresolvedComponentImplementation", component, component.getName(), implementation.getURI()); + + } else { + + // Index properties, services and references, also check for + // duplicates + for (Property property : implementation.getProperties()) { + if (properties.containsKey(property.getName())) { + warning("DuplicateImplementationPropertyName", component, component.getName(), property.getName()); + } else { + properties.put(property.getName(), property); + } + } + for (Service service : implementation.getServices()) { + if (services.containsKey(service.getName())) { + warning("DuplicateImplementationServiceName", component, component.getName(), service.getName()); + } else { + services.put(service.getName(), service); + } + } + for (Reference reference : implementation.getReferences()) { + if (references.containsKey(reference.getName())) { + warning("DuplicateImplementationReferenceName", component, component.getName(), reference.getName()); + } else { + references.put(reference.getName(), reference); + } + } + } + + } + + /** + * For all the references with callbacks, create a corresponding callback + * service. + * + * @param component + */ + private void configureCallbackServices(Component component, + Map componentServices) { + for (ComponentReference reference : component.getReferences()) { + if (reference.getInterfaceContract() != null && // can be null in + // unit tests + reference.getInterfaceContract().getCallbackInterface() != null) { + ComponentService service = + componentServices.get(reference.getName()); + if (service == null) { + service = createCallbackService(component, reference); + } + if (reference.getCallback() != null) { + if (service.getBindings().isEmpty()) { + service.getBindings().addAll(reference.getCallback().getBindings()); + } + } + reference.setCallbackService(service); + } + } + } + + /** + * Create a callback service for a component reference + * + * @param component + * @param reference + */ + private ComponentService createCallbackService(Component component, ComponentReference reference) { + ComponentService componentService = assemblyFactory.createComponentService(); + componentService.setIsCallback(true); + componentService.setName(reference.getName()); + try { + InterfaceContract contract = + (InterfaceContract)reference.getInterfaceContract().clone(); + contract.setInterface(contract.getCallbackInterface()); + contract.setCallbackInterface(null); + componentService.setInterfaceContract(contract); + } catch (CloneNotSupportedException e) { + // will not happen + } + Reference implReference = reference.getReference(); + if (implReference != null) { + Service implService = assemblyFactory.createService(); + implService.setName(implReference.getName()); + try { + InterfaceContract implContract = + (InterfaceContract)implReference.getInterfaceContract().clone(); + implContract.setInterface(implContract.getCallbackInterface()); + implContract.setCallbackInterface(null); + implService.setInterfaceContract(implContract); + } catch (CloneNotSupportedException e) { + // will not happen + } + componentService.setService(implService); + } + component.getServices().add(componentService); + return componentService; + } + + /** + * For all the services with callbacks, create a corresponding callback + * reference. + * + * @param component + */ + private void configureCallbackReferences(Component component, + Map componentReferences) { + for (ComponentService service : component.getServices()) { + if (service.getInterfaceContract() != null && // can be null in + // unit tests + service.getInterfaceContract().getCallbackInterface() != null) { + ComponentReference reference = + componentReferences.get(service.getName()); + if (reference == null) { + reference = createCallbackReference(component, service); + } + if (service.getCallback() != null) { + if (reference.getBindings().isEmpty()) { + reference.getBindings().addAll(service.getCallback().getBindings()); + } + } + service.setCallbackReference(reference); + } + } + } + + /** + * Create a callback reference for a component service + * + * @param component + * @param service + */ + private ComponentReference createCallbackReference(Component component, ComponentService service) { + return createCallbackReference(component, service, assemblyFactory); + } + + /** + * Create a callback reference for a component service + * + * @param component + * @param service + * @param assemblyFactory + */ + protected static ComponentReference createCallbackReference(Component component, + ComponentService service, + AssemblyFactory assemblyFactory) { + ComponentReference componentReference = assemblyFactory.createComponentReference(); + componentReference.setIsCallback(true); + componentReference.setName(service.getName()); + try { + InterfaceContract contract = (InterfaceContract)service.getInterfaceContract().clone(); + contract.setInterface(contract.getCallbackInterface()); + contract.setCallbackInterface(null); + componentReference.setInterfaceContract(contract); + } catch (CloneNotSupportedException e) { + // will not happen + } + Service implService = service.getService(); + if (implService != null) { + Reference implReference = assemblyFactory.createReference(); + implReference.setName(implService.getName()); + try { + InterfaceContract implContract = + (InterfaceContract)implService.getInterfaceContract().clone(); + implContract.setInterface(implContract.getCallbackInterface()); + implContract.setCallbackInterface(null); + implReference.setInterfaceContract(implContract); + } catch (CloneNotSupportedException e) { + // will not happen + } + componentReference.setReference(implReference); + } + component.getReferences().add(componentReference); + return componentReference; + } + + /** + * @param composite + */ + private void configureSourcedProperties(Composite composite, List propertySettings) { + // Resolve properties + Map compositeProperties = new HashMap(); + ComponentProperty componentProperty = null; + for (Property p : composite.getProperties()) { + componentProperty = getComponentPropertyByName(p.getName(), propertySettings); + if (componentProperty != null) { + compositeProperties.put(p.getName(), componentProperty); + } else { + compositeProperties.put(p.getName(), p); + } + } + + for (Component component : composite.getComponents()) { + try { + PropertyConfigurationUtil.sourceComponentProperties(compositeProperties, component, + documentBuilderFactory, transformerFactory); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Implementation impl = component.getImplementation(); + if (impl instanceof Composite) { + configureSourcedProperties((Composite)impl, component.getProperties()); + } + } + } + + private ComponentProperty getComponentPropertyByName(String propertyName, List properties) { + if (properties != null) { + for (ComponentProperty aProperty : properties) { + if (aProperty.getName().equals(propertyName)) { + return aProperty; + } + } + } + return null; + } + + private SCABinding createSCABinding() { + SCABinding scaBinding = scaBindingFactory.createSCABinding(); + + // mark the bindings that are added automatically so that they can + // be disregarded for overriding purposes + if (scaBinding instanceof AutomaticBinding){ + ((AutomaticBinding)scaBinding).setIsAutomatic(true); + } + + if ( policyDefinitions != null ) { + for ( IntentAttachPointType attachPointType : policyDefinitions.getBindingTypes() ) { + if ( attachPointType.getName().equals(BINDING_SCA_QNAME)) { + ((IntentAttachPoint)scaBinding).setType(attachPointType); + } + } + } + + return scaBinding; + } + + /** + * Called by CompositeBindingURIBuilderImpl + * + * @param composite the composite to be configured + */ + protected void configureBindingURIsAndNames(Composite composite) throws CompositeBuilderException { + configureBindingURIs(composite, null, null); + configureBindingNames(composite); + } + + /** + * Fully resolve the binding URIs based on available information. This includes information + * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, + * from any associated policies and from the default information for each binding type. + * + * @param composite the composite to be configured + * @param defaultBindings list of default binding configurations + */ + protected void configureBindingURIs(Composite composite, List defaultBindings) throws CompositeBuilderException { + configureBindingURIs(composite, null, defaultBindings); + } + + /** + * Fully resolve the binding URIs based on available information. This includes information + * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, + * from any associated policies and from the default information for each binding type. + * + * NOTE: This method repeats some of the processing performed by the configureComponents() + * method above. The duplication is needed because NodeConfigurationServiceImpl + * calls this method without previously calling configureComponents(). In the + * normal builder sequence used by CompositeBuilderImpl, both of these methods + * are called. + * + * TODO: Share the URL calculation algorithm with the configureComponents() method above + * although keeping the configureComponents() methods signature as is because when + * a composite is actually build in a node the node default information is currently + * available + * + * @param composite the composite to be configured + * @param uri the path to the composite provided through any nested composite component implementations + * @param defaultBindings list of default binding configurations + */ + private void configureBindingURIs(Composite composite, String uri, List defaultBindings) throws CompositeBuilderException { + + String parentComponentURI = uri; + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + + // Initialize component URI + String componentURI; + if (parentComponentURI == null) { + componentURI = component.getName(); + } else { + componentURI = URI.create(parentComponentURI + '/').resolve(component.getName()).toString(); + } + component.setURI(componentURI); + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // Process nested composite + configureBindingURIs((Composite)implementation, componentURI, defaultBindings); + } + } + + // Initialize composite service binding URIs + List compositeServices = composite.getServices(); + for (Service service : compositeServices) { + + // Create default SCA binding + if (service.getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + service.getBindings().add(scaBinding); + } + + // Create default SCA callback binding + if (service.getInterfaceContract() != null + && service.getInterfaceContract().getCallbackInterface() != null + && service.getCallback() != null + && service.getCallback().getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + scaBinding.setName(service.getName() + "Callback"); + service.getCallback().getBindings().add(scaBinding); + } + + // Initialize binding names and URIs + for (Binding binding : service.getBindings()) { + constructBindingName(service, binding); + constructBindingURI(parentComponentURI, composite, service, binding, defaultBindings); + } + } + + // Initialize composite reference callback binding URIs + for (Reference reference : composite.getReferences()) { + + // Create default SCA callback binding + if (reference.getInterfaceContract() != null + && reference.getInterfaceContract().getCallbackInterface() != null + && reference.getCallback() != null + && reference.getCallback().getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + scaBinding.setName(reference.getName() + "Callback"); + reference.getCallback().getBindings().add(scaBinding); + } + + // Initialize binding names and URIs + if (reference.getCallback() != null) { + for (Binding binding : reference.getCallback().getBindings()) { + constructBindingName(reference, binding); + constructBindingURI(parentComponentURI, composite, reference, binding, defaultBindings); + } + } + } + + // Initialize component service binding URIs + for (Component component : composite.getComponents()) { + + // Index properties, services and references + Map services = new HashMap(); + Map references = new HashMap(); + Map properties = new HashMap(); + indexImplementationPropertiesServicesAndReferences(component, + services, + references, + properties); + + // Index component services, references and properties + // Also check for duplicates + Map componentServices = + new HashMap(); + Map componentReferences = + new HashMap(); + Map componentProperties = + new HashMap(); + indexComponentPropertiesServicesAndReferences(component, + componentServices, + componentReferences, + componentProperties); + + // Reconcile component services/references/properties and + // implementation services/references and create component + // services/references/properties for the services/references + // declared by the implementation + reconcileServices(component, services, componentServices); + reconcileReferences(component, references, componentReferences); + reconcileProperties(component, properties, componentProperties); + + for (ComponentService service : component.getServices()) { + + // Create default SCA binding + if (service.getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + service.getBindings().add(scaBinding); + } + + // Create default SCA callback binding + if (service.getInterfaceContract() != null + && service.getInterfaceContract().getCallbackInterface() != null + && service.getCallback() != null + && service.getCallback().getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + scaBinding.setName(service.getName() + "Callback"); + service.getCallback().getBindings().add(scaBinding); + } + + // Add all SCA bindings for the service callback to the bindingMap + // so that BindingConfigurationUtil.matchBinding() can identify the node + // for the target component. + if (service.getInterfaceContract() != null + && service.getInterfaceContract().getCallbackInterface() != null + && service.getCallback() != null + && bindingMap != null + && defaultBindings != null) { + for (Binding binding : service.getCallback().getBindings()) { + if (binding instanceof SCABinding) { + for (Binding nodeBinding : defaultBindings) { + if (nodeBinding instanceof SCABinding) { + bindingMap.put(binding, nodeBinding); + break; + } + } + } + } + } + + // Initialize binding names and URIs + for (Binding binding : service.getBindings()) { + constructBindingName(service, binding); + constructBindingURI(component, service, binding, defaultBindings); + } + } + + for (ComponentReference reference : component.getReferences()) { + + // Create default SCA binding + if (reference.getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + reference.getBindings().add(scaBinding); + } + + // Add all SCA bindings for the reference to the bindingMap so that + // BindingConfigurationUtil.matchBinding() can identify the node for + // the source component. + if (bindingMap != null && defaultBindings != null) { + for (Binding binding : reference.getBindings()) { + if (binding instanceof SCABinding) { + for (Binding nodeBinding : defaultBindings) { + if (nodeBinding instanceof SCABinding) { + bindingMap.put(binding, nodeBinding); + break; + } + } + } + } + } + + // Create default SCA callback binding + if (reference.getInterfaceContract() != null + && reference.getInterfaceContract().getCallbackInterface() != null + && reference.getCallback() != null + && reference.getCallback().getBindings().isEmpty()) { + SCABinding scaBinding = createSCABinding(); + scaBinding.setName(reference.getName() + "Callback"); + reference.getCallback().getBindings().add(scaBinding); + } + + // Add all SCA bindings for the reference callback to the bindingMap + // so that BindingConfigurationUtil.matchBinding() can identify the node + // for the source component. + if (reference.getInterfaceContract() != null + && reference.getInterfaceContract().getCallbackInterface() != null + && reference.getCallback() != null + && bindingMap != null + && defaultBindings != null) { + for (Binding binding : reference.getCallback().getBindings()) { + if (binding instanceof SCABinding) { + for (Binding nodeBinding : defaultBindings) { + if (nodeBinding instanceof SCABinding) { + bindingMap.put(binding, nodeBinding); + break; + } + } + } + } + } + + // Initialize binding names and URIs + if (reference.getCallback() != null) { + for (Binding binding : reference.getCallback().getBindings()) { + constructBindingName(reference, binding); + constructBindingURI(component, reference, binding, defaultBindings); + } + } + } + } + } + + /** + * Add default names for callback bindings and reference bindings. Needs to be + * separate from configureBindingURIs() because configureBindingURIs() is called + * by NodeConfigurationServiceImpl as well as by CompositeBuilderImpl. + */ + private void configureBindingNames(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // Process nested composite + configureBindingNames((Composite)implementation); + } + } + + // Initialize composite service callback binding names + for (Service service : composite.getServices()) { + + if (service.getCallback() != null) { + for (Binding binding : service.getCallback().getBindings()) { + constructBindingName(service, binding); + } + } + } + + // Initialize composite reference binding names + for (Reference reference : composite.getReferences()) { + + for (Binding binding : reference.getBindings()) { + constructBindingName(reference, binding); + } + + if (reference.getCallback() != null) { + for (Binding binding : reference.getCallback().getBindings()) { + constructBindingName(reference, binding); + } + } + } + + // Initialize component service and reference binding names + for (Component component : composite.getComponents()) { + + // Initialize component service callback binding names + for (ComponentService service : component.getServices()) { + + if (service.getCallback() != null) { + for (Binding binding : service.getCallback().getBindings()) { + constructBindingName(service, binding); + } + } + } + + // Initialize component reference binding names + for (ComponentReference reference : component.getReferences()) { + + // Initialize binding names + for (Binding binding : reference.getBindings()) { + constructBindingName(reference, binding); + } + + if (reference.getCallback() != null) { + for (Binding binding : reference.getCallback().getBindings()) { + constructBindingName(reference, binding); + } + } + } + } + } + + /** + * If a binding name is not provided by the user, construct it based on the service + * or reference name + * + * @param contract the service or reference + * @param binding + */ + private void constructBindingName(Contract contract, Binding binding) { + if(binding == null) { + warning("Binding is null", binding, contract.getName()); + return; + } + + // set the default binding name if one is required + // if there is no name on the binding then set it to the service or reference name + if (binding.getName() == null){ + binding.setName(contract.getName()); + } + + // Check that multiple bindings do not have the same name + for (Binding otherBinding : contract.getBindings()) { + if (otherBinding == binding) { + // Skip the current binding + continue; + } + if (binding.getClass() != otherBinding.getClass()) { + // Look for a binding of the same type + continue; + } + if (binding.getName().equals(otherBinding.getName())) { + warning(contract instanceof Service ? "MultipleBindingsForService" : "MultipleBindingsForReference", + binding, contract.getName(), binding.getName()); + } + } + } + + /** + * URI construction for composite bindings based on Assembly Specification section 1.7.2, This method + * assumes that the component URI part of the binding URI is formed from the part to the + * composite in question and just calls the generic constructBindingURI method with this + * information + * + * @param parentComponentURI + * @param composite + * @param service + * @param binding + * @param defaultBindings + */ + private void constructBindingURI(String parentComponentURI, Composite composite, Service service, Binding binding, List defaultBindings) + throws CompositeBuilderException{ + // This is a composite service so there is no component to provide a component URI + // The path to this composite (through nested composites) is used. + boolean includeBindingName = composite.getServices().size() != 1; + constructBindingURI(parentComponentURI, service, binding, includeBindingName, defaultBindings); + } + + private void constructBindingURI(String parentComponentURI, Composite composite, Reference reference, Binding binding, List defaultBindings) + throws CompositeBuilderException{ + // This is a composite reference so there is no component to provide a component URI + // The path to this composite (through nested composites) is used. + boolean includeBindingName = true; + constructBindingURI(parentComponentURI, reference, binding, includeBindingName, defaultBindings); + } + + /** + * URI construction for component bindings based on Assembly Specification section 1.7.2. This method + * calculates the component URI part based on component information before calling the generic + * constructBindingURI method + * + * @param component the component that holds the service + * @param service the service that holds the binding + * @param binding the binding for which the URI is being constructed + * @param defaultBindings the list of default binding configurations + */ + private void constructBindingURI(Component component, Service service, Binding binding, List defaultBindings) + throws CompositeBuilderException{ + boolean includeBindingName = component.getServices().size() != 1; + constructBindingURI(component.getURI(), service, binding, includeBindingName, defaultBindings); + } + + private void constructBindingURI(Component component, Reference reference, Binding binding, List defaultBindings) + throws CompositeBuilderException{ + boolean includeBindingName = true; + constructBindingURI(component.getURI(), reference, binding, includeBindingName, defaultBindings); + } + + /** + * Generic URI construction for bindings based on Assembly Specification section 1.7.2 + * + * @param componentURIString the string version of the URI part that comes from the component name + * @param service the service in question + * @param binding the binding for which the URI is being constructed + * @param includeBindingName when set true the serviceBindingURI part should be used + * @param defaultBindings the list of default binding configurations + * @throws CompositeBuilderException + */ + private void constructBindingURI(String componentURIString, Contract contract, Binding binding, boolean includeBindingName, List defaultBindings) + throws CompositeBuilderException{ + + try { + // calculate the service binding URI + URI bindingURI; + if (binding.getURI() != null){ + bindingURI = new URI(binding.getURI()); + + // if the user has provided an absolute binding URI then use it + if (bindingURI.isAbsolute()){ + binding.setURI(bindingURI.toString()); + return; + } + } else { + bindingURI = null; + } + + // Get the service binding name + URI bindingName; + if (binding.getName() != null) { + bindingName = new URI(binding.getName()); + } else { + bindingName = new URI(""); + } + + // calculate the component URI + URI componentURI; + if (componentURIString != null) { + componentURI = new URI(addSlashToPath(componentURIString)); + } else { + componentURI = null; + } + + // if the user has provided an absolute component URI then use it + if (componentURI != null && componentURI.isAbsolute()){ + binding.setURI(constructBindingURI(null, componentURI, bindingURI, includeBindingName, bindingName)); + return; + } + + // calculate the base URI + + // get the protocol for this binding/URI +/* some code that allows binding specific code to run. Being discussed on ML + BindingURICalculator uriCalculator = bindingURICalcualtorExtensionPoint.getBindingURICalculator(binding); + + if (uriCalculator != null){ + String protocol = uriCalculator.getProtocol(binding); + + // find the default binding with the right protocol + Binding defaultBinding = nodeInfo.getBindingDefault(binding, protocol); + + if (defaultBinding != null){ + baseURI = new URI(defaultBinding.getURI()); + } else { + baseURI = null; + } + + } else { + baseURI = null; + } +*/ + // as a simpler alternative to the above commented out code. + URI baseURI = null; + if (defaultBindings != null) { + for (Binding defaultBinding : defaultBindings){ + if (binding.getClass() == defaultBinding.getClass()){ + // if the domain manager is generating a URI for an SCA binding, + // tentatively omit the base URI for now. The base URI will be added + // to the service URI by BindingConfigurationUtil.matchBinding() + // if the service needs a remote SCA binding because it is a + // wiring target for a reference running on a different node. + if (bindingMap != null && binding instanceof SCABinding) { + bindingMap.put(binding, defaultBinding); + } else { + baseURI = new URI(addSlashToPath(defaultBinding.getURI())); + } + break; + } + } + } + + binding.setURI(constructBindingURI(baseURI, componentURI, bindingURI, includeBindingName, bindingName)); + } catch (URISyntaxException ex) { + error("URLSyntaxException", binding, componentURIString, contract.getName(), binding.getName()); + } + } + + /** + * Use to ensure that URI paths end in "/" as here we want to maintain the + * last path element of an base URI when other URI are resolved against it. This is + * not the default behaviour of URI resolution as defined in RFC 2369 + * + * @param path the path string to which the "/" is to be added + * @return the resulting path with a "/" added if it not already there + */ + private static String addSlashToPath(String path){ + if (path.endsWith("/") || path.endsWith("#")){ + return path; + } else { + return path + "/"; + } + } + + /** + * Concatenate binding URI parts together based on Assembly Specification section 1.7.2 + * + * @param baseURI the base of the binding URI + * @param componentURI the middle part of the binding URI derived from the component name + * @param bindingURI the end part of the binding URI + * @param includeBindingName when set true the binding name part should be used + * @param bindingName the binding name + * @return the resulting URI as a string + */ + private static String constructBindingURI(URI baseURI, URI componentURI, URI bindingURI, boolean includeBindingName, URI bindingName){ + String uriString; + + if (baseURI == null) { + if (componentURI == null){ + if (bindingURI != null ) { + uriString = bindingURI.toString(); + } else { + uriString = bindingName.toString(); + } + } else { + if (bindingURI != null ) { + uriString = componentURI.resolve(bindingURI).toString(); + } else { + if (includeBindingName) { + uriString = componentURI.resolve(bindingName).toString(); + } else { + uriString = componentURI.toString(); + } + } + } + } else { + if (componentURI == null) { + if (bindingURI != null ) { + uriString = basedURI(baseURI, bindingURI).toString(); + } else { + if (includeBindingName) { + uriString = basedURI(baseURI, bindingName).toString(); + } else { + uriString = baseURI.toString(); + } + } + } else { + if (bindingURI != null ) { + uriString = basedURI(baseURI, componentURI.resolve(bindingURI)).toString(); + } else { + if (includeBindingName) { + uriString = basedURI(baseURI, componentURI.resolve(bindingName)).toString(); + } else { + uriString = basedURI(baseURI, componentURI).toString(); + } + } + } + } + + // tidy up by removing any trailing "/" + if (uriString.endsWith("/")){ + uriString = uriString.substring(0, uriString.length()-1); + } + + URI uri = URI.create(uriString); + if (!uri.isAbsolute()) { + uri = URI.create("/").resolve(uri); + } + return uri.toString(); + } + + /** + * Combine a URI with a base URI. + * + * @param baseURI + * @param uri + * @return + */ + private static URI basedURI(URI baseURI, URI uri) { + if (uri.getScheme() != null) { + return uri; + } + String str = uri.toString(); + if (str.startsWith("/")) { + str = str.substring(1); + } + return URI.create(baseURI.toString() + str).normalize(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java new file mode 100644 index 0000000000..cc70cbcac8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java @@ -0,0 +1,1154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointFactory; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.assembly.builder.DefaultEndpointBuilder; +import org.apache.tuscany.sca.assembly.builder.EndpointBuilder; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.policy.util.PolicyComputationUtils; + +/** + * A composite builder that handles wiring inside a composite. + * + * @version $Rev$ $Date$ + */ +class BaseWireBuilderImpl { + + private Monitor monitor; + private AssemblyFactory assemblyFactory; + private EndpointFactory endpointFactory; + private InterfaceContractMapper interfaceContractMapper; + private Map bindingMap; + private EndpointBuilder endpointBuilder; + + protected BaseWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, + InterfaceContractMapper interfaceContractMapper, Monitor monitor, + Map bindingMap) { + this.assemblyFactory = assemblyFactory; + this.endpointFactory = endpointFactory; + this.interfaceContractMapper = interfaceContractMapper; + this.monitor = monitor; + this.bindingMap = bindingMap; + this.endpointBuilder = new DefaultEndpointBuilder(monitor, bindingMap); + } + + /** + * Wire component references to component services and connect promoted + * services/references to component services/references inside a composite. + * + * @param composite + */ + protected void wireComponentReferences(Composite composite) { + + // Wire nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + wireComponentReferences((Composite)implementation); + } + } + + // Index components, services and references + Map components = new HashMap(); + Map componentServices = new HashMap(); + Map componentReferences = new HashMap(); + indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences); + + // Connect composite services and references to the component + // services and references that they promote + //connectCompositeServices(composite, components, componentServices); + //connectCompositeReferences(composite, componentReferences); + + // Compute the policies before connecting component references + //computePolicies(composite); + + // Connect component references as described in wires + connectWires(composite, componentServices, componentReferences); + + // Connect component references to their targets + connectComponentReferences(composite, components, componentServices, componentReferences); + + // Validate that references are wired or promoted, according + // to their multiplicity + for (ComponentReference componentReference : componentReferences.values()) { + if (!ReferenceConfigurationUtil.validateMultiplicityAndTargets(componentReference.getMultiplicity(), componentReference + .getTargets(), componentReference.getBindings())) { + if (componentReference.getTargets().isEmpty()) { + + // No warning if the reference is promoted out of the current composite + boolean promoted = false; + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + if (compositeReference.getPromotedReferences().contains(componentReference)) { + promoted = true; + break; + } + } + if (!promoted && !componentReference.isCallback()) { + warning("ReferenceWithoutTargets", composite, composite.getName().toString(), componentReference.getName()); + } + } else { + warning("TooManyReferenceTargets", composite, componentReference.getName()); + } + } + } + + // Finally clear the original reference target lists as we now have + // bindings to represent the targets + for (ComponentReference componentReference : componentReferences.values()) { + componentReference.getTargets().clear(); + } + } + + /** + * Index components, services and references inside a composite. + * @param composite + * @param components + * @param componentServices + * @param componentReferences + */ + private void indexComponentsServicesAndReferences(Composite composite, + Map components, + Map componentServices, + Map componentReferences) { + + for (Component component : composite.getComponents()) { + + // Index components by name + components.put(component.getName(), component); + + ComponentService nonCallbackService = null; + int nonCallbackServices = 0; + for (ComponentService componentService : component.getServices()) { + + // Index component services by component name / service name + String uri = component.getName() + '/' + componentService.getName(); + componentServices.put(uri, componentService); + + boolean promotedService = false; + if (componentService.getName() != null && componentService.getName().indexOf("$promoted$") > -1) { + promotedService = true; + } + + // count how many non-callback, non-promoted services there are + // if there is only one the component name also acts as the service name + if ((!componentService.isCallback()) && (!promotedService)) { + + // Check how many non callback non-promoted services we have + if (nonCallbackServices == 0) { + nonCallbackService = componentService; + } + nonCallbackServices++; + } + + } + + if (nonCallbackServices == 1) { + // If we have a single non callback service, index it by + // component name as well + componentServices.put(component.getName(), nonCallbackService); + } + + // Index references by component name / reference name + for (ComponentReference componentReference : component.getReferences()) { + String uri = component.getName() + '/' + componentReference.getName(); + componentReferences.put(uri, componentReference); + } + } + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void warning(String message, Object model, String... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = null; + problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + /** + * Connect composite references and services to the reference and services that they promote. + * + * @param composite + * @param componentServices + * @param problems + */ + protected void connectCompositeReferencesAndServices(Composite composite){ + // Wire nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + connectCompositeReferencesAndServices((Composite)implementation); + } + } + + // Index components, services and references + Map components = new HashMap(); + Map componentServices = new HashMap(); + Map componentReferences = new HashMap(); + indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences); + + // Connect composite services and references to the component + // services and references that they promote + connectCompositeServices(composite, components, componentServices); + connectCompositeReferences(composite, componentReferences); + } + + /** + * Connect composite services to the component services that they promote. + * + * @param composite + * @param componentServices + * @param problems + */ + private void connectCompositeServices(Composite composite, + Map components, + Map componentServices) { + + // Propagate interfaces from inner composite components' services to + // their component services + for (Component component : composite.getComponents()) { + if (component.getImplementation() instanceof Composite) { + for (ComponentService componentService : component.getServices()) { + Service service = componentService.getService(); + if (service != null) { + if (componentService.getInterfaceContract() == null) { + componentService.setInterfaceContract(service.getInterfaceContract()); + } + } + } + } + } + + // Connect composite services to the component services that they + // promote + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + ComponentService componentService = compositeService.getPromotedService(); + if (componentService != null && componentService.isUnresolved()) { + + String promotedComponentName = compositeService.getPromotedComponent().getName(); + String promotedServiceName; + if (componentService.getName() != null) { + promotedServiceName = promotedComponentName + '/' + componentService.getName(); + } else { + promotedServiceName = promotedComponentName; + } + ComponentService promotedService = componentServices.get(promotedServiceName); + if (promotedService != null) { + + // Point to the resolved component + Component promotedComponent = components.get(promotedComponentName); + compositeService.setPromotedComponent(promotedComponent); + + // Point to the resolved component service + compositeService.setPromotedService(promotedService); + + // Use the interface contract from the component service if + // none is specified on the composite service + InterfaceContract compositeServiceInterfaceContract = compositeService.getInterfaceContract(); + InterfaceContract promotedServiceInterfaceContract = promotedService.getInterfaceContract(); + if (compositeServiceInterfaceContract == null) { + compositeService.setInterfaceContract(promotedServiceInterfaceContract); + } else if (promotedServiceInterfaceContract != null) { + // Check the compositeServiceInterfaceContract and promotedServiceInterfaceContract + boolean isCompatible = interfaceContractMapper.isCompatible(compositeServiceInterfaceContract, promotedServiceInterfaceContract); + if(!isCompatible){ + warning("ServiceInterfaceNotSubSet", compositeService, promotedServiceName); + } + } + + } else { + warning("PromotedServiceNotFound", composite, composite.getName().toString(), promotedServiceName); + } + } + } + + } + + /** + * Resolves promoted references. + * + * @param composite + * @param componentReferences + * @param problems + */ + private void connectCompositeReferences(Composite composite, Map componentReferences) { + + // Propagate interfaces from inner composite components' references to + // their component references + for (Component component : composite.getComponents()) { + if (component.getImplementation() instanceof Composite) { + for (ComponentReference componentReference : component.getReferences()) { + Reference reference = componentReference.getReference(); + if (reference != null) { + if (componentReference.getInterfaceContract() == null) { + componentReference.setInterfaceContract(reference.getInterfaceContract()); + } + } + } + } + } + + // Connect composite references to the component references + // that they promote + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + List promotedReferences = compositeReference.getPromotedReferences(); + for (int i = 0, n = promotedReferences.size(); i < n; i++) { + ComponentReference componentReference = promotedReferences.get(i); + if (componentReference.isUnresolved()) { + String componentReferenceName = componentReference.getName(); + componentReference = componentReferences.get(componentReferenceName); + if (componentReference != null) { + + // Point to the resolved component reference + promotedReferences.set(i, componentReference); + + // Use the interface contract from the component + // reference if none + // is specified on the composite reference + + InterfaceContract compositeReferenceInterfaceContract = compositeReference.getInterfaceContract(); + InterfaceContract componentReferenceInterfaceContract = componentReference.getInterfaceContract(); + if (compositeReferenceInterfaceContract == null) { + compositeReference.setInterfaceContract(componentReferenceInterfaceContract); + } else if (componentReferenceInterfaceContract != null) { + // Check the compositeInterfaceContract and componentInterfaceContract + boolean isCompatible = interfaceContractMapper.isCompatible(compositeReferenceInterfaceContract, componentReferenceInterfaceContract); + if (!isCompatible) { + warning("ReferenceInterfaceNotSubSet", compositeReference, componentReferenceName); + } + } + } else { + warning("PromotedReferenceNotFound", composite, composite.getName().toString(), componentReferenceName); + } + } + } + } + } + + private List createComponentReferenceTargets(Composite composite, + Map components, + Map componentServices, + ComponentReference componentReference) { + + List endpoints = new ArrayList(); + + if (!componentReference.getTargets().isEmpty()) { + + // Check if the component reference does not mix the use of endpoints specified via + // binding elements with target endpoints specified via the target attribute + for (Binding binding : componentReference.getBindings()) { + if (binding.getURI() != null) { + warning("ReferenceEndPointMixWithTarget", composite, componentReference.getName()); + } + } + + // Resolve targets specified on the component reference + for (ComponentService componentService : componentReference.getTargets()) { + + // Resolve the target component and service + String name = componentService.getName(); + ComponentService targetComponentService = componentServices.get(name); + Component targetComponent; + int s = name.indexOf('/'); + if (s == -1) { + targetComponent = components.get(name); + } else { + targetComponent = components.get(name.substring(0, s)); + } + + if (targetComponentService != null) { + + // Check that the target component service provides + // a superset of the component reference interface + if (componentReference.getInterfaceContract() == null || + interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) { + + Endpoint endpoint = endpointFactory.createEndpoint(); + endpoint.setTargetName(targetComponent.getName()); + endpoint.setSourceComponent(null); // TODO - fixed up at start + endpoint.setSourceComponentReference(componentReference); + endpoint.setInterfaceContract(componentReference.getInterfaceContract()); + endpoint.setTargetComponent(targetComponent); + endpoint.setTargetComponentService(targetComponentService); + endpoint.getCandidateBindings().addAll(componentReference.getBindings()); + endpoints.add(endpoint); + + // mark the reference target as resolved. Used later when we are looking to + // see if an sca binding is associated with a resolved target or not + componentService.setUnresolved(false); + } else { + warning("ReferenceIncompatibleInterface", composite, composite.getName().toString(), + componentReference.getName(), componentService.getName()); + } + } else { + // add all the reference bindings into the target so that they + // can be used for comparison when the target is resolved at runtime + componentService.getBindings().addAll(componentReference.getBindings()); + + Endpoint endpoint = endpointFactory.createEndpoint(); + endpoint.setTargetName(name); + endpoint.setSourceComponent(null); // TODO - fixed up at start + endpoint.setSourceComponentReference(componentReference); + endpoint.setInterfaceContract(componentReference.getInterfaceContract()); + endpoint.getCandidateBindings().addAll(componentReference.getBindings()); + endpoints.add(endpoint); + + // The bindings will be cloned back into the reference when the + // target is finally resolved. + warning("ComponentReferenceTargetNotFound", composite, + composite.getName().toString(), componentService.getName()); + } + } + } else if ((componentReference.getReference() != null) && + (!componentReference.getReference().getTargets().isEmpty())) { + + // Resolve targets from the corresponding reference in the + // componentType + for (ComponentService componentService : componentReference.getReference().getTargets()) { + + // Resolve the target component and service + String name = componentService.getName(); + ComponentService targetComponentService = componentServices.get(name); + Component targetComponent; + int s = name.indexOf('/'); + if (s == -1) { + targetComponent = components.get(name); + } else { + targetComponent = components.get(name.substring(0, s)); + } + + if (targetComponentService != null) { + + // Check that the target component service provides + // a superset of + // the component reference interface + if (componentReference.getInterfaceContract() == null || + interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) { + + Endpoint endpoint = endpointFactory.createEndpoint(); + endpoint.setTargetName(targetComponent.getName()); + endpoint.setSourceComponent(null); // TODO - fixed up at start + endpoint.setSourceComponentReference(componentReference); + endpoint.setInterfaceContract(componentReference.getInterfaceContract()); + endpoint.setTargetComponent(targetComponent); + endpoint.setTargetComponentService(targetComponentService); + endpoint.getCandidateBindings().addAll(componentReference.getBindings()); + endpoints.add(endpoint); + + // mark the reference target as resolved. Used later when we are looking to + // see if an sca binding is associated with a resolved target or not + componentService.setUnresolved(false); + } else { + warning("ComponentIncompatibleInterface", composite, + componentReference.getName(), componentService.getName()); + } + } else { + // add all the reference bindings into the target so that they + // can be used for comparison when the target is resolved at runtime + componentService.getBindings().addAll(componentReference.getBindings()); + + // The bindings will be cloned back into the reference when the + // target is finally resolved. + + Endpoint endpoint = endpointFactory.createEndpoint(); + endpoint.setTargetName(name); + endpoint.setSourceComponent(null); // TODO - fixed up at start + endpoint.setSourceComponentReference(componentReference); + endpoint.setInterfaceContract(componentReference.getInterfaceContract()); + endpoint.getCandidateBindings().addAll(componentReference.getBindings()); + endpoints.add(endpoint); + + warning("ComponentReferenceTargetNotFound", composite, + composite.getName().toString(), componentService.getName()); + } + } + } else if (componentReference.getAutowire() == Boolean.TRUE) { + + // Find suitable targets in the current composite for an + // autowired reference + Multiplicity multiplicity = componentReference.getMultiplicity(); + for (Component targetComponent : composite.getComponents()) { + // prevent autowire connecting to self + boolean skipSelf = false; + for (ComponentReference targetComponentReference : targetComponent.getReferences()) { + if (componentReference == targetComponentReference){ + skipSelf = true; + } + } + + if (!skipSelf){ + for (ComponentService targetComponentService : targetComponent.getServices()) { + if (componentReference.getInterfaceContract() == null || + interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) { + + Endpoint endpoint = endpointFactory.createEndpoint(); + endpoint.setTargetName(targetComponent.getName()); + endpoint.setSourceComponent(null); // TODO - fixed up at start + endpoint.setSourceComponentReference(componentReference); + endpoint.setInterfaceContract(componentReference.getInterfaceContract()); + endpoint.setTargetComponent(targetComponent); + endpoint.setTargetComponentService(targetComponentService); + endpoint.getCandidateBindings().addAll(componentReference.getBindings()); + endpoints.add(endpoint); + + if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) { + break; + } + } + } + } + } + + if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) { + if (endpoints.size() == 0) { + warning("NoComponentReferenceTarget", componentReference, componentReference.getName()); + } + } + } + + + // if no endpoints have found so far retrieve any target names that are in binding URIs + if (endpoints.isEmpty()){ + for (Binding binding : componentReference.getBindings()) { + + String uri = binding.getURI(); + + // user hasn't put a uri on the binding so it's not a target name + if (uri == null) { + continue; + } + + // user might have put a local target name in the uri so get + // the path part and see if it refers to a target we know about + // - if it does the reference binding will be matched with a service binding + // - if it doesn't it is assumed to be an external reference + Component targetComponent = null; + ComponentService targetComponentService = null; + String path = null; + + try { + path = URI.create(uri).getPath(); + } catch(Exception ex){ + // just assume that no target is identified if + // a URI related exception is thrown + } + + if (path != null) { + if (path.startsWith("/")) { + path = path.substring(1); + } + + // Resolve the target component and service + targetComponentService = componentServices.get(path); + int s = path.indexOf('/'); + if (s == -1) { + targetComponent = components.get(path); + } else { + targetComponent = components.get(path.substring(0, s)); + } + } + + // if the path of the binding URI matches a component in the + // composite then configure an endpoint with this component as the target + // if not then the binding URI will be assumed to reference an external service + if (targetComponentService != null) { + + // Check that the target component service provides + // a superset of the component reference interface + if (componentReference.getInterfaceContract() == null || + interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) { + + Endpoint endpoint = endpointFactory.createEndpoint(); + endpoint.setTargetName(targetComponent.getName()); + endpoint.setSourceComponent(null); // TODO - fixed up at start + endpoint.setSourceComponentReference(componentReference); + endpoint.setInterfaceContract(componentReference.getInterfaceContract()); + endpoint.setTargetComponent(targetComponent); + endpoint.setTargetComponentService(targetComponentService); + endpoint.getCandidateBindings().add(binding); + endpoints.add(endpoint); + } else { + warning("ReferenceIncompatibleInterface", + composite, + composite.getName().toString(), + componentReference.getName(), + uri); + } + } else { + + // create endpoints for manually configured bindings + Endpoint endpoint = endpointFactory.createEndpoint(); + endpoint.setTargetName(uri); + endpoint.setSourceComponent(null); // TODO - fixed up at start + endpoint.setSourceComponentReference(componentReference); + endpoint.setInterfaceContract(componentReference.getInterfaceContract()); + endpoint.setSourceBinding(binding); + endpoints.add(endpoint); + } + } + } + + return endpoints; + } + + + /** + * Connect references to their targets. + * + * @param composite + * @param componentServices + * @param componentReferences + * @param problems + */ + private void connectComponentReferences(Composite composite, + Map components, + Map componentServices, + Map componentReferences){ + + for (ComponentReference componentReference : componentReferences.values()) { + + List endpoints = createComponentReferenceTargets(composite, + components, + componentServices, + componentReference); + + componentReference.getEndpoints().addAll(endpoints); + + // the result of calculating the endpoints is either that bindings have been + // configured manually using a URI or that targets have been provided and the + // endpoint remains unresolved. So all endpoints should be either resved or uresolved. + boolean endpointsRequireAutomaticResolution = false; + for(Endpoint endpoint : endpoints){ + endpointsRequireAutomaticResolution = endpoint.isUnresolved(); + } + + // build each endpoint + if (endpointsRequireAutomaticResolution) { + + for(Endpoint endpoint : endpoints){ + endpointBuilder.build(endpoint); + } + + // TODO - The following step ensures that the reference binding list remains + // as the record of resolved targets for now. This needs fixing so + // that the endpoint takes on this responsibility. + componentReference.getBindings().clear(); + + if (componentReference.getCallback() != null){ + componentReference.getCallback().getBindings().clear(); + } + + for(Endpoint endpoint : endpoints){ + if (endpoint.isUnresolved() == false){ + componentReference.getBindings().add(endpoint.getSourceBinding()); + + if (componentReference.getCallback() != null){ + componentReference.getCallback().getBindings().add(endpoint.getSourceCallbackBinding()); + } + } + } + + } else { + // do nothing as no targets have been specified so the bindings + // in the reference binding list are assumed to be manually configured + } + + +/* + // Select the reference bindings matching the target service bindings + List selectedBindings = new ArrayList(); + List selectedCallbackBindings = null; + + // Handle callback + boolean bidirectional = false; + + if (componentReference.getInterfaceContract() != null && componentReference.getInterfaceContract().getCallbackInterface() != null) { + bidirectional = true; + selectedCallbackBindings = new ArrayList(); + } + + for (Target target : targets) { + + Component targetComponent = target.getComponent(); + ComponentService targetComponentService = target.getService(); + if (targetComponentService.getService() instanceof CompositeService) { + CompositeService compositeService = (CompositeService) targetComponentService.getService(); + // Find the promoted component service + targetComponentService = ServiceConfigurationUtil.getPromotedComponentService(compositeService); + } + + try { + PolicyConfigurationUtil.determineApplicableBindingPolicySets(componentReference, targetComponentService); + } catch ( Exception e ) { + warning("Policy related exception: " + e, e); + //throw new RuntimeException(e); + } + + // Match the binding against the bindings of the target service + Binding selected = BindingConfigurationUtil.resolveBindings(componentReference, targetComponent, targetComponentService, + bindingMap); + if (selected == null) { + warning("NoMatchingBinding", componentReference, componentReference.getName(), targetComponentService.getName()); + } else { + selectedBindings.add(selected); + } + if (bidirectional) { + Binding selectedCallback = BindingConfigurationUtil.resolveCallbackBindings(componentReference, targetComponent, + targetComponentService, bindingMap); + if (selectedCallback != null) { + selectedCallbackBindings.add(selectedCallback); + } + } + } +*/ + + // Need to tidy up the reference binding list and add in the bindings that + // have been selected above. The situation so far... + // Wired reference (1 or more targets are specified) + // Binding.uri = null - remove as it's left over from target resolution + // the binding will have been moved to the target from where + // it will be resolved later + // Binding.uri != null - the selected and resolved reference binding + // Unwired reference (0 targets) + // Binding.uri = null - Either a callback reference or the reference is yet to be wired + // by the implementation so leave the binding where it is + // Binding.uri != null - from the composite file so leave it +/* + if ((componentReference.getTargets().size() > 0) || + (!targets.isEmpty())) { + + // Add all the effective bindings + componentReference.getBindings().clear(); + componentReference.getBindings().addAll(selectedBindings); + if (bidirectional) { + componentReference.getCallback().getBindings().clear(); + componentReference.getCallback().getBindings().addAll(selectedCallbackBindings); + } + + // add in sca bindings to represent all unresolved targets. The sca binding + // will try to resolve the target at a later date. + for (ComponentService service : componentReference.getTargets()) { + if (service.isUnresolved()) { + SCABinding scaBinding = null; + + // find the sca binding amongst the candidate binding list. We want to + // find this one and clone it as it may have been configured with + // policies + for (Binding binding : service.getBindings()) { + + if (binding instanceof SCABinding) { + try { + scaBinding = (SCABinding)((OptimizableBinding)binding).clone(); + } catch (CloneNotSupportedException ex){ + // we know it is supported on the SCA binding + } + break; + } + } + + if (scaBinding != null) { + // configure the cloned SCA binding for this reference target + scaBinding.setName(service.getName()); + + // this service object holds the list of candidate bindings which + // can be used for later matching + ((OptimizableBinding)scaBinding).setTargetComponentService(service); + componentReference.getBindings().add(scaBinding); + } else { + // not sure we need to raise a warning here as a warning will already been + // thrown previously to indicate the reason why there is no sca binding + // warning("NoSCABindingAvailableForUnresolvedService", componentReference, componentReference.getName(), service.getName()); + } + } + } + } + +*/ + // Connect the optimizable bindings to their target component and + // service +/* + for (Binding binding : componentReference.getBindings()) { + if (!(binding instanceof OptimizableBinding)) { + continue; + } + OptimizableBinding optimizableBinding = (OptimizableBinding)binding; + if (optimizableBinding.getTargetComponentService() != null) { + continue; + } + String uri = optimizableBinding.getURI(); + if (uri == null) { + continue; + } + uri = URI.create(uri).getPath(); + if (uri.startsWith("/")) { + uri = uri.substring(1); + } + + // Resolve the target component and service + ComponentService targetComponentService = componentServices.get(uri); + Component targetComponent; + int s = uri.indexOf('/'); + if (s == -1) { + targetComponent = components.get(uri); + } else { + targetComponent = components.get(uri.substring(0, s)); + } + + if (targetComponentService != null) { + + // Check that the target component service provides + // a superset of the component reference interface + if (componentReference.getInterfaceContract() == null || + interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) { + + } else { + warning("ReferenceIncompatibleInterface", + composite, + composite.getName().toString(), + componentReference.getName(), + uri); + } + optimizableBinding.setTargetComponent(targetComponent); + optimizableBinding.setTargetComponentService(targetComponentService); + optimizableBinding.setTargetBinding(targetComponentService.getBinding(optimizableBinding.getClass())); + } + } +*/ + } + } + + /** + * Resolve wires and connect the sources to their targets + * + * @param composite + * @param componentServices + * @param componentReferences + * @param problems + */ + private void connectWires(Composite composite, + Map componentServices, + Map componentReferences) { + + // For each wire, resolve the source reference, the target service, and + // add it to the list of targets of the reference + List wires = composite.getWires(); + for (int i = 0, n = wires.size(); i < n; i++) { + Wire wire = wires.get(i); + + ComponentReference resolvedReference; + ComponentService resolvedService; + + // Resolve the source reference + ComponentReference source = wire.getSource(); + if (source != null && source.isUnresolved()) { + resolvedReference = componentReferences.get(source.getName()); + if (resolvedReference != null) { + wire.setSource(resolvedReference); + } else { + warning("WireSourceNotFound", composite, source.getName()); + } + } else { + resolvedReference = wire.getSource(); + } + + // Resolve the target service + ComponentService target = wire.getTarget(); + if (target != null && target.isUnresolved()) { + resolvedService = componentServices.get(target.getName()); + if (resolvedService != null) { + wire.setTarget(target); + } else { + warning("WireTargetNotFound", composite, source.getName()); + } + } else { + resolvedService = wire.getTarget(); + } + + // Add the target service to the list of targets of the + // reference + if (resolvedReference != null && resolvedService != null) { + // Check that the target component service provides + // a superset of + // the component reference interface + if (resolvedReference.getInterfaceContract() == null || interfaceContractMapper + .isCompatible(resolvedReference.getInterfaceContract(), resolvedService.getInterfaceContract())) { + + //resolvedReference.getTargets().add(resolvedService); + resolvedReference.getTargets().add(wire.getTarget()); + } else { + warning("WireIncompatibleInterface", composite, source.getName(), target.getName()); + } + } + } + + // Clear the list of wires + composite.getWires().clear(); + } + + private void addPoliciesFromPromotedService(CompositeService compositeService) { + //inherit intents and policies from promoted service + PolicyComputationUtils.addInheritedIntents(compositeService.getPromotedService().getRequiredIntents(), + compositeService.getRequiredIntents()); + PolicyComputationUtils.addInheritedPolicySets(compositeService.getPromotedService().getPolicySets(), + compositeService.getPolicySets(), true); + addInheritedOperationConfigurations(compositeService.getPromotedService(), compositeService); + } + + private void addPoliciesFromPromotedReference(CompositeReference compositeReference) { + for ( Reference promotedReference : compositeReference.getPromotedReferences() ) { + PolicyComputationUtils.addInheritedIntents(promotedReference.getRequiredIntents(), + compositeReference.getRequiredIntents()); + + PolicyComputationUtils.addInheritedPolicySets(promotedReference.getPolicySets(), + compositeReference.getPolicySets(), true); + addInheritedOperationConfigurations(promotedReference, compositeReference); + } + } + + + protected void computePolicies(Composite composite) { + + // compute policies recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + computePolicies((Composite)implementation); + } + } + + for (Component component : composite.getComponents()) { + + // Inherit default policies from the component to component-level contracts. + // This must be done BEFORE computing implementation policies because the + // implementation policy computer removes from the component any + // intents and policy sets that don't apply to implementations. + PolicyConfigurationUtil.inheritDefaultPolicies(component, component.getServices()); + PolicyConfigurationUtil.inheritDefaultPolicies(component, component.getReferences()); + + Implementation implemenation = component.getImplementation(); + try { + PolicyConfigurationUtil.computeImplementationIntentsAndPolicySets(implemenation, component); + } catch ( Exception e ) { + error("PolicyRelatedException", implemenation, e); + //throw new RuntimeException(e); + } + + for (ComponentService componentService : component.getServices()) { + Service service = componentService.getService(); + if (service != null) { + // reconcile intents and policysets from componentType + PolicyComputationUtils.addInheritedIntents(service.getRequiredIntents(), componentService.getRequiredIntents()); + PolicyComputationUtils.addInheritedPolicySets(service.getPolicySets(), componentService.getPolicySets(), true); + + //reconcile intents and policysets for operations + boolean notFound; + List opsFromComponentType = new ArrayList(); + for ( ConfiguredOperation ctsConfOp : service.getConfiguredOperations() ) { + notFound = true; + for ( ConfiguredOperation csConfOp : componentService.getConfiguredOperations() ) { + if ( csConfOp.getName().equals(ctsConfOp.getName()) ) { + PolicyComputationUtils.addInheritedIntents(ctsConfOp.getRequiredIntents(), csConfOp.getRequiredIntents()); + PolicyComputationUtils.addInheritedPolicySets(ctsConfOp.getPolicySets(), csConfOp.getPolicySets(), true); + notFound = false; + } + } + + if ( notFound ) { + opsFromComponentType.add(ctsConfOp); + } + } + componentService.getConfiguredOperations().addAll(opsFromComponentType); + } + + try { + //compute the intents for operations under service element + PolicyConfigurationUtil.computeIntentsForOperations(componentService); + //compute intents and policyset for each binding + //addInheritedOpConfOnBindings(componentService); + PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(componentService); + PolicyConfigurationUtil.determineApplicableBindingPolicySets(componentService, null); + + } catch ( Exception e ) { + error("PolicyRelatedException", componentService, e); + //throw new RuntimeException(e); + } + } + + for (ComponentReference componentReference : component.getReferences()) { + Reference reference = componentReference.getReference(); + if (reference != null) { + // reconcile intents and policysets + PolicyComputationUtils.addInheritedIntents(reference.getRequiredIntents(), componentReference.getRequiredIntents()); + PolicyComputationUtils.addInheritedPolicySets(reference.getPolicySets(), componentReference.getPolicySets(), true); + } + + + try { + //compute the intents for operations under reference element + PolicyConfigurationUtil.computeIntentsForOperations(componentReference); + //compute intents and policyset for each binding + //addInheritedOpConfOnBindings(componentReference); + PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(componentReference); + PolicyConfigurationUtil.determineApplicableBindingPolicySets(componentReference, null); + + + if ( componentReference.getCallback() != null ) { + PolicyComputationUtils.addInheritedIntents(componentReference.getRequiredIntents(), + componentReference.getCallback().getRequiredIntents()); + PolicyComputationUtils.addInheritedPolicySets(componentReference.getPolicySets(), + componentReference.getCallback().getPolicySets(), + false); + } + } catch ( Exception e ) { + error("PolicyRelatedException", componentReference, e); + //throw new RuntimeException(e); + } + } + } + + PolicyConfigurationUtil.inheritDefaultPolicies(composite, composite.getServices()); + PolicyConfigurationUtil.inheritDefaultPolicies(composite, composite.getReferences()); + + //compute policies for composite service bindings + for (Service service : composite.getServices()) { + addPoliciesFromPromotedService((CompositeService)service); + try { + //compute the intents for operations under service element + PolicyConfigurationUtil.computeIntentsForOperations(service); + //add or merge service operations to the binding + //addInheritedOpConfOnBindings(service); + PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(service); + PolicyConfigurationUtil.determineApplicableBindingPolicySets(service, null); + } catch ( Exception e ) { + error("PolicyRelatedException", service, e); + //throw new RuntimeException(e); + } + + } + + for (Reference reference : composite.getReferences()) { + CompositeReference compReference = (CompositeReference)reference; + addPoliciesFromPromotedReference(compReference); + try { + //compute the intents for operations under service element + PolicyConfigurationUtil.computeIntentsForOperations(reference); + //addInheritedOpConfOnBindings(reference); + + if (compReference.getCallback() != null) { + PolicyComputationUtils.addInheritedIntents(compReference.getRequiredIntents(), + compReference.getCallback().getRequiredIntents()); + PolicyComputationUtils.addInheritedPolicySets(compReference.getPolicySets(), + compReference.getCallback().getPolicySets(), + false); + } + + PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(reference); + PolicyConfigurationUtil.determineApplicableBindingPolicySets(reference, null); + } catch ( Exception e ) { + error("PolicyRelatedException", reference, e); + //throw new RuntimeException(e); + } + } + + } + + private void addInheritedOperationConfigurations(OperationsConfigurator source, + OperationsConfigurator target) { + boolean found = false; + + List additionalOperations = new ArrayList(); + for ( ConfiguredOperation sourceConfOp : source.getConfiguredOperations() ) { + for ( ConfiguredOperation targetConfOp : target.getConfiguredOperations() ) { + if ( sourceConfOp.getName().equals(targetConfOp.getName())) { + PolicyComputationUtils.addInheritedIntents(sourceConfOp.getRequiredIntents(), + targetConfOp.getRequiredIntents()); + PolicyComputationUtils.addInheritedPolicySets(sourceConfOp.getPolicySets(), + targetConfOp.getPolicySets(), true); + found = true; + break; + } + } + + if ( !found ) { + additionalOperations.add(sourceConfOp); + } + } + + if ( !additionalOperations.isEmpty() ) { + target.getConfiguredOperations().addAll(additionalOperations); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java new file mode 100644 index 0000000000..2842ae82bb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * This class encapsulates utility methods to deal with binding definitions + * + * @version $Rev$ $Date$ + */ +abstract class BindingConfigurationUtil { + private static boolean hasCompatiblePolicySets(Binding refBinding, Binding svcBinding) { + boolean isCompatible = true; + if ( refBinding instanceof PolicySetAttachPoint && svcBinding instanceof PolicySetAttachPoint ) { + //TODO : need to add more compatibility checks at the policy attachment levels + for ( PolicySet svcPolicySet : ((PolicySetAttachPoint)svcBinding).getPolicySets() ) { + isCompatible = false; + for ( PolicySet refPolicySet : ((PolicySetAttachPoint)refBinding).getPolicySets() ) { + if ( svcPolicySet.equals(refPolicySet) ) { + isCompatible = true; + break; + } + } + //if there exists no matching policy set in the reference binding + if ( !isCompatible ) { + return isCompatible; + } + } + } + return isCompatible; + } + + + static Binding matchBinding(Component targetComponent, ComponentService targetComponentService, + List source, List target, + Map bindingMap, boolean isCallback) { + List matched = new ArrayList(); + // Find the corresponding bindings from the service side + for (Binding binding : source) { + for (Binding serviceBinding : target) { + if (binding.getClass() == serviceBinding.getClass() && + hasCompatiblePolicySets(binding, serviceBinding)) { + + try { + // If the service binding or callback binding was given a tentative URI by + // constructBindingURI() and the target component is running on a different node + // than the source component, add host/port information to the binding URI + if (bindingMap != null) { + Binding sourceNodeBinding = bindingMap.get(binding); + Binding targetNodeBinding = bindingMap.get(serviceBinding); + if (targetNodeBinding != null + && sourceNodeBinding != null + && targetNodeBinding != sourceNodeBinding) { + if (!isCallback) { + serviceBinding.setURI(targetNodeBinding.getURI() + serviceBinding.getURI()); + bindingMap.remove(serviceBinding); // don't add this again + } else { + binding.setURI(sourceNodeBinding.getURI() + binding.getURI()); + bindingMap.remove(binding); // don't add this again + } + } + } + + Binding cloned = (Binding)binding.clone(); + + //Customise the binding name to make it unique + // regardless of how many bindings or targets there are + if ( targetComponent != null){ + cloned.setName(binding.getName() + "--" + targetComponent.getName() + ".." + serviceBinding.getName()); + } else { + cloned.setName(binding.getName() + "--" + serviceBinding.getName()); + } + + // Set the binding URI to the URI of the target service + // that has been matched + if (binding.getURI() == null) { + cloned.setURI(serviceBinding.getURI()); + } + + if (binding instanceof OptimizableBinding) { + OptimizableBinding endpoint = ((OptimizableBinding)cloned); + endpoint.setTargetComponent(targetComponent); + endpoint.setTargetComponentService(targetComponentService); + endpoint.setTargetBinding(serviceBinding); + } + + matched.add(cloned); + break; + } catch (Exception ex) { + // do nothing + } + } + } + } + if (matched.isEmpty()) { + // No matching binding + return null; + } else { + for (Binding binding : matched) { + // If binding.sca is present, use it + if (SCABinding.class.isInstance(binding)) { + return binding; + } + } + // Use the first one + return matched.get(0); + } + } + + /** + * Choose a binding for the reference based on the bindings available on the + * service + * + * @param reference The component reference + * @param service The component service + * @return Resolved binding + */ + static Binding resolveBindings(ComponentReference reference, Component component, ComponentService service, + Map bindingMap) { + List source = reference.getBindings(); + List target = service.getBindings(); + + return matchBinding(component, service, source, target, bindingMap, false); + + } + + + /** + * @param reference + * @param service + * @return + */ + static Binding resolveCallbackBindings(ComponentReference reference, Component component, ComponentService service, + Map bindingMap) { + List source = reference.getCallback().getBindings(); + List target = service.getCallback().getBindings(); + + return matchBinding(component, service, source, target, bindingMap, true); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java new file mode 100644 index 0000000000..0643421a45 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that handles the configuration of components. + * + * @version $Rev$ $Date$ + */ +public class ComponentConfigurationBuilderImpl extends BaseConfigurationBuilderImpl implements CompositeBuilder { + + @Deprecated + public ComponentConfigurationBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + super(assemblyFactory, scaBindingFactory, + null, null, + interfaceContractMapper, policyDefinitions, monitor); + } + + public ComponentConfigurationBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + super(assemblyFactory, scaBindingFactory, + documentBuilderFactory, transformerFactory, + interfaceContractMapper, policyDefinitions, monitor); + } + + public void build(Composite composite) throws CompositeBuilderException { + configureComponents(composite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java new file mode 100644 index 0000000000..4913705e91 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.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.sca.assembly.builder.impl; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that performs any additional building steps that + * component reference bindings may need. Used for WSDL generation. + * + * @version $Rev$ $Date$ + */ +public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { + private Monitor monitor; + + public ComponentReferenceBindingBuilderImpl(Monitor monitor) { + this.monitor = monitor; + } + + public void build(Composite composite) throws CompositeBuilderException { + buildReferenceBindings(composite); + } + + private void buildReferenceBindings(Composite composite) { + + // find all the component reference bindings (starting at top level) + for (Component component : composite.getComponents()) { + for (ComponentReference componentReference : component.getReferences()) { + for (Binding binding : componentReference.getBindings()) { + if (binding instanceof BindingBuilderExtension) { + ((BindingBuilderExtension)binding).getBuilder().build(component, componentReference, binding, monitor); + } + } + } + } + + // build bindings recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + buildReferenceBindings((Composite)implementation); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java new file mode 100644 index 0000000000..c0702c87b3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.EndpointFactory; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that handles the creation of promoted composite services. + * + * @version $Rev$ $Date$ + */ +public class ComponentReferencePromotionWireBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + private EndpointFactory endpointFactory; + private Monitor monitor; + + public ComponentReferencePromotionWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, Monitor monitor) { + this.assemblyFactory = assemblyFactory; + this.endpointFactory = endpointFactory; + this.monitor = monitor; + } + + public void build(Composite composite) throws CompositeBuilderException { + wireCompositeReferences(composite); + } + + /** + * Wire composite references in nested composites. + * + * @param composite + * @param problems + */ + private void wireCompositeReferences(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + wireCompositeReferences((Composite)implementation); + } + } + + // Process component references declared on components in this composite + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + for (ComponentReference componentReference : component.getReferences()) { + Reference implReference = componentReference.getReference(); + if (implReference != null && implReference instanceof CompositeReference) { + + // If the component reference is wired, it is a promotion override + if (!componentReference.getEndpoints().isEmpty()) { + componentReference.setPromotionOverride(true); + } + + // If the component reference is a promotion override, override the + // configuration of the promoted reference + if (componentReference.isPromotionOverride()) { + CompositeReference compositeReference = (CompositeReference)implReference; + List promotedReferences = + ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference); + for (ComponentReference promotedReference : promotedReferences) { + ReferenceConfigurationUtil.reconcileReferenceBindings( + componentReference, promotedReference, assemblyFactory, endpointFactory, monitor); + if (componentReference.getInterfaceContract() != null && // can be null in unit tests + componentReference.getInterfaceContract().getCallbackInterface() != null) { + SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class); + if (promotedReference.getCallback() != null) { + promotedReference.getCallback().getBindings().clear(); + } else { + promotedReference.setCallback(assemblyFactory.createCallback()); + } + if (scaCallbackBinding != null) { + promotedReference.getCallback().getBindings().add(scaCallbackBinding); + } + if (componentReference.getCallback() != null) { + promotedReference.getCallback().getBindings().addAll(componentReference + .getCallback().getBindings()); + } + } + + // Wire the promoted reference to the actual non-composite component services + if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE) { + // promotedReference.getTargets().clear(); + } + for (ComponentService target : componentReference.getTargets()) { + if (target.getService() instanceof CompositeService) { + + // Wire to the actual component service + // promoted by a composite service + CompositeService compositeService = (CompositeService)target.getService(); + // Find the promoted component service + ComponentService componentService = + ServiceConfigurationUtil.getPromotedComponentService(compositeService); + if (componentService != null) { + promotedReference.getTargets().add(componentService); + } + } else { + + // Wire to a non-composite target service + promotedReference.getTargets().add(target); + } + } + } + } + } + } + } else { + for (ComponentReference componentReference : component.getReferences()) { + + // Wire the component reference to the actual + // non-composite component services + List targets = componentReference.getTargets(); + for (int i = 0, n = targets.size(); i < n; i++) { + ComponentService target = targets.get(i); + if (target.getService() instanceof CompositeService) { + + // Wire to the actual component service + // promoted by a composite service + CompositeService compositeService = (CompositeService)target.getService(); + ComponentService componentService = compositeService.getPromotedService(); + if (componentService != null) { + targets.set(i, componentService); + } + } + } + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java new file mode 100644 index 0000000000..723b478889 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.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.sca.assembly.builder.impl; + +import java.util.Map; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.EndpointFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that wires component references. + * + * @version $Rev$ $Date$ + */ +public class ComponentReferenceWireBuilderImpl extends BaseWireBuilderImpl implements CompositeBuilder { + + public ComponentReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, + InterfaceContractMapper interfaceContractMapper, Monitor monitor, + Map bindingMap) { + super(assemblyFactory, endpointFactory, interfaceContractMapper, monitor, bindingMap); + } + + public void build(Composite composite) throws CompositeBuilderException { + wireComponentReferences(composite); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java new file mode 100644 index 0000000000..12ea86eac3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.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.sca.assembly.builder.impl; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.BindingBuilder; +import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that performs any additional building steps that + * component service bindings may need. Used for WSDL generation. + * + * @version $Rev$ $Date$ + */ +public class ComponentServiceBindingBuilderImpl implements CompositeBuilder { + private Monitor monitor; + + public ComponentServiceBindingBuilderImpl(Monitor monitor) { + this.monitor = monitor; + } + + public void build(Composite composite) throws CompositeBuilderException { + buildServiceBindings(composite); + } + + private void buildServiceBindings(Composite composite) { + + // build bindings recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + buildServiceBindings((Composite)implementation); + } + } + + // find all the component service bindings + for (Component component : composite.getComponents()) { + for (ComponentService componentService : component.getServices()) { + for (Binding binding : componentService.getBindings()) { + if (binding instanceof BindingBuilderExtension) { + BindingBuilder builder = ((BindingBuilderExtension)binding).getBuilder(); + if (builder != null) { + builder.build(component, componentService, binding, monitor); + } + } + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java new file mode 100644 index 0000000000..ce3f817acf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.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.sca.assembly.builder.impl; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; + +/** + * A composite builder that handles the creation of promoted services. + * + * @version $Rev$ $Date$ + */ +public class ComponentServicePromotionBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + + public ComponentServicePromotionBuilderImpl(AssemblyFactory assemblyFactory) { + this.assemblyFactory = assemblyFactory; + } + + public void build(Composite composite) throws CompositeBuilderException { + + // Process nested composites recursively + configureNestedCompositeServices(composite); + } + + private void configureNestedCompositeServices(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // First process nested composites + configureNestedCompositeServices((Composite)implementation); + + // Process the component services declared on components in this composite + for (ComponentService componentService : component.getServices()) { + Service implService = componentService.getService(); + if (implService != null && implService instanceof CompositeService) { + CompositeService compositeService = (CompositeService)implService; + + // Get the innermost promoted service + ComponentService promotedService = + ServiceConfigurationUtil.getPromotedComponentService(compositeService); + if (promotedService != null) { + Component promotedComponent = ServiceConfigurationUtil.getPromotedComponent(compositeService); + + // Create a new component service to represent this + // component service on the promoted component + ComponentService newComponentService = assemblyFactory.createComponentService(); + newComponentService.setName("$promoted$" + component.getName() + "$slash$" + componentService.getName()); + promotedComponent.getServices().add(newComponentService); + newComponentService.setService(promotedService.getService()); + newComponentService.getBindings().addAll(componentService.getBindings()); + newComponentService.setInterfaceContract(componentService.getInterfaceContract()); + + if (componentService.getInterfaceContract() != null && + componentService.getInterfaceContract().getCallbackInterface() != null) { + newComponentService.setCallback(assemblyFactory.createCallback()); + newComponentService.getCallback().getBindings() + .addAll(componentService.getCallback().getBindings()); + ComponentReference callbackReference = + BaseConfigurationBuilderImpl.createCallbackReference(promotedComponent, newComponentService, + assemblyFactory); + callbackReference.getBindings().addAll(componentService.getCallback().getBindings()); + newComponentService.setCallbackReference(callbackReference); + } + + // Change the composite service to now promote the + // newly created component service directly + compositeService.setPromotedComponent(promotedComponent); + compositeService.setPromotedService(newComponentService); + } + } + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java new file mode 100644 index 0000000000..85af173c0d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that handles the configuration of binding URIs. + * + * @version $Rev$ $Date$ + */ +public class CompositeBindingURIBuilderImpl extends BaseConfigurationBuilderImpl implements CompositeBuilder { + + @Deprecated + public CompositeBindingURIBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + super(assemblyFactory, scaBindingFactory, + null, null, + interfaceContractMapper, policyDefinitions, monitor); + } + + public CompositeBindingURIBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + super(assemblyFactory, scaBindingFactory, + documentBuilderFactory, transformerFactory, + interfaceContractMapper, policyDefinitions, monitor); + } + + public void build(Composite composite) throws CompositeBuilderException { + configureBindingURIsAndNames(composite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java new file mode 100644 index 0000000000..5eedcae190 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java @@ -0,0 +1,278 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.Map; +import java.util.logging.Logger; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.DefaultEndpointFactory; +import org.apache.tuscany.sca.assembly.EndpointFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; + +/** + * A builder that handles the configuration of the components inside a composite + * and the wiring of component references to component services. + * + * @version $Rev$ $Date$ + */ +public class CompositeBuilderImpl implements CompositeBuilder { + private static final Logger logger = Logger.getLogger(CompositeBuilderImpl.class.getName()); + private CompositeBuilder compositeIncludeBuilder; + private CompositeBuilder componentReferenceWireBuilder; + private CompositeBuilder componentReferencePromotionWireBuilder; + private CompositeBuilder compositeReferenceWireBuilder; + private CompositeBuilder compositeCloneBuilder; + private CompositeBuilder componentConfigurationBuilder; + private CompositeBuilder compositeServiceConfigurationBuilder; + private CompositeBuilder compositeReferenceConfigurationBuilder; + private CompositeBuilder compositeBindingURIBuilder; + private CompositeBuilder componentServicePromotionBuilder; + private CompositeBuilder compositeServicePromotionBuilder; + private CompositeBuilder compositePromotionBuilder; + private CompositeBuilder compositePolicyBuilder; + private CompositeBuilder componentServiceBindingBuilder; + private CompositeBuilder componentReferenceBindingBuilder; + private Map bindingMap = null; + + /** + * Constructs a new composite builder. + * + * @param assemblyFactory + * @param endpointFactory + * @param scaBindingFactory + * @param intentAttachPointTypeFactory + * @param interfaceContractMapper + * @param policyDefinitions + * @param monitor + */ + @Deprecated + public CompositeBuilderImpl(AssemblyFactory assemblyFactory, + EndpointFactory endpointFactory, + SCABindingFactory scaBindingFactory, + IntentAttachPointTypeFactory intentAttachPointTypeFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + this(assemblyFactory, endpointFactory, scaBindingFactory, intentAttachPointTypeFactory, + null, null, interfaceContractMapper, policyDefinitions, monitor, null); + } + + /** + * Constructs a new composite builder. + * + * @param assemblyFactory + * @param scaBindingFactory + * @param intentAttachPointTypeFactory + * @param interfaceContractMapper + * @param monitor + */ + @Deprecated + public CompositeBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + IntentAttachPointTypeFactory intentAttachPointTypeFactory, + InterfaceContractMapper interfaceContractMapper, + Monitor monitor) { + this(assemblyFactory, null, scaBindingFactory, intentAttachPointTypeFactory, + null, null, interfaceContractMapper, null, monitor, null); + } + + /** + * Constructs a new composite builder. + * + * @param assemblyFactory + * @param scaBindingFactory + * @param intentAttachPointTypeFactory + * @param documentBuilderFactory + * @param transformerFactory + * @param interfaceContractMapper + * @param monitor + */ + public CompositeBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + IntentAttachPointTypeFactory intentAttachPointTypeFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, + InterfaceContractMapper interfaceContractMapper, + Monitor monitor) { + this(assemblyFactory, null, scaBindingFactory, intentAttachPointTypeFactory, + documentBuilderFactory, transformerFactory, interfaceContractMapper, null, monitor, null); + } + + /** + * Constructs a new composite builder. + * + * @param assemblyFactory + * @param scaBindingFactory + * @param intentAttachPointTypeFactory + * @param documentBuilderFactory + * @param transformerFactory + * @param interfaceContractMapper + * @param monitor + * @param bindingMap + */ + public CompositeBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + IntentAttachPointTypeFactory intentAttachPointTypeFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, + InterfaceContractMapper interfaceContractMapper, + Monitor monitor, + Map bindingMap) { + this(assemblyFactory, null, scaBindingFactory, intentAttachPointTypeFactory, + documentBuilderFactory, transformerFactory, interfaceContractMapper, null, monitor, bindingMap); + } + + /** + * Constructs a new composite builder. + * + * @param assemblyFactory + * @param endpointFactory + * @param scaBindingFactory + * @param intentAttachPointTypeFactory + * @param documentBuilderFactory + * @param transformerFactory + * @param interfaceContractMapper + * @param policyDefinitions + * @param monitor + */ + public CompositeBuilderImpl(AssemblyFactory assemblyFactory, + EndpointFactory endpointFactory, + SCABindingFactory scaBindingFactory, + IntentAttachPointTypeFactory intentAttachPointTypeFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + this(assemblyFactory, endpointFactory, scaBindingFactory, intentAttachPointTypeFactory, + documentBuilderFactory, transformerFactory, interfaceContractMapper, + policyDefinitions, monitor, null); + } + + /** + * Constructs a new composite builder. + * + * @param assemblyFactory + * @param endpointFactory + * @param scaBindingFactory + * @param intentAttachPointTypeFactory + * @param documentBuilderFactory + * @param transformerFactory + * @param interfaceContractMapper + * @param policyDefinitions + * @param bindingMap + */ + public CompositeBuilderImpl(AssemblyFactory assemblyFactory, + EndpointFactory endpointFactory, + SCABindingFactory scaBindingFactory, + IntentAttachPointTypeFactory intentAttachPointTypeFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor, + Map bindingMap) { + + if (endpointFactory == null){ + endpointFactory = new DefaultEndpointFactory(); + } + + compositeIncludeBuilder = new CompositeIncludeBuilderImpl(monitor); + componentReferenceWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor, bindingMap); + componentReferencePromotionWireBuilder = new ComponentReferencePromotionWireBuilderImpl(assemblyFactory, endpointFactory, monitor); + compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, endpointFactory, monitor); + compositeCloneBuilder = new CompositeCloneBuilderImpl(monitor); + componentConfigurationBuilder = new ComponentConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, documentBuilderFactory, transformerFactory, interfaceContractMapper, policyDefinitions, monitor); + compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(assemblyFactory); + compositeReferenceConfigurationBuilder = new CompositeReferenceConfigurationBuilderImpl(assemblyFactory); + compositeBindingURIBuilder = new CompositeBindingURIBuilderImpl(assemblyFactory, scaBindingFactory, documentBuilderFactory, transformerFactory, interfaceContractMapper, policyDefinitions, monitor); + componentServicePromotionBuilder = new ComponentServicePromotionBuilderImpl(assemblyFactory); + compositeServicePromotionBuilder = new CompositeServicePromotionBuilderImpl(assemblyFactory); + compositePromotionBuilder = new CompositePromotionBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor); + compositePolicyBuilder = new CompositePolicyBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor); + componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(monitor); + componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(monitor); + } + + public void build(Composite composite) throws CompositeBuilderException { + + // Collect and fuse includes + compositeIncludeBuilder.build(composite); + + // Expand nested composites + compositeCloneBuilder.build(composite); + + // Configure all components + componentConfigurationBuilder.build(composite); + + // Connect composite services/references to promoted services/references + compositePromotionBuilder.build(composite); + + // Compute the policies across the model hierarchy + compositePolicyBuilder.build(composite); + + // Configure composite services + compositeServiceConfigurationBuilder.build(composite); + + // Configure composite references + compositeReferenceConfigurationBuilder.build(composite); + + // Configure binding URIs + compositeBindingURIBuilder.build(composite); + + // Create promoted component services + componentServicePromotionBuilder.build(composite); + + // Create promoted composite services + compositeServicePromotionBuilder.build(composite); + + // Build component service binding-related information + componentServiceBindingBuilder.build(composite); + + // Wire the components + componentReferenceWireBuilder.build(composite); + + // Wire the promoted component references + componentReferencePromotionWireBuilder.build(composite); + + // Wire the composite references + compositeReferenceWireBuilder.build(composite); + + // Build component reference binding-related information + componentReferenceBindingBuilder.build(composite); + + // Fuse nested composites + //FIXME do this later + //cloneBuilder.fuseCompositeImplementations(composite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java new file mode 100644 index 0000000000..5779ddbc78 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that clones nested composites. + * + * @version $Rev$ $Date$ + */ +public class CompositeCloneBuilderImpl implements CompositeBuilder { + + public CompositeCloneBuilderImpl(Monitor monitor) { + } + + public void build(Composite composite) throws CompositeBuilderException { + expandCompositeImplementations(composite); + } + + /** + * Expand composite component implementations. + * + * @param composite + * @param problems + */ + private void expandCompositeImplementations(Composite composite) { + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + Composite compositeImplementation = (Composite)implementation; + Composite clone; + try { + clone = (Composite)compositeImplementation.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + component.setImplementation(clone); + expandCompositeImplementations(clone); + } + } + } + + /** + * Collect all nested composite implementations in a graph of composites. + * + * @param composite + * @param nested + */ + private void collectNestedComposites(Composite composite, List nested) { + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + Composite nestedComposite = (Composite)implementation; + nested.add(nestedComposite); + collectNestedComposites(nestedComposite, nested); + } + } + } + + /** + * Fuse nested composites into a top level composite. + * + * @param composite + */ + private void fuseCompositeImplementations(Composite composite) { + + // First collect all nested composites + List nested = new ArrayList(); + collectNestedComposites(composite, nested); + + // Then add all the non-composite components they contain + for (Composite nestedComposite : nested) { + for (Component component: nestedComposite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (!(implementation instanceof Composite)) { + composite.getComponents().add(component); + } + } + } + + // Clear the initial list of composite components + for (Iterator i = composite.getComponents().iterator(); i.hasNext();) { + Component component = i.next(); + if (component.getImplementation() instanceof Composite) { + i.remove(); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java new file mode 100644 index 0000000000..28f40a077d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Implementation of a CompositeBuilder. + * + * @version $Rev$ $Date$ + */ +public class CompositeIncludeBuilderImpl implements CompositeBuilder { + + private Monitor monitor; + + public CompositeIncludeBuilderImpl(Monitor monitor) { + this.monitor = monitor; + } + + public void build(Composite composite) throws CompositeBuilderException { + fuseIncludes(composite); + } + + private void warning(String message, Object model, String... messageParameters) { + if (monitor != null){ + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Collect all includes in a graph of includes. + * + * @param composite + * @param includes + */ + private void collectIncludes(Composite composite, List includes, Set visited) { + for (Composite include : composite.getIncludes()) { + if (visited.contains(include)) { + warning("CompositeAlreadyIncluded", composite, include.getName().toString()); + continue; + } + + includes.add(include); + visited.add(include); + collectIncludes(include, includes, visited); + } + } + + /** + * Copy a list of includes into a composite. + * + * @param composite + */ + private void fuseIncludes(Composite composite) { + + // First collect all includes + List includes = new ArrayList(); + Set visited = new HashSet(); + visited.add(composite); + collectIncludes(composite, includes, visited); + // Then clone them + for (Composite include : includes) { + Composite clone; + try { + clone = (Composite)include.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + composite.getComponents().addAll(clone.getComponents()); + composite.getServices().addAll(clone.getServices()); + composite.getReferences().addAll(clone.getReferences()); + composite.getProperties().addAll(clone.getProperties()); + composite.getWires().addAll(clone.getWires()); + composite.getPolicySets().addAll(clone.getPolicySets()); + composite.getRequiredIntents().addAll(clone.getRequiredIntents()); + } + + // Clear the list of includes + composite.getIncludes().clear(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java new file mode 100644 index 0000000000..a7c9a87038 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.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.sca.assembly.builder.impl; + + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.EndpointFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that computes policy sets based on attached intents and policy sets. + * Useful if you want to build the model without making any runtime decisions such as + * reference/services matching + * + * @version $Rev$ $Date$ + */ +public class CompositePolicyBuilderImpl extends BaseWireBuilderImpl implements CompositeBuilder { + + public CompositePolicyBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) { + super(assemblyFactory, endpointFactory, interfaceContractMapper, monitor, null); + } + + public void build(Composite composite) throws CompositeBuilderException { + computePolicies(composite); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java new file mode 100644 index 0000000000..9add794a81 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.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.sca.assembly.builder.impl; + + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.EndpointFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that makes the connections between composite services and references + * and the services and references that they promote + * + * @version $Rev$ $Date$ + */ +public class CompositePromotionBuilderImpl extends BaseWireBuilderImpl implements CompositeBuilder { + + public CompositePromotionBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) { + super(assemblyFactory, endpointFactory, interfaceContractMapper, monitor, null); + } + + public void build(Composite composite) throws CompositeBuilderException { + connectCompositeReferencesAndServices(composite); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java new file mode 100644 index 0000000000..41462b151d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.List; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.AutomaticBinding; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; + +/** + * A composite builder that handles the configuration of composite references. + * + * @version $Rev: 651179 $ $Date: 2008-04-24 08:21:13 +0100 (Thu, 24 Apr 2008) $ + */ +public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + + public CompositeReferenceConfigurationBuilderImpl(AssemblyFactory assemblyFactory) { + this.assemblyFactory = assemblyFactory; + } + + public void build(Composite composite) throws CompositeBuilderException { + + // Process nested composites recursively + configureNestedCompositeReferences(composite); + + // Process top level composite references + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + + // Get the next lower level promoted reference + List promotedRefs = compositeReference.getPromotedReferences(); + if (!promotedRefs.isEmpty()) { + if (promotedRefs.size() == 1) { + ComponentReference promotedReference = promotedRefs.get(0); + + // Set the bindings using the top level bindings to override the lower level bindings + if (bindingsSpecifiedManually(compositeReference.getBindings())) { + compositeReference.setPromotionOverride(true); + } else if (bindingsSpecifiedManually(promotedReference.getBindings()) ) { + compositeReference.getBindings().clear(); + for (Binding binding : promotedReference.getBindings()) { + try { + compositeReference.getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted reference + } + } + } + if (compositeReference.getInterfaceContract() != null && + compositeReference.getInterfaceContract().getCallbackInterface() != null) { + if (compositeReference.getCallback() != null && + bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) { + compositeReference.setPromotionOverride(true); + } else if (promotedReference.getCallback() != null && + bindingsSpecifiedManually(promotedReference.getCallback().getBindings())) { + if (compositeReference.getCallback() != null) { + compositeReference.getCallback().getBindings().clear(); + } else { + compositeReference.setCallback(assemblyFactory.createCallback()); + } + for (Binding binding : promotedReference.getCallback().getBindings()) { + try { + compositeReference.getCallback().getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted reference + } + } + } + } + } else { + // This composite reference promotes multiple component references. + // Because the component reference bindings can all be different, we don't + // copy any of them up to this composite reference, which will therefore always + // have its own binding, even if it's only the default SCA binding. + if (bindingsSpecifiedManually(compositeReference.getBindings()) || + (compositeReference.getCallback() != null && + bindingsSpecifiedManually(compositeReference.getCallback().getBindings()))) { + compositeReference.setPromotionOverride(true); + } + } + } + } + } + + private void configureNestedCompositeReferences(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // First process nested composites + configureNestedCompositeReferences((Composite)implementation); + + // Process the component references declared on components in this composite + for (ComponentReference componentReference : component.getReferences()) { + Reference implReference = componentReference.getReference(); + if (implReference != null && implReference instanceof CompositeReference) { + CompositeReference compositeReference = (CompositeReference)implReference; + + // Get the next lower level promoted reference + List promotedRefs = compositeReference.getPromotedReferences(); + if (!promotedRefs.isEmpty()) { + if (promotedRefs.size() == 1) { + ComponentReference promotedReference = promotedRefs.get(0); + + // Set the bindings using the top level bindings to override the lower level bindings + if (!bindingsSpecifiedManually(compositeReference.getBindings()) && + bindingsSpecifiedManually(promotedReference.getBindings()) ) { + compositeReference.getBindings().clear(); + for (Binding binding : promotedReference.getBindings()) { + try { + compositeReference.getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted reference + } + } + } + if (bindingsSpecifiedManually(componentReference.getBindings())) { + componentReference.setPromotionOverride(true); + } else if (bindingsSpecifiedManually(compositeReference.getBindings()) ) { + componentReference.getBindings().clear(); + componentReference.getBindings().addAll(compositeReference.getBindings()); + } + if (componentReference.getInterfaceContract() != null && + componentReference.getInterfaceContract().getCallbackInterface() != null) { + if (!(compositeReference.getCallback() != null && + bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) && + promotedReference.getCallback() != null && + bindingsSpecifiedManually(promotedReference.getCallback().getBindings())) { + if (compositeReference.getCallback() != null) { + compositeReference.getCallback().getBindings().clear(); + } else { + compositeReference.setCallback(assemblyFactory.createCallback()); + } + compositeReference.getCallback().getBindings().addAll( + promotedReference.getCallback().getBindings()); + } + if (componentReference.getCallback() != null && + bindingsSpecifiedManually(componentReference.getCallback().getBindings())) { + componentReference.setPromotionOverride(true); + } else if (compositeReference.getCallback() != null && + bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) { + if (componentReference.getCallback() != null) { + componentReference.getCallback().getBindings().clear(); + } else { + componentReference.setCallback(assemblyFactory.createCallback()); + } + for (Binding binding : compositeReference.getCallback().getBindings()) { + try { + componentReference.getCallback().getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted reference + } + } + } + } + } else { + // This component reference promotes multiple lower-level component references. + // Because the lower-level component reference bindings can all be different, + // we don't copy any of them up to this component reference, which will therefore + // always have its own binding, even if it's only the default SCA binding. + if (bindingsSpecifiedManually(componentReference.getBindings()) || + (componentReference.getCallback() != null && + bindingsSpecifiedManually(componentReference.getCallback().getBindings()))) { + componentReference.setPromotionOverride(true); + } + } + } + } + } + } + } + } + + /** + * If the bindings are specified in the composite file return true as they should + * otherwise return false + * + * @param bindings + * @return true if the bindings were specified manually + */ + private boolean bindingsSpecifiedManually(List bindings) { + + if (bindings.size() > 1) { + return true; + } else if (bindings.size() == 1 && + bindings.get(0) instanceof AutomaticBinding && + ((AutomaticBinding)bindings.get(0)).getIsAutomatic()) { + return false; + } else if (bindings.size() == 1) { + return true; + } else { + return false; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java new file mode 100644 index 0000000000..8aa1897311 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.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.sca.assembly.builder.impl; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.EndpointFactory; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that wires composite references. + * + * @version $Rev$ $Date$ + */ +public class CompositeReferenceWireBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + private EndpointFactory endpointFactory; + private Monitor monitor; + + public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, Monitor monitor) { + this.assemblyFactory = assemblyFactory; + this.endpointFactory = endpointFactory; + this.monitor = monitor; + } + + /** + * Wire composite references in a deployment composite. + * + * @param composite + */ + public void build(Composite composite) throws CompositeBuilderException { + + // Process composite references declared in this composite + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + + // If the composite reference is a promotion override, override the + // configuration of the promoted reference. + //FIXME: Policy configuration or wiring of domain-level composite references + // doesn't cause a promotion override, unless the composite reference has + // additional bindings. Do we need to detect this and force an override? + if (compositeReference.isPromotionOverride()) { + List promotedReferences = + ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference); + for (ComponentReference promotedReference : promotedReferences) { + ReferenceConfigurationUtil.reconcileReferenceBindings( + compositeReference, promotedReference, assemblyFactory, endpointFactory, monitor); + if (compositeReference.getInterfaceContract() != null && // can be null in unit tests + compositeReference.getInterfaceContract().getCallbackInterface() != null) { + SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class); + if (promotedReference.getCallback() != null) { + promotedReference.getCallback().getBindings().clear(); + } else { + promotedReference.setCallback(assemblyFactory.createCallback()); + } + if (scaCallbackBinding != null) { + promotedReference.getCallback().getBindings().add(scaCallbackBinding); + } + if (compositeReference.getCallback() != null) { + promotedReference.getCallback().getBindings().addAll(compositeReference.getCallback() + .getBindings()); + } + } + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java new file mode 100644 index 0000000000..3aa9f3bf85 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.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.sca.assembly.builder.impl; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that performs any additional building steps that + * composite service bindings may need. Used for WSDL generation. + * + * @version $Rev$ $Date$ + */ +public class CompositeServiceBindingBuilderImpl implements CompositeBuilder { + private Monitor monitor; + + public CompositeServiceBindingBuilderImpl(Monitor monitor) { + this.monitor = monitor; + } + + public void build(Composite composite) throws CompositeBuilderException { + buildServiceBindings(composite); + } + + private void buildServiceBindings(Composite composite) { + + // build bindings recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + buildServiceBindings((Composite)implementation); + } + } + + // find all the composite service bindings + for (Service service : composite.getServices()) { + for (Binding binding : service.getBindings()) { + if (binding instanceof BindingBuilderExtension) { + Component component = ServiceConfigurationUtil.getPromotedComponent((CompositeService)service); + ((BindingBuilderExtension)binding).getBuilder().build(component, service, binding, monitor); + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java new file mode 100644 index 0000000000..a3f31ea2fa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.List; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.AutomaticBinding; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; + +/** + * A composite builder that handles the configuration of composite services. + * + * @version $Rev$ $Date$ + */ +public class CompositeServiceConfigurationBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + + public CompositeServiceConfigurationBuilderImpl(AssemblyFactory assemblyFactory) { + this.assemblyFactory = assemblyFactory; + } + + public void build(Composite composite) throws CompositeBuilderException { + + // Process nested composites recursively + configureNestedCompositeServices(composite); + + // Process top level composite services + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + + // Get the next lower level promoted service + ComponentService promotedService = compositeService.getPromotedService(); + if (promotedService != null) { + + // Set the bindings using the top level bindings to override the lower level bindings + if (!bindingsSpecifiedManually(compositeService.getBindings()) && + bindingsSpecifiedManually(promotedService.getBindings())) { + compositeService.getBindings().clear(); + for (Binding binding : promotedService.getBindings()) { + try { + compositeService.getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted service + } + } + } + if (compositeService.getInterfaceContract() != null && + compositeService.getInterfaceContract().getCallbackInterface() != null) { + if (!(compositeService.getCallback() != null && + bindingsSpecifiedManually(compositeService.getCallback().getBindings())) && + promotedService.getCallback() != null && + bindingsSpecifiedManually(promotedService.getCallback().getBindings())) { + if (compositeService.getCallback() != null) { + compositeService.getCallback().getBindings().clear(); + } else { + compositeService.setCallback(assemblyFactory.createCallback()); + } + for (Binding binding : promotedService.getCallback().getBindings()) { + try { + compositeService.getCallback().getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted service + } + } + } + } + } + } + } + + private void configureNestedCompositeServices(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // First process nested composites + configureNestedCompositeServices((Composite)implementation); + + // Process the component services declared on components in this composite + for (ComponentService componentService : component.getServices()) { + Service implService = componentService.getService(); + if (implService != null && implService instanceof CompositeService) { + CompositeService compositeService = (CompositeService)implService; + + // Get the next lower level promoted service + ComponentService promotedService = compositeService.getPromotedService(); + if (promotedService != null) { + + // Set the bindings using the top level bindings to override the lower level bindings + if (!bindingsSpecifiedManually(compositeService.getBindings()) && + bindingsSpecifiedManually(promotedService.getBindings()) ) { + compositeService.getBindings().clear(); + for (Binding binding : promotedService.getBindings()) { + try { + compositeService.getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted service + } + } + } + if (!bindingsSpecifiedManually(componentService.getBindings()) && + bindingsSpecifiedManually(compositeService.getBindings()) ) { + componentService.getBindings().clear(); + componentService.getBindings().addAll(compositeService.getBindings()); + } + if (componentService.getInterfaceContract() != null && + componentService.getInterfaceContract().getCallbackInterface() != null) { + if (!(compositeService.getCallback() != null && + bindingsSpecifiedManually(compositeService.getCallback().getBindings())) && + promotedService.getCallback() != null && + bindingsSpecifiedManually(promotedService.getCallback().getBindings())) { + if (compositeService.getCallback() != null) { + compositeService.getCallback().getBindings().clear(); + } else { + compositeService.setCallback(assemblyFactory.createCallback()); + } + for (Binding binding : promotedService.getCallback().getBindings()) { + try { + compositeService.getCallback().getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted service + } + } + } + if (!(componentService.getCallback() != null && + bindingsSpecifiedManually(componentService.getCallback().getBindings())) && + compositeService.getCallback() != null && + bindingsSpecifiedManually(compositeService.getCallback().getBindings())) { + if (componentService.getCallback() != null) { + componentService.getCallback().getBindings().clear(); + } else { + componentService.setCallback(assemblyFactory.createCallback()); + } + componentService.getCallback().getBindings().addAll( + compositeService.getCallback().getBindings()); + } + } + } + } + } + } + } + } + + /** + * If the bindings are specified in the composite file return true as they should + * otherwise return false + * + * @param bindings + * @return true if the bindings were specified manually + */ + private boolean bindingsSpecifiedManually(List bindings) { + + if (bindings.size() > 1) { + return true; + } else if (bindings.size() == 1 && + bindings.get(0) instanceof AutomaticBinding && + ((AutomaticBinding)bindings.get(0)).getIsAutomatic()) { + return false; + } else if (bindings.size() == 1) { + return true; + } else { + return false; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java new file mode 100644 index 0000000000..38cbaf7744 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.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.sca.assembly.builder.impl; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; + +/** + * A composite builder that handles the creation of promoted composite services. + * + * @version $Rev$ $Date$ + */ +public class CompositeServicePromotionBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + + public CompositeServicePromotionBuilderImpl(AssemblyFactory assemblyFactory) { + this.assemblyFactory = assemblyFactory; + } + + public void build(Composite composite) throws CompositeBuilderException { + + // Process top level composite services + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + + // Get the innermost promoted service + ComponentService promotedService = ServiceConfigurationUtil.getPromotedComponentService(compositeService); + if (promotedService != null) { + Component promotedComponent = ServiceConfigurationUtil.getPromotedComponent(compositeService); + + // Create a new component service to represent this composite + // service on the promoted component + ComponentService newComponentService = assemblyFactory.createComponentService(); + newComponentService.setName("$promoted$" + compositeService.getName()); + promotedComponent.getServices().add(newComponentService); + newComponentService.setService(promotedService.getService()); + newComponentService.getBindings().addAll(compositeService.getBindings()); + newComponentService.setInterfaceContract(compositeService.getInterfaceContract()); + if (compositeService.getInterfaceContract() != null && + compositeService.getInterfaceContract().getCallbackInterface() != null) { + newComponentService.setCallback(assemblyFactory.createCallback()); + newComponentService.getCallback().getBindings() + .addAll(compositeService.getCallback().getBindings()); + ComponentReference callbackReference = + BaseConfigurationBuilderImpl.createCallbackReference(promotedComponent, newComponentService, + assemblyFactory); + callbackReference.getBindings().addAll(compositeService.getCallback().getBindings()); + newComponentService.setCallbackReference(callbackReference); + } + + // Change the composite service to now promote the newly + // created component service directly + compositeService.setPromotedComponent(promotedComponent); + compositeService.setPromotedService(newComponentService); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java new file mode 100644 index 0000000000..c261ba82f1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.Map; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.builder.EndpointBuilder; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * A factory for the Endpoint model. + * + * @version $Rev$ $Date$ + */ +public abstract class EndpointBuilderImpl implements EndpointBuilder { + + private Monitor monitor; + private Map bindingMap; + + public EndpointBuilderImpl (Monitor monitor, Map bindingMap) { + this.monitor = monitor; + this.bindingMap = bindingMap; + } + + private void warning(String message, Object model, String... messageParameters) { + if (monitor != null){ + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + private void error(String message, Object model, Exception ex) { + if (monitor != null){ + Problem problem = null; + problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + /** + * Resolve an endpoint against the provided target information and the + * set of candidate bindings. + */ + public void build(Endpoint endpoint) { + + // If this endpoint is not fully configured then don't try and resolve it + if (endpoint.getTargetComponentService() == null){ + return; + } + + // Does the reference expect callbacks + boolean bidirectional = false; + + if (endpoint.getSourceComponentReference().getInterfaceContract() != null && + endpoint.getSourceComponentReference().getInterfaceContract().getCallbackInterface() != null) { + bidirectional = true; + } + + // if the target service is a promoted service then find the + // service it promotes + if (endpoint.getTargetComponentService().getService() instanceof CompositeService) { + CompositeService compositeService = (CompositeService) endpoint.getTargetComponentService().getService(); + // Find the promoted component service + ComponentService promotedComponentService = ServiceConfigurationUtil.getPromotedComponentService(compositeService); + if (promotedComponentService != null && !promotedComponentService.isUnresolved()) { + endpoint.setTargetComponentService(promotedComponentService); + } + } + + try { + PolicyConfigurationUtil.determineApplicableBindingPolicySets(endpoint.getSourceComponentReference(), + endpoint.getTargetComponentService()); + } catch ( Exception e ) { + error("PolicyRelatedException", endpoint, e); + } + + + // Match the binding against the bindings of the target service + Binding resolvedBinding = BindingConfigurationUtil.matchBinding(endpoint.getTargetComponent(), + endpoint.getTargetComponentService(), + endpoint.getCandidateBindings(), + endpoint.getTargetComponentService().getBindings(), + bindingMap, false); + if (resolvedBinding == null) { + warning("NoMatchingBinding", + endpoint.getSourceComponentReference(), + endpoint.getSourceComponentReference().getName(), + endpoint.getTargetComponentService().getName()); + } else { + endpoint.setSourceBinding(resolvedBinding); + } + + if (bidirectional) { + Binding resolvedCallbackBinding = BindingConfigurationUtil.matchBinding(endpoint.getTargetComponent(), + endpoint.getTargetComponentService(), + endpoint.getSourceComponentReference().getCallback().getBindings(), + endpoint.getTargetComponentService().getCallback().getBindings(), + bindingMap, true); + if (resolvedBinding == null) { + warning("NoMatchingCallbackBinding", + endpoint.getSourceComponentReference(), + endpoint.getSourceComponentReference().getName(), + endpoint.getTargetComponentService().getName()); + } else { + endpoint.setSourceCallbackBinding(resolvedCallbackBinding); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.java new file mode 100644 index 0000000000..944cf2cf36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.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.sca.assembly.builder.impl; + +/** + * Exception to be throw for invalid policy intents / policysets + * + * @version $Rev$ $Date$ + */ +public class PolicyConfigurationException extends Exception { + private static final long serialVersionUID = 506979037642587755L; + + public PolicyConfigurationException(String message) { + super(message); + } + + public PolicyConfigurationException(Throwable e) { + super(e); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java new file mode 100644 index 0000000000..9adfaa2c56 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java @@ -0,0 +1,758 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.QualifiedIntent; +import org.apache.tuscany.sca.policy.util.PolicyComputationUtils; +import org.apache.tuscany.sca.policy.util.PolicyValidationException; +import org.apache.tuscany.sca.policy.util.PolicyValidationUtils; + +/** + * This class contains policy computation methods common to computing implementation and binding policies + * + * @version $Rev$ $Date$ + */ +abstract class PolicyConfigurationUtil { + + private static List computeInheritableIntents(IntentAttachPointType attachPointType, + List inheritableIntents) throws PolicyValidationException { + List validInheritableIntents = new ArrayList(); + + //expand profile intents in inherited intents + PolicyComputationUtils.expandProfileIntents(inheritableIntents); + + //validate if inherited intent applies to the attachpoint (binding / implementation) and + //only add such intents to the attachpoint (binding / implementation) + for (Intent intent : inheritableIntents) { + if ( !intent.isUnresolved() ) { + for (QName constrained : intent.getConstrains()) { + if ( PolicyValidationUtils.isConstrained(constrained, attachPointType)) { + validInheritableIntents.add(intent); + break; + } + } + } else { + throw new PolicyValidationException("Policy Intent '" + intent.getName() + "' is not defined in this domain"); + } + } + + return validInheritableIntents; + } + + private static void normalizeIntents(IntentAttachPoint intentAttachPoint) { + //expand profile intents specified in the attachpoint (binding / implementation) + PolicyComputationUtils.expandProfileIntents(intentAttachPoint.getRequiredIntents()); + + //remove duplicates and ... + //where qualified form of intent exists retain it and remove the qualifiable intent + filterDuplicatesAndQualifiableIntents(intentAttachPoint); + } + + private static void trimInherentlyProvidedIntents(IntentAttachPointType attachPointType, Listintents) { + //exclude intents that are inherently supported by the + //attachpoint-type (binding-type / implementation-type) + List requiredIntents = new ArrayList(intents); + for ( Intent intent : requiredIntents ) { + if ( isProvidedInherently(attachPointType, intent) ) { + intents.remove(intent); + } + } + } + + + static void computeIntentsForOperations(IntentAttachPoint intentAttachPoint) throws PolicyValidationException { + if ( intentAttachPoint instanceof OperationsConfigurator ) { + computeIntentsForOperations((OperationsConfigurator)intentAttachPoint, + intentAttachPoint, + intentAttachPoint.getRequiredIntents()); + } + } + + private static void computeIntentsForOperations(OperationsConfigurator opConfigurator, + IntentAttachPoint intentAttachPoint, + List parentIntents) throws PolicyValidationException { + IntentAttachPointType attachPointType = intentAttachPoint.getType(); + + boolean found = false; + for ( ConfiguredOperation confOp : opConfigurator.getConfiguredOperations() ) { + //expand profile intents specified on operations + PolicyComputationUtils.expandProfileIntents(confOp.getRequiredIntents()); + + //validateIntents(confOp, attachPointType); + + //add intents specified for parent intent attach point (binding / implementation) + //wherever its not overridden in the operation + Intent tempIntent = null; + List attachPointOpIntents = new ArrayList(); + for (Intent anIntent : parentIntents) { + found = false; + + tempIntent = anIntent; + while ( tempIntent instanceof QualifiedIntent ) { + tempIntent = ((QualifiedIntent)tempIntent).getQualifiableIntent(); + } + + for ( Intent opIntent : confOp.getRequiredIntents() ) { + if ( opIntent.getName().getLocalPart().startsWith(tempIntent.getName().getLocalPart())) { + found = true; + break; + } + } + + if ( !found ) { + boolean conflict = false; + for (Intent excluded : anIntent.getExcludedIntents()) { + if (confOp.getRequiredIntents().contains(excluded)) { + conflict = true; + break; + } + } + if (!conflict) { + attachPointOpIntents.add(anIntent); + } + } + } + + confOp.getRequiredIntents().addAll(attachPointOpIntents); + + //remove duplicates and ... + //where qualified form of intent exists retain it and remove the qualifiable intent + filterDuplicatesAndQualifiableIntents(confOp); + + } + } + + private static List computeInheritablePolicySets(List inheritablePolicySets, + List applicablePolicySets) + throws PolicyValidationException { + List validInheritablePolicySets = new ArrayList(); + for (PolicySet policySet : inheritablePolicySets) { + if ( !policySet.isUnresolved() ) { + if ( applicablePolicySets.contains(policySet) ) { + validInheritablePolicySets.add(policySet); + } + } else { + throw new PolicyValidationException("Policy Set '" + policySet.getName() + + "' is not defined in this domain "); + } + } + + return validInheritablePolicySets; + } + + private static void normalizePolicySets(PolicySetAttachPoint policySetAttachPoint ) { + //get rid of duplicate entries + HashMap policySetTable = new HashMap(); + for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) { + policySetTable.put(policySet.getName(), policySet); + } + + policySetAttachPoint.getPolicySets().clear(); + policySetAttachPoint.getPolicySets().addAll(policySetTable.values()); + + //expand profile intents + for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) { + PolicyComputationUtils.expandProfileIntents(policySet.getProvidedIntents()); + } + } + + private static void computePolicySetsForOperations(List applicablePolicySets, + PolicySetAttachPoint policySetAttachPoint) + throws PolicyValidationException { + if ( policySetAttachPoint instanceof OperationsConfigurator ) { + computePolicySetsForOperations(applicablePolicySets, + (OperationsConfigurator)policySetAttachPoint, + policySetAttachPoint); + } + + } + + private static void computePolicySetsForOperations(List applicablePolicySets, + OperationsConfigurator opConfigurator, + PolicySetAttachPoint policySetAttachPoint) + throws PolicyValidationException { + //String appliesTo = null; + //String scdlFragment = ""; + HashMap policySetTable = new HashMap(); + IntentAttachPointType attachPointType = policySetAttachPoint.getType(); + + for ( ConfiguredOperation confOp : opConfigurator.getConfiguredOperations() ) { + //validate policysets specified for the attachPoint + for (PolicySet policySet : confOp.getPolicySets()) { + if ( !policySet.isUnresolved() ) { + //appliesTo = policySet.getAppliesTo(); + + //if (!PolicyValidationUtils.isPolicySetApplicable(scdlFragment, appliesTo, attachPointType)) { + if (!applicablePolicySets.contains(policySet)) { + throw new PolicyValidationException("Policy Set '" + policySet.getName() + + " specified for operation " + confOp.getName() + + "' does not constrain extension type " + + attachPointType.getName()); + + } + } else { + throw new PolicyValidationException("Policy Set '" + policySet.getName() + + " specified for operation " + confOp.getName() + + "' is not defined in this domain "); + } + } + + //get rid of duplicate entries + for ( PolicySet policySet : confOp.getPolicySets() ) { + policySetTable.put(policySet.getName(), policySet); + } + + confOp.getPolicySets().clear(); + confOp.getPolicySets().addAll(policySetTable.values()); + policySetTable.clear(); + + //expand profile intents + for ( PolicySet policySet : confOp.getPolicySets() ) { + PolicyComputationUtils.expandProfileIntents(policySet.getProvidedIntents()); + } + } + } + + + private static void trimProvidedIntents(List requiredIntents, List policySets) { + for ( PolicySet policySet : policySets ) { + trimProvidedIntents(requiredIntents, policySet); + } + } + + private static void determineApplicableDomainPolicySets(List applicablePolicySets, + PolicySetAttachPoint policySetAttachPoint, + IntentAttachPointType intentAttachPointType) { + + if (policySetAttachPoint.getRequiredIntents().size() > 0) { + + // form a list of all intents required by the attach point + List combinedTargetIntents = new ArrayList(); + combinedTargetIntents.addAll(policySetAttachPoint.getRequiredIntents()); + for (PolicySet targetPolicySet : policySetAttachPoint.getPolicySets()) { + combinedTargetIntents.addAll(PolicyComputationUtils.findAndExpandProfileIntents(targetPolicySet.getProvidedIntents())); + } + + //since the set of applicable policysets for this attachpoint is known + //we only need to check in that list if there is a policyset that matches + for (PolicySet policySet : applicablePolicySets) { + // do not use the policy set if it provides intents that conflict with required intents + boolean conflict = false; + List providedIntents = PolicyComputationUtils.findAndExpandProfileIntents(policySet.getProvidedIntents()); + checkConflict: for (Intent intent : providedIntents) { + for (Intent excluded : intent.getExcludedIntents()) { + if (combinedTargetIntents.contains(excluded)) { + conflict = true; + break checkConflict; + } + } + } + if (conflict) + continue; + int prevSize = policySetAttachPoint.getRequiredIntents().size(); + trimProvidedIntents(policySetAttachPoint.getRequiredIntents(), policySet); + // if any intent was trimmed off, then this policyset must + // be attached to the intent attachpoint's policyset + if (prevSize != policySetAttachPoint.getRequiredIntents().size()) { + policySetAttachPoint.getPolicySets().add(policySet); + } + } + } + } + + private static boolean isProvidedInherently(IntentAttachPointType attachPointType, Intent intent) { + return ( attachPointType != null && + (( attachPointType.getAlwaysProvidedIntents() != null && + attachPointType.getAlwaysProvidedIntents().contains(intent) ) || + ( attachPointType.getMayProvideIntents() != null && + attachPointType.getMayProvideIntents().contains(intent) ) + ) ); + } + + private static void trimProvidedIntents(List requiredIntents, PolicySet policySet) { + for ( Intent providedIntent : policySet.getProvidedIntents() ) { + if ( requiredIntents.contains(providedIntent) ) { + requiredIntents.remove(providedIntent); + } + } + + for ( Intent mappedIntent : policySet.getMappedPolicies().keySet() ) { + if ( requiredIntents.contains(mappedIntent) ) { + requiredIntents.remove(mappedIntent); + } + } + } + + private static void filterDuplicatesAndQualifiableIntents(IntentAttachPoint intentAttachPoint) { + //remove duplicates + Map intentsTable = new HashMap(); + for ( Intent intent : intentAttachPoint.getRequiredIntents() ) { + intentsTable.put(intent.getName(), intent); + } + + //where qualified form of intent exists retain it and remove the qualifiable intent + Map intentsTableCopy = new HashMap(intentsTable); + //if qualified form of intent exists remove the unqualified form + for ( Intent intent : intentsTableCopy.values() ) { + if ( intent instanceof QualifiedIntent ) { + QualifiedIntent qualifiedIntent = (QualifiedIntent)intent; + if ( intentsTable.get(qualifiedIntent.getQualifiableIntent().getName()) != null ) { + intentsTable.remove(qualifiedIntent.getQualifiableIntent().getName()); + } + } + } + intentAttachPoint.getRequiredIntents().clear(); + intentAttachPoint.getRequiredIntents().addAll(intentsTable.values()); + } + + private static void validateIntents(ConfiguredOperation confOp, IntentAttachPointType attachPointType) throws PolicyValidationException { + boolean found = false; + if ( attachPointType != null ) { + //validate intents specified against the parent (binding / implementation) + found = false; + for (Intent intent : confOp.getRequiredIntents()) { + if ( !intent.isUnresolved() ) { + for (QName constrained : intent.getConstrains()) { + if (PolicyValidationUtils.isConstrained(constrained, attachPointType)) { + found = true; + break; + } + } + + if (!found) { + throw new PolicyValidationException("Policy Intent '" + intent.getName() + + " specified for operation " + confOp.getName() + + "' does not constrain extension type " + + attachPointType.getName()); + } + } else { + throw new PolicyValidationException("Policy Intent '" + intent.getName() + + " specified for operation " + confOp.getName() + + "' is not defined in this domain "); + } + } + } + } + + static void computeBindingIntentsAndPolicySets(Contract contract) throws PolicyValidationException { + for (Binding binding : contract.getBindings()) { + if (binding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding; + computeIntents((IntentAttachPoint)binding, contract.getRequiredIntents()); + + aggregateAndPruneApplicablePolicySets(contract.getApplicablePolicySets(), + policiedBinding.getApplicablePolicySets()); + + computePolicySets(policiedBinding, contract.getPolicySets()); + + PolicyComputationUtils.checkForMutuallyExclusiveIntents( + policiedBinding.getRequiredIntents(), + policiedBinding.getPolicySets(), + policiedBinding.getType(), + contract.getName()); + + if ( binding instanceof OperationsConfigurator && + contract instanceof OperationsConfigurator ) { + //add or merge service operations to the binding + addInheritedOpConfOnBindings((OperationsConfigurator)contract, + (OperationsConfigurator)binding, + (PolicySetAttachPoint)binding); + + computeIntentsForOperations((IntentAttachPoint)binding); + computePolicySetsForOperations(contract.getApplicablePolicySets(), + policiedBinding); + + for ( ConfiguredOperation confOp : ((OperationsConfigurator)binding).getConfiguredOperations() ) { + PolicyComputationUtils.checkForMutuallyExclusiveIntents( + confOp.getRequiredIntents(), + confOp.getPolicySets(), + policiedBinding.getType(), + contract.getName() + "." + confOp.getName()); + } + + } + } + } + + if ( contract.getCallback() != null ) { + for (Binding binding : contract.getCallback().getBindings()) { + if (binding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding; + computeIntents((IntentAttachPoint)binding, contract.getCallback().getRequiredIntents()); + + aggregateAndPruneApplicablePolicySets(contract.getApplicablePolicySets(), + policiedBinding.getApplicablePolicySets()); + + computePolicySets(policiedBinding, contract.getCallback().getPolicySets()); + + PolicyComputationUtils.checkForMutuallyExclusiveIntents( + policiedBinding.getRequiredIntents(), + policiedBinding.getPolicySets(), + policiedBinding.getType(), + contract.getName() + " callback"); + + } + } + } + } + + private static void computeIntents(IntentAttachPoint policiedBinding, List inheritedIntents) + throws PolicyValidationException { + //since the parent component could also contain intents that apply to implementation + //and binding elements within, we filter out only those that apply to this binding type + List prunedIntents = computeInheritableIntents(policiedBinding.getType(), + inheritedIntents); + policiedBinding.getRequiredIntents().addAll(prunedIntents); + + normalizeIntents(policiedBinding); + } + + private static void computePolicySets(PolicySetAttachPoint policiedBinding, + List inheritedPolicySets) throws PolicyValidationException { + + List prunedPolicySets = computeInheritablePolicySets(inheritedPolicySets, + policiedBinding.getApplicablePolicySets()); + policiedBinding.getPolicySets().addAll(prunedPolicySets); + normalizePolicySets(policiedBinding); + } + + static void determineApplicableBindingPolicySets(Contract source, Contract target) throws PolicyConfigurationException { + List intentsCopy = null; + for (Binding aBinding : source.getBindings()) { + if (aBinding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)aBinding; + IntentAttachPointType bindingType = policiedBinding.getType(); + + + intentsCopy = new ArrayList(policiedBinding.getRequiredIntents()); + // add the target component's intents to the reference binding + if (target != null) { + for (Intent intent : target.getRequiredIntents()) { + if (!policiedBinding.getRequiredIntents().contains(intent)) { + for (QName constrained : intent.getConstrains()) { + if (bindingType != null && bindingType.getName().getNamespaceURI() + .equals(constrained.getNamespaceURI()) + && bindingType.getName().getLocalPart().startsWith(constrained + .getLocalPart())) { + policiedBinding.getRequiredIntents().add(intent); + break; + } + } + } + } + } + + //trim intents specified in operations. First check for policysets specified on the operation + //and then in the parent implementation + if ( aBinding instanceof OperationsConfigurator ) { + OperationsConfigurator opConfigurator = (OperationsConfigurator)aBinding; + + for ( ConfiguredOperation confOp : opConfigurator.getConfiguredOperations() ) { + List opsIntentsCopy = new ArrayList(confOp.getRequiredIntents()); + + trimInherentlyProvidedIntents(policiedBinding.getType(), + confOp.getRequiredIntents()); + trimProvidedIntents(confOp.getRequiredIntents(), confOp.getPolicySets()); + trimProvidedIntents(confOp.getRequiredIntents(), policiedBinding.getPolicySets()); + + determineApplicableDomainPolicySets(policiedBinding.getApplicablePolicySets(), + confOp, + policiedBinding.getType()); + + if (confOp.getRequiredIntents().size() > 0) { + throw new PolicyConfigurationException("The following are unfulfilled intents for operations configured in " + + "binding - " + aBinding.getName() + "\nUnfulfilled Intents = " + + confOp.getRequiredIntents()); + } + + //the intents list could have been trimmed when matching for policysets + //since the bindings may need the original set of intents we copy that back + confOp.getRequiredIntents().clear(); + confOp.getRequiredIntents().addAll(opsIntentsCopy); + + } + } + + trimInherentlyProvidedIntents(policiedBinding.getType(), + policiedBinding.getRequiredIntents()); + trimProvidedIntents(policiedBinding.getRequiredIntents(), policiedBinding + .getPolicySets()); + + // determine additional policysets that match remaining intents + // TODO: resolved to domain policy registry and attach suitable + // policy sets to the binding + // for now using the SCA Definitions instead of registry + // if there are intents that are not provided by any policy set + // throw a warning + determineApplicableDomainPolicySets(source, policiedBinding); + + //the intents list could have been trimmed when matching for policysets + //since the bindings may need the original set of intents we copy that back + policiedBinding.getRequiredIntents().clear(); + policiedBinding.getRequiredIntents().addAll(intentsCopy); + + } + } + } + + private static void determineApplicableDomainPolicySets(Contract contract, + PolicySetAttachPoint policiedBinding) + throws PolicyConfigurationException { + //if ( domainPolicySets != null) { + determineApplicableDomainPolicySets(policiedBinding.getApplicablePolicySets(), + policiedBinding, + policiedBinding.getType()); + + if ( policiedBinding.getRequiredIntents().size() > 0 ) { + if ( contract instanceof Service ) { + throw new PolicyConfigurationException("The following are unfulfilled intents for " + + "binding in service - " + contract.getName() + "\nUnfulfilled Intents = " + + policiedBinding.getRequiredIntents()); + } else { + throw new PolicyConfigurationException("The are unfulfilled intents for " + + "binding in reference - " + contract.getName() + "\nUnfulfilled Intents = " + + policiedBinding.getRequiredIntents()); + } + } + //} + } + + private static void addInheritedOpConfOnBindings(OperationsConfigurator source, + OperationsConfigurator target, + PolicySetAttachPoint attachPoint) throws PolicyValidationException { + + List additionalOperations = new ArrayList(); + for ( ConfiguredOperation sourceConfOp : source.getConfiguredOperations() ) { + boolean found = false; + ConfiguredOperation targetConfOp = null; + for ( ConfiguredOperation confOp : target.getConfiguredOperations() ) { + if ( sourceConfOp.getName().equals(confOp.getName())) { + targetConfOp = confOp; + found = true; + break; + } + } + if ( !found ) { + // Create a new target configured operation and copy everything from the source + // except the intents and policy sets (which must be computed below). + try { + targetConfOp = (ConfiguredOperation) sourceConfOp.clone(); + targetConfOp.setRequiredIntents(new ArrayList()); + targetConfOp.setPolicySets(new ArrayList()); + } catch (CloneNotSupportedException e) { + // will not happen + } + } + + + List prunedIntents = + computeInheritableIntents(attachPoint.getType(), sourceConfOp.getRequiredIntents()); + PolicyComputationUtils.addInheritedIntents(prunedIntents, targetConfOp.getRequiredIntents()); + + List prunedPolicySets = + computeInheritablePolicySets(sourceConfOp.getPolicySets(), attachPoint.getApplicablePolicySets()); + PolicyComputationUtils.addInheritedPolicySets(prunedPolicySets, targetConfOp.getPolicySets(), true); + + // If this is a new target configured operation, we will add it to the target list + // if it has required intents or policy sets. + if (!found && (!targetConfOp.getRequiredIntents().isEmpty() || !targetConfOp.getPolicySets().isEmpty())) { + additionalOperations.add(targetConfOp); + } + } + + if ( !additionalOperations.isEmpty() ) { + target.getConfiguredOperations().addAll(additionalOperations); + } + } + + private static void aggregateAndPruneApplicablePolicySets(List source, List target) { + target.addAll(source); + //strip duplicates + Hashtable policySetTable = new Hashtable(); + for ( PolicySet policySet : target ) { + policySetTable.put(policySet.getName(), policySet); + } + + target.clear(); + target.addAll(policySetTable.values()); + } + + static void inheritDefaultPolicies(Base parent, List contracts) { + + for (Contract contract : contracts) { + + // The contract inherits default policies from the parent composite/component. + if ( parent instanceof PolicySetAttachPoint ) { + PolicyComputationUtils.addDefaultPolicies( + ((PolicySetAttachPoint)parent).getRequiredIntents(), + ((PolicySetAttachPoint)parent).getPolicySets(), + contract.getRequiredIntents(), + contract.getPolicySets()); + } + + // The contract's configured operations inherit default policies from the contract. + for ( ConfiguredOperation confOp : contract.getConfiguredOperations() ) { + PolicyComputationUtils.addDefaultPolicies( + contract.getRequiredIntents(), + contract.getPolicySets(), + confOp.getRequiredIntents(), + confOp.getPolicySets()); + } + + // The contract's callback inherits default policies from the contract. + if (contract.getCallback() != null) { + PolicyComputationUtils.addDefaultPolicies( + contract.getRequiredIntents(), + contract.getPolicySets(), + contract.getCallback().getRequiredIntents(), + contract.getCallback().getPolicySets()); + } + + } + } + + static void computeImplementationIntentsAndPolicySets(Implementation implementation, Component parent) + throws PolicyValidationException, PolicyConfigurationException { + if ( implementation instanceof PolicySetAttachPoint ) { + PolicySetAttachPoint policiedImplementation = (PolicySetAttachPoint)implementation; + //since for an implementation the component has its policy intents and policysets its possible + //that there are some intents there that does not constrain the implementation.. so prune + List prunedIntents = computeInheritableIntents(policiedImplementation.getType(), + parent.getRequiredIntents()); + parent.getRequiredIntents().clear(); + parent.getRequiredIntents().addAll(prunedIntents); + normalizeIntents(parent); + + computeIntentsForOperations((OperationsConfigurator)parent, + (IntentAttachPoint)implementation, + parent.getRequiredIntents()); + + + List prunedPolicySets = computeInheritablePolicySets(parent.getPolicySets(), + parent.getApplicablePolicySets()); + parent.getPolicySets().clear(); + parent.getPolicySets().addAll(prunedPolicySets); + normalizePolicySets(parent); + + PolicyComputationUtils.checkForMutuallyExclusiveIntents( + parent.getRequiredIntents(), + parent.getPolicySets(), + policiedImplementation.getType(), + parent.getName()); + + computePolicySetsForOperations(parent.getApplicablePolicySets(), + (OperationsConfigurator)parent, + (PolicySetAttachPoint)implementation); + + for ( ConfiguredOperation confOp : ((OperationsConfigurator)parent).getConfiguredOperations() ) { + PolicyComputationUtils.checkForMutuallyExclusiveIntents( + confOp.getRequiredIntents(), + confOp.getPolicySets(), + policiedImplementation.getType(), + parent.getName() + "." + confOp.getName()); + } + + determineApplicableImplementationPolicySets(parent); + + } + } + + private static void determineApplicableImplementationPolicySets(Component component) throws PolicyConfigurationException { + List intentsCopy = null; + if ( component.getImplementation() instanceof PolicySetAttachPoint ) { + PolicySetAttachPoint policiedImplementation = (PolicySetAttachPoint)component.getImplementation(); + + //trim intents specified in operations. First check for policysets specified on the operation + //and then in the parent implementation + if ( component instanceof OperationsConfigurator ) { + OperationsConfigurator opConfigurator = (OperationsConfigurator)component; + + for ( ConfiguredOperation confOp : opConfigurator.getConfiguredOperations() ) { + intentsCopy = new ArrayList(confOp.getRequiredIntents()); + trimInherentlyProvidedIntents(policiedImplementation.getType(), + confOp.getRequiredIntents()); + trimProvidedIntents(confOp.getRequiredIntents(), confOp.getPolicySets()); + trimProvidedIntents(confOp.getRequiredIntents(), component.getPolicySets()); + + determineApplicableDomainPolicySets(component.getApplicablePolicySets(), + confOp, + policiedImplementation.getType()); + + if (confOp.getRequiredIntents().size() > 0) { + throw new PolicyConfigurationException("The following are unfulfilled intents for operations configured in " + + "component implementation - " + component.getName() + "\nUnfulfilled Intents = " + + confOp.getRequiredIntents()); + } + + //the intents list could have been trimmed when matching for policysets + //since the implementation may need the original set of intents we copy that back + confOp.getRequiredIntents().clear(); + confOp.getRequiredIntents().addAll(intentsCopy); + } + } + + intentsCopy = new ArrayList(component.getRequiredIntents()); + trimInherentlyProvidedIntents(policiedImplementation.getType(), + component.getRequiredIntents()); + trimProvidedIntents(component.getRequiredIntents(), component.getPolicySets()); + + //determine additional policysets that match remaining intents + //if there are intents that are not provided by any policy set throw a warning + //TODO: resolved to domain policy registry and attach suitable policy sets to the implementation + //...for now using the SCA Definitions instead of registry + //if ( domainPolicySets != null) { + determineApplicableDomainPolicySets(component.getApplicablePolicySets(), + component, + policiedImplementation.getType()); + + if (component.getRequiredIntents().size() > 0) { + throw new PolicyConfigurationException("The following are unfulfilled intents for component implementation - " + component + .getName() + "\nUnfulfilled Intents = " + component.getRequiredIntents()); + } + //} + + //the intents list could have been trimmed when matching for policysets + //since the bindings may need the original set of intents we copy that back + component.getRequiredIntents().clear(); + component.getRequiredIntents().addAll(intentsCopy); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java new file mode 100644 index 0000000000..e85aec8cea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java @@ -0,0 +1,273 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.w3c.dom.Node; + +/** + * A simple print utility class to help print model instances. + * + * @version $Rev$ $Date$ + */ +class PrintUtil { + private boolean useGetters = false; + private PrintWriter out; + private int indent; + + public PrintUtil(PrintWriter out, boolean useGetters) { + this.out = out; + this.useGetters = useGetters; + } + + public PrintUtil(OutputStream out) { + this.out = new PrintWriter(new OutputStreamWriter(out), true); + } + + void indent() { + for (int i = 0; i < indent; i++) { + out.print(" "); + } + } + + /** + * Print an object. + * + * @param object + */ + public void print(Object object) { + Set objects = new HashSet(); + print(object, objects); + } + + /** + * Print an object. + * + * @param object + */ + private void print(Object object, Set printed) { + if (object == null) { + return; + } + int id = System.identityHashCode(object); + if (printed.contains(id)) { + + // If we've already printed an object, print just it's HashCode + indent(); + out.println(object.getClass().getName() + "@" + id); + } else { + printed.add(id); + try { + + // Print the object class name + indent(); + out.println(object.getClass().getSimpleName() + " {"); + + // Get the object's properties + ValueAccessor accessor = useGetters ? new PropertyAccessor(object) : new FieldAccessor(object); + for (int i = 0; i < accessor.size(); i++) { + try { + + // Get the value of each property + Object value = accessor.getValue(i); + if (value != null) { + + // Convert array value into a list + if (value.getClass().isArray()) { + value = Arrays.asList((Object[])value); + } + + // Print elements in a list + if (value instanceof List) { + if (!((List)value).isEmpty()) { + indent++; + indent(); + out.println(accessor.getName(i) + "= ["); + + // Print each element, recursively + for (Object element : (List)value) { + indent++; + print(element, printed); + indent--; + } + indent(); + out.println(" ]"); + indent--; + } + } else { + Class valueClass = value.getClass(); + + // Print a primitive, java built in type or + // enum, using toString() + if (valueClass.isPrimitive() || valueClass.getName().startsWith("java.") + || valueClass.getName().startsWith("javax.") + || valueClass.isEnum()) { + if (!accessor.getName(i).equals("class")) { + if (!(Boolean.FALSE.equals(value))) { + indent++; + indent(); + out.println(accessor.getName(i) + "=" + value.toString()); + indent--; + } + } + } else if (value instanceof Node) { + indent++; + indent(); + out.println(accessor.getName(i) + "=" + value.toString()); + indent--; + } else { + + // Print an object, recursively + indent++; + indent(); + out.println(accessor.getName(i) + "= {"); + indent++; + print(value, printed); + indent--; + indent(); + out.println("}"); + indent--; + } + } + } + } catch (Exception e) { + } + } + indent(); + out.println("}"); + } catch (Exception e) { + indent(); + out.println(e); + } + } + } + + public static interface ValueAccessor { + int size(); + + String getName(int i); + + Object getValue(int i) throws Exception; + } + + /** + * Java field reflection based value accessor + */ + private static class FieldAccessor implements ValueAccessor { + + private Object object; + private List fields; + + public FieldAccessor(Object object) { + this.fields = getAllFields(object.getClass()); + this.object = object; + } + + public String getName(int i) { + return fields.get(i).getName(); + } + + public Object getValue(int i) throws Exception { + return fields.get(i).get(object); + } + + public int size() { + return fields.size(); + } + + } + + /** + * JavaBean-based value accessor + */ + private static class PropertyAccessor implements ValueAccessor { + + private Object object; + private PropertyDescriptor[] fields; + + public PropertyAccessor(Object object) throws IntrospectionException { + BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass()); + this.fields = beanInfo.getPropertyDescriptors(); + this.object = object; + } + + public String getName(int i) { + return fields[i].getName(); + } + + public Object getValue(int i) throws Exception { + Method getter = fields[i].getReadMethod(); + if (getter != null) { + return getter.invoke(object); + } + return null; + } + + public int size() { + return fields.length; + } + + } + + /** + * Returns a collection of fields declared by a class + * or one of its supertypes + */ + private static List getAllFields(Class clazz) { + return getAllFields(clazz, new ArrayList()); + } + + /** + * Recursively evaluates the type hierarchy to return all fields + */ + private static List getAllFields(Class clazz, List fields) { + if (clazz == null || clazz.isArray() || Object.class.equals(clazz)) { + return fields; + } + fields = getAllFields(clazz.getSuperclass(), fields); + Field[] declaredFields = clazz.getDeclaredFields(); + for (final Field field : declaredFields) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + field.setAccessible(true); // ignore Java accessibility + return null; + } + }); + fields.add(field); + } + return fields; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java new file mode 100644 index 0000000000..0105d4af50 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.XMLConstants; +import javax.xml.namespace.NamespaceContext; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.sax.SAXSource; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; + +/** + * Utility class to deal with processing of component properties that are taking values from the parent + * composite's properties or an external file. + * + * @version $Rev$ $Date$ + */ +abstract class PropertyConfigurationUtil { + + private static Document evaluate(Document node, XPathExpression expression, DocumentBuilderFactory documentBuilderFactory) + throws XPathExpressionException, ParserConfigurationException { + + Node value = node.getDocumentElement(); + Node result = (Node)expression.evaluate(value, XPathConstants.NODE); + if (result == null) { + return null; + } + + // TODO: How to wrap the result into a Document? + Document document = documentBuilderFactory.newDocumentBuilder().newDocument(); + if (result instanceof Document) { + return (Document)result; + } else { + //Element root = document.createElementNS(null, "value"); + //document.appendChild(root); + document.appendChild(document.importNode(result, true)); + return document; + } + } + + private static Document loadFromFile(String file, TransformerFactory transformerFactory) throws MalformedURLException, IOException, + TransformerException, ParserConfigurationException { + URI uri = URI.create(file); + // URI resolution for relative URIs is done when the composite is resolved. + URL url = uri.toURL(); + URLConnection connection = url.openConnection(); + connection.setUseCaches(false); + InputStream is = null; + try { + is = connection.getInputStream(); + + Source streamSource = new SAXSource(new InputSource(is)); + DOMResult result = new DOMResult(); + javax.xml.transform.Transformer transformer = transformerFactory.newTransformer(); + transformer.transform(streamSource, result); + + Document document = (Document)result.getNode(); + + // TUSCANY-2377, Add a fake value element so it's consistent with + // the DOM tree loaded from inside SCDL + Element root = document.createElementNS(null, "value"); + root.appendChild(document.getDocumentElement()); + document.appendChild(root); + return document; + } finally { + if (is != null) { + is.close(); + } + } + } + + static void sourceComponentProperties(Map compositeProperties, + Component componentDefinition, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory) throws CompositeBuilderException, + ParserConfigurationException, + XPathExpressionException, + TransformerException, + IOException { + + List componentProperties = componentDefinition.getProperties(); + for (ComponentProperty aProperty : componentProperties) { + String source = aProperty.getSource(); + String file = aProperty.getFile(); + if (source != null) { + // $/... + int index = source.indexOf('/'); + if (index == -1) { + // Tolerating $prop + source = source + "/"; + index = source.length() - 1; + } + if (source.charAt(0) == '$') { + String name = source.substring(1, index); + Property compositeProp = compositeProperties.get(name); + if (compositeProp == null) { + throw new CompositeBuilderException("The 'source' cannot be resolved to a composite property: " + source); + } + + Document compositePropDefValues = (Document)compositeProp.getValue(); + + // FIXME: How to deal with namespaces? + Document node = evaluate(compositePropDefValues, aProperty.getSourceXPathExpression(), documentBuilderFactory); + + if (node != null) { + aProperty.setValue(node); + } + } else { + throw new CompositeBuilderException("The 'source' has an invalid value: " + source); + } + } else if (file != null) { + aProperty.setValue(loadFromFile(aProperty.getFile(), transformerFactory)); + + } + } + } + + private static class DOMNamespaceContext implements NamespaceContext { + private Node node; + + /** + * @param node + */ + public DOMNamespaceContext(Node node) { + super(); + this.node = node; + } + + public String getNamespaceURI(String prefix) { + if (prefix == null) { + throw new IllegalArgumentException("Prefix is null"); + } else if (XMLConstants.XML_NS_PREFIX.equals(prefix)) { + return XMLConstants.XML_NS_URI; + } else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) { + return XMLConstants.XMLNS_ATTRIBUTE_NS_URI; + } + String ns = node.lookupNamespaceURI(prefix); + return ns == null ? XMLConstants.NULL_NS_URI : ns; + } + + public String getPrefix(String namespaceURI) { + if (namespaceURI == null) { + throw new IllegalArgumentException("Namespace URI is null"); + } else if (XMLConstants.XML_NS_URI.equals(namespaceURI)) { + return XMLConstants.XML_NS_PREFIX; + } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) { + return XMLConstants.XMLNS_ATTRIBUTE; + } + return node.lookupPrefix(namespaceURI); + } + + public Iterator getPrefixes(String namespaceURI) { + // Not implemented + if (namespaceURI == null) { + throw new IllegalArgumentException("Namespace URI is null"); + } else if (XMLConstants.XML_NS_URI.equals(namespaceURI)) { + return Arrays.asList(XMLConstants.XML_NS_PREFIX).iterator(); + } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) { + return Arrays.asList(XMLConstants.XMLNS_ATTRIBUTE).iterator(); + } + String prefix = getPrefix(namespaceURI); + if (prefix == null) { + return Collections.emptyList().iterator(); + } + return Arrays.asList(prefix).iterator(); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java new file mode 100644 index 0000000000..20a964a08d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java @@ -0,0 +1,265 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointFactory; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * This class encapsulates utility methods to deal with reference definitions + * + * @version $Rev$ $Date$ + */ +abstract class ReferenceConfigurationUtil { + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private static void warning(Monitor monitor, String message, Object model, String... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(ReferenceConfigurationUtil.class.getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + static boolean isValidMultiplicityOverride(Multiplicity definedMul, Multiplicity overridenMul) { + if (definedMul != overridenMul) { + switch (definedMul) { + case ZERO_N: + return overridenMul == Multiplicity.ZERO_ONE; + case ONE_N: + return overridenMul == Multiplicity.ONE_ONE; + default: + return false; + } + } else { + return true; + } + } + + static boolean validateMultiplicityAndTargets(Multiplicity multiplicity, + List targets, List bindings) { + + // Count targets + int count = targets.size(); + + //FIXME workaround, this validation is sometimes invoked too early + // before we get a chance to init the multiplicity attribute + if (multiplicity == null) { + return true; + } + + switch (multiplicity) { + case ZERO_N: + break; + case ZERO_ONE: + if (count > 1) { + return false; + } + break; + case ONE_ONE: + if (count != 1) { + if (count == 0) { + for (Binding binding: bindings) { + if (!(binding instanceof OptimizableBinding) || binding.getURI()!=null) { + return true; + } + } + } + return false; + } + break; + case ONE_N: + if (count < 1) { + if (count == 0) { + for (Binding binding: bindings) { + if (!(binding instanceof OptimizableBinding) || binding.getURI()!=null) { + return true; + } + } + } + return false; + } + break; + } + return true; + } + + /** + * Follow a reference promotion chain down to the innermost (non composite) + * component references. + * + * @param compositeReference + * @return + */ + static List getPromotedComponentReferences(CompositeReference compositeReference) { + List componentReferences = new ArrayList(); + collectPromotedComponentReferences(compositeReference, componentReferences); + return componentReferences; + } + + /** + * Follow a reference promotion chain down to the innermost (non composite) + * component references. + * + * @param compositeReference + * @param componentReferences + * @return + */ + private static void collectPromotedComponentReferences(CompositeReference compositeReference, + List componentReferences) { + for (ComponentReference componentReference : compositeReference.getPromotedReferences()) { + Reference reference = componentReference.getReference(); + if (reference instanceof CompositeReference) { + + // Continue to follow the reference promotion chain + collectPromotedComponentReferences((CompositeReference)reference, componentReferences); + + } else if (reference != null) { + + // Found a non-composite reference + componentReferences.add(componentReference); + } + } + } + + /** + * Override the bindings for a promoted reference from an outer component + * reference + * + * @param reference + * @param promotedReference + */ + static void reconcileReferenceBindings(Reference reference, + ComponentReference promotedReference, + AssemblyFactory assemblyFactory, + EndpointFactory endpointFactory, + Monitor monitor) { + + if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE || + promotedReference.getMultiplicity() == Multiplicity.ZERO_ONE) { + + // if necessary override the promoted endpoints (and bindings) with the top level bindings + if (reference.getBindings().size() > 0 ){ + + List bindingsToCopyDown = new ArrayList(); + List endpointsToCopyDown = new ArrayList(); + + for (Binding binding : reference.getBindings()) { + if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { + bindingsToCopyDown.add(binding); + + if (reference instanceof ComponentReference){ + for (Endpoint endpoint : ((ComponentReference)reference).getEndpoints()){ + if ( endpoint.getSourceBinding() == binding){ + endpointsToCopyDown.add(endpoint); + break; + } + } + } else { + // create a new endpoint to represent this promoted binding + Endpoint endpoint = endpointFactory.createEndpoint(); + endpoint.setTargetName(binding.getURI()); + endpoint.setSourceComponent(null); // TODO - fixed up at start + endpoint.setSourceComponentReference(promotedReference); + endpoint.setInterfaceContract(reference.getInterfaceContract()); + endpoint.setSourceBinding(binding); + endpointsToCopyDown.add(endpoint); + } + } + } + + if (bindingsToCopyDown.size() > 0) { + promotedReference.getBindings().clear(); + promotedReference.getBindings().addAll(bindingsToCopyDown); + + promotedReference.getEndpoints().clear(); + promotedReference.getEndpoints().addAll(endpointsToCopyDown); + } + } + + if (promotedReference.getBindings().size() > 1) { + warning(monitor, "ComponentReferenceMoreWire", promotedReference, promotedReference.getName()); + } + } else { + // if necessary merge the promoted endpoints (and bindings) with the top level bindings + if (reference.getBindings().size() > 0 ){ + + for (Binding binding : reference.getBindings()) { + if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { + promotedReference.getBindings().add(binding); + + if (reference instanceof ComponentReference){ + for (Endpoint endpoint : ((ComponentReference)reference).getEndpoints()){ + if ( endpoint.getSourceBinding() == binding){ + promotedReference.getEndpoints().add(endpoint); + break; + } + } + } else { + // create a new endpoint to represent this promoted binding + Endpoint endpoint = endpointFactory.createEndpoint(); + endpoint.setTargetName(binding.getURI()); + endpoint.setSourceComponent(null); // TODO - fixed up at start + endpoint.setSourceComponentReference(promotedReference); + endpoint.setInterfaceContract(reference.getInterfaceContract()); + endpoint.setSourceBinding(binding); + promotedReference.getEndpoints().add(endpoint); + } + } + } + } + } + + Set callbackBindings = new HashSet(); + if (promotedReference.getCallback() != null) { + callbackBindings.addAll(promotedReference.getCallback().getBindings()); + } + if (reference.getCallback() != null) { + callbackBindings.addAll(reference.getCallback().getBindings()); + } + promotedReference.setCallback(assemblyFactory.createCallback()); + for (Binding binding : callbackBindings) { + if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { + promotedReference.getCallback().getBindings().add(binding); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java new file mode 100644 index 0000000000..41a8b3f8ba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.builder.impl; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Service; + +/** + * This class encapsulates utility methods to deal with service definitions. + * + * @version $Rev$ $Date$ + */ +abstract class ServiceConfigurationUtil { + + /** + * Follow a service promotion chain down to the inner most (non composite) + * component service. + * + * @param topCompositeService + * @return + */ + static ComponentService getPromotedComponentService(CompositeService compositeService) { + ComponentService componentService = compositeService.getPromotedService(); + if (componentService != null) { + Service service = componentService.getService(); + if (componentService.getName() != null && service instanceof CompositeService) { + + // Continue to follow the service promotion chain + return getPromotedComponentService((CompositeService)service); + + } else { + + // Found a non-composite service + return componentService; + } + } else { + + // No promoted service + return null; + } + } + + /** + * Follow a service promotion chain down to the innermost (non-composite) component. + * + * @param compositeService + * @return + */ + static Component getPromotedComponent(CompositeService compositeService) { + ComponentService componentService = compositeService.getPromotedService(); + if (componentService != null) { + Service service = componentService.getService(); + if (componentService.getName() != null && service instanceof CompositeService) { + + // Continue to follow the service promotion chain + return getPromotedComponent((CompositeService)service); + + } else { + + // Found a non-composite service + return compositeService.getPromotedComponent(); + } + } else { + + // No promoted service + return null; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java new file mode 100644 index 0000000000..b7c63dc2b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; + +/** + * Represents an abstract property. + * + * @version $Rev$ $Date$ + */ +public class AbstractPropertyImpl extends ExtensibleImpl implements AbstractProperty { + private Object value; + private String name; + private QName xsdType; + private QName xsdElement; + private boolean many; + private boolean mustSupply; + private List requiredIntents = new ArrayList(); + + + public List getRequiredIntents() { + return requiredIntents; + } + + /** + * Constructs a new abstract property. + */ + protected AbstractPropertyImpl() { + } + + public Object getValue() { + return value; + } + + public String getName() { + return name; + } + + public QName getXSDElement() { + return xsdElement; + } + + public QName getXSDType() { + return xsdType; + } + + public boolean isMany() { + return many; + } + + public boolean isMustSupply() { + return mustSupply; + } + + public void setValue(Object defaultValue) { + this.value = defaultValue; + } + + public void setMany(boolean many) { + this.many = many; + } + + public void setMustSupply(boolean mustSupply) { + this.mustSupply = mustSupply; + } + + public void setName(String name) { + this.name = name; + } + + public void setXSDElement(QName element) { + this.xsdElement = element; + } + + public void setXSDType(QName type) { + this.xsdType = type; + } + + public IntentAttachPointType getType() { + return null; + } + + public void setType(IntentAttachPointType type) { + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java new file mode 100644 index 0000000000..d0ee3832c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.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.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.Multiplicity; + +/** + * Represents an abstract reference + * + * @version $Rev$ $Date$ + */ +public class AbstractReferenceImpl extends ContractImpl implements AbstractReference { + private Multiplicity multiplicity = Multiplicity.ONE_ONE; + + /** + * Constructs a new abstract reference. + */ + protected AbstractReferenceImpl() { + } + + public Multiplicity getMultiplicity() { + return multiplicity; + } + + public void setMultiplicity(Multiplicity multiplicity) { + this.multiplicity = multiplicity; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java new file mode 100644 index 0000000000..346764b1b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.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.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.AbstractService; + +/** + * Represents an abstract service + * + * @version $Rev$ $Date$ + */ +public class AbstractServiceImpl extends ContractImpl implements AbstractService { + + /** + * Constructs a new abstract service. + */ + protected AbstractServiceImpl() { + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java new file mode 100644 index 0000000000..016a9a5b05 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.AbstractService; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Wire; + +/** + * A factory for the assembly model. + * + * @version $Rev$ $Date$ + */ +public abstract class AssemblyFactoryImpl implements AssemblyFactory { + + public AbstractProperty createAbstractProperty() { + return new AbstractPropertyImpl(); + } + + public AbstractReference createAbstractReference() { + return new AbstractReferenceImpl(); + } + + public AbstractService createAbstractService() { + return new AbstractServiceImpl(); + } + + public Callback createCallback() { + return new CallbackImpl(); + } + + public Component createComponent() { + return new ComponentImpl(); + } + + public ComponentProperty createComponentProperty() { + return new ComponentPropertyImpl(); + } + + public ComponentReference createComponentReference() { + return new ComponentReferenceImpl(); + } + + public ComponentService createComponentService() { + return new ComponentServiceImpl(); + } + + public ComponentType createComponentType() { + return new ComponentTypeImpl(); + } + + public Composite createComposite() { + return new CompositeImpl(); + } + + public CompositeReference createCompositeReference() { + return new CompositeReferenceImpl(); + } + + public CompositeService createCompositeService() { + return new CompositeServiceImpl(); + } + + public ConstrainingType createConstrainingType() { + return new ConstrainingTypeImpl(); + } + + public Property createProperty() { + return new PropertyImpl(); + } + + public Reference createReference() { + return new ReferenceImpl(); + } + + public Service createService() { + return new ServiceImpl(); + } + + public Wire createWire() { + return new WireImpl(); + } + + public ConfiguredOperation createConfiguredOperation() { + return new ConfiguredOperationImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java new file mode 100644 index 0000000000..553e600bc9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.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.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.Base; + +/** + * Convenience base class for assembly model objects. + * + * @version $Rev$ $Date$ + */ +public abstract class BaseImpl implements Base { + private boolean unresolved; + + /** + * Constructs a new base model object. + */ + protected BaseImpl() { + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java new file mode 100644 index 0000000000..4082d81fdb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a reference. + * + * @version $Rev$ $Date$ + */ +public class CallbackImpl extends ExtensibleImpl implements Callback { + private List bindings = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private List configuredOperations = new ArrayList(); + private List applicablePolicySets = new ArrayList(); + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + protected CallbackImpl() { + } + + public List getBindings() { + return bindings; + } + + public IntentAttachPointType getType() { + return null; + } + + public void setType(IntentAttachPointType type) { + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public List getConfiguredOperations() { + return configuredOperations; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java new file mode 100644 index 0000000000..34429a6703 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a component. + * + * @version $Rev$ $Date$ + */ +public class ComponentImpl extends ExtensibleImpl implements Component, Cloneable, OperationsConfigurator { + private ConstrainingType constrainingType; + private Implementation implementation; + private String name; + private String uri; + private List properties = new ArrayList(); + private List references = new ArrayList(); + private List services = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private Boolean autowire; + private IntentAttachPointType type; + private List configuredImplOperations = new ArrayList(); + private List applicablePolicySets = new ArrayList(); + /** + * Constructs a new component. + */ + protected ComponentImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + ComponentImpl clone = (ComponentImpl)super.clone(); + + clone.properties = new ArrayList(); + for (ComponentProperty property : getProperties()) { + clone.properties.add((ComponentProperty)property.clone()); + } + clone.references = new ArrayList(); + for (ComponentReference reference : getReferences()) { + clone.references.add((ComponentReference)reference.clone()); + } + clone.services = new ArrayList(); + for (ComponentService service : getServices()) { + clone.services.add((ComponentService)service.clone()); + } + return clone; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public ConstrainingType getConstrainingType() { + return constrainingType; + } + + public Implementation getImplementation() { + return implementation; + } + + public String getName() { + return name; + } + + public List getProperties() { + return properties; + } + + public List getReferences() { + return references; + } + + public List getServices() { + return services; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + this.constrainingType = constrainingType; + } + + public void setImplementation(Implementation implementation) { + this.implementation = implementation; + } + + public void setName(String name) { + this.name = name; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public List getPolicySets() { + return policySets; + } + + public boolean isAutowire() { + return (autowire == null) ? false : autowire.booleanValue(); + } + + public void setAutowire(Boolean autowire) { + this.autowire = autowire; + } + + public Boolean getAutowire() { + return autowire; + } + + public IntentAttachPointType getType() { + return type; + } + + public void setType(IntentAttachPointType type) { + this.type = type; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + + } + + public List getConfiguredOperations() { + return configuredImplOperations; + } + + public void setConfiguredOperations(List configuredOperations) { + this.configuredImplOperations = configuredOperations; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java new file mode 100644 index 0000000000..e2e7b59896 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import javax.xml.xpath.XPathExpression; + +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.Property; + +/** + * Represents a component property. + * + * @version $Rev$ $Date$ + */ +public class ComponentPropertyImpl extends PropertyImpl implements ComponentProperty, Cloneable { + private String file; + private Property property; + private String source; + private XPathExpression sourceXPathExpression; + + /** + * Constructs a new component property. + */ + protected ComponentPropertyImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + // FIXME getValue should not delegate to property.getValue() + // Doing this violates the setValue/getValue semantics, as you + // can call setValue() then get a different value from getValue() + @Override + public Object getValue() { + if (super.getValue() == null && property != null) { + return property.getValue(); + } else { + return super.getValue(); + } + } + + public String getFile() { + return file; + } + + public Property getProperty() { + return property; + } + + public String getSource() { + return source; + } + + public void setFile(String file) { + this.file = file; + } + + public void setProperty(Property property) { + this.property = property; + } + + public void setSource(String source) { + this.source = source; + } + + public XPathExpression getSourceXPathExpression() { + return sourceXPathExpression; + } + + public void setSourceXPathExpression(XPathExpression sourceXPathExpression) { + this.sourceXPathExpression = sourceXPathExpression; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java new file mode 100644 index 0000000000..488023090c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +/** + * Represents a component reference + * + * @version $Rev$ $Date$ + */ +public class ComponentReferenceImpl extends ReferenceImpl implements ComponentReference, Cloneable { + private Reference reference; + private Boolean autowire; + private List promotedAs = new ArrayList(); + private ComponentService callbackService; + private List endpoints = new ArrayList(); + + /** + * Constructs a new component reference. + */ + protected ComponentReferenceImpl() { + // Set multiplicity to null so that by default it'll inherit from the Reference + setMultiplicity(null); + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public Reference getReference() { + return reference; + } + + public void setReference(Reference reference) { + this.reference = reference; + } + + public boolean isAutowire() { + return (autowire == null) ? false : autowire.booleanValue(); + } + + public void setAutowire(Boolean autowire) { + this.autowire = autowire; + } + + public Boolean getAutowire() { + return autowire; + } + + public List promotedAs() { + return promotedAs; + } + + public ComponentService getCallbackService() { + return callbackService; + } + + public void setCallbackService(ComponentService callbackService) { + this.callbackService = callbackService; + } + + public List getEndpoints(){ + return endpoints; + } + + /** + * Use endpoint information to work out what the interface contract for the + * binding is. + */ + @Override + public InterfaceContract getInterfaceContract(Binding binding){ + InterfaceContract interfaceContract = null; + + for (Endpoint theEndpoint : endpoints){ + if (theEndpoint.getSourceBinding() == binding){ + interfaceContract = theEndpoint.getInterfaceContract(); + } + } + + if (interfaceContract == null){ + interfaceContract = getInterfaceContract(); + } + return interfaceContract; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java new file mode 100644 index 0000000000..0c78a2505f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Service; + +/** + * Represents a component service + * + * @version $Rev$ $Date$ + */ +public class ComponentServiceImpl extends ServiceImpl implements ComponentService, Cloneable { + private Service service; + private List promotedAs = new ArrayList(); + private ComponentReference callbackReference; + + /** + * Constructs a new component service. + */ + protected ComponentServiceImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public Service getService() { + return service; + } + + public void setService(Service service) { + this.service = service; + } + + public List promotedAs() { + return promotedAs; + } + + public ComponentReference getCallbackReference() { + return callbackReference; + } + + public void setCallbackReference(ComponentReference callbackReference) { + this.callbackReference = callbackReference; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java new file mode 100644 index 0000000000..bbe665d52f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; + +/** + * Represents a component type. + * + * @version $Rev$ $Date$ + */ +public class ComponentTypeImpl extends ExtensibleImpl implements ComponentType, Cloneable { + private String uri; + private ConstrainingType constrainingType; + private List properties = new ArrayList(); + private List references = new ArrayList(); + private List services = new ArrayList(); + /** + * Constructs a new component type. + */ + protected ComponentTypeImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + ComponentTypeImpl clone = (ComponentTypeImpl)super.clone(); + + clone.services = new ArrayList(); + for (Service service : getServices()) { + clone.services.add((Service)service.clone()); + } + clone.references = new ArrayList(); + for (Reference reference : getReferences()) { + clone.references.add((Reference)reference.clone()); + } + clone.properties = new ArrayList(); + for (Property property : getProperties()) { + clone.properties.add((Property)property.clone()); + } + return clone; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public ConstrainingType getConstrainingType() { + return constrainingType; + } + + public List getProperties() { + return properties; + } + + public List getReferences() { + return references; + } + + public List getServices() { + return services; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + this.constrainingType = constrainingType; + } + + @Override + public int hashCode() { + return String.valueOf(getURI()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else { + if (obj instanceof ComponentType) { + if (getURI() != null) { + return getURI().equals(((ComponentType)obj).getURI()); + } else { + return ((ComponentType)obj).getURI() == null; + } + } else { + return false; + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java new file mode 100644 index 0000000000..9dd26b5e8e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Wire; + +/** + * Implementation of a Composite. + * + * @version $Rev$ $Date$ + */ +public class CompositeImpl extends ImplementationImpl implements Composite, Cloneable { + private List components = new ArrayList(); + private List includes = new ArrayList(); + private QName name; + private List wires = new ArrayList(); + private Boolean autowire; + private boolean local = true; + + /** + * Constructs a new composite. + */ + protected CompositeImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + CompositeImpl clone = (CompositeImpl)super.clone(); + + clone.components = new ArrayList(); + for (Component component : getComponents()) { + Component clonedComponent = (Component)component.clone(); + for (Service service : clone.getServices()) { + CompositeService compositeService = (CompositeService)service; + // Force the promoted component/service to be rebuilt against the clone + if (compositeService.getPromotedComponent() != null) { + compositeService.getPromotedComponent().setUnresolved(true); + } + if (compositeService.getPromotedService() != null) { + compositeService.getPromotedService().setUnresolved(true); + } + } + for (Reference reference : clone.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + for (ComponentReference ref : compositeReference.getPromotedReferences()) { + // Force the promoted reference to be rebuilt against the clone + ref.setUnresolved(true); + } + } + + clone.components.add(clonedComponent); + } + clone.wires = new ArrayList(); + for (Wire wire : getWires()) { + clone.wires.add((Wire)wire.clone()); + } + return clone; + } + + public List getComponents() { + return components; + } + + public List getIncludes() { + return includes; + } + + public QName getName() { + return name; + } + + public List getWires() { + return wires; + } + + public boolean isLocal() { + return local; + } + + public void setLocal(boolean local) { + this.local = local; + } + + public boolean isAutowire() { + return (autowire == null) ? false : autowire.booleanValue(); + } + + public void setAutowire(Boolean autowire) { + this.autowire = autowire; + } + + public Boolean getAutowire() { + return autowire; + } + + public void setName(QName name) { + this.name = name; + } + + @Override + public int hashCode() { + return String.valueOf(getName()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj instanceof Composite) { + if (getName() != null) { + return getName().equals(((Composite)obj).getName()); + } else { + return ((Composite)obj).getName() == null; + } + } else { + return false; + } + } + + @Override + public String toString(){ + return ( this.name != null ) ? getName().toString() : "null"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java new file mode 100644 index 0000000000..bebc9e3619 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.CompositeReference; + +/** + * Represents a composite reference. + * + * @version $Rev$ $Date$ + */ +public class CompositeReferenceImpl extends ReferenceImpl implements CompositeReference, Cloneable { + private List promotedReferences = new ArrayList(); + + /** + * Constructs a new composite reference. + */ + protected CompositeReferenceImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + CompositeReferenceImpl copy = (CompositeReferenceImpl)super.clone(); + copy.promotedReferences = new ArrayList(promotedReferences); + return copy; + } + + public List getPromotedReferences() { + return promotedReferences; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java new file mode 100644 index 0000000000..6777a96982 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.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.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.CompositeService; + +/** + * Represents a composite service + * + * @version $Rev$ $Date$ + */ +public class CompositeServiceImpl extends ServiceImpl implements CompositeService, Cloneable { + private ComponentService promotedService; + private Component promotedComponent; + + /** + * Constructs a new composite service. + */ + protected CompositeServiceImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public ComponentService getPromotedService() { + return promotedService; + } + + public void setPromotedService(ComponentService promotedService) { + this.promotedService = promotedService; + } + + public Component getPromotedComponent() { + return promotedComponent; + } + + public void setPromotedComponent(Component promotedComponent) { + this.promotedComponent = promotedComponent; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConfiguredOperationImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConfiguredOperationImpl.java new file mode 100644 index 0000000000..ca88e39750 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConfiguredOperationImpl.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents an Operation. + * + * @version $Rev$ $Date$ + */ +public class ConfiguredOperationImpl extends BaseImpl implements ConfiguredOperation { + private List policySets = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List applicablePolicySets = new ArrayList(); + + private String name; + private String contractName; + + /** + * Constructs a new Operation. + */ + protected ConfiguredOperationImpl() { + } + + public List getPolicySets() { + return policySets; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public String getContractName() { + return contractName; + } + + public void setContractName(String contractName) { + this.contractName = contractName; + } + + public IntentAttachPointType getType() { + return null; + } + + public void setType(IntentAttachPointType type) { + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + @Override + public Object clone() throws CloneNotSupportedException { + // Note this is a shallow copy. + return super.clone(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java new file mode 100644 index 0000000000..d5701df74e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.AbstractService; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; + +/** + * Represents a constraining type. + * + * @version $Rev$ $Date$ + */ +public class ConstrainingTypeImpl extends ExtensibleImpl implements ConstrainingType { + private QName name; + private List properties = new ArrayList(); + private List references = new ArrayList(); + private List services = new ArrayList(); + private List requiredIntents = new ArrayList(); + + /** + * Constructs a new ConstrainingType + */ + protected ConstrainingTypeImpl() { + } + + public QName getName() { + return name; + } + + public void setName(QName name) { + this.name = name; + } + + public List getProperties() { + return properties; + } + + public List getReferences() { + return references; + } + + public List getServices() { + return services; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + @Override + public int hashCode() { + return String.valueOf(getName()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj instanceof ConstrainingType) { + if (getName() != null) { + return getName().equals(((ConstrainingType)obj).getName()); + } else { + return ((ConstrainingType)obj).getName() == null; + } + } else { + return false; + } + } + + public IntentAttachPointType getType() { + return null; + } + + public void setType(IntentAttachPointType type) { + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java new file mode 100644 index 0000000000..491c835246 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; + +/** + * Implementation of a Contract. + * + * @version $Rev$ $Date$ + */ +public class ContractImpl extends ExtensibleImpl implements AbstractContract { + private InterfaceContract interfaceContract; + private String name; + private List requiredIntents = new ArrayList(); + private List configuredOperations = new ArrayList(); + + private boolean isCallback = false; + + /** + * Constructs a new contract. + */ + protected ContractImpl() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public InterfaceContract getInterfaceContract() { + return interfaceContract; + } + + public void setInterfaceContract(InterfaceContract interfaceContract) { + this.interfaceContract = interfaceContract; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public boolean isCallback() { + return isCallback; + } + + public void setIsCallback(boolean isCallback) { + this.isCallback = isCallback; + } + + public IntentAttachPointType getType() { + return null; + } + + public void setType(IntentAttachPointType type) { + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public List getConfiguredOperations() { + return configuredOperations; + } + + public void setConfiguredOperations(List configuredOperations) { + this.configuredOperations = configuredOperations; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.java new file mode 100644 index 0000000000..ece51cbe9b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.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.sca.assembly.impl; + + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointFactory; + +/** + * A factory for the Endpoint model. + * + * @version $Rev$ $Date$ + */ +public abstract class EndpointFactoryImpl implements EndpointFactory { + + public EndpointFactoryImpl (){ + + } + + public Endpoint createEndpoint() { + return new EndpointImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java new file mode 100644 index 0000000000..5748abb07d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +/** + * The assembly model object for an endpoint. + * + * @version $Rev$ $Date$ + */ +public class EndpointImpl implements Endpoint { + + private String targetName; + + private Component sourceComponent; + private ComponentReference sourceComponentReference; + private Binding resolvedBinding; + private Binding resolvedCallbackBinding; + + private List candidateBindings = new ArrayList(); + + private Component targetComponent; + private ComponentService targetComponentService; + private Binding targetBinding; + private Binding targetCallbackBinding; + + private InterfaceContract interfaceContract; + + protected EndpointImpl() { + } + + public boolean isUnresolved() { + return resolvedBinding == null; + } + + public void setUnresolved(boolean unresolved) { + // do nothing as the status is determined by having + // a resolved source binding + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public String getTargetName(){ + return targetName; + } + + public void setTargetName(String targetName){ + this.targetName = targetName; + } + + public Component getSourceComponent() { + return sourceComponent; + } + + public void setSourceComponent(Component sourceComponent) { + this.sourceComponent = sourceComponent; + } + + public ComponentReference getSourceComponentReference() { + return sourceComponentReference; + } + + public void setSourceComponentReference(ComponentReference sourceComponentReference) { + this.sourceComponentReference = sourceComponentReference; + } + + public Binding getSourceBinding() { + return resolvedBinding; + } + + public void setSourceBinding(Binding resolvedBinding) { + this.resolvedBinding = resolvedBinding; + } + + public Binding getSourceCallbackBinding(){ + return resolvedCallbackBinding; + } + + public void setSourceCallbackBinding(Binding resolvedCallbackBinding){ + this.resolvedCallbackBinding = resolvedCallbackBinding; + } + + public List getCandidateBindings() { + return candidateBindings; + } + + public Component getTargetComponent() { + return targetComponent; + } + + public void setTargetComponent(Component targetComponent) { + this.targetComponent = targetComponent; + } + + public ComponentService getTargetComponentService() { + return targetComponentService; + } + + public void setTargetComponentService(ComponentService targetComponentService) { + this.targetComponentService = targetComponentService; + } + + public Binding getTargetBinding() { + return targetBinding; + } + + public void setTargetBinding(Binding targetBinding) { + this.targetBinding = targetBinding; + } + + public Binding getTargetCallbackBinding(){ + return targetCallbackBinding; + } + + public void setTargetCallbackBinding(Binding targetCallbackBinding){ + this.targetCallbackBinding = targetCallbackBinding; + } + + public InterfaceContract getInterfaceContract() { + return interfaceContract; + } + + public void setInterfaceContract(InterfaceContract interfaceContract) { + this.interfaceContract = interfaceContract; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java new file mode 100644 index 0000000000..0a2e25aa43 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.Extension; + +/** + * Convenience base class for extensible assembly model objects. + * + * @version $Rev$ $Date$ + */ +public abstract class ExtensibleImpl extends BaseImpl implements Extensible { + private List extensions = new ArrayList(); + private List attributeExtensions = new ArrayList(); + + /** + * Constructs a new base model object. + */ + protected ExtensibleImpl() { + } + + public List getExtensions() { + return extensions; + } + + public List getAttributeExtensions() { + return attributeExtensions; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.java new file mode 100644 index 0000000000..2753bcc091 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensionImpl.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.sca.assembly.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Extension; + +public class ExtensionImpl implements Extension { + private QName qName; + private Object value; + boolean isAttribute = false; + + public ExtensionImpl() { + + } + + public ExtensionImpl(QName qName, Object value, boolean isAttribute) { + this.qName = qName; + this.value = value; + this.isAttribute = isAttribute; + } + + public QName getQName() { + return qName; + } + + public void setQName(QName qName) { + this.qName = qName; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public boolean isAttribute() { + return isAttribute; + } + + public void setIsAttribute(boolean isAttribute) { + this.isAttribute = isAttribute; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java new file mode 100644 index 0000000000..aa75922489 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Base implementation class of Implementation model interface + * + * @version $Rev$ $Date$ + */ +public abstract class ImplementationImpl extends ComponentTypeImpl implements Implementation, PolicySetAttachPoint, + OperationsConfigurator { + + private List applicablePolicySets = new ArrayList(); + private List configuredOperations = new ArrayList(); + private IntentAttachPointType type; + private List policySets = new ArrayList(); + private List requiredIntents = new ArrayList(); + + protected ImplementationImpl() { + super(); + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + public List getConfiguredOperations() { + return configuredOperations; + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return type; + } + + public void setType(IntentAttachPointType type) { + this.type = type; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java new file mode 100644 index 0000000000..0c1051199f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a property. + * + * @version $Rev$ $Date$ + */ +public class PropertyImpl extends AbstractPropertyImpl implements Property, Cloneable { + private List policySets = new ArrayList(); + private List applicablePolicySets = new ArrayList(); + + /** + * Constructs a new property. + */ + protected PropertyImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public List getPolicySets() { + return policySets; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java new file mode 100644 index 0000000000..1800222bfb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a reference. + * + * @version $Rev$ $Date$ + */ +public class ReferenceImpl extends AbstractReferenceImpl implements Reference, Cloneable { + private List bindings = new ArrayList(); + private boolean wiredByImpl; + private List policySets = new ArrayList(); + private List targets = new ArrayList(); + private Callback callback; + private List applicablePolicySets = new ArrayList(); + private boolean promotionOverride; + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + /** + * Constructs a new reference. + */ + protected ReferenceImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + ReferenceImpl clone = (ReferenceImpl)super.clone(); + clone.bindings = new ArrayList(); + clone.bindings.addAll(getBindings()); + clone.targets = new ArrayList(); + clone.targets.addAll(getTargets()); + return clone; + } + + public List getBindings() { + return bindings; + } + + public B getBinding(Class bindingClass) { + for (Binding binding : bindings) { + if (bindingClass.isInstance(binding)) { + return bindingClass.cast(binding); + } + } + return null; + } + + public B getCallbackBinding(Class bindingClass) { + if (callback != null) { + for (Binding binding : callback.getBindings()) { + if (bindingClass.isInstance(binding)) { + return bindingClass.cast(binding); + } + } + } + return null; + } + + public boolean isWiredByImpl() { + return wiredByImpl; + } + + public void setWiredByImpl(boolean wiredByImpl) { + this.wiredByImpl = wiredByImpl; + } + + public boolean isPromotionOverride() { + return promotionOverride; + } + + public void setPromotionOverride(boolean promotionOverride) { + this.promotionOverride = promotionOverride; + } + + public List getPolicySets() { + return policySets; + } + + public List getTargets() { + return targets; + } + + public Callback getCallback() { + return callback; + } + + public void setCallback(Callback callback) { + this.callback = callback; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + /** + * By default return the interface contract for the reference + */ + public InterfaceContract getInterfaceContract(Binding binding){ + return getInterfaceContract(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java new file mode 100644 index 0000000000..8d745cb7e1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a reference. + * + * @version $Rev$ $Date$ + */ +public class ServiceImpl extends AbstractServiceImpl implements Service, Cloneable { + private List bindings = new ArrayList(); + private List policySets = new ArrayList(); + private Callback callback; + private List applicablePolicySets = new ArrayList(); + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + /** + * Constructs a new service. + */ + protected ServiceImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + ServiceImpl clone = (ServiceImpl)super.clone(); + clone.bindings = new ArrayList(); + clone.bindings.addAll(getBindings()); + return clone; + } + + public List getBindings() { + return bindings; + } + + public B getBinding(Class bindingClass) { + for (Binding binding : bindings) { + if (bindingClass.isInstance(binding)) { + return bindingClass.cast(binding); + } + } + return null; + } + + public B getCallbackBinding(Class bindingClass) { + if (callback != null) { + for (Binding binding : callback.getBindings()) { + if (bindingClass.isInstance(binding)) { + return bindingClass.cast(binding); + } + } + } + return null; + } + + public List getPolicySets() { + return policySets; + } + + public Callback getCallback() { + return callback; + } + + public void setCallback(Callback callback) { + this.callback = callback; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + /** + * By default return the interface contract for the service + */ + public InterfaceContract getInterfaceContract(Binding binding){ + return getInterfaceContract(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java new file mode 100644 index 0000000000..1a7abc8564 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.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.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a wire + * + * @version $Rev$ $Date$ + */ +public class WireImpl extends ExtensibleImpl implements Wire, Cloneable { + private ComponentReference source; + private ComponentService target; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private List applicablePolicySets = new ArrayList(); + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + /** + * Constructs a new wire. + */ + protected WireImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public ComponentReference getSource() { + return source; + } + + public ComponentService getTarget() { + return target; + } + + public void setSource(ComponentReference source) { + this.source = source; + } + + public void setTarget(ComponentService target) { + this.target = target; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public List getPolicySets() { + return policySets; + } + + public IntentAttachPointType getType() { + return null; + } + + public void setType(IntentAttachPointType type) { + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory new file mode 100644 index 0000000000..859c4bde4b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.assembly.DefaultAssemblyFactory \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory new file mode 100644 index 0000000000..8dbff76ad9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.assembly.DefaultEndpointFactory \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.ExtensionFactory b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.ExtensionFactory new file mode 100644 index 0000000000..bea25da958 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.ExtensionFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.assembly.DefaultExtensionFactory \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/assembly-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/assembly-validation-messages.properties new file mode 100644 index 0000000000..e827f7e78a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/assembly-validation-messages.properties @@ -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. +# +# +DuplicateComponentName = Duplicate component name: Composite = {0} Component = {1} +DuplicateComponentServiceName = Duplicate component service name: Component = {0} Service = {1} +DuplicateComponentReferenceName = Duplicate component reference name: Component = {0} Reference = {1} +DuplicateComponentPropertyName = Duplicate component property name: Component = {0} Property = {1} +NoComponentImplementation = No implementation for component: Component = {0} +ServiceNotFoundForComponentService = Service not found for component service: Component = {0} Service = {1} +UnresolvedComponentImplementation = Component implementation not found: Component = {0} Uri = {1} +DuplicateImplementationPropertyName = Duplicate property name: Component = {0} Property = {1} +DuplicateImplementationServiceName = Duplicate service name: Component = {0} Service = {1} +DuplicateImplementationReferenceName = Duplicate reference name: Component = {0} Reference = {1} +PropertyNotFound = Property not found for component property: Component = {0} Property = {1} +PropertyMustSupplyIncompatible = Component property mustSupply attribute incompatible with property: Component = {0} Property = {1} +PropertyMustSupplyNull = No value configured on a mustSupply property: Component = {0} Property = {1} +PropertyOverrideManyAttribute = Component property many attribute incompatible with property: Component = {0} Property = {1} +ReferenceNotFound = Reference not found for component reference: Component = {0} Reference = {1} +ReferenceIncompatibleMultiplicity = Component reference multiplicity incompatible with reference multiplicity: Component = {0} Reference = {1} +ReferenceIncompatibleInterface = Incompatible interfaces on component reference and target: Composite = {0} Reference = {1} Service = {2} +ReferenceIncompatibleComponentInterface = Component reference interface incompatible with reference interface: Component = {0} Reference = {1} +ServiceIncompatibleComponentInterface = Component service interface incompatible with service interface: Component = {0} Service = {1} +MultipleBindingsForService = Multiple bindings with the same name for a service: Service = {0} Binding name = {1} +MultipleBindingsForReference = Multiple bindings with the same name for a reference: Reference = {0} Binding name = {1} +ReferenceWithoutTargets = No targets for reference: Composite = {0} Reference = {1} +PromotedReferenceNotFound = Promoted component reference not found: Composite = {0} Reference = {1} +PromotedServiceNotFound = Promoted component service not found: Composite = {0} Service = {1} +ComponentReferenceTargetNotFound = Component reference target not found, it might be a remote service running elsewhere in the SCA Domain: Composite = {0} Service = {1} +NoSCABindingAvailableForUnresolvedService = A local service cannot be found for reference {0} target {1} and there is no SCA binding available to represent the unresolved target +NoMatchingBinding = Component reference {0} does not have a binding which matches the bindings of service {1} +NoMatchingCallbackBinding = Component reference {0} does not have a callback binding which matches the callback bindings of service {1} +ReferenceEndPointMixWithTarget = Reference {0} must not specify endpoints using both target attribute and with binding uri attribute +PolicyRelatedException = Policy Related Exception occured due to : {0} +CompositeAlreadyIncluded = Composite {0} has already been included. +ComponentReferenceMoreWire = Component reference {0} has more than one wires +WireTargetNotFound = Wire target not found : {0} +WireSourceNotFound = Wire source not found : {0} +WireIncompatibleInterface = Incompatible interfaces on wire source and target : source = {0} target = {1} +ComponentIncompatibleInterface = Incompatible interfaces on component reference and target : reference = {0} target = {1} +TooManyReferenceTargets = Too many targets on reference: {0} +ReferenceInterfaceNotSubSet = Interface of composite reference must be compatible with the interface declared by promoted component reference {0} +ServiceInterfaceNotSubSet = Interface of composite service must be a subset of the interface declared by promoted component service {0} +NoComponentReferenceTarget = No target services found for the component reference to be autowired: {0} +NoTypeForComponentProperty = No type specified on component property: Component = {0} Property = {1} +URLSyntaxException = URLSyntaxException when creating binding URI at component = {0} service = {1} binding = {2} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/assembly-validation-messages_it.properties b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/assembly-validation-messages_it.properties new file mode 100644 index 0000000000..b94d37ba2d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/main/resources/assembly-validation-messages_it.properties @@ -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. +# +# +DuplicateComponentName = Nome del componente duplicato: Composite = {0} Component = {1} +DuplicateComponentServiceName = Nome del servizio del componente duplicato: Component = {0} Service = {1} +DuplicateComponentReferenceName = Nome del reference del componente duplicato: Component = {0} Reference = {1} +DuplicateComponentPropertyName = Nome della property del componente duplicato: Component = {0} Property = {1} +NoComponentImplementation = Implementazione insistente per il componente: Component = {0} +ServiceNotFoundForComponentService = Servizio non trovato per il componente: Component = {0} Service = {1} +UnresolvedComponentImplementation = Implementazione del componente non trovata: Component = {0} Uri = {1} +DuplicateImplementationPropertyName = Nome della property del componente duplicata: Component = {0} Property = {1} +DuplicateImplementationReferenceName = Nome del riferimento duplicato: Component = {0} Reference = {1} +PropertyNotFound = Property non trovata per il componente: Component = {0} Property = {1} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java new file mode 100644 index 0000000000..8a3a89aba4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + + +/** + * Test building of assembly model instances using the assembly factory. + * + * @version $Rev$ $Date$ + */ +public class AssemblyFactoryTestCase extends TestCase { + + private AssemblyFactory assemblyFactory; + + @Override + public void setUp() throws Exception { + assemblyFactory = new DefaultAssemblyFactory(); + } + + public void testCreateComponent() { + createComponent("AccountServiceComponent1"); + } + + public void testCreateComponentType() { + createComponentType(); + } + + public void testCreateComposite() { + createComposite(); + } + + public void testCreateConstrainingType() { + createConstrainingType(); + } + + /** + * Create a composite + */ + Composite createComposite() { + Composite c = assemblyFactory.createComposite(); + + Component c1 = createComponent("AccountServiceComponent1"); + c.getComponents().add(c1); + Component c2 = createComponent("AccountServiceComponent2"); + c.getComponents().add(c2); + + Wire w = assemblyFactory.createWire(); + w.setSource(c1.getReferences().get(0)); + w.setTarget(c2.getServices().get(0)); + c.getWires().add(w); + + CompositeService cs = assemblyFactory.createCompositeService(); + cs.setName("AccountService"); + cs.setPromotedService(c1.getServices().get(0)); + cs.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + c.getServices().add(cs); + cs.getBindings().add(new TestBinding(assemblyFactory)); + + CompositeReference cr = assemblyFactory.createCompositeReference(); + cr.setName("StockQuoteService"); + cr.getPromotedReferences().add(c2.getReferences().get(1)); + cr.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + c.getReferences().add(cr); + cr.getBindings().add(new TestBinding(assemblyFactory)); + + return c; + } + + /** + * Create a new component + */ + Component createComponent(String name) { + Component c = assemblyFactory.createComponent(); + c.setName(name); + + ConstrainingType constraint = createConstrainingType(); + c.setConstrainingType(constraint); + + Implementation i = new TestImplementation(assemblyFactory); + c.setImplementation(i); + + ComponentProperty p = assemblyFactory.createComponentProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + p.setProperty(i.getProperties().get(0)); + c.getProperties().add(p); + + ComponentReference ref1 = assemblyFactory.createComponentReference(); + ref1.setName("accountDataService"); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ref1.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ref1.setReference(i.getReferences().get(0)); + c.getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(assemblyFactory)); + + ComponentReference ref2 = assemblyFactory.createComponentReference(); + ref2.setName("stockQuoteService"); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ref2.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ref2.setReference(i.getReferences().get(1)); + c.getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(assemblyFactory)); + + ComponentService s = assemblyFactory.createComponentService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + s.setService(i.getServices().get(0)); + c.getServices().add(s); + s.getBindings().add(new TestBinding(assemblyFactory)); + + return c; + } + + /** + * Create a new component type + * + * @return + */ + ComponentType createComponentType() { + ComponentType ctype = assemblyFactory.createComponentType(); + + Property p = assemblyFactory.createProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + ctype.getProperties().add(p); + + Reference ref1 = assemblyFactory.createReference(); + ref1.setName("accountDataService"); + ref1.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(assemblyFactory)); + + Reference ref2 = assemblyFactory.createReference(); + ref2.setName("stockQuoteService"); + ref2.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(assemblyFactory)); + + Service s = assemblyFactory.createService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ctype.getServices().add(s); + s.getBindings().add(new TestBinding(assemblyFactory)); + + return ctype; + } + + /** + * Create a new constraining type + * + * @return + */ + ConstrainingType createConstrainingType() { + ConstrainingType ctype = assemblyFactory.createConstrainingType(); + + AbstractProperty p = assemblyFactory.createAbstractProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + ctype.getProperties().add(p); + + AbstractReference ref1 = assemblyFactory.createAbstractReference(); + ref1.setName("accountDataService"); + ref1.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref1); + + AbstractReference ref2 = assemblyFactory.createAbstractReference(); + ref2.setName("stockQuoteService"); + ref2.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref2); + + AbstractService s = assemblyFactory.createAbstractService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ctype.getServices().add(s); + + return ctype; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java new file mode 100644 index 0000000000..5e0a2335d1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.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.sca.assembly; + + +/** + * A test interface model. + * + * @version $Rev$ $Date$ + */ +public class TestBinding implements Binding { + public TestBinding(AssemblyFactory factory) { + } + + public String getName() { + return null; + } + + public String getURI() { + return "http://test"; + } + + public void setName(String name) { + } + + public void setURI(String uri) { + } + + public void setUnresolved(boolean unresolved) { + } + + public boolean isUnresolved() { + return false; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java new file mode 100644 index 0000000000..19702954c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.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.sca.assembly; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; + +/** + * A test component implementation model. + * + * @version $Rev$ $Date$ + */ +public class TestImplementation extends ImplementationImpl implements Implementation { + public TestImplementation(AssemblyFactory factory) { + + Property p = factory.createProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + getProperties().add(p); + + Reference ref1 = factory.createReference(); + ref1.setName("accountDataService"); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(factory)); + + Reference ref2 = factory.createReference(); + ref2.setName("stockQuoteService"); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ref2.setInterfaceContract(new TestInterfaceContract(factory)); + getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(factory)); + + Service s = factory.createService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(factory)); + getServices().add(s); + s.getBindings().add(new TestBinding(factory)); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java new file mode 100644 index 0000000000..dbe0cb8225 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.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.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceImpl; + +/** + * A test interface model. + * + * @version $Rev$ $Date$ + */ +public class TestInterface extends InterfaceImpl implements Interface { + + public TestInterface(AssemblyFactory factory) { + + setRemotable(true); + + Operation operation = new TestOperation(); + operation.setName("test"); + getOperations().add(operation); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java new file mode 100644 index 0000000000..ee6b95edc9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.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.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractImpl; + +/** + * A test interface contract model. + * + * @version $Rev$ $Date$ + */ +public class TestInterfaceContract extends InterfaceContractImpl implements InterfaceContract { + + public TestInterfaceContract(AssemblyFactory factory) { + + TestInterface testInterface = new TestInterface(factory); + setInterface(testInterface); + + TestInterface testCallbackInterface = new TestInterface(factory); + setCallbackInterface(testCallbackInterface); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java new file mode 100644 index 0000000000..d94a7e93a3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.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.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; + +/** + * A test operation model. + * + * @version $Rev$ $Date$ + */ +public class TestOperation extends OperationImpl { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java new file mode 100644 index 0000000000..fabafc998b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.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.sca.assembly.builder.impl; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; + +/** + * Test the CompositeBuilder. + * + * @version $Rev$ $Date$ + */ +public class CompositeBuilderTestCase extends TestCase { + + private AssemblyFactory assemblyFactory; + + @Override + protected void setUp() throws Exception { + assemblyFactory = new DefaultAssemblyFactory(); + } + + public void testFuseIncludes() throws Exception { + Composite c1 = assemblyFactory.createComposite(); + c1.setName(new QName("http://foo", "C1")); + Component a = assemblyFactory.createComponent(); + a.setName("a"); + c1.getComponents().add(a); + CompositeService s = assemblyFactory.createCompositeService(); + s.setName("s"); + c1.getServices().add(s); + CompositeReference r = assemblyFactory.createCompositeReference(); + r.setName("r"); + c1.getReferences().add(r); + + Composite c2 = assemblyFactory.createComposite(); + c2.setName(new QName("http://foo", "C2")); + c1.getIncludes().add(c2); + Component b = assemblyFactory.createComponent(); + b.setName("b"); + c2.getComponents().add(b); + + Composite c = assemblyFactory.createComposite(); + c.setName(new QName("http://foo", "C")); + c.getIncludes().add(c1); + + new CompositeIncludeBuilderImpl(null).build(c); + + assertTrue(c.getComponents().get(0).getName().equals("a")); + assertTrue(c.getComponents().get(1).getName().equals("b")); + assertTrue(c.getServices().get(0).getName().equals("s")); + assertTrue(c.getReferences().get(0).getName().equals("r")); + } + + public void testExpandComposites() throws Exception { + Composite c1 = assemblyFactory.createComposite(); + c1.setName(new QName("http://foo", "C1")); + Component a = assemblyFactory.createComponent(); + a.setName("a"); + c1.getComponents().add(a); + CompositeService s = assemblyFactory.createCompositeService(); + s.setName("s"); + c1.getServices().add(s); + CompositeReference r = assemblyFactory.createCompositeReference(); + r.setName("r"); + c1.getReferences().add(r); + + Composite c2 = assemblyFactory.createComposite(); + c2.setName(new QName("http://foo", "C2")); + Component b = assemblyFactory.createComponent(); + b.setName("b"); + c2.getComponents().add(b); + + Composite c = assemblyFactory.createComposite(); + c.setName(new QName("http://foo", "C")); + Component x = assemblyFactory.createComponent(); + x.setName("x"); + x.setImplementation(c1); + c.getComponents().add(x); + Component y = assemblyFactory.createComponent(); + y.setName("y"); + y.setImplementation(c2); + c.getComponents().add(y); + Component z = assemblyFactory.createComponent(); + z.setName("z"); + z.setImplementation(c1); + c.getComponents().add(z); + + new CompositeCloneBuilderImpl(null).build(c); + + assertTrue(c.getComponents().get(0).getImplementation() != c1); + assertTrue(c.getComponents().get(1).getImplementation() != c2); + assertTrue(c.getComponents().get(2).getImplementation() != c1); + + Composite i = (Composite)c.getComponents().get(0).getImplementation(); + assertTrue(i.getComponents().get(0) != a); + assertTrue(i.getComponents().get(0).getName().equals("a")); + assertTrue(i.getServices().get(0).getName().equals("s")); + assertTrue(i.getServices().get(0) != s); + assertTrue(i.getReferences().get(0).getName().equals("r")); + assertTrue(i.getReferences().get(0) != r); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java new file mode 100644 index 0000000000..82b1fd8665 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.AbstractService; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.TestBinding; +import org.apache.tuscany.sca.assembly.TestImplementation; +import org.apache.tuscany.sca.assembly.TestInterfaceContract; +import org.apache.tuscany.sca.assembly.Wire; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class PrintUtilTestCase { + + private AssemblyFactory factory = new DefaultAssemblyFactory(); + + /** + * Create a composite + */ + Composite createComposite() { + Composite c = factory.createComposite(); + + Component c1 = createComponent("AccountServiceComponent1"); + c.getComponents().add(c1); + Component c2 = createComponent("AccountServiceComponent2"); + c.getComponents().add(c2); + + Wire w = factory.createWire(); + w.setSource(c1.getReferences().get(0)); + w.setTarget(c2.getServices().get(0)); + c.getWires().add(w); + + CompositeService cs = factory.createCompositeService(); + cs.setName("AccountService"); + cs.setPromotedService(c1.getServices().get(0)); + cs.setInterfaceContract(new TestInterfaceContract(factory)); + c.getServices().add(cs); + cs.getBindings().add(new TestBinding(factory)); + + CompositeReference cr = factory.createCompositeReference(); + cr.setName("StockQuoteService"); + cr.getPromotedReferences().add(c2.getReferences().get(1)); + cr.setInterfaceContract(new TestInterfaceContract(factory)); + c.getReferences().add(cr); + cr.getBindings().add(new TestBinding(factory)); + + return c; + } + + /** + * Create a new component + */ + Component createComponent(String name) { + Component c = factory.createComponent(); + c.setName(name); + + ConstrainingType constraint = createConstrainingType(); + c.setConstrainingType(constraint); + + Implementation i = new TestImplementation(factory); + c.setImplementation(i); + + ComponentProperty p = factory.createComponentProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + p.setProperty(i.getProperties().get(0)); + c.getProperties().add(p); + + ComponentReference ref1 = factory.createComponentReference(); + ref1.setName("accountDataService"); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ref1.setInterfaceContract(new TestInterfaceContract(factory)); + ref1.setReference(i.getReferences().get(0)); + c.getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(factory)); + + ComponentReference ref2 = factory.createComponentReference(); + ref2.setName("stockQuoteService"); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ref2.setInterfaceContract(new TestInterfaceContract(factory)); + ref2.setReference(i.getReferences().get(1)); + c.getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(factory)); + + ComponentService s = factory.createComponentService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(factory)); + s.setService(i.getServices().get(0)); + c.getServices().add(s); + s.getBindings().add(new TestBinding(factory)); + + return c; + } + + /** + * Create a new component type + * + * @return + */ + ComponentType createComponentType() { + ComponentType ctype = factory.createComponentType(); + + Property p = factory.createProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + ctype.getProperties().add(p); + + Reference ref1 = factory.createReference(); + ref1.setName("accountDataService"); + ref1.setInterfaceContract(new TestInterfaceContract(factory)); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(factory)); + + Reference ref2 = factory.createReference(); + ref2.setName("stockQuoteService"); + ref2.setInterfaceContract(new TestInterfaceContract(factory)); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(factory)); + + Service s = factory.createService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(factory)); + ctype.getServices().add(s); + s.getBindings().add(new TestBinding(factory)); + + return ctype; + } + + /** + * Create a new constraining type + * + * @return + */ + ConstrainingType createConstrainingType() { + ConstrainingType ctype = factory.createConstrainingType(); + + AbstractProperty p = factory.createAbstractProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + ctype.getProperties().add(p); + + AbstractReference ref1 = factory.createAbstractReference(); + ref1.setName("accountDataService"); + ref1.setInterfaceContract(new TestInterfaceContract(factory)); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref1); + + AbstractReference ref2 = factory.createAbstractReference(); + ref2.setName("stockQuoteService"); + ref2.setInterfaceContract(new TestInterfaceContract(factory)); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref2); + + AbstractService s = factory.createAbstractService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(factory)); + ctype.getServices().add(s); + + return ctype; + } + + @Test + public void testPrint1() { + Composite composite = createComposite(); + StringWriter sw = new StringWriter(); + PrintUtil p = new PrintUtil(new PrintWriter(sw), true); + p.print(composite); + // System.out.println(sw.toString()); + } + + @Test + public void testPrint2() { + Composite composite = createComposite(); + StringWriter sw = new StringWriter(); + PrintUtil p = new PrintUtil(new PrintWriter(sw), false); + p.print(composite); + // System.out.println(sw.toString()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/pom.xml new file mode 100644 index 0000000000..d17470a17f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/pom.xml @@ -0,0 +1,233 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-atom-abdera + Apache Tuscany SCA Abdera Atom Feed Binding Extension + + + + org.apache.tuscany.sca + tuscany-binding-atom + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-http + 1.6-SNAPSHOT + + + + commons-httpclient + commons-httpclient + 3.1 + + + + org.apache.abdera + abdera-core + 0.4.0-incubating + + + org.apache.geronimo.specs + geronimo-activation_1.0.2_spec + + + + + + org.apache.abdera + abdera-parser + 0.4.0-incubating + + + stax + stax-api + + + xom + xom + + + org.apache.ws.commons.axiom + axiom-impl + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.7 + + + + org.apache.abdera + abdera-client + 0.4.0-incubating + + + + org.apache.abdera + abdera-extensions-main + 0.4.0-incubating + + + + org.apache.abdera + abdera-extensions-json + 0.4.0-incubating + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + commons-codec + commons-codec + 1.3 + + + commons-codec + commons-codec + + + + + + commons-logging + commons-logging + 1.1.1 + + + javax.servlet + servlet-api + + + avalon-framework + avalon-framework + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.atom.abdera + ${pom.name} + org.apache.tuscany.sca.binding.atom* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/Collection.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/Collection.java new file mode 100644 index 0000000000..7356cd0d2a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/Collection.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom.collection; + +import org.apache.abdera.model.Entry; +import org.apache.abdera.model.Feed; +import org.osoa.sca.annotations.Remotable; + +/** + * Provides access to a collection of resources using Atom. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Collection { + + /** + * Get an Atom feed for a collection of resources. + * + * @return the Atom feed + */ + Feed getFeed(); + + /** + * Get an Atom feed for a collection of resources resulting + * from a query. + * + * @param queryString a query string + * @return the Atom feed + */ + Feed query(String queryString); + + /** + * Creates a new entry. + * + * @param entry + * @return + */ + Entry post(Entry entry); + + /** + * Retrieves an entry. + * + * @param id + * @return + */ + Entry get(String id) throws NotFoundException; + + /** + * Update an entry. + * + * @param id + * @param entry + * @return + */ + void put(String id, Entry entry) throws NotFoundException; + + /** + * Delete an entry. + * + * @param id + */ + void delete(String id) throws NotFoundException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/MediaCollection.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/MediaCollection.java new file mode 100644 index 0000000000..cc351442e7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/MediaCollection.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.sca.binding.atom.collection; + +import java.io.InputStream; + +import org.osoa.sca.annotations.Remotable; + +import org.apache.abdera.model.Entry; + +/** + * Provides access to a collection of resources using Atom. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface MediaCollection extends Collection { + + /** + * Creates a new media entry + * + * @param title + * @param slug + * @param contentType + * @param media + */ + Entry postMedia(String title, String slug, String contentType, InputStream media); + + /** + * Update a media entry. + * + * @param id + * @param contentType + * @param media + * @return + */ + void putMedia(String id, String contentType, InputStream media) throws NotFoundException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/NotFoundException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/NotFoundException.java new file mode 100644 index 0000000000..b457840922 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/collection/NotFoundException.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.sca.binding.atom.collection; + +/** + * Indicates that a resource could not be found. + * + * @version $Rev$ $Date$ + */ +public class NotFoundException extends Exception { + private static final long serialVersionUID = -5046027674128627383L; + + public NotFoundException() { + } + + public NotFoundException(String message) { + super(message); + } + + public NotFoundException(Throwable cause) { + super(cause); + } + + public NotFoundException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java new file mode 100644 index 0000000000..99fa3a2e73 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingInvoker.java @@ -0,0 +1,516 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom.provider; + +import static org.apache.tuscany.sca.binding.atom.provider.AtomBindingUtil.entry; +import static org.apache.tuscany.sca.binding.atom.provider.AtomBindingUtil.feedEntry; + +import java.io.InputStreamReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import org.apache.abdera.Abdera; +import org.apache.abdera.factory.Factory; +import org.apache.abdera.model.Document; +import org.apache.abdera.model.Feed; +import org.apache.abdera.parser.Parser; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.DeleteMethod; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.tuscany.sca.binding.atom.collection.NotFoundException; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Invoker for the Atom binding. + * + * @version $Rev$ $Date$ + */ +class AtomBindingInvoker implements Invoker, DataExchangeSemantics { + + private static final Factory abderaFactory = Abdera.getNewFactory(); + private static final Parser abderaParser = Abdera.getNewParser(); + + Operation operation; + String uri; + HttpClient httpClient; + String authorizationHeader; + AtomReferenceBindingProvider provider; + + AtomBindingInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader, AtomReferenceBindingProvider bindingProvider) { + this.operation = operation; + this.uri = uri; + this.httpClient = httpClient; + this.authorizationHeader = authorizationHeader; + this.provider = bindingProvider; + } + + public Message invoke(Message msg) { + // Shouldn't get here, as the only supported methods are + // defined in the ResourceCollection interface, and implemented + // by specific invoker subclasses + throw new UnsupportedOperationException(operation.getName()); + } + + public boolean allowsPassByReference() { + return true; + } + + + /** + * Get operation invoker + */ + public static class GetInvoker extends AtomBindingInvoker { + + public GetInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader, AtomReferenceBindingProvider bindingProvider) { + super(operation, uri, httpClient, authorizationHeader, bindingProvider); + } + + @Override + public Message invoke(Message msg) { + // Get an entry + String id = (String)((Object[])msg.getBody())[0]; + + // Send an HTTP GET + GetMethod getMethod = new GetMethod(uri + "/" + id); + getMethod.setRequestHeader("Authorization", authorizationHeader); + boolean parsing = false; + try { + httpClient.executeMethod(getMethod); + int status = getMethod.getStatusCode(); + + // Read the Atom entry + if (status == 200) { + Document doc = + abderaParser.parse(new InputStreamReader(getMethod.getResponseBodyAsStream())); + parsing = true; + org.apache.abdera.model.Entry feedEntry = doc.getRoot(); + + if (provider.supportsFeedEntries()) { + + // Return the Atom entry + msg.setBody(feedEntry); + + } else { + + // Convert the feed entry to a data entry and return the data item + Entry entry = entry(feedEntry, provider.getItemClassType(), + provider.getItemXMLType(), provider.getMediator()); + msg.setBody(entry.getData()); + } + + } else if (status == 404) { + if ( provider.supportsFeedEntries()) + msg.setFaultBody(new NotFoundException()); + else + msg.setFaultBody(new org.apache.tuscany.sca.data.collection.NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + if (!parsing) { + // Release the connection unless the Abdera parser is + // parsing the response, in this case it will release it + getMethod.releaseConnection(); + } + } + + return msg; + } + } + + /** + * Post operation invoker + */ + public static class PostInvoker extends AtomBindingInvoker { + + public PostInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader, AtomReferenceBindingProvider bindingProvider) { + super(operation, uri, httpClient, authorizationHeader, bindingProvider); + } + + @Override + public Message invoke(Message msg) { + // Post an entry + Object[] args = (Object[])msg.getBody(); + org.apache.abdera.model.Entry feedEntry; + if (provider.supportsFeedEntries()) { + + // Expect an Atom entry + feedEntry = (org.apache.abdera.model.Entry)args[0]; + } else { + + // Expect a key and data item + Entry entry = new Entry(args[0], args[1]); + feedEntry = feedEntry(entry, provider.getItemClassType(), + provider.getItemXMLType(), provider.getMediator(), abderaFactory); + } + + // Send an HTTP POST + PostMethod postMethod = new PostMethod(uri); + postMethod.setRequestHeader("Authorization", authorizationHeader); + boolean parsing = false; + try { + + // Write the Atom entry + StringWriter writer = new StringWriter(); + feedEntry.writeTo(writer); + // postMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8"); + postMethod.setRequestHeader("Content-type", "application/atom+xml;type=entry"); + postMethod.setRequestEntity(new StringRequestEntity(writer.toString())); + + httpClient.executeMethod(postMethod); + int status = postMethod.getStatusCode(); + + // Read the Atom entry + if (status == 200 || status == 201) { + Document doc = abderaParser.parse(new InputStreamReader(postMethod.getResponseBodyAsStream())); + parsing = true; + org.apache.abdera.model.Entry createdEntry = doc.getRoot(); + + // Returns the created Atom entry ID + if (provider.supportsFeedEntries()) { + + // Returns the created entry + msg.setBody(createdEntry); + + } else { + + // Returns the id of the created entry + msg.setBody(createdEntry.getId().toString()); + } + + } else if (status == 404) { + if ( provider.supportsFeedEntries()) + msg.setFaultBody(new NotFoundException()); + else + msg.setFaultBody(new org.apache.tuscany.sca.data.collection.NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + if (!parsing) { + // Release the connection unless the Abdera parser is + // parsing the response, in this case it will release it + postMethod.releaseConnection(); + } + } + + return msg; + } + } + + /** + * Put operation invoker + */ + public static class PutInvoker extends AtomBindingInvoker { + + public PutInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader, AtomReferenceBindingProvider bindingProvider) { + super(operation, uri, httpClient, authorizationHeader, bindingProvider); + } + + @Override + public Message invoke(Message msg) { + // Put an entry + Object[] args = (Object[])msg.getBody(); + String id; + org.apache.abdera.model.Entry feedEntry; + if (provider.supportsFeedEntries()) { + + // Expect a key and Atom entry + id = (String)args[0]; + feedEntry = (org.apache.abdera.model.Entry)args[1]; + } else { + + // Expect a key and data item + id = (String)args[0]; + Entry entry = new Entry(id, args[1]); + feedEntry = feedEntry(entry, provider.getItemClassType(), + provider.getItemXMLType(), provider.getMediator(), abderaFactory); + } + + // Send an HTTP PUT + PutMethod putMethod = new PutMethod(uri + "/" + id); + putMethod.setRequestHeader("Authorization", authorizationHeader); + + try { + + // Write the Atom entry + StringWriter writer = new StringWriter(); + feedEntry.writeTo(writer); + putMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8"); + putMethod.setRequestEntity(new StringRequestEntity(writer.toString())); + + httpClient.executeMethod(putMethod); + int status = putMethod.getStatusCode(); + if (status == 200 || status == 201 || status == 412) { + + msg.setBody(null); + + } else if (status == 404) { + if ( provider.supportsFeedEntries()) + msg.setFaultBody(new NotFoundException()); + else + msg.setFaultBody(new org.apache.tuscany.sca.data.collection.NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + putMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * Delete operation invoker + */ + public static class DeleteInvoker extends AtomBindingInvoker { + + public DeleteInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader, AtomReferenceBindingProvider bindingProvider) { + super(operation, uri, httpClient, authorizationHeader, bindingProvider); + } + + @Override + public Message invoke(Message msg) { + // Delete an entry + String id = (String)((Object[])msg.getBody())[0]; + + // Send an HTTP DELETE + DeleteMethod deleteMethod = new DeleteMethod(uri + "/" + id); + deleteMethod.setRequestHeader("Authorization", authorizationHeader); + try { + httpClient.executeMethod(deleteMethod); + int status = deleteMethod.getStatusCode(); + if (status == 200) { + msg.setBody(null); + + } else if (status == 404) { + if ( provider.supportsFeedEntries()) + msg.setFaultBody(new NotFoundException()); + else + msg.setFaultBody(new org.apache.tuscany.sca.data.collection.NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + deleteMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * GetAll operation invoker + */ + public static class GetAllInvoker extends AtomBindingInvoker { + + public GetAllInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader, AtomReferenceBindingProvider bindingProvider) { + super(operation, uri, httpClient, authorizationHeader, bindingProvider); + } + + @Override + public Message invoke(Message msg) { + // Get a feed + + // Send an HTTP GET + GetMethod getMethod = new GetMethod(uri); + getMethod.setRequestHeader("Authorization", authorizationHeader); + boolean parsing = false; + try { + httpClient.executeMethod(getMethod); + int status = getMethod.getStatusCode(); + // AtomBindingInvoker.printResponseHeader( getMethod ); + + // Read the Atom feed + if (status == 200) { + Document doc = abderaParser.parse(new InputStreamReader(getMethod.getResponseBodyAsStream())); + parsing = true; + + Feed feed = null; + try { + feed = doc.getRoot(); + } catch(Exception e) { + throw new IllegalArgumentException("Invalid feed format :" + uri); + } + + if (provider.supportsFeedEntries()) { + + // Returns the Atom feed + msg.setBody(feed); + + } else { + + // Returns an array of data entries + List> entries = new ArrayList>(); + for (org.apache.abdera.model.Entry feedEntry: feed.getEntries()) { + Entry entry = entry(feedEntry, provider.getItemClassType(), + provider.getItemXMLType(), provider.getMediator()); + entries.add(entry); + } + msg.setBody(entries.toArray(new Entry[entries.size()])); + } + + } else if (status == 404) { + if ( provider.supportsFeedEntries()) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new org.apache.tuscany.sca.data.collection.NotFoundException()); + } + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + if (!parsing) { + // Release the connection unless the Abdera parser is + // parsing the response, in this case it will release it + getMethod.releaseConnection(); + } + } + + return msg; + } + } + + /** + * Query operation invoker + */ + public static class QueryInvoker extends AtomBindingInvoker { + + public QueryInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader, AtomReferenceBindingProvider bindingProvider) { + super(operation, uri, httpClient, authorizationHeader, bindingProvider); + } + + @Override + public Message invoke(Message msg) { + // Get a feed from a query + String queryString = (String)((Object[])msg.getBody())[0]; + + // Send an HTTP GET + GetMethod getMethod = new GetMethod(uri); + getMethod.setRequestHeader("Authorization", authorizationHeader); + getMethod.setQueryString(queryString); + boolean parsing = false; + try { + httpClient.executeMethod(getMethod); + int status = getMethod.getStatusCode(); + + // Read the Atom feed + if (status == 200) { + Document doc = abderaParser.parse(new InputStreamReader(getMethod.getResponseBodyAsStream())); + parsing = true; + Feed feed = doc.getRoot(); + + if (provider.supportsFeedEntries()) { + + // Returns the Atom feed + msg.setBody(feed); + + } else { + + // Returns an array of data entries + List> entries = new ArrayList>(); + for (org.apache.abdera.model.Entry feedEntry: feed.getEntries()) { + Entry entry = entry(feedEntry, provider.getItemClassType(), + provider.getItemXMLType(), provider.getMediator()); + entries.add(entry); + } + msg.setBody(entries.toArray(new Entry[entries.size()])); + } + + } else if (status == 404) { + if ( provider.supportsFeedEntries()) + msg.setFaultBody(new NotFoundException()); + else + msg.setFaultBody(new org.apache.tuscany.sca.data.collection.NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + if (!parsing) { + // Release the connection unless the Abdera parser is + // parsing the response, in this case it will release it + getMethod.releaseConnection(); + } + } + + return msg; + } + } + + /** + * PostMedia operation invoker + */ + public static class PostMediaInvoker extends AtomBindingInvoker { + + public PostMediaInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader, AtomReferenceBindingProvider bindingProvider) { + super(operation, uri, httpClient, authorizationHeader, bindingProvider); + } + + @Override + public Message invoke(Message msg) { + // PostInvoker can detect media by content type (non-Feed, non-Entry) + return super.invoke(msg); + } + } + + /** + * PutMedia operation invoker + */ + public static class PutMediaInvoker extends AtomBindingInvoker { + + public PutMediaInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader, AtomReferenceBindingProvider bindingProvider) { + super(operation, uri, httpClient, authorizationHeader, bindingProvider); + } + + @Override + public Message invoke(Message msg) { + // PutInvoker can detect media by content type (non-Feed, non-Entry) + return super.invoke(msg); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java new file mode 100644 index 0000000000..5ba07f5e22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java @@ -0,0 +1,914 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom.provider; + +import static org.apache.tuscany.sca.binding.atom.provider.AtomBindingUtil.entry; +import static org.apache.tuscany.sca.binding.atom.provider.AtomBindingUtil.feedEntry; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.net.URLDecoder; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.StringTokenizer; +import java.util.logging.Logger; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.abdera.Abdera; +import org.apache.abdera.factory.Factory; +import org.apache.abdera.i18n.iri.IRI; +import org.apache.abdera.model.Category; +import org.apache.abdera.model.Collection; +import org.apache.abdera.model.Document; +import org.apache.abdera.model.Feed; +import org.apache.abdera.model.Link; +import org.apache.abdera.model.Service; +import org.apache.abdera.model.Workspace; +import org.apache.abdera.parser.ParseException; +import org.apache.abdera.parser.Parser; +import org.apache.abdera.writer.WriterFactory; +import org.apache.commons.codec.binary.Base64; +import org.apache.tuscany.sca.binding.http.HTTPCacheContext; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * A resource collection binding listener, implemented as a Servlet and + * registered in a Servlet host provided by the SCA hosting runtime. + * + * @version $Rev$ $Date$ + */ +class AtomBindingListenerServlet extends HttpServlet { + private static final Logger logger = Logger.getLogger(AtomBindingListenerServlet.class.getName()); + private static final long serialVersionUID = 1L; + + private static final Factory abderaFactory = Abdera.getNewFactory(); + private static final Parser abderaParser = Abdera.getNewParser(); + private static final String ETAG = "ETag"; + private static final String LASTMODIFIED = "Last-Modified"; + private static final String LOCATION = "Location"; + private static final String CONTENTLOCATION = "Content-Location"; + private static final SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time + + private RuntimeWire wire; + private Invoker getFeedInvoker; + private Invoker getAllInvoker; + private Invoker queryInvoker; + private Invoker getInvoker; + private Invoker postInvoker; + private Invoker postMediaInvoker; + private Invoker putInvoker; + private Invoker putMediaInvoker; + private Invoker deleteInvoker; + private MessageFactory messageFactory; + private String title; + private String description; + private Mediator mediator; + private DataType itemClassType; + private DataType itemXMLType; + private boolean supportsFeedEntries; + + /** + * Constructs a new binding listener. + * + * @param wire + * @param messageFactory + * @param feedType + */ + AtomBindingListenerServlet(RuntimeWire wire, MessageFactory messageFactory, Mediator mediator, String title, String description) { + this.wire = wire; + this.messageFactory = messageFactory; + this.mediator = mediator; + this.title = title; + this.description = description; + + // Get the invokers for the supported operations + Operation getOperation = null; + for (InvocationChain invocationChain : this.wire.getInvocationChains()) { + invocationChain.setAllowsPassByReference(true); + Operation operation = invocationChain.getTargetOperation(); + String operationName = operation.getName(); + if (operationName.equals("getFeed")) { + getFeedInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("getAll")) { + getAllInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("query")) { + queryInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("get")) { + getInvoker = invocationChain.getHeadInvoker(); + getOperation = operation; + } else if (operationName.equals("put")) { + putInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("putMedia")) { + putMediaInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("post")) { + postInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("postMedia")) { + postMediaInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("delete")) { + deleteInvoker = invocationChain.getHeadInvoker(); + } + } + + // Determine the collection item type + if (getOperation != null) { + itemXMLType = new DataTypeImpl>(String.class.getName(), String.class, String.class); + Class itemClass = getOperation.getOutputType().getPhysical(); + if (itemClass == org.apache.abdera.model.Entry.class) { + supportsFeedEntries = true; + } + //We assume that the item type is the same for both input and + //ouput for all operations on the interface + itemClassType = getOperation.getOutputType(); + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // No authentication required for a get request + + // Test for any cache info in the request + HTTPCacheContext cacheContext = null; + try { + cacheContext = HTTPCacheContext.getCacheContextFromRequest( request ); + } catch ( java.text.ParseException e ) { + } + // System.out.println( "AtomBindingListener.doGet cache context=" + cacheContext ); + + // Get the request path + //int servletPathLength = request.getContextPath().length() + request.getServletPath().length(); + //String path = URLDecoder.decode(request.getRequestURI().substring(servletPathLength), "UTF-8"); + + String path = URLDecoder.decode(getRequestPath(request), "UTF-8"); + + logger.fine("get " + request.getRequestURI()); + + // Handle an Atom request + if (path != null && path.equals("/atomsvc")) { + /* + + + + resource + + entries + application/atom+xml;type=entry + + + + + */ + + // Return the Atom service document + response.setContentType("application/atomsvc+xml; charset=utf-8"); + + String href = request.getRequestURL().toString(); + href = href.substring(0, href.length() - "/atomsvc".length()); + + String workspaceURL = new String( href ); + int pathIndex = workspaceURL.indexOf( request.getServletPath() ); + if ( -1 != pathIndex ) { + workspaceURL = workspaceURL.substring( 0, pathIndex ) + "/"; + } + + Service service = abderaFactory.newService(); + //service.setText("service"); + + Workspace workspace = abderaFactory.newWorkspace(); + if ( title != null ) { + workspace.setTitle(title); + } else { + workspace.setTitle("workspace"); + } + workspace.setBaseUri( new IRI( workspaceURL )); + + Collection collection = workspace.addCollection("collection", href ); + Feed feed = getFeed( request ); + if ( feed != null ) { + String title = feed.getTitle(); + if ( title != null ) { + collection.setTitle(title); + } else { + collection.setTitle("entries"); + } + collection.addAccepts("application/atom+xml;type=feed"); + collection.addAccepts("application/json;type=feed"); + collection.addAccepts("application/atom+xml;type=entry"); + collection.addAccepts("application/json;type=entry"); + List categories = feed.getCategories(); + if ( categories != null ) { + collection.addCategories(categories, false, null); + } else { + collection.addCategories().setFixed(false); + } + + } else { + collection.setTitle("entries"); + // collection.addAccepts("application/atom+xml;type=feed"); + collection.addAccepts("application/atom+xml; type=entry"); + collection.addAccepts("application/json;type=entry"); + collection.addCategories().setFixed(false); + } + workspace.addCollection(collection); + service.addWorkspace(workspace); + + //FIXME add prettyPrint support + try { + service.getDocument().writeTo(response.getOutputStream()); + } catch (IOException ioe) { + throw new ServletException(ioe); + } + + } else if (path == null || path.length() == 0 || path.equals("/")) { + + // Return a feed containing the entries in the collection + Feed feed = getFeed( request ); + if (feed != null) { + String feedETag = null; + if (feed.getId() != null) + feedETag = "\"" + feed.getId().toString() + "\""; + Date feedUpdated = feed.getUpdated(); + // Test request for predicates. + String predicate = request.getHeader( "If-Match" ); + if (( predicate != null ) && ( !predicate.equals(feedETag) )) { + // No match, should short circuit + response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); + return; + } + predicate = request.getHeader( "If-None-Match" ); + if (( predicate != null ) && ( predicate.equals(feedETag) )) { + // Match, should short circuit + response.sendError(HttpServletResponse.SC_NOT_MODIFIED); + return; + } + if ( feedUpdated != null ) { + predicate = request.getHeader( "If-Unmodified-Since" ); + if ( predicate != null ) { + try { + Date predicateDate = dateFormat.parse( predicate ); + if ( predicateDate.compareTo( feedUpdated ) < 0 ) { + // Match, should short circuit + response.sendError(HttpServletResponse.SC_NOT_MODIFIED); + return; + } + } catch ( java.text.ParseException e ) { + // Ignore and move on + } + } + predicate = request.getHeader( "If-Modified-Since" ); + if ( predicate != null ) { + try { + Date predicateDate = dateFormat.parse( predicate ); + if ( predicateDate.compareTo( feedUpdated ) > 0 ) { + // Match, should short circuit + response.sendError(HttpServletResponse.SC_NOT_MODIFIED); + return; + } + } catch ( java.text.ParseException e ) { + // Ignore and move on + } + } + } + // Provide Etag based on Id and time if given. + // Ignore if not given. (Browser may cache if trivial ETag is given.) + if ( feedETag != null ) { + response.addHeader(ETAG, feedETag); + } + if ( feedUpdated != null ) { + response.addHeader(LASTMODIFIED, dateFormat.format( feedUpdated )); + } + + // Content negotiation + String acceptType = request.getHeader( "Accept" ); + String preferredType = getContentPreference( acceptType ); + if (( preferredType != null ) && ((preferredType.indexOf( "json") > -1) || (preferredType.indexOf( "JSON") > -1 ))) { + // JSON response body + response.setContentType("application/json;type=feed"); + + try { + Abdera abdera = new Abdera(); + WriterFactory wf = abdera.getWriterFactory(); + org.apache.abdera.writer.Writer json = wf.getWriter("json"); + feed.writeTo(json, response.getWriter()); + } catch (Exception e) { + throw new ServletException(e); + } + + } else { + // Write the Atom feed + response.setContentType("application/atom+xml;type=feed"); + try { + feed.getDocument().writeTo(response.getOutputStream()); + } catch (IOException ioe) { + throw new ServletException(ioe); + } + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else if (path.startsWith("/")) { + // Return a specific entry in the collection + org.apache.abdera.model.Entry feedEntry; + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + String id = path.substring(1); + requestMessage.setBody(new Object[] {id}); + Message responseMessage = getInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + return; + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + + } + if (supportsFeedEntries) { + // The service implementation returns a feed entry + feedEntry = responseMessage.getBody(); + } else { + // The service implementation only returns a data item, create an entry + // from it + Entry entry = new Entry(id, responseMessage.getBody()); + feedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator, abderaFactory); + } + // Write the Atom entry + if (feedEntry != null) { + String entryETag = null; + if (feedEntry.getId() != null) + entryETag = feedEntry.getId().toString(); + Date entryUpdated = feedEntry.getUpdated(); + if ( entryUpdated != null ) + response.addHeader(LASTMODIFIED, dateFormat.format( entryUpdated )); + // TODO Check If-Modified-Since If-Unmodified-Since predicates against LASTMODIFIED. + // If true return 304 and null body. + + Link link = feedEntry.getSelfLink(); + if (link != null) { + response.addHeader(LOCATION, link.getHref().toString()); + } else { + link = feedEntry.getLink( "Edit" ); + if (link != null) { + response.addHeader(LOCATION, link.getHref().toString()); + } + } + + // Test request for predicates. + String predicate = request.getHeader( "If-Match" ); + if (( predicate != null ) && ( !predicate.equals(entryETag) )) { + // No match, should short circuit + response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); + return; + } + predicate = request.getHeader( "If-None-Match" ); + if (( predicate != null ) && ( predicate.equals(entryETag) )) { + // Match, should short circuit + response.sendError(HttpServletResponse.SC_NOT_MODIFIED); + return; + } + if ( entryUpdated != null ) { + predicate = request.getHeader( "If-Unmodified-Since" ); + if ( predicate != null ) { + try { + Date predicateDate = dateFormat.parse( predicate ); + if ( predicateDate.compareTo( entryUpdated ) < 0 ) { + // Match, should short circuit + response.sendError(HttpServletResponse.SC_NOT_MODIFIED); + return; + } + } catch ( java.text.ParseException e ) { + // Ignore and move on + } + } + predicate = request.getHeader( "If-Modified-Since" ); + if ( predicate != null ) { + try { + Date predicateDate = dateFormat.parse( predicate ); + if ( predicateDate.compareTo( entryUpdated ) > 0 ) { + // Match, should short circuit + response.sendError(HttpServletResponse.SC_NOT_MODIFIED); + return; + } + } catch ( java.text.ParseException e ) { + // Ignore and move on + } + } + } + // Provide Etag based on Id and time if given. + // Ignore if not given. (Browser may cache if trivial ETag is given.) + if (entryETag != null) { + response.addHeader(ETAG, entryETag ); + } + if ( entryUpdated != null ) { + response.addHeader(LASTMODIFIED, dateFormat.format( entryUpdated )); + } + + // Content negotiation + String acceptType = request.getHeader( "Accept" ); + String preferredType = getContentPreference( acceptType ); + if (( preferredType != null ) && ((preferredType.indexOf( "json") > -1) || (preferredType.indexOf( "JSON") > -1 ))) { + // JSON response body + response.setContentType("application/json;type=entry"); + try { + Abdera abdera = new Abdera(); + WriterFactory wf = abdera.getWriterFactory(); + org.apache.abdera.writer.Writer json = wf.getWriter("json"); + feedEntry.writeTo(json, response.getWriter()); + } catch (Exception e) { + throw new ServletException(e); + } + } else { + // XML response body + response.setContentType("application/atom+xml;type=entry"); + try { + feedEntry.writeTo(getWriter(response)); + } catch (IOException ioe) { + throw new ServletException(ioe); + } + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } else { + // Path doesn't match any known pattern + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } + + protected Feed getFeed( HttpServletRequest request ) throws ServletException { + if (supportsFeedEntries) { + // The service implementation supports feed entries, invoke its getFeed operation + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + requestMessage.setBody(new Object[] {request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + responseMessage = getFeedInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + return (Feed)responseMessage.getBody(); + } else { + + // The service implementation does not support feed entries, + // invoke its getAll operation to get the data item collection, then create + // feed entries from the items + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + requestMessage.setBody(new Object[] {request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + responseMessage = getAllInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + Entry[] collection = (Entry[])responseMessage.getBody(); + if (collection != null) { + + // Create the feed + Feed feed = abderaFactory.newFeed(); + + // Set the feed title + if (title != null) { + feed.setTitle(title); + } else { + feed.setTitle("Feed"); + } + if (description != null) { + feed.setSubtitle(description); + } + // All feeds must provide Id and updated elements. + // However, some do not, so provide some program protection. + feed.setId( "Feed" + feed.hashCode()); + Date responseLastModified = new Date( 0 ); + + // Add entries to the feed + for (Entry entry: collection) { + org.apache.abdera.model.Entry feedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator, abderaFactory); + // Use the most recent entry update as the feed update + Date entryUpdated = feedEntry.getUpdated(); + if (( entryUpdated != null ) && (entryUpdated.compareTo( responseLastModified ) > 0 )) { + responseLastModified = entryUpdated; + } + feed.addEntry(feedEntry); + } + // If no entries were newly updated, + if ( responseLastModified.compareTo( new Date( 0 ) ) == 0 ) { + responseLastModified = new Date(); + } + return feed; + } + } + return null; + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(getRequestPath(request), "UTF-8"); + + if (path == null || path.length() == 0 || path.equals("/")) { + org.apache.abdera.model.Entry createdFeedEntry = null; + + // Create a new Atom entry + String contentType = request.getContentType(); + if (contentType != null && contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + org.apache.abdera.model.Entry feedEntry; + try { + Document doc = abderaParser.parse(request.getReader()); + feedEntry = doc.getRoot(); + } catch (ParseException pe) { + throw new ServletException(pe); + } + + // Let the component implementation create it + if (supportsFeedEntries) { + + // The service implementation supports feed entries, pass the entry to it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {feedEntry}); + Message responseMessage = postInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + createdFeedEntry = responseMessage.getBody(); + } else { + + // The service implementation does not support feed entries, pass the data item to it + Message requestMessage = messageFactory.createMessage(); + Entry entry = entry(feedEntry, itemClassType, itemXMLType, mediator); + requestMessage.setBody(new Object[] {entry.getKey(), entry.getData()}); + Message responseMessage = postInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + entry.setKey(responseMessage.getBody()); + createdFeedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator, abderaFactory); + } + + } else if (contentType != null) { + // Create a new media entry + + // Get incoming headers + String title = request.getHeader("Title"); + String slug = request.getHeader("Slug"); + + // Let the component implementation create the media entry + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {title, slug, contentType, request.getInputStream()}); + Message responseMessage = postMediaInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + createdFeedEntry = responseMessage.getBody(); + + // Transfer media info to response header. + // Summary is a comma separated list of header properties. + String summary = createdFeedEntry.getSummary(); + addPropertiesToHeader( response, summary ); + + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + + // A new entry for non-media was created successfully. + if (createdFeedEntry != null) { + // Set location of the created entry in the Location header + IRI feedId = createdFeedEntry.getId(); + if ( feedId != null ) { + response.addHeader(ETAG, "\"" + feedId.toString() + "\"" ); + } + Date entryUpdated = createdFeedEntry.getUpdated(); + if ( entryUpdated != null ) { + response.addHeader(LASTMODIFIED, dateFormat.format( entryUpdated )); + } + Link link = createdFeedEntry.getSelfLink(); + if (link != null) { + response.addHeader(LOCATION, link.getHref().toString()); + } + Link editLink = createdFeedEntry.getEditLink(); + if (editLink != null) { + response.addHeader(LOCATION, editLink.getHref().toString()); + } + Link editMediaLink = createdFeedEntry.getEditMediaLink(); + if (editMediaLink != null) { + response.addHeader(CONTENTLOCATION, editMediaLink.getHref().toString()); + } + + // Write the created Atom entry + response.setStatus(HttpServletResponse.SC_CREATED); + response.setContentType("application/atom+xml;type=entry"); + try { + createdFeedEntry.writeTo(getWriter(response)); + } catch (ParseException pe) { + throw new ServletException(pe); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + private Writer getWriter(HttpServletResponse response) throws UnsupportedEncodingException, IOException { + Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8"); + return writer; + } + + @Override + protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(getRequestPath(request), "UTF-8"); + + if (path != null && path.startsWith("/")) { + String id = path.substring(1); + + // Update an Atom entry + String contentType = request.getContentType(); + if (contentType != null && contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + org.apache.abdera.model.Entry feedEntry; + try { + Document doc = abderaParser.parse(request.getReader()); + feedEntry = doc.getRoot(); + } catch (ParseException pe) { + throw new ServletException(pe); + } + + // Let the component implementation create it + if (supportsFeedEntries) { + // The service implementation supports feed entries, pass the entry to it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id, feedEntry}); + Message responseMessage = putInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } else { + // The service implementation does not support feed entries, pass the data item to it + Message requestMessage = messageFactory.createMessage(); + Entry entry = entry(feedEntry, itemClassType, itemXMLType, mediator); + requestMessage.setBody(new Object[] {entry.getKey(), entry.getData()}); + Message responseMessage = putInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } + + } else if (contentType != null) { + + // Update a media entry + + // Let the component implementation create the media entry + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id, contentType, request.getInputStream()}); + Message responseMessage = putMediaInvoker.invoke(requestMessage); + + Object body = responseMessage.getBody(); + if (responseMessage.isFault()) { + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + + // Transfer content to response header. + + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + @Override + protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(getRequestPath(request), "UTF-8"); + + String id; + if (path != null && path.startsWith("/")) { + id = path.substring(1); + } else { + id = ""; + } + + // Delete a specific entry from the collection + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id}); + Message responseMessage = deleteInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } + + + /** + * + * @param request + * @return + */ + private static String getRequestPath(HttpServletRequest request) { + // Get the request path + String contextPath = request.getContextPath(); + String servletPath = request.getServletPath(); + String requestURI = request.getRequestURI(); + + int contextPathLength = request.getContextPath().length(); + int servletPathLenght = servletPath.contains(contextPath) ? servletPath.length() - contextPath.length() : servletPath.length(); + + String requestPath = requestURI.substring(contextPathLength + servletPathLenght); + + return requestPath; + } + + /** + * Process the authorization header + * + * @param request + * @return + * @throws ServletException + */ + private String processAuthorizationHeader(HttpServletRequest request) throws ServletException { + + // FIXME temporarily disabling this as it doesn't work with all browsers + if (true) + return "admin"; + + try { + String authorization = request.getHeader("Authorization"); + if (authorization != null) { + StringTokenizer tokens = new StringTokenizer(authorization); + if (tokens.hasMoreTokens()) { + String basic = tokens.nextToken(); + if (basic.equalsIgnoreCase("Basic")) { + String credentials = tokens.nextToken(); + String userAndPassword = new String(Base64.decodeBase64(credentials.getBytes())); + int colon = userAndPassword.indexOf(":"); + if (colon != -1) { + String user = userAndPassword.substring(0, colon); + String password = userAndPassword.substring(colon + 1); + + // Authenticate the User. + if (authenticate(user, password)) { + return user; + } + } + } + } + } + } catch (Exception e) { + throw new ServletException(e); + } + return null; + } + + /** + * Authenticate a user. + * + * @param user + * @param password + * @return + */ + private boolean authenticate(String user, String password) { + // TODO Handle this using SCA security policies + return ("admin".equals(user) && "admin".equals(password)); + } + + /** + * Reject an unauthorized request. + * + * @param response + */ + private void unauthorized(HttpServletResponse response) throws IOException { + response.setHeader("WWW-Authenticate", "BASIC realm=\"Tuscany\""); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } + + /** + * Get content-type preference using application/atom-xml as default + * @param acceptType content-type preference using application/atom-xml as default + * @return + */ + private static String getContentPreference( String acceptType ) { + if (( acceptType == null ) || ( acceptType.length() < 1 )) { + return "application/atom+xml"; + } + StringTokenizer st = new StringTokenizer( acceptType, "," ); + if ( st.hasMoreTokens() ) { + return st.nextToken(); + } + return "application/atom+xml"; + } + + /** Take a list of key values and add them to the header. + * For instance "Content-Type=image/gif,Content-Length=14201" + * @param response + * @param properties + */ + private static void addPropertiesToHeader( HttpServletResponse response, String properties ) { + if ( properties == null ) return; + StringTokenizer props = new StringTokenizer( properties, ","); + while( props.hasMoreTokens()) { + String prop = props.nextToken(); + StringTokenizer keyVal = new StringTokenizer( prop, "="); + String key = null; + String val = null; + if ( keyVal.hasMoreTokens() ) + key = keyVal.nextToken(); + if ( keyVal.hasMoreTokens() ) + val = keyVal.nextToken(); + if (( key != null ) && ( val != null )) { + response.addHeader(key, val); + } + } + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java new file mode 100644 index 0000000000..00df45a49e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.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.sca.binding.atom.provider; + +import org.apache.tuscany.sca.binding.atom.AtomBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of a Binding provider factory for the Atom binding. + * + * @version $Rev$ $Date$ + */ +public class AtomBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private Mediator mediator; + private ServletHost servletHost; + + public AtomBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + AtomBinding binding) { + return new AtomReferenceBindingProvider(component, reference, binding, mediator); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + AtomBinding binding) { + return new AtomServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator); + } + + public Class getModelType() { + return AtomBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingUtil.java new file mode 100644 index 0000000000..fad06a0c99 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingUtil.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.atom.provider; + +import java.util.Date; + +import org.apache.abdera.factory.Factory; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Link; +import org.apache.abdera.model.Content.Type; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * Utility methods used in this package. + * + * @version $Rev$ $Date$ + */ +class AtomBindingUtil { + + /** + * Create a data item from an Atom entry. + * @param feedEntry + * @param itemClassType + * @param itemXMLType + * @param mediator + * @return + */ + static Entry entry(org.apache.abdera.model.Entry feedEntry, + DataType itemClassType, DataType itemXMLType, Mediator mediator) { + if (feedEntry != null) { + if (itemClassType.getPhysical() == Item.class || feedEntry.getContentType() == Type.HTML ) { + String key = feedEntry.getId().toString(); + + Item item = new Item(); + item.setTitle(feedEntry.getTitle()); + item.setContents(feedEntry.getContent()); + + for (Link link : feedEntry.getLinks()) { + if (link.getRel() == null || "self".equals(link.getRel())) { + if (item.getLink() == null) { + item.setLink(link.getHref().toString()); + } + } else if ("related".equals(link.getRel())) { + item.setRelated(link.getHref().toString()); + } else if ("alternate".equals(link.getRel())) { + item.setAlternate(link.getHref().toString()); + } + } + + item.setDate(feedEntry.getUpdated()); + + return new Entry(key, item); + + } else { + String key = null; + if ( feedEntry.getId() != null) { + key = feedEntry.getId().toString(); + } + + // Create the item from XML + if (feedEntry.getContentElement().getElements().size() == 0) { + return null; + } + + String value = feedEntry.getContent(); + Object data = mediator.mediate(value, itemXMLType, itemClassType, null); + + return new Entry(key, data); + } + } else { + return null; + } + } + + /** + * Create an Atom entry for a key and item from a collection. + * @param entry + * @param itemClassType + * @param itemXMLType + * @param mediator + * @param factory + * @return + */ + static org.apache.abdera.model.Entry feedEntry(Entry entry, + DataType itemClassType, DataType itemXMLType, Mediator mediator, + Factory factory) { + Object key = entry.getKey(); + Object data = entry.getData(); + if (data instanceof Item) { + Item item = (Item)data; + + org.apache.abdera.model.Entry feedEntry = factory.newEntry(); + if (key != null) { + feedEntry.setId(key.toString()); + } + feedEntry.setTitle(item.getTitle()); + feedEntry.setContentAsHtml(item.getContents()); + + String href = item.getLink(); + if (href == null && key != null) { + href = key.toString(); + } + + if (href != null) { + feedEntry.addLink(href); + } + String related = item.getRelated(); + if (related != null) { + feedEntry.addLink(related, "related"); + } + String alternate = item.getAlternate(); + if (alternate != null) { + feedEntry.addLink(alternate, "alternate"); + } + + Date date = item.getDate(); + if (date != null) { + feedEntry.setUpdated(date); + } + return feedEntry; + + } else if (data != null) { + org.apache.abdera.model.Entry feedEntry = factory.newEntry(); + feedEntry.setId(key.toString()); + feedEntry.setTitle("item"); + + + // Convert the item to XML + String value = mediator.mediate(data, itemClassType, itemXMLType, null).toString(); + + Content content = factory.newContent(); + content.setContentType(Content.Type.XML); + content.setValue(value); + + feedEntry.setContentElement(content); + + feedEntry.addLink(key.toString()); + + return feedEntry; + } else { + return null; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.java new file mode 100644 index 0000000000..65331af34c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomReferenceBindingProvider.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.sca.binding.atom.provider; + +import java.net.URI; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpConnectionManager; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; +import org.apache.tuscany.sca.binding.atom.AtomBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the Atom binding provider. + * + * @version $Rev$ $Date$ + */ +class AtomReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private AtomBinding binding; + private String authorizationHeader; + private HttpClient httpClient; + private Mediator mediator; + private DataType itemClassType; + private DataType itemXMLType; + private boolean supportsFeedEntries; + + /** + * Constructs a new AtomReferenceBindingProvider + * @param component + * @param reference + * @param binding + * @param mediator + */ + AtomReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + AtomBinding binding, + Mediator mediator) { + this.reference = reference; + this.binding = binding; + this.mediator = mediator; + + // Prepare authorization header + String authorization = "admin" + ":" + "admin"; + authorizationHeader = "Basic " + new String(Base64.encodeBase64(authorization.getBytes())); + + // Create an HTTP client + HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); + connectionManager.getParams().setDefaultMaxConnectionsPerHost(10); + connectionManager.getParams().setConnectionTimeout(60000); + httpClient = new HttpClient(connectionManager); + } + + public Invoker createInvoker(Operation operation) { + + String operationName = operation.getName(); + if (operationName.equals("get")) { + + // Determine the collection item type + itemXMLType = new DataTypeImpl>(String.class.getName(), String.class, String.class); + Class itemClass = operation.getOutputType().getPhysical(); + DataType outputType = operation.getOutputType(); + itemClassType = outputType; + if (itemClassType.getPhysical() == org.apache.abdera.model.Entry.class) { + supportsFeedEntries = true; + } + + return new AtomBindingInvoker.GetInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + + } else if (operationName.equals("post")) { + return new AtomBindingInvoker.PostInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + } else if (operationName.equals("put")) { + return new AtomBindingInvoker.PutInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + } else if (operationName.equals("delete")) { + return new AtomBindingInvoker.DeleteInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + } else if (operationName.equals("getFeed") || operationName.equals("getAll")) { + return new AtomBindingInvoker.GetAllInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + } else if (operationName.equals("postMedia")) { + return new AtomBindingInvoker.PostMediaInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + } else if (operationName.equals("putMedia")) { + return new AtomBindingInvoker.PutMediaInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + } else if (operationName.equals("query")) { + return new AtomBindingInvoker.QueryInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + } + + return new AtomBindingInvoker(operation, binding.getURI(), httpClient, authorizationHeader, this); + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + + // Configure the HTTP client credentials + Credentials credentials = new UsernamePasswordCredentials("admin", "admin"); + httpClient.getParams().setAuthenticationPreemptive(true); + URI uri = URI.create(binding.getURI()); + httpClient.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), credentials); + + // Find the get operation on the reference interface + if (true) { + return; + } + } + + public void stop() { + + } + + public boolean supportsOneWayInvocation() { + return false; + } + + /** + * Returns the mediator. + * @return + */ + Mediator getMediator() { + return mediator; + } + + /** + * Returns the item class type. + * @return + */ + DataType getItemClassType() { + return itemClassType; + } + + /** + * Returns the item XML type. + * @return + */ + DataType getItemXMLType() { + return itemXMLType; + } + + /** + * Returns true if the invoker should work with Atom + * feed entries. + * @return + */ + boolean supportsFeedEntries() { + return supportsFeedEntries; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomServiceBindingProvider.java new file mode 100644 index 0000000000..d794dd4ee8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomServiceBindingProvider.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.sca.binding.atom.provider; + +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.binding.atom.AtomBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the Atom binding provider. + * + * @version $Rev$ $Date$ + */ +class AtomServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private InterfaceContract serviceContract; + private AtomBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private Mediator mediator; + + private String servletMapping; + private String bindingURI; + + AtomServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + AtomBinding binding, + ServletHost servletHost, + MessageFactory messageFactory, + Mediator mediator) { + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.mediator = mediator; + + // TUSCANY-3166 + this.serviceContract = service.getInterfaceContract(); + if (this.serviceContract instanceof WSDLInterfaceContract) { + for (Service componentService : component.getImplementation().getServices()) { + if (componentService.getName().equals(service.getName())) { + this.serviceContract = (InterfaceContract) componentService.getInterfaceContract(); + break; + } + } + + } + } + + public InterfaceContract getBindingInterfaceContract() { + return serviceContract; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + RuntimeComponentService componentService = (RuntimeComponentService)service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + + AtomBindingListenerServlet servlet = + new AtomBindingListenerServlet(wire, messageFactory, mediator, binding.getTitle(), binding.getDescription()); + + servletMapping = binding.getURI(); + if (!servletMapping.endsWith("/")) { + servletMapping += "/"; + } + if (!servletMapping.endsWith("*")) { + servletMapping += "*"; + } + servletHost.addServletMapping(servletMapping, servlet); + + bindingURI = binding.getURI(); + if (!bindingURI.endsWith("/")) { + bindingURI += "/"; + } + + servletHost.addServletMapping(bindingURI, servlet); + } + + public void stop() { + servletHost.removeServletMapping(servletMapping); + servletHost.removeServletMapping(bindingURI); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..1b9052299c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.atom.provider.AtomBindingProviderFactory;model=org.apache.tuscany.sca.binding.atom.AtomBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java new file mode 100644 index 0000000000..a427a076cd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom; + +import java.util.UUID; + +import junit.framework.Assert; + +import org.apache.abdera.Abdera; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.tuscany.sca.binding.atom.collection.Collection; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AtomDeleteTestCase { + protected static SCADomain scaConsumerDomain; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + protected static Abdera abdera; + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>AtomDeleteTestCase.init entry"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); + scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite"); + testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient"); + abdera = new Abdera(); + } + + @AfterClass + public static void destroy() throws Exception { + // System.out.println(">>>AtomDeleteTestCase.destroy entry"); + if (scaConsumerDomain != null) { + scaConsumerDomain.close(); + } + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull(scaConsumerDomain); + Assert.assertNotNull(testService); + Assert.assertNotNull(abdera); + } + + @Test + public void testAtomDelete() throws Exception { + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry postEntry = postEntry("Sponge Bob"); + System.out.println(">>> post entry= " + postEntry.getTitle()); + + Entry newEntry = resourceCollection.post(postEntry); + System.out.println("<<< Entry posted for " + newEntry.getTitle()); + + System.out.println(">>> get id=" + newEntry.getId()); + + resourceCollection.delete(newEntry.getId().toString()); + + } + + @Test + public void testAtomDeleteException() throws Exception { + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + try { + // Generates custom ID + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + resourceCollection.delete(id); + } catch (Exception e) { + // ID doesn't match with the existing IDs and NotFoundException is + // thrown + Assert.assertEquals("NotFoundException", e.getClass().getSimpleName()); + } + + } + + private Entry postEntry(String value) { + Entry entry = abdera.newEntry(); + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java new file mode 100644 index 0000000000..4f91ff492a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.atom; + +import java.util.Date; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import junit.framework.Assert; + +import org.apache.abdera.model.Link; +import org.apache.tuscany.sca.binding.atom.collection.Collection; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test cases for using an Atom feed that does not implement + * the Collections interface but does have a getAll() method. + */ +public class AtomFeedNonCollectionTest { + /** + * Used to generate unique IDs for the feed entries. + */ + private static final AtomicInteger ID_GEN = new AtomicInteger(); + + /** + * Data used for creating test feed entries. + */ + private static final String[] FEED_ENTRY_TITLES = {"Apache Tuscany", "Apache"}; + + /** + * Data used for creating test feed entries. + */ + private static final String[] FEED_ENTRY_CONTENT = {"This is Apache Tuscany", "This is Apache"}; + + /** + * Data used for creating test feed entries. + */ + private static final String[] FEED_ENTRY_LINK = {"http://tuscany.apache.org", "http://www.apache.org"}; + + /** + * The number of test feed entries. + */ + private static final int FEED_ENTRY_COUNT = FEED_ENTRY_TITLES.length; + + private static SCADomain scaConsumerDomain; + private static SCADomain scaProviderDomain; + private static CustomerClient testService; + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>AtomFeedNonCollectionTest.init entry"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/ProviderNonCollection.composite"); + scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite"); + testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient"); + } + + @AfterClass + public static void destroy() throws Exception { + System.out.println(">>>AtomFeedNonCollectionTest.destroy entry"); + if (scaConsumerDomain != null) { + scaConsumerDomain.close(); + } + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + /** + * Make sure everything has been initialised correctly. + */ + @Before + public void testPrelim() { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull(scaConsumerDomain); + Assert.assertNotNull(testService); + + // Add some entries to the Atom feed + final Entry[] testEntries = new Entry[FEED_ENTRY_COUNT]; + for (int i = 0; i < FEED_ENTRY_COUNT; i++) { + testEntries[i] = createFeedEntry(FEED_ENTRY_TITLES[i], FEED_ENTRY_CONTENT[i], FEED_ENTRY_LINK[i]); + } + CustomerNonCollectionImpl.entries = testEntries; + } + + /** + * Post test cleanup + */ + @After + public void testPostCleanup() + { + // Clear any old feed entries that have been added by previous tests + CustomerNonCollectionImpl.entries = null; + } + + /** + * Test that we can retrieve entries from a feed that does not implement + * the Collection interface. + */ + @Test + public void testThatCanGetFeedEntriesFromNonCollectionImplementation() { + // Get the entries from the feed + final Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + final List entries = resourceCollection.getFeed().getEntries(); + + // Validate the feed entries + Assert.assertNotNull(entries); + Assert.assertEquals(FEED_ENTRY_COUNT, entries.size()); + for (int i = 0; i < FEED_ENTRY_COUNT; i++) { + final org.apache.abdera.model.Entry entry = entries.get(i); + Assert.assertEquals(FEED_ENTRY_TITLES[i], entry.getTitle()); + Assert.assertEquals(FEED_ENTRY_CONTENT[i], entry.getContent()); + final List links = entry.getLinks(); + Assert.assertNotNull(links); + Assert.assertEquals(1, links.size()); + final Link link = links.get(0); + final String linkStr = link.getHref().toString(); + Assert.assertEquals(FEED_ENTRY_LINK[i], linkStr); + } + } + + /** + * Creates a feed entry. + * + * @param title Title for the feed entry + * @param content Contents of the feed entry + * @param link Link for the feed entry + * @return A new feed entry. + */ + private Entry createFeedEntry(String title, String content, String link) { + final Item item = new Item(title, content, link, null, new Date()); + final Entry entry = new Entry(nextFeedID(), item); + return entry; + } + + /** + * Generates the feed entry ID. + * + * @return Next feed entry ID + */ + private String nextFeedID() { + return Integer.toString(ID_GEN.incrementAndGet()); + } + + /** + * Tests that the title of the feed can be set by the title + * attribute on the binding.atom + */ + @Test + public void testThatFeedTitleSet() { + final String expectedFeedTitle = "Atom binding Non Collection"; + + // Get the title of the feed + final Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + final String feedTitle = resourceCollection.getFeed().getTitle(); + + // Validate the title + Assert.assertEquals(expectedFeedTitle, feedTitle); + } + + /** + * Tests that the description of the feed can be set by the description + * attribute on the binding.atom + */ + @Test + public void testThatFeedDescriptionSet() { + final String expectedFeedDescription = "Feed used for unit testing"; + + // Get the description of the feed + final Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + final String feedDescription = resourceCollection.getFeed().getSubtitle(); + + // Validate the description + Assert.assertEquals(expectedFeedDescription, feedDescription); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java new file mode 100644 index 0000000000..32a01ebe2a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.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.sca.binding.atom; + +import junit.framework.Assert; + +import org.apache.abdera.Abdera; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.tuscany.sca.binding.atom.collection.Collection; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AtomGetTestCase { + protected static SCADomain scaConsumerDomain; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + protected static Abdera abdera; + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>AtomGetTestCase.init entry"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); + scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite"); + testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient"); + abdera = new Abdera(); + } + + @AfterClass + public static void destroy() throws Exception { + // System.out.println(">>>AtomGetTestCase.destroy entry"); + if (scaConsumerDomain != null) { + scaConsumerDomain.close(); + } + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull(scaConsumerDomain); + Assert.assertNotNull(testService); + Assert.assertNotNull(abdera); + } + + @Test + public void testAtomGet() throws Exception { + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry postEntry = postEntry("Sponge Bob"); + System.out.println(">>> post entry= " + postEntry.getTitle()); + + Entry newEntry = resourceCollection.post(postEntry); + System.out.println("<<< Entry posted for " + newEntry.getTitle()); + + System.out.println(">>> get id=" + newEntry.getId()); + + Entry getEntry = resourceCollection.get(newEntry.getId().toString()); + + Assert.assertEquals(newEntry.getTitle(), getEntry.getTitle()); + System.out.println("<<< get id=" + getEntry.getId() + " entry=" + getEntry.getTitle()); + } + + @Test + public void testAtomGetException() throws Exception { + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry postEntry = postEntry("Sponge Bob"); + System.out.println(">>> post entry= " + postEntry.getTitle()); + + Entry newEntry = resourceCollection.post(postEntry); + System.out.println("<<< Entry posted for " + newEntry.getTitle()); + System.out.println(newEntry.getId()); + + // Delete the entry to force the Collection to throw NotFoundException + resourceCollection.delete(newEntry.getId().toString()); + + try { + resourceCollection.get(newEntry.getId().toString()); + } catch (Exception e) { + Assert.assertEquals("NotFoundException", e.getClass().getSimpleName()); + } + } + + private Entry postEntry(String value) { + Entry entry = abdera.newEntry(); + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java new file mode 100644 index 0000000000..49e9c2f25f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom; + +import junit.framework.Assert; + +import org.apache.abdera.Abdera; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.tuscany.sca.binding.atom.collection.Collection; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AtomPostTestCase { + protected static SCADomain scaConsumerDomain; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + protected static Abdera abdera; + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>AtomPostTestCase.init entry"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); + scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite"); + testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient"); + abdera = new Abdera(); + } + + @AfterClass + public static void destroy() throws Exception { + System.out.println(">>>AtomPostTestCase.destroy entry"); + if (scaConsumerDomain != null) { + scaConsumerDomain.close(); + } + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull(scaConsumerDomain); + Assert.assertNotNull(testService); + Assert.assertNotNull(abdera); + } + + @Test + public void testAtomPost() throws Exception { + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry postEntry = postEntry("Sponge Bob"); + System.out.println(">>> post entry= " + postEntry.getTitle()); + + Entry newEntry = resourceCollection.post(postEntry); + + Assert.assertEquals(postEntry.getTitle(), newEntry.getTitle()); + + System.out.println("<<< new entry= " + newEntry.getTitle()); + + } + + @Test + public void testAtomPostException() throws Exception { + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry postEntry = postEntry("Exception_Test"); + + try { + resourceCollection.post(postEntry); + } catch (Exception e) { + Assert.assertEquals("HTTP status code: 500", e.getMessage()); + } + } + + private Entry postEntry(String value) { + Entry entry = abdera.newEntry(); + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java new file mode 100644 index 0000000000..3aaad681f4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom; + +import java.util.UUID; + +import junit.framework.Assert; + +import org.apache.abdera.Abdera; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.tuscany.sca.binding.atom.collection.Collection; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AtomPutTestCase { + protected static SCADomain scaConsumerDomain; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + protected static Abdera abdera; + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>AtomPutTestCase.init entry"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); + scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite"); + testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient"); + abdera = new Abdera(); + } + + @AfterClass + public static void destroy() throws Exception { + // System.out.println(">>>AtomPutTestCase.destroy entry"); + if (scaConsumerDomain != null) { + scaConsumerDomain.close(); + } + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull(scaConsumerDomain); + Assert.assertNotNull(testService); + Assert.assertNotNull(abdera); + } + + @Test + public void testAtomPut() throws Exception { + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry postEntry = postEntry("Sponge Bob"); + System.out.println(">>> post entry= " + postEntry.getTitle()); + + Entry newEntry = resourceCollection.post(postEntry); + System.out.println("<<< Entry posted for " + newEntry.getTitle()); + System.out.println(newEntry.getId()); + + System.out.println(">>> put id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + resourceCollection.put(newEntry.getId().toString(), updateEntry(newEntry, "James Bond")); + System.out.println("<<< put id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + } + + @Test + public void testAtomPutException() throws Exception { + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry postEntry = postEntry("Sponge Bob"); + System.out.println(">>> post entry= " + postEntry.getTitle()); + + // Generate random ID to pass as parameter in PUT() -- + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + try { + // ID doesn't match with the existing IDs and NotFoundException is thrown + resourceCollection.put(id, updateEntry(postEntry, "James Bond")); + } catch (Exception e) { + Assert.assertEquals("NotFoundException", e.getClass().getSimpleName()); + } + } + + private Entry postEntry(String value) { + Entry entry = abdera.newEntry(); + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + + private Entry updateEntry(Entry entry, String value) { + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomTestCaseUtils.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomTestCaseUtils.java new file mode 100644 index 0000000000..6beed6881f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomTestCaseUtils.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.sca.binding.atom; + +import java.io.IOException; + +import org.apache.abdera.Abdera; +import org.apache.abdera.model.Base; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.abdera.protocol.client.ClientResponse; +import org.apache.abdera.protocol.client.RequestOptions; +import org.apache.abdera.writer.Writer; +import org.apache.abdera.writer.WriterFactory; + +/** + * Utilities to help print and test various aspects of entity tag support. + */ +public class AtomTestCaseUtils { + + public static void prettyPrint(Abdera abdera, Base doc) throws IOException { + WriterFactory factory = abdera.getWriterFactory(); + Writer writer = factory.getWriter("prettyxml"); + writer.writeTo(doc, System.out); + System.out.println(); + } + + public static void printRequestHeaders( String title, String indent, RequestOptions request ) { + System.out.println( title ); + if ( request == null ) { + System.out.println( indent + " request is null"); + return; + } + String [] headerNames = request.getHeaderNames(); + for ( String headerName: headerNames) { + String header = request.getHeader(headerName); + System.out.println( indent + " header name,value=" + headerName + "," + header ); + } + } + + public static void printResponseHeaders( String title, String indent, ClientResponse response ) { + System.out.println( title ); + if ( response == null ) { + System.out.println( indent + " response is null"); + return; + } + String [] headerNames = response.getHeaderNames(); + for ( String headerName: headerNames) { + String header = response.getHeader(headerName); + System.out.println( indent + " header name,value=" + headerName + "," + header ); + } + + } + + public static Entry newEntry(String value) { + Abdera abdera = new Abdera(); + Entry entry = abdera.newEntry(); + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + + public static Entry updateEntry(Entry entry, String value) { + Abdera abdera = new Abdera(); + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java new file mode 100644 index 0000000000..34d3ed1d1c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.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.sca.binding.atom; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Consumer { + + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite"); + + CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient"); + testService.testCustomerCollection(); + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java new file mode 100644 index 0000000000..9af85a970c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom; + +import java.util.Date; + +import junit.framework.Assert; + +import org.apache.abdera.Abdera; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.abdera.model.Feed; +import org.apache.tuscany.sca.binding.atom.collection.Collection; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test case for the given package. + */ +public class ConsumerProviderAtomTestCase { + + protected static SCADomain scaConsumerDomain; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + protected static Abdera abdera; + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>AtomBindingIntegratedTestCase.init entry"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); + scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite"); + testService = scaConsumerDomain.getService(CustomerClient.class,"CustomerClient"); + abdera = new Abdera(); + } + + @AfterClass + public static void destroy() throws Exception { + System.out.println(">>>AtomBindingIntegratedTestCase.destroy entry"); + scaConsumerDomain.close(); + scaProviderDomain.close(); + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull(scaConsumerDomain); + Assert.assertNotNull(testService); + Assert.assertNotNull(abdera); + } + + @Test + public void testEntry() throws Exception { + // System.out.println( getClass().getName() + ".testEntry entry" ); + Entry entry = abdera.newEntry(); + Assert.assertNotNull(entry); + + String testTitle = "Sponge Bob"; + entry.setTitle(testTitle); + Assert.assertEquals(testTitle, entry.getTitle()); + + String testContent = "This is the content"; + entry.setContent(testContent); + Assert.assertEquals(testContent, entry.getContent()); + + Date now = new Date(); + entry.setEdited(now); + Assert.assertEquals(now, entry.getEdited()); + + Date later = new Date(); + entry.setPublished(later); + Assert.assertEquals(later, entry.getPublished()); + + String testSummary = "This is the summary"; + entry.setSummary(testSummary); + Assert.assertEquals(testSummary, entry.getSummary()); + } + + @Test + public void testCustomerCollection() throws Exception { + System.out.println(getClass().getName() + ".testCustomerCollection entry"); + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry newEntry = newEntry("Sponge Bob"); + System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = resourceCollection.post(newEntry); + System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + newEntry = newEntry("Jane Bond"); + System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = resourceCollection.post(newEntry); + System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + System.out.println(">>> get id=" + newEntry.getId()); + Entry entry = resourceCollection.get(newEntry.getId().toString()); + System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle()); + + System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle()); + resourceCollection.put(entry.getId().toString(), updateEntry(entry, "James Bond")); + System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle()); + + System.out.println(">>> delete id=" + entry.getId()); + resourceCollection.delete(entry.getId().toString()); + System.out.println("<<< delete id=" + entry.getId()); + + System.out.println(">>> get collection"); + Feed feed = resourceCollection.getFeed(); + System.out.println("<<< get collection"); + for (Object o : feed.getEntries()) { + Entry e = (Entry)o; + System.out.println("id = " + e.getId() + " entry = " + e.getTitle()); + } + } + + private Entry newEntry(String value) { + Entry entry = abdera.newEntry(); + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + + private Entry updateEntry(Entry entry, String value) { + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java new file mode 100644 index 0000000000..72101f1531 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom; + +import java.io.IOException; +import java.io.Reader; +import java.util.Date; + +import junit.framework.Assert; + +import org.apache.abdera.Abdera; +import org.apache.abdera.factory.Factory; +import org.apache.abdera.i18n.iri.IRI; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Document; +import org.apache.abdera.model.Entry; +import org.apache.abdera.model.Feed; +import org.apache.abdera.parser.Parser; +import org.apache.abdera.protocol.Response.ResponseType; +import org.apache.abdera.protocol.client.AbderaClient; +import org.apache.abdera.protocol.client.ClientResponse; +import org.apache.abdera.protocol.client.RequestOptions; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * Tests use of content negotiation for Atom binding in Tuscany. + * Uses the SCA provided Provider composite to act as a server. + * Uses the Abdera provided Client to act as a client. + */ +public class ContentNegotiationTest { + public final static String providerURI = "http://localhost:8084/customer"; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + protected static Abdera abdera; + protected static AbderaClient client; + protected static Parser abderaParser; + protected static String lastId; + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>ContentNegotiationTest.init"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); + abdera = new Abdera(); + client = new AbderaClient(abdera); + abderaParser = Abdera.getNewParser(); + } + + @AfterClass + public static void destroy() throws Exception { + System.out.println(">>>ContentNegotiationTest.destroy"); + scaProviderDomain.close(); + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull( client ); + } + + @Test + public void testPost() throws Exception { + System.out.println(">>>ContentNegotiationTest.testPost"); + // Testing of entry creation + Factory factory = abdera.getFactory(); + String customerName = "Fred Farkle"; + Entry entry = factory.newEntry(); + entry.setTitle("customer " + customerName); + entry.setUpdated(new Date()); + entry.addAuthor("Apache Tuscany"); + // ID created by collection. + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(customerName); + entry.setContentElement(content); + + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + // AtomTestCaseUtils.printRequestHeaders( "Post request headers", " ", opts ); + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + ClientResponse res = client.post(colUri.toString(), entry, opts); + + // Assert response status code is 201-OK. + // Assert response header Content-Type: application/atom+xml; charset=UTF-8 + Assert.assertEquals(201, res.getStatus()); + String returnedContentType = res.getContentType().toString().trim(); + Assert.assertEquals(contentType, returnedContentType ); + + String eTag = res.getHeader( "ETag" ); + if ( eTag != null) + lastId = eTag.substring( 1, eTag.length()-1); + + // AtomTestCaseUtils.printResponseHeaders( "Entry post response headers:", " ", res ); + // System.out.println("Entry post response content:"); + // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); + } + + @Test + public void testXMLEntryGet() throws Exception { + System.out.println(">>>ContentNegotiationTest.testXMLEntryGet"); + RequestOptions opts = new RequestOptions(); + opts.setHeader( "Accept", "application/atom+xml" ); + + IRI colUri = new IRI(providerURI).resolve("customer"); + ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts); + Assert.assertEquals(200, res.getStatus()); + String returnedContentType = res.getContentType().toString().trim(); + // Assert.assertEquals(contentType, returnedContentType ); + res.release(); + } + + @Test + public void testJSONEntryGet() throws Exception { + System.out.println(">>>ContentNegotiationTest.testJSONEntryGet"); + RequestOptions opts = new RequestOptions(); + opts.setHeader( "Accept", "application/json" ); + + IRI colUri = new IRI(providerURI).resolve("customer"); + ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts); + try { + Assert.assertEquals(200, res.getStatus()); + // Abdera 0.4 throws exception on getContentType with application/json. + // System.out.println( "ContentNegotiationTest.testJSONEntryGet contentType=" + res.getContentType()); + String contentType = res.getHeader( "Content-Type"); + Assert.assertTrue( -1 < contentType.indexOf( "application/json" )); + // Following is a poor man's JSONObject test to avoid dependency on JSON libs. + // JSONObject jsonResp = new JSONObject(res.); + // Assert.assertEquals(12345, jsonResp.getInt("result")); + String responseBody = readResponse( res.getReader() ); + Assert.assertTrue( responseBody.startsWith( "{") ); + Assert.assertTrue( responseBody.endsWith( "}") ); + Assert.assertTrue( -1 < responseBody.indexOf( "\"id\"" )); + Assert.assertTrue( -1 < responseBody.indexOf( "\"title\"" )); + Assert.assertTrue( -1 < responseBody.indexOf( "\"updated\"" )); + // AtomTestCaseUtils.printResponseHeaders( "JSON Entry response headers:", " ", res ); + // System.out.println( "ContentNegotiationTest.testJSONEntryGet JSON entry body=" + responseBody ); + } finally { + res.release(); + } + } + + @Test + public void testXMLFeedGet() throws Exception { + System.out.println(">>>ContentNegotiationTest.testXMLFeedGet"); + RequestOptions opts = new RequestOptions(); + opts.setHeader( "Accept", "application/atom+xml" ); + + // Atom feed request + ClientResponse res = client.get(providerURI, opts); + Assert.assertNotNull(res); + try { + // Asser feed provided since no predicates + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(ResponseType.SUCCESS, res.getType()); + // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res ); + // System.out.println("Feed response content:"); + // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); + + // Perform other tests on feed. + Document doc = res.getDocument(); + Assert.assertNotNull( doc ); + Feed feed = doc.getRoot(); + Assert.assertNotNull( feed ); + // RFC 4287 requires non-null id, title, updated elements + Assert.assertNotNull( feed.getId() ); + Assert.assertNotNull( feed.getTitle() ); + Assert.assertNotNull( feed.getUpdated() ); + // AtomTestCaseUtils.printFeed( "Feed values", " ", feed ); + } finally { + res.release(); + } + } + + @Test + public void testJSONFeedGet() throws Exception { + System.out.println(">>>ContentNegotiationTest.testJSONFeedGet"); + RequestOptions opts = new RequestOptions(); + opts.setHeader( "Accept", "application/json" ); + + // JSON feed request + ClientResponse res = client.get(providerURI, opts); + Assert.assertNotNull(res); + try { + // Assert feed provided since no predicates + Assert.assertEquals(200, res.getStatus()); + // Abdera 0.4 throws exception on getContentType with application/json. + // System.out.println( "ContentNegotiationTest.testJSONEntryGet contentType=" + res.getContentType()); + String contentType = res.getHeader( "Content-Type"); + Assert.assertTrue( -1 < contentType.indexOf( "application/json" )); + // Following is a poor man's JSONObject test to avoid dependency on JSON libs. + // JSONObject jsonResp = new JSONObject(res.); + // Assert.assertEquals(12345, jsonResp.getInt("result")); + String responseBody = readResponse( res.getReader() ); + Assert.assertTrue( responseBody.startsWith( "{") ); + Assert.assertTrue( responseBody.endsWith( "}") ); + Assert.assertTrue( -1 < responseBody.indexOf( "\"id\"" )); + Assert.assertTrue( -1 < responseBody.indexOf( "\"title\"" )); + Assert.assertTrue( -1 < responseBody.indexOf( "\"updated\"" )); + Assert.assertTrue( -1 < responseBody.indexOf( "\"entries\"" )); + // AtomTestCaseUtils.printResponseHeaders( "JSON Entry response headers:", " ", res ); + // System.out.println( "ContentNegotiationTest.testJSONEntryGet JSON entry body=" + responseBody ); + } finally { + res.release(); + } + } + + protected String readResponse( Reader responseReader ) { + if ( responseReader == null ) return ""; + StringBuffer sb = new StringBuffer(1024); + try { + int charValue = 0; + while ((charValue = responseReader.read()) != -1) { + //result = result + (char) charValue; + sb.append((char)charValue); + } + } catch ( IOException e ) { + } + return sb.toString(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java new file mode 100644 index 0000000000..bc32b91367 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.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.sca.binding.atom; + +import org.apache.tuscany.sca.binding.atom.collection.Collection; + +public interface CustomerClient { + + void testCustomerCollection() throws Exception; + + Collection getCustomerCollection(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java new file mode 100644 index 0000000000..3e5705b14c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.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.sca.binding.atom; + +import org.apache.abdera.Abdera; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.abdera.model.Feed; +import org.apache.tuscany.sca.binding.atom.collection.Collection; +import org.osoa.sca.annotations.Reference; + +public class CustomerClientImpl implements CustomerClient { + + protected final Abdera abdera = new Abdera(); + + @Reference + public Collection customerCollection; + + public void testCustomerCollection() throws Exception { + + Entry newEntry = newEntry("Sponge Bob"); + System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = customerCollection.post(newEntry); + System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + newEntry = newEntry("Jane Bond"); + System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = customerCollection.post(newEntry); + System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + System.out.println(">>> get id=" + newEntry.getId()); + Entry entry = customerCollection.get(newEntry.getId().toString()); + System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle()); + + System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle()); + customerCollection.put(entry.getId().toString(), updateEntry(entry, "James Bond")); + System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle()); + + System.out.println(">>> delete id=" + entry.getId()); + customerCollection.delete(entry.getId().toString()); + System.out.println("<<< delete id=" + entry.getId()); + + System.out.println(">>> get collection"); + Feed feed = customerCollection.getFeed(); + System.out.println("<<< get collection"); + for (Object o : feed.getEntries()) { + Entry e = (Entry)o; + System.out.println("id = " + e.getId() + " entry = " + e.getTitle()); + } + } + + public Collection getCustomerCollection() { + return customerCollection; + } + + private Entry newEntry(String value) { + + Entry entry = this.abdera.newEntry(); + entry.setTitle("customer " + value); + + Content content = this.abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + + entry.setContentElement(content); + + return entry; + } + + private Entry updateEntry(Entry entry, String value) { + + entry.setTitle("customer " + value); + + Content content = this.abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + + entry.setContentElement(content); + + return entry; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java new file mode 100644 index 0000000000..db66b00a50 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.atom; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.abdera.Abdera; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.abdera.model.Feed; +import org.apache.tuscany.sca.binding.atom.collection.Collection; +import org.apache.tuscany.sca.binding.atom.collection.NotFoundException; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class CustomerCollectionImpl implements Collection { + private final Abdera abdera = new Abdera(); + private Map entries = new HashMap(); + public Date lastModified = new Date(); + + /** + * Default constructor + */ + public CustomerCollectionImpl() { + + } + + public Entry post(Entry entry) { + System.out.println(">>> CustomerCollectionImpl.post entry=" + entry.getTitle()); + + if(!("Exception_Test".equalsIgnoreCase(entry.getTitle()))) + { + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + entry.setId(id); + + entry.addLink("" + id, "edit"); + entry.addLink("" + id, "alternate"); + Date now = new Date(); + entry.setUpdated(now); + lastModified = now; + entries.put(id, entry); + + System.out.println(">>> CustomerCollectionImpl.post return id=" + id); + + return entry; + + } + else + { + throw new IllegalArgumentException("Exception in Post method"); + } + } + + public Entry get(String id) { + System.out.println(">>> CustomerCollectionImpl.get id=" + id); + return entries.get(id); + } + + public void put(String id, Entry entry) throws NotFoundException { + System.out.println(">>> CustomerCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); + if(entries.containsKey(id)){ + Date now = new Date(); + entry.setUpdated(now); + lastModified = now; + entries.put(id, entry); + } + else { + throw new NotFoundException(); + } + } + + public void delete(String id) throws NotFoundException { + System.out.println(">>> CustomerCollectionImpl.delete id=" + id); + if(entries.containsKey(id)){ + entries.remove(id); + lastModified = new Date(); + } + else { + throw new NotFoundException(); + } + } + + public Feed getFeed() { + System.out.println(">>> CustomerCollectionImpl.getFeed"); + + Feed feed = this.abdera.getFactory().newFeed(); + feed.setId("customers" + this.hashCode() ); // provide unique id for feed instance. + feed.setTitle("customers"); + feed.setSubtitle("This is a sample feed"); + feed.setUpdated(lastModified); + feed.addLink(""); + feed.addLink("", "self"); + + for (Entry entry : entries.values()) { + feed.addEntry(entry); + } + + return feed; + } + + public Feed query(String queryString) { + System.out.println(">>> CustomerCollectionImpl.query collection " + queryString); + return getFeed(); + } + + // This method used for testing. + protected void testPut(String value) { + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + + Entry entry = abdera.getFactory().newEntry(); + entry.setId(id); + entry.setTitle("customer " + value); + + Content content = this.abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + + entry.setContentElement(content); + + entry.addLink("" + id, "edit"); + entry.addLink("" + id, "alternate"); + + entry.setUpdated(new Date()); + + entries.put(id, entry); + System.out.println(">>> id=" + id); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java new file mode 100644 index 0000000000..a25e19838f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.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.sca.binding.atom; + +import org.apache.tuscany.sca.data.collection.Entry; +import org.osoa.sca.annotations.Scope; + +/** + * Implementation of an Atom feed that does not implement the Collections + * interface but does have a getAll() method that will be used by the Atom + * binding to get the feed entries. + */ +@Scope("COMPOSITE") +public class CustomerNonCollectionImpl { + /** + * All feed entries. + * This is set directly by the unit tests. + * @see AtomFeedNonCollectionTest + */ + public static Entry[] entries; + + /** + * Default constructor + */ + public CustomerNonCollectionImpl() { + } + + /** + * Get all entries for this feed. + * + * @return All entries for this feed + */ + public Entry[] getAll() { + return entries; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java new file mode 100644 index 0000000000..385510b93f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.atom; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.abdera.Abdera; +import org.apache.abdera.factory.Factory; +import org.apache.abdera.i18n.iri.IRI; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.abdera.model.Feed; +import org.apache.tuscany.sca.binding.atom.collection.MediaCollection; +import org.apache.tuscany.sca.binding.atom.collection.NotFoundException; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class MediaCollectionImpl implements MediaCollection { + private final Abdera abdera = new Abdera(); + private Map entries = new HashMap(); + private Map mediaFiles = new HashMap(); + public Date lastModified = new Date(); + + public Entry post(Entry entry) { + System.out.println(">>> MediaCollectionImpl.post entry=" + entry.getTitle()); + + if(!("Exception_Test".equalsIgnoreCase(entry.getTitle()))) + { + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + entry.setId(id); + + entry.addLink("" + id, "edit"); + entry.addLink("" + id, "alternate"); + Date now = new Date(); + entry.setUpdated(now); + lastModified = now; + entries.put(id, entry); + + System.out.println(">>> MediaCollectionImpl.post return id=" + id); + + return entry; + + } + else + { + throw new IllegalArgumentException("Exception in Post method"); + } + } + + public Entry get(String id) { + System.out.println(">>> MediaCollectionImpl.get id=" + id); + return entries.get(id); + } + + public void put(String id, Entry entry) throws NotFoundException { + System.out.println(">>> MediaCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); + if(entries.containsKey(id)){ + Date now = new Date(); + entry.setUpdated(now); + lastModified = now; + entries.put(id, entry); + } + else { + throw new NotFoundException(); + } + } + + public void delete(String id) throws NotFoundException { + System.out.println(">>> MediaCollectionImpl.delete id=" + id); + if(entries.containsKey(id)){ + entries.remove(id); + lastModified = new Date(); + } + else { + throw new NotFoundException(); + } + } + + public Feed getFeed() { + System.out.println(">>> MediaCollectionImpl.getFeed"); + + Feed feed = this.abdera.getFactory().newFeed(); + feed.setId("customers" + this.hashCode() ); // provide unique id for feed instance. + feed.setTitle("customers"); + feed.setSubtitle("This is a sample feed"); + feed.setUpdated(lastModified); + feed.addLink(""); + feed.addLink("", "self"); + + for (Entry entry : entries.values()) { + feed.addEntry(entry); + } + + return feed; + } + + public Feed query(String queryString) { + System.out.println(">>> MediaCollectionImpl.query collection " + queryString); + return getFeed(); + } + + // This method used for testing. + protected void testPut(String value) { + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + + Entry entry = abdera.getFactory().newEntry(); + entry.setId(id); + entry.setTitle("customer " + value); + + Content content = this.abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + + entry.setContentElement(content); + + entry.addLink("" + id, "edit"); + entry.addLink("" + id, "alternate"); + + entry.setUpdated(new Date()); + + entries.put(id, entry); + System.out.println(">>> id=" + id); + } + + // MediaCollection role + public Entry postMedia(String title, String slug, String contentType, InputStream media) { + System.out.println(">>> MediaCollectionImpl.postMedia title=" + title + ", slug=" + slug + ", contentType=" + contentType ); + + Factory factory = abdera.getFactory(); + Entry entry = factory.newEntry(); + // Must provide entry to media as per Atom Pub spec (http://tools.ietf.org/html/rfc5023#section-9.6) + // + // + // The Beach (REQUIRED) + // urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a (REQUIRED) + // 2005-10-07T17:17:08Z + // (REQUIRED, OPTIONAL to populate + // + // + // + // + + // Normalize title + entry.setTitle( title ); + String normalTitle = title.replace( " ", "_" ); + String hostURL = "http://media.example.org/"; + int lastDelimiterPos = contentType != null ? contentType.lastIndexOf( "/" ) : -1; + String extension = ""; + if ( lastDelimiterPos != -1 ) { + extension = contentType.substring( lastDelimiterPos + 1 ); + } else { + extension = contentType; + } + long mediaLength = -1; + try { + mediaLength = media.skip( Long.MAX_VALUE ); + } catch ( IOException e ){} + + // A true implementation would store the media to a repository, e.g. file system. + // This implementation record's the id and the location. + String id = "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a-" + mediaFiles.size(); + String reposLocation = hostURL + "edit/" + normalTitle; + mediaFiles.put( id, reposLocation ); + + // Build entry for media link. + entry.setUpdated( new Date() ); + entry.setId( id ); + // Convention. Return header properties as key values. + entry.setSummary( "Content-Type=" + contentType + ",Content-Length=" + mediaLength ); + entry.setContent( new IRI( hostURL + normalTitle + "." + extension ), contentType ); + entry.addLink( reposLocation + ".atom", "edit" ); + entry.addLink( reposLocation + "." + extension, "edit-media" ); + return entry; + } + + public void putMedia(String id, String contentType, InputStream media) throws NotFoundException { + System.out.println(">>> MediaCollectionImpl.putMedia id=" + id + ", contentType=" + contentType ); + + // Must responsd with success or not found as per Atom Pub spec (http://tools.ietf.org/html/rfc5023#section-9.6) + // Body is null. + if ( !id.endsWith( "0" ) ) + throw new NotFoundException( "Media at id=" + id + " not found." ); + + // A true implementation would update the media in the media repository. + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java new file mode 100644 index 0000000000..2ed0729b00 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java @@ -0,0 +1,279 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom; + +import java.io.File; +import java.io.FileInputStream; +import java.text.SimpleDateFormat; +import java.util.Date; + +import junit.framework.Assert; + +import org.apache.abdera.Abdera; +import org.apache.abdera.i18n.iri.IRI; +import org.apache.abdera.model.Document; +import org.apache.abdera.model.Entry; +import org.apache.abdera.model.Link; +import org.apache.abdera.parser.Parser; +import org.apache.abdera.protocol.client.AbderaClient; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.InputStreamRequestEntity; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests use of server provided entry entity tags for Atom binding in Tuscany. + * Tests conditional gets (e.g. get if-none-match) or conditional posts (post if-match) + * using entity tags or last modified header entries. + * Uses the SCA provided Provider composite to act as a server. + * Uses the Abdera provided Client to act as a client. + */ +public class MediaCollectionTestCase { + public final static String providerURI = "http://localhost:8084/receipt"; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + protected static Abdera abdera; + protected static AbderaClient client; + protected static Parser abderaParser; + protected static String eTag; + protected static Date lastModified; + protected static String mediaId; + protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>MediaCollectionTestCase.init"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite"); + abdera = new Abdera(); + client = new AbderaClient(abdera); + abderaParser = Abdera.getNewParser(); + } + + @AfterClass + public static void destroy() throws Exception { + System.out.println(">>>MediaCollectionTestCase.destroy"); + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull( client ); + } + + @Test + public void testMediaEntryPost() throws Exception { + // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) + // Post request + // POST /edit/ HTTP/1.1 + // Host: media.example.org + // Content-Type: image/png + // Slug: The Beach + // Content-Length: nnn + // ...binary data... + + // Testing of entry creation + String receiptName = "Auto Repair Bill"; + String fileName = "target/test-classes/ReceiptToms.gif"; + File input = new File( fileName ); + boolean exists = input.exists(); + Assert.assertTrue( exists ); + + // Prepare HTTP post + // PostMethod post = new PostMethod( colUri.toString() ); + PostMethod post = new PostMethod( providerURI ); + post.addRequestHeader( "Content-Type", "image/gif" ); + post.addRequestHeader( "Title", "Title " + receiptName + "" ); + post.addRequestHeader( "Slug", "Slug " + receiptName + "" ); + post.setRequestEntity( new InputStreamRequestEntity( new FileInputStream( input ), "image/gif" ) ); + + // Get HTTP client + HttpClient httpclient = new HttpClient(); + try { + // Execute request + int result = httpclient.executeMethod(post); + // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) + // Post response + // Tuscany responds with proper media links. Note that the media is + // stored in a different location than the media information which is + // stored in the Atom feed. + // HTTP/1.1 201 Created + // Display status code + // System.out.println("Response status code: " + result + ", status text=" + post.getStatusText() ); + Assert.assertEquals(201, result ); + // Display response + // System.out.println("Response body: "); + // System.out.println(post.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream + + // Location: http://example.org/media/edit/the_beach.atom (REQUIRED) + // System.out.println( "Response Location=" + post.getResponseHeader( "Location" ).getValue() + "." ); + Header header = post.getResponseHeader( "Location" ); + Assert.assertNotNull( header ); + Assert.assertNotNull( header.getValue() ); + // ContentLocation: http://example.org/media/edit/the_beach.jpg (REQUIRED) + // System.out.println( "Response Content-Location=" + post.getResponseHeader( "Content-Location" ).getValue() ); + header = post.getResponseHeader( "Content-Location" ); + Assert.assertNotNull( header ); + Assert.assertNotNull( header.getValue() ); + // Content-Type: application/atom+xml;type=entry;charset="utf-8" + // System.out.println( "Response Content-Type=" + post.getResponseHeader( "Content-Type" ).getValue()); + header = post.getResponseHeader( "Content-Type" ); + Assert.assertNotNull( header ); + Assert.assertNotNull( header.getValue() ); + // Content-Length: nnn (OPTIONAL) + // System.out.println( "Response Content-Length=" + post.getResponseHeader( "Content-Length" ).getValue() ); + header = post.getResponseHeader( "Content-Length" ); + Assert.assertNotNull( header ); + Assert.assertNotNull( header.getValue() ); + // + // + // The Beach (REQUIRED) + // urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a (REQUIRED) + // 2005-10-07T17:17:08Z + // Daffy + // (REQUIRED, OPTIONAL to populate + // + // + // + // + Document document = abderaParser.parse( post.getResponseBodyAsStream() ); + Entry entry = document.getRoot(); + String title = entry.getTitle(); + // System.out.println( "mediaPost entry.title=" + title ); + Assert.assertNotNull( title ); + IRI id = entry.getId(); + // System.out.println( "mediaPost entry.id=" + id ); + Assert.assertNotNull( id ); + mediaId = id.toString(); + Assert.assertNotNull( mediaId ); // Save for put/update request + Date updated = entry.getUpdated(); + // System.out.println( "mediaPost entry.updated=" + updated); + Assert.assertNotNull( updated ); + String summary = entry.getSummary(); + // System.out.println( "mediaPost entry.summary=" + summary); + Assert.assertNotNull( summary ); + IRI contentSrc = entry.getContentSrc(); + // System.out.println( "mediaPost entry.content.src=" + contentSrc + ", type=" + entry.getContentType()); + Assert.assertNotNull( contentSrc ); + Link editLink = entry.getEditLink(); + // System.out.println( "mediaPost entry.editLink" + " rel=" + editLink.getRel() + ", href=" + editLink.getHref() ); + Assert.assertNotNull( editLink ); + Assert.assertNotNull( editLink.getRel() ); + Assert.assertNotNull( editLink.getHref() ); + Link editMediaLink = entry.getEditMediaLink(); + // System.out.println( "mediaPost entry.editMediaLink" + " rel=" + editMediaLink.getRel() + ", href=" + editMediaLink.getHref() ); + Assert.assertNotNull( editMediaLink ); + Assert.assertNotNull( editMediaLink.getRel() ); + Assert.assertNotNull( editMediaLink.getHref() ); + + } finally { + // Release current connection to the connection pool once you are done + post.releaseConnection(); + } + } + + @Test + public void testMediaEntryPutFound() throws Exception { + // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) + // Testing of entry update + String receiptName = "Value Autoglass Bill"; + String fileName = "target/test-classes/ReceiptValue.jpg"; + File input = new File( fileName ); + boolean exists = input.exists(); + Assert.assertTrue( exists ); + + // Prepare HTTP put request + // PUT /edit/the_beach.png HTTP/1.1 + // Host: media.example.org + // Content-Type: image/png + // Content-Length: nnn + // ...binary data... + PutMethod put = new PutMethod( providerURI + "/" + mediaId ); + put.addRequestHeader( "Content-Type", "image/jpg" ); + put.addRequestHeader( "Title", "Title " + receiptName + "" ); + put.addRequestHeader( "Slug", "Slug " + receiptName + "" ); + put.setRequestEntity( + new InputStreamRequestEntity( new FileInputStream( input ), "image/jpg" ) ); + + // Get HTTP client + HttpClient httpclient = new HttpClient(); + try { + // Execute request + int result = httpclient.executeMethod(put); + // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) + // Display status code + // System.out.println("Response status code: " + result + ", status text=" + put.getStatusText() ); + Assert.assertEquals(200, result ); + // Display response. Should be empty for put. + // System.out.println("Response body: "); + // System.out.println(put.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream + } finally { + // Release current connection to the connection pool once you are done + put.releaseConnection(); + } + } + + @Test + public void testMediaEntryPutNotFound() throws Exception { + // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) + // Testing of entry update + String receiptName = "Value Autoglass Bill"; + String fileName = "target/test-classes/ReceiptValue.jpg"; + File input = new File( fileName ); + boolean exists = input.exists(); + Assert.assertTrue( exists ); + + // Prepare HTTP put request + // PUT /edit/the_beach.png HTTP/1.1 + // Host: media.example.org + // Content-Type: image/png + // Content-Length: nnn + // ...binary data... + PutMethod put = new PutMethod( providerURI + "/" + mediaId + "-bogus" ); // Does not exist. + put.addRequestHeader( "Content-Type", "image/jpg" ); + put.addRequestHeader( "Title", "Title " + receiptName + "" ); + put.addRequestHeader( "Slug", "Slug " + receiptName + "" ); + put.setRequestEntity( + new InputStreamRequestEntity( new FileInputStream( input ), "image/jpg" ) ); + + // Get HTTP client + HttpClient httpclient = new HttpClient(); + try { + // Execute request + int result = httpclient.executeMethod(put); + // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) + // Display status code + // System.out.println("Response status code: " + result + ", status text=" + put.getStatusText() ); + Assert.assertEquals(404, result ); + // Display response. Should be empty for put. + // System.out.println("Response body: "); + // System.out.println(put.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream + } finally { + // Release current connection to the connection pool once you are done + put.releaseConnection(); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java new file mode 100644 index 0000000000..3e1bf543e5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.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.sca.binding.atom; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Provider { + + public static void main(String[] args) { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); + System.out.println("Provider.composite ready..."); + + try { + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java new file mode 100644 index 0000000000..c209e2dfe6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java @@ -0,0 +1,421 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import junit.framework.Assert; + +import org.apache.abdera.Abdera; +import org.apache.abdera.factory.Factory; +import org.apache.abdera.i18n.iri.IRI; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.abdera.parser.Parser; +import org.apache.abdera.protocol.client.AbderaClient; +import org.apache.abdera.protocol.client.ClientResponse; +import org.apache.abdera.protocol.client.RequestOptions; +import org.apache.abdera.protocol.client.util.BaseRequestEntity; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests use of server provided entry entity tags for Atom binding in Tuscany. + * Tests conditional gets (e.g. get if-none-match) or conditional posts (post if-match) + * using entity tags or last modified header entries. + * Uses the SCA provided Provider composite to act as a server. + * Uses the Abdera provided Client to act as a client. + */ +public class ProviderEntryEntityTagsTestCase { + public final static String providerURI = "http://localhost:8084/customer"; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + protected static Abdera abdera; + protected static AbderaClient client; + protected static Parser abderaParser; + protected static String eTag; + protected static Date lastModified; + protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>ProviderEntryEntityTagsTestCase.init"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); + abdera = new Abdera(); + client = new AbderaClient(abdera); + abderaParser = Abdera.getNewParser(); + } + + @AfterClass + public static void destroy() throws Exception { + System.out.println(">>>ProviderEntryEntityTagsTestCase.destroy"); + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull( client ); + } + + @Test + public void testEmptyCachePost() throws Exception { + // Pseudo-code + // 1) Example HTTP POST request (new entry put, new etag response) + // User client post request + // POST /myblog/entries HTTP/1.1 + // Slug: First Post + // + // + // + // Atom-Powered Robots Run Amok + // urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + // 2007-02-123T17:09:02Z + // Captain Lansing + // It's something moving... solid metal + // + + // Expected Atom server response (note unique ETag) + // HTTP/1.1 201 Created + // Date: Fri, 23 Feb 2007 21:17:11 GMT + // Content-Length: nnn + // Content-Type: application/atom+xml;type=entry + // Location: http://example.org/edit/first-post.atom + // Content-Location: http://example.org/edit/first-post.atom + // ETag: "e180ee84f0671b1" + // Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 + // + // + // + // Atom-Powered Robots Run Amok + // urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + // 2007-02-123T17:09:02Z + // Captain Lansing + // It's something moving... solid metal + // + + // Testing of entry creation + Factory factory = abdera.getFactory(); + String customerName = "Fred Farkle"; + Entry entry = factory.newEntry(); + entry.setTitle("customer " + customerName); + entry.setUpdated(new Date()); + entry.addAuthor("Apache Tuscany"); + // ID created by collection. + // entry.setId(id); // auto-provided + // entry.addLink("" + id, "edit"); // auto-provided + // entry.addLink("" + id, "alternate"); // auto-provided + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(customerName); + entry.setContentElement(content); + + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + // AtomTestCaseUtils.printRequestHeaders( "Post request headers", " ", opts ); + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + ClientResponse res = client.post(colUri.toString(), entry, opts); + + // Assert response status code is 201-OK. + // Assert response header Content-Type: application/atom+xml; charset=UTF-8 + // Assert response header Location: http://example.org/edit/first-post.atom + // Assert response header Content-Location: http://example.org/edit/first-post.atom + // Assert response header ETag: "e180ee84f0671b1" + // Assert response header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 + // Assert collection size is 1. + Assert.assertEquals(201, res.getStatus()); + Assert.assertEquals(contentType, res.getContentType().toString().trim()); + // Assert.assertNotNull( res.getLocation().toString() ); + // Assert.assertEquals( "", res.getContentLocation().toString() ); + // Save eTag for subsequent tests; + eTag = res.getHeader( "ETag" ); + Assert.assertNotNull( eTag ); + lastModified = res.getLastModified(); + Assert.assertNotNull(lastModified); + } + + @Test + public void testDirtyCachePut() throws Exception { + // 2) Conditional PUT request (post with etag. entry provided is stale) + // User client PUT request + // PUT /edit/first-post.atom HTTP/1.1 + // > If-Match: "e180ee84f0671b1" + // + // + // + // Atom-Powered Robots Run Amok + // urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + // 2007-02-24T16:34:06Z + // Captain Lansing + // Update: it's a hoax! + // + // Testing of entry creation + Factory factory = abdera.getFactory(); + String customerName = "Molly Ringwald"; + Entry entry = factory.newEntry(); + entry.setTitle("customer " + customerName); + entry.setUpdated( new Date()); + entry.addAuthor("Apache Tuscany"); + String id = eTag.substring( 1, eTag.length()-1); + entry.setId(id); // auto-provided + // entry.addLink("" + id, "edit"); // auto-provided + // entry.addLink("" + id, "alternate"); // auto-provided + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(customerName); + entry.setContentElement(content); + + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-None-Match", eTag); + + // AtomTestCaseUtils.printRequestHeaders( "Put request headers", " ", opts ); + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + ClientResponse res = client.put(colUri.toString() + "/" + id, new BaseRequestEntity( entry ), opts); + // Expected Atom server response (item was edited by another user) + // > HTTP/1.1 412 Precondition Failed + // Date: Sat, 24 Feb 2007 16:34:11 GMT + + // If-Match Assert response status code is 412. Precondition failed. + // If-None-Match Assert response status code is 200. OK + Assert.assertEquals(200, res.getStatus()); + // Put provides null body and no etags. + res.release(); + } + + @Test + public void testETagMissGet() throws Exception { + // 4) Conditional GET example (get with etag. etag not in cache) + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // > If-None-Match: "e180ee84f0671b1" + + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-None-Match", "123456"); + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + ClientResponse res = client.get(colUri.toString() + "/" + id, opts); + // Expected Atom server response (item was edited by another user) + // > HTTP/1.1 412 Precondition Failed + // Date: Sat, 24 Feb 2007 16:34:11 GMT + + // Atom server response (item was up to date) + // > HTTP/1.1 200 OK + // Date: Sat, 24 Feb 2007 13:17:11 GMT + // > ETag: "bb4f5e86e92ddb8549604a0df0763581" + // > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500 + + // Assert response status code is 200 OK. + // Assert header Content-Type: application/atom+xml;type=entry + // Assert header Location: http://example.org/edit/first-post.atom + // Assert header Content-Location: http://example.org/edit/first-post.atom + // Assert header ETag: "555555" (etag response != etag request) + // Assert header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(contentType, res.getContentType().toString().trim()); + // Assert.assertNotNull( res.getLocation().toString() ); + // Assert.assertEquals( "", res.getContentLocation().toString() ); + Assert.assertNotNull( res.getHeader( "ETag" ) ); + lastModified = res.getLastModified(); + Assert.assertNotNull(lastModified); + res.release(); + } + + @Test + public void testETagHitGet() throws Exception { + // 3) Conditional GET example (get with etag. etag match) + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // > If-None-Match: "e180ee84f0671b1" + + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-None-Match", eTag); + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + ClientResponse res = client.get(colUri.toString() + "/" + id, opts); + // Atom server response (item was up to date) + // > HTTP/1.1 304 Not Modified + // Date: Sat, 24 Feb 2007 13:17:11 GMT + + // Assert response status code is 304 Not Modified. + // Assert header ETag: "e180ee84f0671b1" + // Assert header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 + // Assert.assertEquals(304, res.getStatus()); + res.release(); + } + + + @Test + public void testUpToDateGet() throws Exception { + // 3) Conditional GET example (get with If-Mod. entry is up to date) + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // > If-Modified-Since: Sat, 29 Oct 2025 19:43:31 GMT + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-Modified-Since", "Sat, 29 Oct 2025 19:43:31 GMT"); // "EEE, dd MMM yyyy HH:mm:ss Z // RFC 822 Date + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.get(colUri.toString() + "/" + id, opts); + ClientResponse res = client.execute( "GET", colUri.toString(), (BaseRequestEntity)null, opts); + + // Atom server response (item was up to date) + // > HTTP/1.1 304 Not Modified + // Date: Sat, 24 Feb 2007 13:17:11 GMT + + // Assert response status code is 304 Not Modified. + Assert.assertEquals(304, res.getStatus()); + res.release(); + } + + @Test + public void testOutOfDateGet() throws Exception { + // 4) Conditional GET example (get with If-Mod. entry is not to date) + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // > If-Modified-Since: Sat, 29 Oct 1844 19:43:31 GMT + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-Modified-Since", "Sat, 29 Oct 1844 19:43:31 GMT"); // "EEE, dd MMM yyyy HH:mm:ss Z // RFC 822 Date + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + ClientResponse res = client.get(colUri.toString() + "/" + id, opts); + + // Atom server response (item was up to date) + // > HTTP/1.1 200 OK + // Date: Sat, 24 Feb 2007 13:17:11 GMT + // > ETag: "bb4f5e86e92ddb8549604a0df0763581" + // > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500 + + // Assert response status code is 200 OK. + // Assert header ETag: "e180ee84f0671b1" + // Assert header Last-Modified: Greater than If-Mod + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(contentType, res.getContentType().toString().trim()); + // Assert.assertNotNull( res.getLocation().toString() ); + // Assert.assertEquals( "", res.getContentLocation().toString() ); + Assert.assertNotNull( res.getHeader( "ETag" ) ); + lastModified = res.getLastModified(); + Assert.assertNotNull(lastModified); + res.release(); + } + + @Test + public void testUpToDateUnModGet() throws Exception { + // 3) Conditional GET example (get with If-Unmod. entry is not modified (< predicate date). + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // > If-Unmodified-Since: Sat, 29 Oct 2025 19:43:31 GMT + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-Unmodified-Since", "Sat, 29 Oct 2050 19:43:31 GMT" ); + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + ClientResponse res = client.get(colUri.toString() + "/" + id, opts); + + // Atom server response (item was up to date) + // > HTTP/1.1 200 OK + // Date: Sat, 24 Feb 2007 13:17:11 GMT + // > ETag: "bb4f5e86e92ddb8549604a0df0763581" + // > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500 + + // Assert response status code is 200 OK. + // Assert header Content-Type: application/atom+xml;type=entry + // Assert header Location: http://example.org/edit/first-post.atom + // Assert header Content-Location: http://example.org/edit/first-post.atom + // Assert header ETag: "e180ee84f0671b1" + // Assert header Last-Modified: Less than If-Unmod + Assert.assertEquals(200, res.getStatus()); + res.release(); + } + + @Test + public void testOutOfDateUnModGet() throws Exception { + // 4) Conditional GET example (get with If-Unmod. entry is modified (> predicate date) + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // Host: example.org + // > If-Unmodified-Since: Sat, 29 Oct 1844 19:43:31 GMT + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-Unmodified-Since", "Sat, 29 Oct 1844 19:43:31 GMT" ); + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + ClientResponse res = client.get(colUri.toString() + "/" + id, opts); + + // Atom server response (item was up to date) + // > HTTP/1.1 304 Not Modified + // Date: Sat, 24 Feb 2007 13:17:11 GMT + + // Assert response status code is 304 Not Modified. + Assert.assertEquals(304, res.getStatus()); + res.release(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java new file mode 100644 index 0000000000..42edeb8f0d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java @@ -0,0 +1,375 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.atom; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.text.SimpleDateFormat; +import java.util.Date; + +import junit.framework.Assert; + +import org.apache.abdera.Abdera; +import org.apache.abdera.factory.Factory; +import org.apache.abdera.i18n.iri.IRI; +import org.apache.abdera.model.Collection; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Entry; +import org.apache.abdera.model.Feed; +import org.apache.abdera.parser.Parser; +import org.apache.abdera.protocol.Response.ResponseType; +import org.apache.abdera.protocol.client.AbderaClient; +import org.apache.abdera.protocol.client.ClientResponse; +import org.apache.abdera.protocol.client.RequestOptions; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests use of server provided feed entity tags for Atom binding in Tuscany. + * Tests conditional gets (e.g. get if-none-match) or conditional posts (post if-match) + * using entity tags and last modified entries in headers. + * Uses the SCA provided Provider composite to act as a server. + * Uses the Abdera provided Client to act as a client. + */ +public class ProviderFeedEntityTagsTestCase { + public final static String providerURI = "http://localhost:8084/customer"; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + protected static Abdera abdera; + protected static AbderaClient client; + protected static Parser abderaParser; + protected static String eTag; + protected static Date lastModified; + protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.init"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); + abdera = new Abdera(); + client = new AbderaClient(abdera); + abderaParser = Abdera.getNewParser(); + } + + @AfterClass + public static void destroy() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.destroy"); + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull( client ); + } + + @Test + public void testFeedBasics() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedBasics"); + // Normal feed request + ClientResponse res = client.get(providerURI); + Assert.assertNotNull(res); + try { + // Assert feed provided since no predicates + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(ResponseType.SUCCESS, res.getType()); + // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res ); + // System.out.println("Feed response content:"); + // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); + + // Perform other tests on feed. + // Warning. AbderaClient.getEntityTag is very particular on tag pattern. + // Document doc = res.getDocument(); + String body = read( res.getInputStream() ); + // RFC 4287 requires non-null id, title, updated elements + Assert.assertTrue( -1 != body.indexOf( "" )); + Assert.assertTrue( -1 != body.indexOf( "" )); + Assert.assertTrue( -1 != body.indexOf( "" )); + + eTag = res.getHeader("ETag"); + Assert.assertNotNull( eTag ); + lastModified = res.getLastModified(); + Assert.assertNotNull( lastModified ); + } finally { + res.release(); + } + } + + @Test + public void testUnmodifiedGetIfMatch() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfMatch"); + // Feed request with predicates + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml"; + opts.setContentType(contentType); + opts.setHeader( "If-Match", eTag); + + ClientResponse res = client.get(providerURI, opts); + Assert.assertNotNull(res); + try { + String thisETag = res.getHeader("ETag"); + Assert.assertNotNull( thisETag ); + Date thisLastModified = res.getLastModified(); + Assert.assertNotNull( thisLastModified ); + + // Should return 200 - Feed provided since it matches etag. + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(ResponseType.SUCCESS, res.getType()); + // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res ); + // System.out.println("Feed response content:"); + // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); + } finally { + res.release(); + } + } + + @Test + public void testUnmodifiedGetIfNoneMatch() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfNoneMatch"); + // Feed request with predicates + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml"; + opts.setContentType(contentType); + opts.setHeader( "If-None-Match", eTag); + + ClientResponse res = client.get(providerURI, opts); + Assert.assertNotNull(res); + try { + // Should return 304 - Feed not provided since it matches ETag. + Assert.assertEquals(304, res.getStatus()); + } finally { + res.release(); + } + } + + @Test + public void testUnmodifiedGetIfUnModified() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfUnModified"); + // Feed request with predicates + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml"; + opts.setContentType(contentType); + opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() )); + + ClientResponse res = client.get(providerURI, opts); + Assert.assertNotNull(res); + try { + // Should return 304 - Feed not provided since feed is modified since. + Assert.assertEquals(304, res.getStatus()); + } finally { + res.release(); + } + } + + @Test + public void testUnmodifiedGetIfModified() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfModified"); + // Feed request with predicates + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml"; + opts.setContentType(contentType); + opts.setHeader( "If-Modified-Since", dateFormat.format( new Date( 0 ) )); + + ClientResponse res = client.get(providerURI, opts); + Assert.assertNotNull(res); + try { + // Should return 200 - Feed provided since feed is changed. + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(ResponseType.SUCCESS, res.getType()); + + String thisETag = res.getHeader("ETag"); + Assert.assertNotNull( thisETag ); + Date thisLastModified = res.getLastModified(); + Assert.assertNotNull( thisLastModified ); + } finally { + res.release(); + } + } + + @Test + public void testModifiedGetIfNoneMatch() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfNoneMatch"); + // Post some new content to the feed. + Factory factory = abdera.getFactory(); + String customerName = "Fred Farkle"; + Entry entry = factory.newEntry(); + entry.setTitle("customer " + customerName); + entry.setUpdated(new Date()); + entry.addAuthor("Apache Tuscany"); + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(customerName); + entry.setContentElement(content); + + RequestOptions opts = new RequestOptions(); + String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + IRI colUri = new IRI(providerURI).resolve("customer"); + ClientResponse res = client.post(colUri.toString(), entry, opts); + + // Feed request with predicates + opts = new RequestOptions(); + contentType = "application/atom+xml"; + opts.setContentType(contentType); + opts.setHeader( "If-None-Match", eTag); + + res = client.get(providerURI, opts); + Assert.assertNotNull(res); + try { + // Should return 304 - Feed not provided since it matches ETag. + Assert.assertEquals(304, res.getStatus()); + // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res ); + // System.out.println("Feed response content:"); + // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); + } finally { + res.release(); + } + } + + @Test + public void testModifiedGetIfMatch() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfMatch"); + // Feed request with predicates + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml"; + opts.setContentType(contentType); + opts.setHeader( "If-Match", eTag); + + ClientResponse res = client.get(providerURI, opts); + Assert.assertNotNull(res); + try { + String thisETag = res.getHeader("ETag"); + Assert.assertNotNull( thisETag ); + Date thisLastModified = res.getLastModified(); + Assert.assertNotNull( thisLastModified ); + + // Should return 200 - value since feed is changed + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(ResponseType.SUCCESS, res.getType()); + + // AtomTestCaseUtils.printResponseHeaders( "Feed modified if-none-match response headers:", " ", res ); + // System.out.println("Feed response content:"); + // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); + } finally { + res.release(); + } + } + + @Test + public void testModifiedGetIfUnModified() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfUnModified"); + // Feed request with predicates + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml"; + opts.setContentType(contentType); + opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() )); + + ClientResponse res = client.get(providerURI, opts); + Assert.assertNotNull(res); + try { + // Should return 304 - Feed not provided since feed is modified since. + Assert.assertEquals(304, res.getStatus()); + } finally { + res.release(); + } + } + + @Test + public void testModifiedGetIfModified() throws Exception { + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfModified"); + // Feed request with predicates + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml"; + opts.setContentType(contentType); + opts.setHeader( "If-Modified-Since", dateFormat.format( lastModified )); + + ClientResponse res = client.get(providerURI, opts); + Assert.assertNotNull(res); + try { + // Should return 200 - Feed provided since feed is changed. + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(ResponseType.SUCCESS, res.getType()); + + String thisETag = res.getHeader("ETag"); + Assert.assertNotNull( thisETag ); + Date thisLastModified = res.getLastModified(); + Assert.assertNotNull( thisLastModified ); + } finally { + res.release(); + } + } + + + public static void printFeed( String title, String indent, Feed feed ) { + if ( feed == null ) { + System.out.println( title + " feed is null"); + return; + } + + System.out.println( title ); + System.out.println( indent + "id=" + feed.getId() ); + System.out.println( indent + "title=" + feed.getTitle() ); + System.out.println( indent + "updated=" + feed.getUpdated() ); + System.out.println( indent + "author=" + feed.getAuthor() ); + Collection collection = feed.getCollection(); + if ( collection == null ) { + System.out.println( indent + "collection=null" ); + } else { + System.out.println( indent + "collection=" + collection ); + } + // System.out.println( indent + "collection size=" + feed.getCollection() ); + // for (Collection collection : workspace.getCollections()) { + // if (collection.getTitle().equals("customers")) { + // String expected = uri + "customers"; + // String actual = collection.getResolvedHref().toString(); + // assertEquals(expected, actual); + // } + // } + + } + + /** + * Read response ream from the given socket. + * @param socket + * @return + * @throws IOException + */ + private static String read(InputStream inputStream) throws IOException { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader( inputStream )); + StringBuffer sb = new StringBuffer(); + String str; + while ((str = reader.readLine()) != null) { + sb.append(str); + } + return sb.toString(); + } finally { + if (reader != null) { + reader.close(); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java new file mode 100644 index 0000000000..0d4194070d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.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.sca.binding.atom; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import junit.framework.Assert; + +import org.apache.abdera.Abdera; +import org.apache.abdera.model.Content; +import org.apache.abdera.model.Document; +import org.apache.abdera.model.Entry; +import org.apache.abdera.model.Feed; +import org.apache.abdera.model.Service; +import org.apache.abdera.parser.Parser; +import org.apache.abdera.protocol.Response.ResponseType; +import org.apache.abdera.protocol.client.AbderaClient; +import org.apache.abdera.protocol.client.ClientResponse; +import org.apache.tuscany.sca.binding.atom.collection.Collection; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests use of service documents provided by atom binding based collections. + * Uses the SCA provided Provider composite to act as a server. + * Uses the Abdera provided Client to act as a client. + */ +public class ProviderServiceDocumentTestCase { + public final static String providerURI = "http://localhost:8084/customer"; + protected static SCADomain scaProviderDomain; + protected static SCADomain scaConsumerDomain; + protected static CustomerClient testService; + protected static Abdera abdera; + protected static AbderaClient client; + protected static Parser abderaParser; + + @BeforeClass + public static void init() throws Exception { + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); + scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite"); + testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient"); + abdera = new Abdera(); + client = new AbderaClient(abdera); + abderaParser = Abdera.getNewParser(); + } + + @AfterClass + public static void destroy() throws Exception { + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull( client ); + } + + @Test + public void testFeedBasics() throws Exception { + // Normal feed request + ClientResponse res = client.get(providerURI); + Assert.assertNotNull(res); + try { + // Assert feed provided since no predicates + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(ResponseType.SUCCESS, res.getType()); + // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res ); + // System.out.println("Feed response content:"); + // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); + + // Perform other tests on feed. + // Warning. AbderaClient.getEntityTag is very particular on tag pattern. + // Document doc = res.getDocument(); + String body = read( res.getInputStream() ); + // RFC 4287 requires non-null id, title, updated elements + Assert.assertTrue( -1 != body.indexOf( "" )); + Assert.assertTrue( -1 != body.indexOf( "" )); + Assert.assertTrue( -1 != body.indexOf( "" )); + } finally { + res.release(); + } + } + + @Test + public void testServiceDocumentGet() throws Exception { + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry postEntry = postEntry("Sponge Bob"); + Entry newEntry = resourceCollection.post(postEntry); + postEntry = postEntry("Austin Powers"); + newEntry = resourceCollection.post(postEntry); + postEntry = postEntry("Count Dracula"); + newEntry = resourceCollection.post(postEntry); + + // Service document + ClientResponse res = client.get(providerURI + "/atomsvc"); + Assert.assertNotNull(res); + try { + // Asser feed provided since no predicates + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(ResponseType.SUCCESS, res.getType()); + + // Perform other tests on feed. + // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); + Document serviceDoc = res.getDocument(); + Service service = serviceDoc.getRoot(); + Assert.assertNotNull( service ); + org.apache.abdera.model.Collection collection = service.getCollection( "workspace", "customers" ); + String title = collection.getTitle(); + Assert.assertEquals("customers", title); + String href = collection.getHref().toString(); + Assert.assertTrue( href.contains( "customer") ); + } finally { + res.release(); + } + } + + public static void printFeed( String title, String indent, Feed feed ) { + if ( feed == null ) { + System.out.println( title + " feed is null"); + return; + } + + System.out.println( title ); + System.out.println( indent + "id=" + feed.getId() ); + System.out.println( indent + "title=" + feed.getTitle() ); + System.out.println( indent + "updated=" + feed.getUpdated() ); + System.out.println( indent + "author=" + feed.getAuthor() ); + // Collection collection = feed.getCollection(); + // if ( collection == null ) { + // System.out.println( indent + "collection=null" ); + // } else { + // System.out.println( indent + "collection=" + collection ); + // } + // System.out.println( indent + "collection size=" + feed.getCollection() ); + // for (Collection collection : workspace.getCollections()) { + // if (collection.getTitle().equals("customers")) { + // String expected = uri + "customers"; + // String actual = collection.getResolvedHref().toString(); + // assertEquals(expected, actual); + // } + // } + + } + + private Entry postEntry(String value) { + Entry entry = abdera.newEntry(); + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + + /** + * Read response ream from the given socket. + * @param socket + * @return + * @throws IOException + */ + private static String read(InputStream inputStream) throws IOException { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader( inputStream )); + StringBuffer sb = new StringBuffer(); + String str; + while ((str = reader.readLine()) != null) { + sb.append(str); + } + return sb.toString(); + } finally { + if (reader != null) { + reader.close(); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Aggregator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Aggregator.java new file mode 100644 index 0000000000..213ae53527 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Aggregator.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.sca.binding.atom.aggregator; + +import org.apache.tuscany.sca.data.collection.Collection; +import org.apache.tuscany.sca.data.collection.Item; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Aggregator extends Collection{ + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java new file mode 100644 index 0000000000..4037babd13 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.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.sca.binding.atom.aggregator; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.data.collection.Collection; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +public class AggregatorImpl implements Aggregator { + + @Reference(required = false) + public Collection atomFeed1; + + @Reference(required = false) + public Collection atomFeed2; + + @Reference(required = false) + public Sort sort; + + @Property + public String feedTitle = "Aggregated Feed"; + @Property + public String feedDescription = "Anonymous Aggregated Feed"; + @Property + public String feedAuthor = "anonymous"; + + public Item get(String id) { + + try { + if (atomFeed1.get(id) != null) + return atomFeed1.get(id); + } catch (NotFoundException ex) { + ex.printStackTrace(); + } + + try { + if (atomFeed2.get(id) != null) + return atomFeed2.get(id); + } catch (NotFoundException ex) { + ex.printStackTrace(); + } + + return null; + + } + + public Entry[] getAll() { + + // Aggregate entries from atomFeed1, atomFeed2, rssFeed1 and rssFeed2 + List entries = new ArrayList(); + if (atomFeed1 != null) { + try { + for (Entry entry : atomFeed1.getAll()) { + entries.add(entry); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + if (atomFeed2 != null) { + try { + for (Entry entry : atomFeed2.getAll()) { + entries.add(entry); + } + } catch (Exception e) { + } + } + + // Sort entries by published date + if (sort != null) { + entries = sort.sort(entries); + } + + return entries.toArray(new Entry[entries.size()]); + + } + + public String post(String key, Item entry) { + return null; + } + + public void put(String id, Item entry) { + } + + public Entry[] query(String queryString) { + ArrayList entries = new ArrayList(); + + Entry[] allFeed = getAll(); + if (queryString.startsWith("title=")) { + String title = queryString.substring(6); + + for (Entry entry : allFeed) { + if (entry.getData().getTitle().contains(title)) { + entries.add(entry); + } + } + } + return entries.toArray(new Entry[entries.size()]); + } + + public void delete(String id) { + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java new file mode 100644 index 0000000000..9cd94b2bd7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.atom.aggregator; + +import java.net.Socket; + +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + + +public class AggregatorTestCase { + private static SCADomain domain; + private static Aggregator aggregatorService; + + @BeforeClass + public static void init() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/aggregator/FeedAggregator.composite"); + Assert.assertNotNull(domain); + aggregatorService = domain.getService(Aggregator.class, "AtomAggregator"); + Assert.assertNotNull(aggregatorService); + } + + @AfterClass + public static void destroy() throws Exception { + if(domain != null) { + domain.close(); + } + } + + @Test + public void testPing() throws Exception { + new Socket("127.0.0.1", 8085); + } + + @Test + public void testAggregator() throws Exception { + Entry[] entries = aggregatorService.getAll(); + + Assert.assertNotNull(entries); + Assert.assertTrue(entries.length > 0); + + for(int pos = 0; pos < entries.length; pos++) { + System.out.println(">>> Entry[" + pos + "] - " + entries[pos].getData().getTitle()); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Sort.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Sort.java new file mode 100644 index 0000000000..19daa1fefb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Sort.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.sca.binding.atom.aggregator; + +import java.util.List; + +import org.apache.tuscany.sca.data.collection.Entry; + +/** + * The Sort service business interface. + * + * @version $Rev$ $Date$ + */ +public interface Sort { + + /** + * Sort feed entries by published date. + * @param entries + * @return + */ + List sort(List entries); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java new file mode 100644 index 0000000000..e81f450626 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.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.sca.binding.atom.aggregator; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.Date; +import java.util.List; + +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.Item; +import org.osoa.sca.annotations.Property; + +/** + * Implementation of a Feed Sort service component. + * + * @version $Rev$ $Date$ + */ +public class SortImpl implements Sort { + + @Property + public boolean newFirst = true; + + @SuppressWarnings("unchecked") + public List sort(List entries) { + Entry[] entriesArray = new Entry[entries.size()]; + entriesArray = (Entry[])entries.toArray(entriesArray); + Arrays.sort(entriesArray, new Comparator() { + public int compare(final Object xObj, final Object yObj) { + Entry x = (Entry) xObj; + Entry y = (Entry) yObj; + Item xItem = (Item) x.getData(); + Item yItem = (Item) y.getData(); + Date xDate = xItem.getDate(); + Date yDate = yItem.getDate(); + if (xDate == null) + return -1; + if (newFirst) + return yDate.compareTo(xDate); + else + return xDate.compareTo(yDate); + } + }); + return Arrays.asList(entriesArray); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/Headline.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/Headline.java new file mode 100644 index 0000000000..95152af73d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/Headline.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.sca.binding.atom.news; + +import java.io.Serializable; + +public class Headline implements Serializable { + private static final long serialVersionUID = 2516853242307046775L; + + private String text; + private String source; + + public Headline() { + + } + + public Headline(String text, String source) { + this.text = text; + this.source = text; + } + + public void setText(String text) { + this.text = text; + } + + public String getText() { + return text; + } + + public void setSoure(String source) { + this.source = source; + } + + public String getSource() { + return source; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsService.java new file mode 100644 index 0000000000..c4fafc30bb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsService.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.sca.binding.atom.news; + +import javax.xml.bind.annotation.XmlSeeAlso; + +import org.apache.tuscany.sca.data.collection.Collection; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface NewsService extends Collection{ + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceImpl.java new file mode 100644 index 0000000000..b51845ba1c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceImpl.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.atom.news; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Service; + +@Service(NewsService.class) +public class NewsServiceImpl implements NewsService { + private Map headlines = new HashMap(); + + @Init + public void init() { + Headline headline; + + headline = new Headline(); + headline.setSoure("http://www.domain.com/source1"); + headline.setText("headline text 1111"); + + headlines.put("h1", headline); + + + headline = new Headline(); + headline.setSoure("http://www.domain.com/source2"); + headline.setText("headline text 2222"); + + headlines.put("h2", headline); + } + + public Entry[] getAll() { + Entry[] entries = new Entry[headlines.size()]; + int i = 0; + for (Map.Entry e: headlines.entrySet()) { + entries[i++] = new Entry(e.getKey(), e.getValue()); + } + return entries; + } + + public Headline get(String key) throws NotFoundException { + Headline item = headlines.get(key); + if (item == null) { + throw new NotFoundException(key); + } else { + return item; + } + } + + public String post(String key, Headline item) { + // TODO Auto-generated method stub + return null; + } + + public void put(String key, Headline item) throws NotFoundException { + // TODO Auto-generated method stub + + } + + public Entry[] query(String queryString) { + // TODO Auto-generated method stub + return null; + } + + public void delete(String key) throws NotFoundException { + // TODO Auto-generated method stub + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceTestCase.java new file mode 100644 index 0000000000..454947ed98 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceTestCase.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.sca.binding.atom.news; + +import java.net.Socket; + +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +public class NewsServiceTestCase { + private static SCADomain domain; + private static NewsService newsService; + + @BeforeClass + public static void init() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/news/news.composite"); + Assert.assertNotNull(domain); + newsService = domain.getService(NewsService.class, "NewsService"); + Assert.assertNotNull(newsService); + } + + @AfterClass + public static void destroy() throws Exception { + if(domain != null) { + domain.close(); + } + } + + @Test + public void testPing() throws Exception { + new Socket("127.0.0.1", 8085); + // System.in.read(); + } + + @Test + //@Ignore("TUSCANY-3288") + public void testNewsService() throws Exception { + Entry[] entries = newsService.getAll(); + + Assert.assertNotNull(entries); + Assert.assertTrue(entries.length > 0); + + for(int pos = 0; pos < entries.length; pos++) { + System.out.println(">>> Entry[" + pos + "] - " + entries[pos].getData().getText()); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/ReceiptToms.gif b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/ReceiptToms.gif new file mode 100644 index 0000000000..bfeee9b2f4 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/ReceiptToms.gif differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/ReceiptValue.jpg b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/ReceiptValue.jpg new file mode 100644 index 0000000000..584f39ea8d Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/ReceiptValue.jpg differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Consumer.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Consumer.composite new file mode 100644 index 0000000000..a2c50f872e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Consumer.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Provider.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Provider.composite new file mode 100644 index 0000000000..60097ee0f7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Provider.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/ProviderNonCollection.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/ProviderNonCollection.composite new file mode 100644 index 0000000000..ddb660cada --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/ProviderNonCollection.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite new file mode 100644 index 0000000000..71aa932a12 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/aggregator/FeedAggregator.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/aggregator/FeedAggregator.composite new file mode 100644 index 0000000000..64c84c5440 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/aggregator/FeedAggregator.composite @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + Atom Aggregator Sample + + + + + true + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/news/news.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/news/news.composite new file mode 100644 index 0000000000..fb994464da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/news/news.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/pom.xml new file mode 100644 index 0000000000..c1b9caa69b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-atom-js-dojo + Apache Tuscany SCA Atom Feed Binding JavaScript using Dojo + + + + org.apache.tuscany.sca + tuscany-binding-atom + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-web-javascript + 1.6-SNAPSHOT + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.atom-js-dojo + ${pom.name} + org.apache.tuscany.sca.binding.atom.js.dojo + org.apache.tuscany.sca.assembly.xml;version="1.4", * + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java new file mode 100644 index 0000000000..050ef91767 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.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.sca.binding.atom.js.dojo; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.binding.atom.AtomBinding; +import org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory; + +public class AtomBindingJavascriptProxyFactoryImpl implements JavascriptProxyFactory { + private static final QName NAME = new QName("http://tuscany.apache.org/xmlns/sca/1.0", "binding.atom"); + + public Class getModelType() { + return AtomBinding.class; + } + + public QName getQName() { + return NAME; + } + + public String getJavascriptProxyFile() { + return null; + } + + public InputStream getJavascriptProxyFileAsStream() throws IOException { + return null; + } + + public String createJavascriptReference(ComponentReference componentReference) throws IOException { + Binding binding = componentReference.getBindings().get(0); + URI targetURI = URI.create(binding.getURI()); + String targetPath = targetURI.getPath(); + + return "tuscany.AtomService(\"" + targetPath + "\")"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory new file mode 100644 index 0000000000..80a63e76ee --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js-dojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the Javascript Proxy Factory +org.apache.tuscany.sca.binding.atom.js.dojo.AtomBindingJavascriptProxyFactoryImpl;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.atom,model=org.apache.tuscany.sca.binding.atom.AtomBinding,model=org.apache.tuscany.sca.binding.atom.AtomBinding \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/pom.xml new file mode 100644 index 0000000000..ab95051606 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-atom-js + Apache Tuscany SCA Atom Feed Binding JavaScript + + + + org.apache.tuscany.sca + tuscany-binding-atom + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-web-javascript + 1.6-SNAPSHOT + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.atom-js + ${pom.name} + org.apache.tuscany.sca.binding.atom.js* + org.apache.tuscany.sca.assembly.xml;version="1.4", * + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/java/org/apache/tuscany/sca/binding/atom/js/AtomBindingJavascriptProxyFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/java/org/apache/tuscany/sca/binding/atom/js/AtomBindingJavascriptProxyFactoryImpl.java new file mode 100644 index 0000000000..6e2ce1895a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/java/org/apache/tuscany/sca/binding/atom/js/AtomBindingJavascriptProxyFactoryImpl.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.sca.binding.atom.js; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.binding.atom.AtomBinding; +import org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory; + +public class AtomBindingJavascriptProxyFactoryImpl implements JavascriptProxyFactory { + private static final QName NAME = new QName("http://tuscany.apache.org/xmlns/sca/1.0", "binding.atom"); + private static final String JAVASCRIPT_FILE_NAME = "binding-atom.js"; + + public Class getModelType() { + return AtomBinding.class; + } + + public QName getQName() { + return NAME; + } + + public String getJavascriptProxyFile() { + return JAVASCRIPT_FILE_NAME; + } + + public InputStream getJavascriptProxyFileAsStream() throws IOException { + InputStream is = this.getClass().getClassLoader().getResourceAsStream(JAVASCRIPT_FILE_NAME); + if (is == null) { + throw new IOException("Could not find Javascript '" + JAVASCRIPT_FILE_NAME + "'" ); + } + + return is; + } + + public String createJavascriptReference(ComponentReference componentReference) throws IOException { + Binding binding = componentReference.getBindings().get(0); + URI targetURI = URI.create(binding.getURI()); + String targetPath = targetURI.getPath(); + + return "AtomClient(\"" + targetPath + "\")"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory new file mode 100644 index 0000000000..5ee927e586 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the Javascript Proxy Factory +org.apache.tuscany.sca.binding.atom.js.AtomBindingJavascriptProxyFactoryImpl;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.atom,model=org.apache.tuscany.sca.binding.atom.AtomBinding,model=org.apache.tuscany.sca.binding.atom.AtomBinding \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/resources/binding-atom.js b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/resources/binding-atom.js new file mode 100644 index 0000000000..2719e9a9b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom-js/src/main/resources/binding-atom.js @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +function AtomClient(uri) { + + this.msxmlNames = [ "MSXML2.XMLHTTP.5.0", + "MSXML2.XMLHTTP.4.0", + "MSXML2.XMLHTTP.3.0", + "MSXML2.XMLHTTP", + "Microsoft.XMLHTTP" ]; + + this.uri=uri; + + this.get = function(id, responseFunction) { + var xhr = this.createXMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + var strDocument = xhr.responseText; + var xmlDocument = xhr.responseXML; + if(!xmlDocument || xmlDocument.childNodes.length==0){ + xmlDocument = (new DOMParser()).parseFromString(strDocument, "text/xml"); + } + if (responseFunction != null) responseFunction(xmlDocument); + } else { + alert("get - Error getting data from the server"); + } + } + } + xhr.open("GET", uri + '/' + id, true); + xhr.send(null); + } + + this.post = function (entry, responseFunction) { + var xhr = this.createXMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + if (xhr.status == 201) { + var strDocument = xhr.responseText; + var xmlDocument = xhr.responseXML; + if(!xmlDocument || xmlDocument.childNodes.length==0){ + xmlDocument = (new DOMParser()).parseFromString(strDocument, "text/xml"); + } + if (responseFunction != null) responseFunction(xmlDocument); + } else { + alert("post - Error getting data from the server"); + } + } + } + xhr.open("POST", uri, true); + xhr.setRequestHeader("Content-Type", "application/atom+xml"); + xhr.send(entry); + } + + this.put = function (id, entry, responseFunction) { + var xhr = this.createXMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + var strDocument = xhr.responseText; + var xmlDocument = xhr.responseXML; + if(!xmlDocument || xmlDocument.childNodes.length==0){ + xmlDocument = (new DOMParser()).parseFromString(strDocument, "text/xml"); + } + if (responseFunction != null) responseFunction(xmlDocument); + } else { + alert("put - Error getting data from the server"); + } + } + } + xhr.open("PUT", uri + '/' + id, true); + xhr.setRequestHeader("Content-Type", "application/atom+xml"); + xhr.send(entry); + } + + this.del = function (id, responseFunction) { + var xhr = this.createXMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + if (responseFunction != null) responseFunction(); + } else { + alert("delete - Error getting data from the server"); + } + } + } + xhr.open("DELETE", uri + '/' + id, true); + xhr.send(null); + } + this.createXMLHttpRequest = function () { + /* Mozilla XMLHttpRequest */ + try {return new XMLHttpRequest();} catch(e) {} + + /* Microsoft MSXML ActiveX */ + for (var i=0;i < this.msxmlNames.length; i++) { + try {return new ActiveXObject(this.msxmlNames[i]);} catch (e) {} + } + alert("XML http request not supported"); + return null; + } + if (typeof DOMParser == "undefined") { + DOMParser = function () {} + + DOMParser.prototype.parseFromString = function (str, contentType) { + if (typeof ActiveXObject != "undefined") { + var d = new ActiveXObject("MSXML.DomDocument"); + d.loadXML(str); + return d; + } else if (typeof XMLHttpRequest != "undefined") { + var req = new XMLHttpRequest; + req.open("GET", "data:" + (contentType || "application/xml") + + ";charset=utf-8," + encodeURIComponent(str), false); + if (req.overrideMimeType) { + req.overrideMimeType(contentType); + } + req.send(null); + return req.responseXML; + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/pom.xml new file mode 100644 index 0000000000..121bf0d137 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/pom.xml @@ -0,0 +1,82 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-atom + Apache Tuscany SCA Atom Feed Binding Extension + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.atom + ${pom.name} + org.apache.tuscany.sca.binding.atom* + org.apache.tuscany.sca.assembly.xml;version="1.4", * + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/AtomBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/AtomBinding.java new file mode 100644 index 0000000000..f81100087c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/AtomBinding.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.sca.binding.atom; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * Atom binding model. + * + * @version $Rev$ $Date$ + */ +public interface AtomBinding extends Binding { + + /** + * Returns the title of the Atom collection. + * @return + */ + String getTitle(); + + /** + * Sets the title of the Atom collection. + * @param title + */ + void setTitle(String title); + + /** + * Returns the description of the Atom collection. + * + * @return The description of the Atom collection + */ + String getDescription(); + + /** + * Sets the description of the Atom collection. + * + * @param description The description of the Atom collection + */ + void setDescription(String description); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/AtomBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/AtomBindingFactory.java new file mode 100644 index 0000000000..6e5623e1a2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/AtomBindingFactory.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.sca.binding.atom; + +/** + * Factory for the Atom binding + * + * @version $Rev$ $Date$ + */ +public interface AtomBindingFactory { + + /** + * Creates a new Atom binding. + * @return the new Atom binding + */ + AtomBinding createAtomBinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/impl/AtomBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/impl/AtomBindingFactoryImpl.java new file mode 100644 index 0000000000..ea06625d34 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/impl/AtomBindingFactoryImpl.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.sca.binding.atom.impl; + +import org.apache.tuscany.sca.binding.atom.AtomBinding; +import org.apache.tuscany.sca.binding.atom.AtomBindingFactory; + +/** + * Factory for the Atom binding model. + * + * @version $Rev$ $Date$ + */ +public class AtomBindingFactoryImpl implements AtomBindingFactory { + + public AtomBinding createAtomBinding() { + return new AtomBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/impl/AtomBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/impl/AtomBindingImpl.java new file mode 100644 index 0000000000..a7c3997b22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/java/org/apache/tuscany/sca/binding/atom/impl/AtomBindingImpl.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.sca.binding.atom.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.binding.atom.AtomBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Implementation of the Atom Feed binding model. + * + * @version $Rev$ $Date$ + */ +class AtomBindingImpl implements AtomBinding, PolicySetAttachPoint { + + private String name; + private String uri; + private String title; + private String description; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + /** + * {@inheritDoc} + */ + public String getDescription() { + return description; + } + + /** + * {@inheritDoc} + */ + public void setDescription(String description) { + this.description = description; + } + + public boolean isUnresolved() { + // The binding is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + //Policy related getters/setters + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.atom.AtomBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.atom.AtomBindingFactory new file mode 100644 index 0000000000..a8117db8f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.atom.AtomBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the model factory +org.apache.tuscany.sca.binding.atom.impl.AtomBindingFactoryImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..52e0e916f5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.atom,model=org.apache.tuscany.sca.binding.atom.AtomBinding,factory=org.apache.tuscany.sca.binding.atom.AtomBindingFactory \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java new file mode 100644 index 0000000000..63dffd5522 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.atom; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; + +/** + * @version $Rev$ $Date$ + */ +public class AtomBindingProcessorTestCase extends TestCase { + + private static final String COMPOSITE = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + @Override + protected void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); + } + + /** + * Test parsing valid composite definition. Valid composite populated with correct values expected. + * @throws Exception + */ + public void testLoadValidComposite() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE)); + + Composite composite = (Composite)staxProcessor.read(reader); + AtomBinding binding = (AtomBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals("Feed Title", binding.getTitle()); + assertEquals("http://localhost:8080/feed", binding.getURI()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/pom.xml new file mode 100644 index 0000000000..19b9e88e27 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/pom.xml @@ -0,0 +1,143 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-corba-runtime + Apache Tuscany SCA CORBA Binding Runtime + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-corba + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-corba + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-corba-jse + 1.6-SNAPSHOT + test + + + + cglib + cglib-nodep + 2.2 + compile + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.corba + ${pom.name} + org.apache.tuscany.sca.binding.corba* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingProviderFactory.java new file mode 100644 index 0000000000..99c9d7736e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingProviderFactory.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.sca.binding.corba.impl; + +import org.apache.tuscany.sca.binding.corba.CorbaBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.corba.CorbaHostExtensionPoint; +import org.apache.tuscany.sca.host.corba.ExtensibleCorbaHost; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class CorbaBindingProviderFactory implements BindingProviderFactory { + + private CorbaHostExtensionPoint chep; + private ExtensibleCorbaHost host; + + public CorbaBindingProviderFactory(ExtensionPointRegistry registry) { + chep = registry.getExtensionPoint(CorbaHostExtensionPoint.class); + host = new ExtensibleCorbaHost(chep); + } + /** + * @see org.apache.tuscany.sca.provider.BindingProviderFactory#createReferenceBindingProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + CorbaBinding binding) { + return new CorbaReferenceBindingProvider(binding, host, reference); + } + + /** + * @see org.apache.tuscany.sca.provider.BindingProviderFactory#createServiceBindingProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + CorbaBinding binding) { + return new CorbaServiceBindingProvider(binding, host, service); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + return CorbaBinding.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaInvoker.java new file mode 100644 index 0000000000..1577184b48 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaInvoker.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.impl; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.Map; + +import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; +import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaRequest; +import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaResponse; +import org.apache.tuscany.sca.binding.corba.impl.util.OperationMapper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.omg.CORBA.Object; +import org.osoa.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class CorbaInvoker implements Invoker { + + private Object remoteObject; + private Class referenceClass; + private Map operationsMap; + private Map operationMethodMapping; + + public CorbaInvoker(RuntimeComponentReference reference, Object remoteObject, Class referenceClass, Map operationsMap) { + this.remoteObject = remoteObject; + this.referenceClass = referenceClass; + this.operationsMap = operationsMap; + this.operationMethodMapping = OperationMapper.mapOperationToMethod(reference.getInterfaceContract().getInterface().getOperations(), referenceClass); + } + + /** + * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message) + */ + public Message invoke(Message msg) { + try { + DynaCorbaRequest request = new DynaCorbaRequest(remoteObject, msg.getOperation().getName()); + request.setReferenceClass(referenceClass); + request.setOperationsMap(operationsMap); + if (msg.getOperation().getOutputType() != null) { + Annotation[] notes = operationMethodMapping.get(msg.getOperation()).getAnnotations(); + request.setOutputType(msg.getOperation().getOutputType().getPhysical(), notes); + } + java.lang.Object[] args = msg.getBody(); + if (args != null) { + Annotation[][] notes = operationMethodMapping.get(msg.getOperation()).getParameterAnnotations(); + for (int i = 0; i < args.length; i++) { + request.addArgument(args[i], notes[i]); + } + } + if (msg.getOperation().getFaultTypes() != null) { + for (DataType type : msg.getOperation().getFaultTypes()) { + request.addExceptionType(type.getPhysical()); + } + } + DynaCorbaResponse response = request.invoke(); + msg.setBody(response.getContent()); + } catch (RequestConfigurationException e) { + throw new ServiceRuntimeException(e); + } catch (Exception e) { + msg.setFaultBody(e); + } + return msg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaReferenceBindingProvider.java new file mode 100644 index 0000000000..43bf984440 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaReferenceBindingProvider.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.impl; + +import java.lang.reflect.Method; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.corba.CorbaBinding; +import org.apache.tuscany.sca.binding.corba.impl.util.OperationMapper; +import org.apache.tuscany.sca.host.corba.CorbaHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.omg.CORBA.Object; + +/** + * @version $Rev$ $Date$ + */ +public class CorbaReferenceBindingProvider implements ReferenceBindingProvider { + + private static final Logger logger = Logger.getLogger(CorbaReferenceBindingProvider.class.getName()); + private CorbaBinding binding; + private CorbaHost host; + private RuntimeComponentReference reference; + private Object remoteObject; + private Class referenceClass; + private Map operationsMap = null; + + public CorbaReferenceBindingProvider(CorbaBinding binding, CorbaHost host, RuntimeComponentReference reference) { + this.binding = binding; + this.host = host; + this.reference = reference; + this.referenceClass = ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass(); + operationsMap = OperationMapper.mapMethodToOperationName(referenceClass); + } + + /** + * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#createInvoker(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Invoker createInvoker(Operation operation) { + try { + if (remoteObject == null) { + remoteObject = host.lookup(binding.getCorbaname()); + } + return new CorbaInvoker(reference, remoteObject, referenceClass, operationsMap); + } catch (Exception e) { + logger.log(Level.WARNING, "Exception during creating CORBA invoker", e); + } + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#getBindingInterfaceContract() + */ + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + /** + * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#start() + */ + public void start() { + } + + /** + * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#stop() + */ + public void stop() { + } + + /** + * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#supportsOneWayInvocation() + */ + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java new file mode 100644 index 0000000000..0465dbe7e9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.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.sca.binding.corba.impl; + +import org.apache.tuscany.sca.binding.corba.CorbaBinding; +import org.apache.tuscany.sca.binding.corba.impl.service.ComponentInvocationProxy; +import org.apache.tuscany.sca.binding.corba.impl.service.DynaCorbaServant; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationProxy; +import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils; +import org.apache.tuscany.sca.host.corba.CorbaHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.osoa.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class CorbaServiceBindingProvider implements ServiceBindingProvider { + + private CorbaBinding binding; + private CorbaHost host; + private RuntimeComponentService service; + private DynaCorbaServant servant; + + public CorbaServiceBindingProvider(CorbaBinding binding, CorbaHost host, RuntimeComponentService service) { + this.binding = binding; + this.host = host; + this.service = service; + } + + /** + * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#getBindingInterfaceContract() + */ + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + /** + * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#start() + */ + public void start() { + try { + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(binding), javaClass); + servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + servant.setIds(new String[] {binding.getId()}); + host.registerServant(binding.getCorbaname(), servant); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + + } + + /** + * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#stop() + */ + public void stop() { + try { + host.unregisterServant(binding.getCorbaname()); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + + } + + /** + * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#supportsOneWayInvocation() + */ + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/CorbaException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/CorbaException.java new file mode 100644 index 0000000000..6e54556a2c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/CorbaException.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.sca.binding.corba.impl.exceptions; + +/** + * @version $Rev$ $Date$ + * Represents CORBA SystemException + */ +public class CorbaException extends Exception { + + private static final long serialVersionUID = 1L; + + public CorbaException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/RequestConfigurationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/RequestConfigurationException.java new file mode 100644 index 0000000000..9a11d205f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/RequestConfigurationException.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.sca.binding.corba.impl.exceptions; + +/** + * @version $Rev$ $Date$ + */ +public class RequestConfigurationException extends Exception { + + private static final long serialVersionUID = 1L; + private String objectId; + + public RequestConfigurationException(String message, String objectId) { + super(message + ", object id was: " + objectId); + this.objectId = objectId; + } + + public RequestConfigurationException(String message) { + super(message); + } + + public String getType() { + return objectId; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java new file mode 100644 index 0000000000..3936bed9f6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java @@ -0,0 +1,253 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.impl.reference; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.binding.corba.impl.exceptions.CorbaException; +import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTree; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeCreator; +import org.apache.tuscany.sca.binding.corba.impl.types.util.TypeHelpersProxy; +import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils; +import org.apache.tuscany.sca.binding.corba.impl.util.MethodFinder; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.Object; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ Represents single CORBA request + */ +public class DynaCorbaRequest { + + private TypeTree returnTree; + private Map exceptions = new HashMap(); + private InputStream inputStream; + private ObjectImpl remoteObject; + private String operation; + private List arguments = new ArrayList(); + private List argumentsTypes = new ArrayList(); + private Class referenceClass; + private Map operationsMap; + + /** + * Creates request. + * + * @param ObjectremoteObject remote object reference + * @param operation operation to invoke + * @param scaBindingRules apply SCA default binding mapping rules + */ + public DynaCorbaRequest(Object remoteObject, String operation) { + this.remoteObject = (ObjectImpl)remoteObject; + this.operation = operation; + } + + /** + * Sets class which will be backed by this reference request + * @param referenceClass + */ + public void setReferenceClass(Class referenceClass) { + this.referenceClass = referenceClass; + } + + /** + * Sets method to operation names mapping + * @param operationsMap + */ + public void setOperationsMap(Map operationsMap) { + this.operationsMap = operationsMap; + } + + /** + * Adds operation argument - stores arguments and caches its TypeTree. Annotations will be set to null by default. + * + * @param argument + */ + public void addArgument(java.lang.Object argument) throws RequestConfigurationException { + addArgument(argument, null); + } + + /** + * Adds operation argument - stores arguments and caches its TypeTree + * + * @param argument + */ + public void addArgument(java.lang.Object argument, Annotation[] notes) throws RequestConfigurationException { + TypeTree tree = TypeTreeCreator.createTypeTree(argument.getClass(), notes); + argumentsTypes.add(tree); + arguments.add(argument); + } + + /** + * Passing stored arguments to CORBA communication output stream + * + * @param outputStream + * @throws RequestConfigurationException + */ + private void passArguments(OutputStream outputStream) throws RequestConfigurationException { + for (int i = 0; i < arguments.size(); i++) { + TypeTree tree = argumentsTypes.get(i); + TypeHelpersProxy.write(tree.getRootNode(), outputStream, arguments.get(i)); + } + } + + /** + * Sets return type for operation. Annotations will be set to null by default. + * + * @param forClass + */ + public void setOutputType(Class forClass) throws RequestConfigurationException { + setOutputType(forClass, null); + } + + /** + * Sets return type for operation + * + * @param forClass + */ + public void setOutputType(Class forClass, Annotation[] notes) throws RequestConfigurationException { + returnTree = TypeTreeCreator.createTypeTree(forClass, notes); + } + + /** + * Configures possible exceptions + * + * @param forClass + */ + public void addExceptionType(Class forClass) throws RequestConfigurationException { + TypeTree tree = TypeTreeCreator.createTypeTree(forClass, null); + String exceptionId = Utils.getTypeId(forClass); + exceptions.put(exceptionId, tree); + } + + /** + * Handles application excpeition. + * + * @param ae occured exception + * @throws Exception + */ + private void handleApplicationException(ApplicationException ae) throws Exception { + try { + if (exceptions.size() == 0) { + RequestConfigurationException exception = + new RequestConfigurationException( + "ApplicationException occured, but no exception type was specified.", + ae.getId()); + throw exception; + } + InputStream is = ae.getInputStream(); + String exceptionId = is.read_string(); + TypeTree tree = exceptions.get(exceptionId); + if (tree == null) { + RequestConfigurationException exception = + new RequestConfigurationException( + "ApplicationException occured, but no such exception was defined", + ae.getId()); + throw exception; + } else { + Exception ex = (Exception)TypeHelpersProxy.read(tree.getRootNode(), is); + throw ex; + } + } catch (Exception e) { + throw e; + } + } + + /** + * Handles exceptions generated by CORBA API + * + * @param se + */ + private void handleSystemException(SystemException se) throws Exception { + if (se instanceof BAD_OPERATION) { + throw new CorbaException("Bad operation name: " + operation, se); + } else if (se instanceof BAD_PARAM) { + throw new CorbaException("Bad parameter", se); + } else { + // TODO: handle more system exception types + throw new CorbaException(se.getMessage(), se); + } + } + + /** + * Gets operation name which is includes mapping rules + * @return + */ + private String getFinalOperationName() { + String result = operation; + if (referenceClass != null) { + Class[] argumentTypes = new Class[arguments.size()]; + for (int i = 0; i < arguments.size(); i++) { + argumentTypes[i] = arguments.get(i).getClass(); + } + Method method = MethodFinder.findMethod(referenceClass, operation, argumentTypes); + String newOperation = (String)operationsMap.get(method); + if (newOperation != null) { + result = newOperation; + } + } + return result; + } + + /** + * Invokes previously configured request + * + * @return + */ + public DynaCorbaResponse invoke() throws Exception { + DynaCorbaResponse response = new DynaCorbaResponse(); + String finalOperationName = getFinalOperationName(); + OutputStream outputStream = ((ObjectImpl)remoteObject)._request(finalOperationName, true); + passArguments(outputStream); + try { + inputStream = remoteObject._invoke(outputStream); + if (inputStream != null && returnTree != null) { + response.setContent(TypeHelpersProxy.read(returnTree.getRootNode(), inputStream)); + } + } catch (ApplicationException ae) { + handleApplicationException(ae); + } catch (SystemException se) { + handleSystemException(se); + } catch (Exception e) { + throw e; + } finally { + release(); + } + return response; + } + + /** + * Releases request resources + */ + private void release() { + remoteObject._releaseReply(inputStream); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaResponse.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaResponse.java new file mode 100644 index 0000000000..25463a7a8a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaResponse.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.sca.binding.corba.impl.reference; + +/** + * @version $Rev$ $Date$ + * Holder for content returned from DynaCorbaRequest + * + */ +public class DynaCorbaResponse { + + private Object content; + + public Object getContent() { + return content; + } + + public void setContent(Object content) { + this.content = content; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceInstanceCreator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceInstanceCreator.java new file mode 100644 index 0000000000..514d7055a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceInstanceCreator.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.sca.binding.corba.impl.reference; + +import java.lang.reflect.Method; + +import net.sf.cglib.proxy.Callback; +import net.sf.cglib.proxy.CallbackFilter; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.NoOp; + +import org.omg.CORBA.Object; + +/** + * @version $Rev$ $Date$ + */ +public class InterfaceInstanceCreator { + + private static final CallbackFilter FILTER = new CallbackFilter() { + public int accept(Method method) { + return 1; + } + }; + + /** + * Dynamically creates instance of user defined interface. Instance is + * enhanced by RemoteMethodInterceptor + * + * @param reference + * CORBA reference + * @param forClass + * user defined interface + * @return dynamic implementation instance + */ + public static java.lang.Object createInstance(Object reference, Class forClass) { + java.lang.Object result = null; + try { + Enhancer enhancer = new Enhancer(); + enhancer.setInterfaces(new Class[] {forClass}); + enhancer.setCallbackFilter(FILTER); + enhancer.setCallbackTypes(new Class[] {NoOp.class, MethodInterceptor.class}); + Class newClass = enhancer.createClass(); + Enhancer.registerStaticCallbacks(newClass, new Callback[] {NoOp.INSTANCE, + new InterfaceMethodInterceptor(reference, forClass)}); + result = newClass.newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceMethodInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceMethodInterceptor.java new file mode 100644 index 0000000000..7fba091b41 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceMethodInterceptor.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.sca.binding.corba.impl.reference; + +import java.lang.reflect.Method; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +import org.omg.CORBA.Object; + +/** + * @version $Rev$ $Date$ + * Interceptor for CORBA reference methods + */ +public class InterfaceMethodInterceptor implements MethodInterceptor { + + private Object reference; + private Class javaClass; + + public InterfaceMethodInterceptor(Object reference, Class javaClass) { + this.reference = reference; + this.javaClass = javaClass; + } + + /** + * Create and execute DynaCorbaRequest instance, basing on intercepted + * method arguments, return types, exceptions + */ + public java.lang.Object intercept(java.lang.Object object, + Method method, + java.lang.Object[] arguments, + MethodProxy arg3) throws Throwable { + DynaCorbaRequest request = new DynaCorbaRequest(reference, method.getName()); + request.setReferenceClass(javaClass); + for (int i = 0; i < arguments.length; i++) { + request.addArgument(arguments[i]); + } + request.setOutputType(method.getReturnType()); + Class[] exceptions = method.getExceptionTypes(); + for (int i = 0; i < exceptions.length; i++) { + request.addExceptionType(exceptions[i]); + } + DynaCorbaResponse response = request.invoke(); + return response.getContent(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/ComponentInvocationProxy.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/ComponentInvocationProxy.java new file mode 100644 index 0000000000..ff4732cfdb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/ComponentInvocationProxy.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.sca.binding.corba.impl.service; + +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTree; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeCreator; +import org.apache.tuscany.sca.binding.corba.impl.util.OperationMapper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * @version $Rev$ $Date$ + * Invocation proxy for SCA components + */ +public class ComponentInvocationProxy implements InvocationProxy { + + private RuntimeWire wire; + private Map methodOperationMapping; + private Map operationMethodMapping; + private Map operationsMap; + private Map operationsCache = new HashMap(); + + public ComponentInvocationProxy(RuntimeComponentService service, RuntimeWire wire, Class javaClass) + throws RequestConfigurationException { + this.wire = wire; + operationsMap = OperationMapper.mapOperationNameToMethod(javaClass); + operationMethodMapping = OperationMapper.mapOperationToMethod(service.getInterfaceContract().getInterface().getOperations(), javaClass); + methodOperationMapping = OperationMapper.mapMethodToOperation(service.getInterfaceContract().getInterface().getOperations(), javaClass); + cacheOperationTypes(service.getInterfaceContract().getInterface().getOperations()); + } + + /** + * Caches TypeTree for every operation in backed component + * + * @param operations + * @throws RequestConfigurationException + */ + private void cacheOperationTypes(List operations) throws RequestConfigurationException { + for (Operation operation : operations) { + try { + OperationTypes operationTypes = new OperationTypes(); + List inputInstances = new ArrayList(); + // cache output type tree + if (operation.getOutputType() != null && operation.getOutputType().getPhysical() != null + && !operation.getOutputType().getPhysical().equals(void.class)) { + Annotation[] notes = operationMethodMapping.get(operation).getAnnotations(); + TypeTree outputType = + TypeTreeCreator.createTypeTree(operation.getOutputType().getPhysical(), notes); + operationTypes.setOutputType(outputType); + } + // cache input types trees + if (operation.getInputType() != null) { + Method method = operationMethodMapping.get(operation); + Annotation[][] notes = method.getParameterAnnotations(); + int i = 0; + for (DataType>> type : operation.getInputType().getLogical()) { + Class forClass = type.getPhysical(); + TypeTree inputType = TypeTreeCreator.createTypeTree(forClass, notes[i]); + inputInstances.add(inputType); + i++; + } + + } + operationTypes.setInputType(inputInstances); + operationsCache.put(operation, operationTypes); + } catch (RequestConfigurationException e) { + throw e; + } + } + } + + private Operation getOperation4Name(String operationName) { + Method method = operationsMap.get(operationName); + return methodOperationMapping.get(method); + } + + public OperationTypes getOperationTypes(String operationName) { + return operationsCache.get(getOperation4Name(operationName)); + } + + public Object invoke(String operationName, List arguments) throws InvocationException { + Object result = null; + try { + result = wire.invoke(getOperation4Name(operationName), arguments.toArray()); + } catch (InvocationTargetException e) { + InvocationException exception = new InvocationException(e.getCause()); + throw exception; + } + return result; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java new file mode 100644 index 0000000000..2a032f5d25 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.impl.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTree; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeCreator; +import org.apache.tuscany.sca.binding.corba.impl.types.util.TypeHelpersProxy; +import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.InvokeHandler; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; + +/** + * @version $Rev$ $Date$ + * General servant which provides target component implementation via CORBA + */ +public class DynaCorbaServant extends ObjectImpl implements InvokeHandler { + + private static final Logger logger = Logger.getLogger(DynaCorbaServant.class.getName()); + + private String[] ids; + private InvocationProxy invocationProxy; + private String typeId; + + /** + * Creates servant object + * @param invocationProxy + * @param typeId + * @throws RequestConfigurationException + */ + public DynaCorbaServant(InvocationProxy invocationProxy, String typeId) throws RequestConfigurationException { + this.invocationProxy = invocationProxy; + this.typeId = typeId; + setDefaultIds(); + } + + /** + * Sets CORBA object ID + * @param ids + */ + public void setIds(String[] ids) { + for (int i = 0; i < ids.length; i++) { + if (ids[i] == null || ids[i].length() == 0) { + // if invalid id was passed then set to default + setDefaultIds(); + return; + } + } + this.ids = ids; + } + + public OutputStream _invoke(String operationName, InputStream in, ResponseHandler rh) { + OperationTypes types = invocationProxy.getOperationTypes(operationName); + if (types == null) { + // operation wasn't found + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + } else { + List inputInstances = new ArrayList(); + try { + // retrieving in arguments + for (TypeTree tree : types.getInputType()) { + Object o = TypeHelpersProxy.read(tree.getRootNode(), in); + inputInstances.add(o); + } + } catch (MARSHAL e) { + // parameter passed by user was not compatible with Java to + // Corba mapping + throw new org.omg.CORBA.BAD_PARAM(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + } + try { + // invocation and sending result + Object result = invocationProxy.invoke(operationName, inputInstances); + OutputStream out = rh.createReply(); + if (types.getOutputType() != null) { + TypeTree tree = types.getOutputType(); + TypeHelpersProxy.write(tree.getRootNode(), out, result); + } + return out; + } catch (InvocationException ie) { + // handling user exception + try { + OutputStream out = rh.createExceptionReply(); + Class exceptionClass = ie.getTargetException().getClass(); + TypeTree tree = TypeTreeCreator.createTypeTree(exceptionClass, null); + String exceptionId = Utils.getTypeId(exceptionClass); + out.write_string(exceptionId); + TypeHelpersProxy.write(tree.getRootNode(), out, ie.getTargetException()); + return out; + } catch (Exception e) { + logger.log(Level.WARNING, "Exception during handling invocation exception", e); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Unexpected exception during sending CORBA result to client", e); + } + } + return null; + } + + @Override + public String[] _ids() { + return ids; + } + + /** + * Sets servant ID to default, based on Java class name + */ + private void setDefaultIds() { + this.ids = new String[] {typeId}; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationException.java new file mode 100644 index 0000000000..a82e43e42e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationException.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.sca.binding.corba.impl.service; + +/** + * @version $Rev$ $Date$ + * Wrapper for exception thrown during target invocation + */ +public class InvocationException extends Exception { + + private static final long serialVersionUID = 1L; + private Throwable targetException; + + public InvocationException(Throwable targetException) { + this.targetException = targetException; + } + + public Throwable getTargetException() { + return targetException; + } + + public void setTargetException(Throwable target) { + this.targetException = target; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationProxy.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationProxy.java new file mode 100644 index 0000000000..5ad9068b8d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationProxy.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.sca.binding.corba.impl.service; + +import java.util.List; + +/** + * @version $Rev$ $Date$ + * Target proxy interface for service bindings + */ +public interface InvocationProxy { + + /** + * Gets operations types for target + * @param operationName + * @return + */ + public OperationTypes getOperationTypes(String operationName); + + /** + * Invokes target operation + * @param operationName + * @param arguments + * @return + * @throws InvocationException + */ + public Object invoke(String operationName, List arguments) throws InvocationException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java new file mode 100644 index 0000000000..d93036d6d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.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.sca.binding.corba.impl.service; + +import java.util.List; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTree; + +/** + * @version $Rev$ $Date$ + * Holder for Java type trees for one method + */ +public class OperationTypes { + + private TypeTree outputType; + private List inputType; + + public TypeTree getOutputType() { + return outputType; + } + + public void setOutputType(TypeTree outputType) { + this.outputType = outputType; + } + + public List getInputType() { + return inputType; + } + + public void setInputType(List inputType) { + this.inputType = inputType; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/AnnotationAttributes.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/AnnotationAttributes.java new file mode 100644 index 0000000000..d2b48d22c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/AnnotationAttributes.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.sca.binding.corba.impl.types; + +/** + * Holds information retrieved from objects annotations + */ +public class AnnotationAttributes { + + private boolean corbaArray; + private int[] corbaArrayLength; + + public boolean isCorbaArray() { + return corbaArray; + } + + public void setCorbaArray(boolean isCorbaArray) { + this.corbaArray = isCorbaArray; + } + + public int[] getCorbaArrayLength() { + return corbaArrayLength; + } + + public void setCorbaArrayLength(int[] corbaArrayLength) { + this.corbaArrayLength = corbaArrayLength; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/NodeType.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/NodeType.java new file mode 100644 index 0000000000..4080a836bc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/NodeType.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.sca.binding.corba.impl.types; + +/** + * @version $Rev$ $Date$ + * Types of CORBA objects. + */ +public enum NodeType { + primitive, struct, union, array, sequence, reference, idl_enum, exception +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTree.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTree.java new file mode 100644 index 0000000000..b8c4f88324 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTree.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.sca.binding.corba.impl.types; + +/** + * @version $Rev$ $Date$ + * Helper tree for Java object hierarchy. It's closer to CORBA types + * structure than plain Java hierarchy - it helps reading and writing + * complex structures. + */ +public class TypeTree { + + private TypeTreeNode rootNode; + + /** + * Returns root node. + * + * @return root of type tree + */ + public TypeTreeNode getRootNode() { + return rootNode; + } + + /** + * Sets root of the type tree. + * + * @param rootNode root node. + */ + public void setRootNode(TypeTreeNode rootNode) { + this.rootNode = rootNode; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java new file mode 100644 index 0000000000..e8441ed177 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java @@ -0,0 +1,497 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.impl.types; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; +import org.apache.tuscany.sca.binding.corba.meta.CorbaArray; +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElement; +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElementType; + +/** + * @version $Rev$ $Date$ + * Creator of types tree. + */ +public class TypeTreeCreator { + + /** + * Helps to determine if type is a primitive. + */ + private static List> primitives = new ArrayList>(); + + static { + primitives.add(boolean.class); + primitives.add(byte.class); + primitives.add(short.class); + primitives.add(int.class); + primitives.add(long.class); + primitives.add(double.class); + primitives.add(float.class); + primitives.add(char.class); + primitives.add(String.class); + primitives.add(Boolean.class); + primitives.add(Byte.class); + primitives.add(Short.class); + primitives.add(Integer.class); + primitives.add(Long.class); + primitives.add(Double.class); + primitives.add(Float.class); + primitives.add(Character.class); + } + + /** + * Creates class for given string argument. + * + * @param name name of type + * @return type + */ + private static Class createClassFromString(String name) { + Class result = null; + try { + if (name.length() == 1) { + // primitives + switch (name.charAt(0)) { + case 'Z': + result = boolean.class; + break; + case 'C': + result = char.class; + break; + case 'B': + result = byte.class; + break; + case 'S': + result = short.class; + break; + case 'I': + result = int.class; + break; + case 'J': + result = long.class; + break; + case 'F': + result = float.class; + break; + case 'D': + result = double.class; + break; + } + } else { + // class + name = name.substring(1, name.length() - 1); + result = Class.forName(name); + } + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + /** + * Reduces dimension of array. + * + * @param forClass array class + * @return reduced array + */ + private static Class reduceArrayDimension(Class forClass) { + String name = forClass.getName(); + try { + String reduced = name.substring(1, name.length()); + if (reduced.startsWith("[")) { + // reduced class is still an array + return Class.forName(reduced); + } else { + // reduced class may be primitive or class + return createClassFromString(reduced); + } + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return null; + } + + /** + * Return given array without first element + * + * @param array + * @return + */ + private static int[] removeFirstElement(int[] array) { + int[] result = new int[array.length - 1]; + System.arraycopy(array, 1, result, 0, result.length); + return result; + } + + /** + * Converts objects annotations to structure which will be used by this + * class + * + * @param notes + * @return + */ + private static AnnotationAttributes createAnnotationAttributes(Annotation[] notes) { + AnnotationAttributes attrs = new AnnotationAttributes(); + for (int i = 0; notes != null && i < notes.length; i++) { + if (notes[i].annotationType().equals(CorbaArray.class)) { + attrs.setCorbaArray(true); + attrs.setCorbaArrayLength(((CorbaArray)notes[i]).value()); + } + } + return attrs; + } + + /** + * Creates tree for given type. + * + * @param forClass + * @return type tree + */ + public static TypeTree createTypeTree(Class forClass, Annotation[] notes) throws RequestConfigurationException { + TypeTree tree = new TypeTree(); + TypeTreeNode rootNode = null; + AnnotationAttributes attrs = createAnnotationAttributes(notes); + rootNode = inspectClassHierarchy(forClass, attrs, tree); + tree.setRootNode(rootNode); + return tree; + + } + + /** + * Recurrent method which builds type tree. + * + * @param forClass + * @param tree + * @return + */ + private static TypeTreeNode inspectClassHierarchy(Class forClass, AnnotationAttributes attributes, TypeTree tree) + throws RequestConfigurationException { + + TypeTreeNode node = null; + node = createTypeNode(forClass, attributes); + + NodeType nodeType = node.getNodeType(); + TypeTreeNode[] children = null; + + if (nodeType.equals(NodeType.primitive)) { + // stop condition for recurrent method + } else if (nodeType.equals(NodeType.array)) { + Class reduced = reduceArrayDimension(node.getJavaClass()); + children = new TypeTreeNode[1]; + int[] newLengths = removeFirstElement(attributes.getCorbaArrayLength()); + attributes.setCorbaArrayLength(newLengths); + children[0] = inspectClassHierarchy(reduced, attributes, tree); + } else if (nodeType.equals(NodeType.sequence)) { + // reducing sequence dimension + Class reduced = reduceArrayDimension(node.getJavaClass()); + children = new TypeTreeNode[1]; + children[0] = inspectClassHierarchy(reduced, attributes, tree); + // System.arraycopy(src, srcPos, dest, destPos, length) + } else if (nodeType.equals(NodeType.struct) || nodeType.equals(NodeType.exception)) { + // inspect types for every structure member + Field[] fields = node.getJavaClass().getFields(); + children = new TypeTreeNode[fields.length]; + for (int i = 0; i < fields.length; i++) { + Class field = fields[i].getType(); + AnnotationAttributes fAttrs = createAnnotationAttributes(fields[i].getAnnotations()); + TypeTreeNode child = inspectClassHierarchy(field, fAttrs, tree); + child.setName(fields[i].getName()); + children[i] = child; + } + } else if (nodeType.equals(NodeType.idl_enum)) { + + } else if (nodeType.equals(NodeType.union)) { + // inspect types for every structure member + Field[] fields = node.getJavaClass().getDeclaredFields(); + children = new TypeTreeNode[fields.length]; + for (int i = 0; i < fields.length; i++) { + Class field = fields[i].getType(); + AnnotationAttributes fAttrs = createAnnotationAttributes(fields[i].getAnnotations()); + TypeTreeNode child = inspectClassHierarchy(field, fAttrs, tree); + child.setName(fields[i].getName()); + children[i] = child; + } + } else if (nodeType.equals(NodeType.reference)) { + // TODO: CORBA references + } + + node.setChildren(children); + return node; + } + + /** + * Creating and configuring TypeTreeNode for given class. + * + * @param forClass class + * @return node + * @throws RequestConfigurationException + */ + private static TypeTreeNode createTypeNode(Class forClass, AnnotationAttributes attributes) + throws RequestConfigurationException { + TypeTreeNode node = new TypeTreeNode(); + if (forClass.isArray() && !attributes.isCorbaArray()) { + node.setNodeType(NodeType.sequence); + node.setJavaClass(forClass); + } else if (forClass.isArray() && attributes.isCorbaArray()) { + node.setNodeType(NodeType.array); + node.setJavaClass(forClass); + try { + // set the actual array size for further use by ArrayTypeHelper + node.setAttributes(attributes.getCorbaArrayLength()[0]); + } catch (ArrayIndexOutOfBoundsException e) { + RequestConfigurationException exc = + new RequestConfigurationException("Annotated array size doesn't match declared arrays size"); + throw exc; + } + } else if (primitives.contains(forClass)) { + node.setNodeType(NodeType.primitive); + node.setJavaClass(forClass); + node.setChildren(null); + } else if (forClass.isInterface()) { + node.setNodeType(NodeType.reference); + node.setJavaClass(forClass); + node.setChildren(null); + } else if (isStructType(forClass)) { + node.setNodeType(NodeType.struct); + node.setJavaClass(forClass); + } else if (isEnumType(forClass)) { + node.setNodeType(NodeType.idl_enum); + node.setJavaClass(forClass); + } else if (isUserException(forClass)) { + node.setNodeType(NodeType.exception); + node.setJavaClass(forClass); + } else if (isUnionType(forClass)) { + node.setNodeType(NodeType.union); + node.setJavaClass(forClass); + node.setAttributes(getUnionAttributes(forClass)); + } else { + RequestConfigurationException e = + new RequestConfigurationException("User defined type which cannot be handled: " + forClass + .getCanonicalName()); + throw e; + } + return node; + } + + /** + * Tells whether given class is structure + * + * @param forClass + * @return + */ + private static boolean isStructType(Class forClass) { + int classMods = forClass.getModifiers(); + if (!Modifier.isFinal(classMods)) { + return false; + } + boolean areCtorsValid = false; + Class[] fieldsTypes = null; + Constructor[] ctors = forClass.getConstructors(); + /* + * Do we have 2 ctors and one of them is null ctor? + */ + if (ctors.length != 2) { + return false; + } + for (int i = 0; i < ctors.length; i++) { + Class[] params = ctors[i].getParameterTypes(); + if (params.length == 0) { + areCtorsValid = true; + } else { + fieldsTypes = params; + } + } + if (!areCtorsValid) { + return false; + } + /* + * Are constructor args declared as class fields? + */ + Field[] fields = forClass.getFields(); + Set> fieldsSet = new HashSet>(Arrays.asList(fieldsTypes)); + for (int i = 0; i < fields.length && !fieldsSet.isEmpty(); i++) { + int mods = fields[i].getModifiers(); + if (Modifier.isPublic(mods) && !Modifier.isStatic(mods) && !Modifier.isFinal(mods)) { + fieldsSet.remove(fields[i].getType()); + } + + } + return fieldsSet.isEmpty(); + } + + /** + * Tells whether given class is enum + * + * @param forClass + * @return + */ + private static boolean isEnumType(Class forClass) { + boolean isValueMethod = false; + boolean isFromIntMethod = false; + /* + * enum type should have value and from_int methods + */ + try { + Method valueMet = forClass.getMethod("value", new Class[] {}); + int modValueMet = valueMet.getModifiers(); + if (valueMet.getReturnType().equals(int.class) && Modifier.isPublic(modValueMet)) { + isValueMethod = true; + } + Method fromIntMet = forClass.getMethod("from_int", new Class[] {int.class}); + int modFromIntMet = fromIntMet.getModifiers(); + if ((fromIntMet.getReturnType().equals(forClass) && Modifier.isPublic(modFromIntMet) && Modifier + .isStatic(modFromIntMet))) { + isFromIntMethod = true; + } + } catch (NoSuchMethodException e) { + } + if (!isFromIntMethod || !isValueMethod) { + return false; + } + /* + * enum type should also contain minimum one pair of fields: EnumType + * field and int _field + */ + int enumCount = 0; + Field[] fields = forClass.getFields(); + for (int i = 0; i < fields.length; i++) { + if (fields[i].getType().equals(forClass)) { + int modifiers = fields[i].getModifiers(); + if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers) && Modifier.isFinal(modifiers)) { + try { + Field field = forClass.getField("_" + fields[i].getName()); + if (field.getType().equals(int.class)) { + enumCount++; + } + } catch (NoSuchFieldException e) { + } + + } + } + } + return enumCount > 0; + } + + /** + * Tells whether given class is CORBA user exception + * + * @param forClass + * @return + */ + private static boolean isUserException(Class forClass) { + do { + if (forClass.equals(Exception.class)) { + return true; + } else { + forClass = forClass.getSuperclass(); + } + } while (forClass != null && !forClass.equals(Object.class)); + return false; + } + + /** + * Tells whether given class is CORBA union. This method validates usage of + * unions annotations. + * + * @param forClass + * @return + * @throws RequestConfigurationException + */ + private static boolean isUnionType(Class forClass) throws RequestConfigurationException { + int classMods = forClass.getModifiers(); + if (!Modifier.isFinal(classMods)) { + return false; + } + boolean atLeastOneOption = false; + boolean discriminatorPresent = false; + for (int i = 0; i < forClass.getDeclaredFields().length; i++) { + CorbaUnionElement note = forClass.getDeclaredFields()[i].getAnnotation(CorbaUnionElement.class); + if (note != null) { + int fieldMod = forClass.getDeclaredFields()[i].getModifiers(); + if (Modifier.isPrivate(fieldMod) && !Modifier.isFinal(fieldMod) && !Modifier.isStatic(fieldMod)) { + if (note.type().equals(CorbaUnionElementType.discriminator)) { + if (discriminatorPresent) { + throw new RequestConfigurationException( + "More than one discriminators declared on: " + forClass); + } + discriminatorPresent = true; + } else { + atLeastOneOption = true; + } + } else { + throw new RequestConfigurationException( + "Annotated union field should be private, not final and no static on class: " + forClass); + } + } + } + if (atLeastOneOption && !discriminatorPresent) { + throw new RequestConfigurationException("No discriminator annotation found on: " + forClass); + } else if (!atLeastOneOption && discriminatorPresent) { + throw new RequestConfigurationException("No union option found on: " + forClass); + } else if (discriminatorPresent && atLeastOneOption) { + return true; + } else { + return false; + } + } + + /** + * Gets union attributes - discriminator field name, option fields etc. This + * method relies that previously scanned class is valid (method isUnionType) + * + * @param forClass + * @return + * @throws RequestConfigurationException + */ + private static UnionAttributes getUnionAttributes(Class forClass) throws RequestConfigurationException { + UnionAttributes attributes = new UnionAttributes(); + for (int i = 0; i < forClass.getDeclaredFields().length; i++) { + CorbaUnionElement note = forClass.getDeclaredFields()[i].getAnnotation(CorbaUnionElement.class); + if (note != null) { + if (note.type().equals(CorbaUnionElementType.discriminator)) { + attributes.setDiscriminatorName(forClass.getDeclaredFields()[i].getName()); + } else if (note.type().equals(CorbaUnionElementType.defaultOption)) { + attributes.setDefaultOptionName(forClass.getDeclaredFields()[i].getName()); + } else if (note.type().equals(CorbaUnionElementType.option)) { + if (attributes.getOptionsMapping().containsKey(note.optionNumber())) { + throw new RequestConfigurationException("In " + forClass + + ": field \"" + + forClass.getDeclaredFields()[i].getName() + + "\" uses already used option id: " + + note.optionNumber()); + } else { + attributes.getOptionsMapping().put(note.optionNumber(), + forClass.getDeclaredFields()[i].getName()); + } + } + } + } + return attributes; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeNode.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeNode.java new file mode 100644 index 0000000000..7d2183fb01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeNode.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.sca.binding.corba.impl.types; + +/** + * @version $Rev$ $Date$ + * Represents single tree node. + * + */ +public class TypeTreeNode { + + private NodeType nodeType; + private TypeTreeNode[] children; + private Class javaClass; + private String name; + private Object attributes; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public NodeType getNodeType() { + return nodeType; + } + + public void setNodeType(NodeType nodeType) { + this.nodeType = nodeType; + } + + public TypeTreeNode[] getChildren() { + return children; + } + + public void setChildren(TypeTreeNode[] children) { + this.children = children; + } + + public Class getJavaClass() { + return javaClass; + } + + public void setJavaClass(Class javaClass) { + this.javaClass = javaClass; + } + + public Object getAttributes() { + return attributes; + } + + public void setAttributes(Object attributes) { + this.attributes = attributes; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/UnionAttributes.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/UnionAttributes.java new file mode 100644 index 0000000000..df6358d118 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/UnionAttributes.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.sca.binding.corba.impl.types; + +import java.util.HashMap; +import java.util.Map; + +/** + * @version $Rev$ $Date$ + * Stores attributes for previously scanned CORBA union type + */ +public class UnionAttributes { + + public String discriminatorName; + public String defaultOptionName; + public Map optionsMapping = new HashMap(); + + public String getDiscriminatorName() { + return discriminatorName; + } + + public void setDiscriminatorName(String discriminatorName) { + this.discriminatorName = discriminatorName; + } + + public String getDefaultOptionName() { + return defaultOptionName; + } + + public void setDefaultOptionName(String defaultOptionName) { + this.defaultOptionName = defaultOptionName; + } + + public Map getOptionsMapping() { + return optionsMapping; + } + + public void setOptionsMapping(Map optionsMapping) { + this.optionsMapping = optionsMapping; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ArrayTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ArrayTypeHelper.java new file mode 100644 index 0000000000..6dbeda3b7c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ArrayTypeHelper.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.sca.binding.corba.impl.types.util; + +import java.lang.reflect.Array; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class ArrayTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + Object array = null; + try { + int size = (Integer)node.getAttributes(); + array = Array.newInstance(node.getChildren()[0].getJavaClass(), size); + for (int i = 0; i < size; i++) { + Array.set(array, i, TypeHelpersProxy.read(node.getChildren()[0], is)); + } + } catch (Exception e) { + e.printStackTrace(); + } + return array; + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + for (int i = 0; i < (Integer)node.getAttributes(); i++) { + TypeHelpersProxy.write(node.getChildren()[0], os, Array.get(data, i)); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/BooleanTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/BooleanTypeHelper.java new file mode 100644 index 0000000000..87d3e93d22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/BooleanTypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class BooleanTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + return is.read_boolean(); + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + os.write_boolean((Boolean)data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ByteTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ByteTypeHelper.java new file mode 100644 index 0000000000..eb02f1cbcb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ByteTypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class ByteTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + return is.read_octet(); + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + os.write_octet((Byte)data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/CharTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/CharTypeHelper.java new file mode 100644 index 0000000000..71f8fbfc47 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/CharTypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class CharTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + return is.read_char(); + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + os.write_char((Character)data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/DoubleTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/DoubleTypeHelper.java new file mode 100644 index 0000000000..c5019c5c0b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/DoubleTypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class DoubleTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + return is.read_double(); + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + os.write_double((Double)data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/EnumTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/EnumTypeHelper.java new file mode 100644 index 0000000000..6220802ce6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/EnumTypeHelper.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.sca.binding.corba.impl.types.util; + +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class EnumTypeHelper implements TypeHelper { + + private static final Logger logger = Logger.getLogger(EnumTypeHelper.class.getName()); + + public Object read(TypeTreeNode node, InputStream is) { + int value = is.read_long(); + Object result = null; + try { + Method method = node.getJavaClass().getMethod("from_int", new Class[] {int.class}); + result = method.invoke(null, new Object[] {value}); + } catch (Exception e) { + logger.log(Level.WARNING, "Exception during reading CORBA enum data", e); + e.printStackTrace(); + } + return result; + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + int value = 0; + try { + Method method = data.getClass().getMethod("value", new Class[] {}); + value = (Integer)method.invoke(data, new Object[] {}); + } catch (Exception e) { + logger.log(Level.WARNING, "Exception during writing CORBA enum data", e); + } + os.write_long(value); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/FloatTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/FloatTypeHelper.java new file mode 100644 index 0000000000..3214f8b30d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/FloatTypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class FloatTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + return is.read_float(); + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + os.write_float((Float)data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/IntTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/IntTypeHelper.java new file mode 100644 index 0000000000..b11175064c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/IntTypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class IntTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + return is.read_long(); + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + os.write_long((Integer)data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/LongTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/LongTypeHelper.java new file mode 100644 index 0000000000..7b4300a1da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/LongTypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class LongTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + return is.read_longlong(); + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + os.write_longlong((Long)data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ReferenceTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ReferenceTypeHelper.java new file mode 100644 index 0000000000..4e0c2893d2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ReferenceTypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.reference.InterfaceInstanceCreator; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.Object; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class ReferenceTypeHelper implements TypeHelper { + + public java.lang.Object read(TypeTreeNode node, InputStream is) { + Object reference = is.read_Object(); + return (java.lang.Object)InterfaceInstanceCreator.createInstance(reference, node.getJavaClass()); + } + + public void write(TypeTreeNode node, OutputStream os, java.lang.Object data) { + os.write_Object((Object)data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/SequenceTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/SequenceTypeHelper.java new file mode 100644 index 0000000000..5862838cd5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/SequenceTypeHelper.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.sca.binding.corba.impl.types.util; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class SequenceTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + Object sequence = null; + try { + int size = is.read_long(); + sequence = Array.newInstance(node.getChildren()[0].getJavaClass(), size); + for (int i = 0; i < size; i++) { + Array.set(sequence, i, TypeHelpersProxy.read(node.getChildren()[0], is)); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sequence; + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + int sum = 0; + // determine length of array + List array = new ArrayList(); + while (true) { + try { + array.add(Array.get(data, sum)); + sum++; + } catch (ArrayIndexOutOfBoundsException e) { + break; + } + } + os.write_long(sum); + Iterator iter = array.iterator(); + while (iter.hasNext()) { + Object elem = iter.next(); + TypeHelpersProxy.write(node.getChildren()[0], os, elem); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ShortTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ShortTypeHelper.java new file mode 100644 index 0000000000..9130db65e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ShortTypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class ShortTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + return is.read_short(); + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + os.write_short((Short)data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StringTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StringTypeHelper.java new file mode 100644 index 0000000000..4d782efcc5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StringTypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class StringTypeHelper implements TypeHelper { + + public Object read(TypeTreeNode node, InputStream is) { + return is.read_string(); + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + os.write_string((String)data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StructTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StructTypeHelper.java new file mode 100644 index 0000000000..365d62fb73 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StructTypeHelper.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.sca.binding.corba.impl.types.util; + +import java.lang.reflect.Field; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class StructTypeHelper implements TypeHelper { + + private static final Logger logger = Logger.getLogger(StructTypeHelper.class.getName()); + + public Object read(TypeTreeNode node, InputStream is) { + TypeTreeNode[] children = node.getChildren(); + Object result = null; + if (children != null) { + try { + result = node.getJavaClass().newInstance(); + for (int i = 0; i < children.length; i++) { + Object childResult = TypeHelpersProxy.read(children[i], is); + Field childField = result.getClass().getField(children[i].getName()); + childField.set(result, childResult); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Exception during reading CORBA struct data", e); + } + } + return result; + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + TypeTreeNode[] children = node.getChildren(); + if (children != null) { + try { + for (int i = 0; i < children.length; i++) { + Field childField = node.getJavaClass().getField(children[i].getName()); + TypeHelpersProxy.write(children[i], os, childField.get(data)); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Exception during writing CORBA struct data", e); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelper.java new file mode 100644 index 0000000000..c9d0dd263f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelper.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.sca.binding.corba.impl.types.util; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public interface TypeHelper { + + /** + * Reads CORBA object + * @param node + * @param is + * @return + */ + Object read(TypeTreeNode node, InputStream is); + + /** + * Writes CORBA object + * @param node + * @param os + * @param data + */ + void write(TypeTreeNode node, OutputStream os, Object data); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelpersProxy.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelpersProxy.java new file mode 100644 index 0000000000..72e4ccc6fb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelpersProxy.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.sca.binding.corba.impl.types.util; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.binding.corba.impl.types.NodeType; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + * Proxies getType(), write(), read() methods to appropriate TypeHelper implementation. + */ +public class TypeHelpersProxy { + + /** + * Maps primitive types to its TypeHelper implementations + */ + private static Map, TypeHelper> primitiveTypes = null; + + /** + * Maps other types to its TypeHelper implementations + */ + private static Map complexTypes = null; + + static { + // initiate type helpers + primitiveTypes = new HashMap, TypeHelper>(); + complexTypes = new HashMap(); + + primitiveTypes.put(boolean.class, new BooleanTypeHelper()); + primitiveTypes.put(char.class, new CharTypeHelper()); + primitiveTypes.put(byte.class, new ByteTypeHelper()); + primitiveTypes.put(short.class, new ShortTypeHelper()); + primitiveTypes.put(int.class, new IntTypeHelper()); + primitiveTypes.put(long.class, new LongTypeHelper()); + primitiveTypes.put(float.class, new FloatTypeHelper()); + primitiveTypes.put(double.class, new DoubleTypeHelper()); + primitiveTypes.put(String.class, new StringTypeHelper()); + primitiveTypes.put(Boolean.class, primitiveTypes.get(boolean.class)); + primitiveTypes.put(Character.class, primitiveTypes.get(char.class)); + primitiveTypes.put(Byte.class, primitiveTypes.get(byte.class)); + primitiveTypes.put(Short.class, primitiveTypes.get(short.class)); + primitiveTypes.put(Integer.class, primitiveTypes.get(int.class)); + primitiveTypes.put(Long.class, primitiveTypes.get(long.class)); + primitiveTypes.put(Float.class, primitiveTypes.get(float.class)); + primitiveTypes.put(Double.class, primitiveTypes.get(double.class)); + primitiveTypes.put(String.class, primitiveTypes.get(String.class)); + complexTypes.put(NodeType.array, new ArrayTypeHelper()); + complexTypes.put(NodeType.struct, new StructTypeHelper()); + complexTypes.put(NodeType.reference, new ReferenceTypeHelper()); + complexTypes.put(NodeType.sequence, new SequenceTypeHelper()); + complexTypes.put(NodeType.idl_enum, new EnumTypeHelper()); + complexTypes.put(NodeType.exception, new StructTypeHelper()); + complexTypes.put(NodeType.union, new UnionTypeHelper()); + } + + /** + * Gets type helper basing on given type + * + * @param node + * @return + */ + private static TypeHelper getTypeHelper(TypeTreeNode node) { + TypeHelper typeHelper = null; + NodeType type = node.getNodeType(); + if (type.equals(NodeType.primitive)) { + typeHelper = primitiveTypes.get(node.getJavaClass()); + } else { + typeHelper = complexTypes.get(type); + } + return typeHelper; + } + + /** + * Proxies read method invocation to appropriate TypeHelper implementation. + * + * @param node + * @param is + * @return + */ + public static final Object read(TypeTreeNode node, InputStream is) { + TypeHelper helper = getTypeHelper(node); + return helper.read(node, is); + } + + /** + * Proxies write method invocation to appropriate TypeHelper implementation. + * + * @param node + * @param os + * @param data + */ + public static final void write(TypeTreeNode node, OutputStream os, Object data) { + TypeHelper helper = getTypeHelper(node); + helper.write(node, os, data); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/UnionTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/UnionTypeHelper.java new file mode 100644 index 0000000000..66c928acec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/UnionTypeHelper.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.sca.binding.corba.impl.types.util; + +import java.lang.reflect.Field; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode; +import org.apache.tuscany.sca.binding.corba.impl.types.UnionAttributes; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + */ +public class UnionTypeHelper implements TypeHelper { + + private static final Logger logger = Logger.getLogger(UnionTypeHelper.class.getName()); + + public Object read(TypeTreeNode node, InputStream is) { + Object result = null; + try { + int discriminator = is.read_long(); + UnionAttributes attrs = (UnionAttributes)node.getAttributes(); + String childName = attrs.getOptionsMapping().get(discriminator); + if (childName == null) { + // get default if option numbers field not found + childName = attrs.getDefaultOptionName(); + } + result = node.getJavaClass().newInstance(); + Field discField = result.getClass().getDeclaredField(attrs.getDiscriminatorName()); + discField.setAccessible(true); + discField.set(result, discriminator); + for (int i = 0; i < node.getChildren().length; i++) { + if (node.getChildren()[i].getName().equals(childName)) { + Object unionValue = TypeHelpersProxy.read(node.getChildren()[i], is); + Field childField = result.getClass().getDeclaredField(childName); + childField.setAccessible(true); + childField.set(result, unionValue); + break; + } + } + } catch (Exception e) { + logger.log(Level.WARNING, "Exception during reading CORBA union data", e); + } + return result; + } + + public void write(TypeTreeNode node, OutputStream os, Object data) { + try { + UnionAttributes attrs = (UnionAttributes)node.getAttributes(); + Field discriminatorField = data.getClass().getDeclaredField(attrs.getDiscriminatorName()); + discriminatorField.setAccessible(true); + int discriminator = discriminatorField.getInt(data); + os.write_long(discriminator); + String childName = attrs.getOptionsMapping().get(discriminator); + if (childName == null) { + // get default if option numbers field not found + childName = attrs.getDefaultOptionName(); + } + for (int i = 0; i < node.getChildren().length; i++) { + if (node.getChildren()[i].getName().equals(childName)) { + Field childField = data.getClass().getDeclaredField(childName); + childField.setAccessible(true); + TypeHelpersProxy.write(node.getChildren()[i], os, childField.get(data)); + break; + } + } + } catch (Exception e) { + logger.log(Level.WARNING, "Exception during writing CORBA union data", e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/Utils.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/Utils.java new file mode 100644 index 0000000000..68f71b7169 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/Utils.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.sca.binding.corba.impl.types.util; + +/** + * @version $Rev$ $Date$ + * Class for type utilities + */ +public class Utils { + + /** + * Creates CORBA id for Java class + * @param forClass + * @return + */ + public static String getTypeId(Class forClass) { + String result = forClass.getName().replace('.', '/'); + result = result.replaceAll("Package", ""); + result = "IDL:" + result + ":1.0"; + return result; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/util/MethodFinder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/util/MethodFinder.java new file mode 100644 index 0000000000..912d355641 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/util/MethodFinder.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.impl.util; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +/** + * @version $Rev$ $Date$ + * Utility for finding method in given class. + */ +public class MethodFinder { + + private static Map, Class> boxingMapping; + + static { + boxingMapping = new HashMap, Class>(); + boxingMapping.put(boolean.class, Boolean.class); + boxingMapping.put(byte.class, Byte.class); + boxingMapping.put(short.class, Short.class); + boxingMapping.put(char.class, Character.class); + boxingMapping.put(int.class, Integer.class); + boxingMapping.put(long.class, Long.class); + boxingMapping.put(float.class, Float.class); + boxingMapping.put(double.class, Double.class); + } + + /** + * Converts primitive class to its object equivalent. + * + * @param parameter class to convert + * @return object equivalent for primitive type. If parameter wasn't + * primitive then returns parameter. + */ + private static Class normalizePrimitive(Class parameter) { + Class result = boxingMapping.get(parameter); + if (result != null) { + return result; + } else { + // not a primitive - no need to normalize + return parameter; + } + } + + /** + * Finds appropriate method. This method ignores difference between + * primitive types and theirs object equivalents. Ie. if we want to find + * method "get" in java.util.List with only one parameter, which type is + * Integer then we'll obtain method get(int). + * + * @param forClass class which possibly contains desired method + * @param methodName desired methods name + * @param parameterTypes desired methods parameter types + * @return desired method, if no method was found then null will be returned + */ + public static Method findMethod(Class forClass, String methodName, Class[] parameterTypes) { + Method[] methods = forClass.getMethods(); + for (int i = 0; i < methods.length; i++) { + if (methods[i].getName().equals(methodName)) { + Class[] methodPTypes = methods[i].getParameterTypes(); + if (methodPTypes.length == parameterTypes.length) { + boolean parameterMatch = true; + for (int j = 0; j < methodPTypes.length; j++) { + Class nMethodPType = normalizePrimitive(methodPTypes[j]); + Class nParameterType = normalizePrimitive(parameterTypes[j]); + if (!nMethodPType.equals(nParameterType)) { + parameterMatch = false; + break; + } + } + if (parameterMatch) { + return methods[i]; + } + } + } + } + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/util/OperationMapper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/util/OperationMapper.java new file mode 100644 index 0000000000..a9fabcb82a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/util/OperationMapper.java @@ -0,0 +1,578 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.corba.impl.util; + +import java.lang.reflect.Method; +import java.rmi.RemoteException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.omg.CORBA.portable.IDLEntity; + +/** + * @version $Rev$ $Date$ + */ +public final class OperationMapper { + + private static Set> getAllInterfaces(Class intfClass) { + Set> allInterfaces = new LinkedHashSet>(); + + LinkedList> stack = new LinkedList>(); + stack.addFirst(intfClass); + + while (!stack.isEmpty()) { + Class intf = stack.removeFirst(); + allInterfaces.add(intf); + for (Class i : intf.getInterfaces()) { + stack.add(0, i); + } + } + + return allInterfaces; + } + + /** + * Maps Java methods to operation names + * @param intfClass + * @return + */ + @SuppressWarnings("unchecked") + public static Map mapMethodToOperationName(Class intfClass) { + return iiopMap(intfClass, false); + } + + /** + * Maps operation names to Java methods + * @param intfClass + * @return + */ + @SuppressWarnings("unchecked") + public static Map mapOperationNameToMethod(Class intfClass) { + return iiopMap(intfClass, true); + } + + @SuppressWarnings("unchecked") + private static Map iiopMap(Class intfClass, boolean operationToMethod) { + Method[] methods = getAllMethods(intfClass); + + // find every valid getter + Map getterByMethod = new HashMap(methods.length); + Map getterByName = new HashMap(methods.length); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + String methodName = method.getName(); + + // no arguments allowed + if (method.getParameterTypes().length != 0) { + continue; + } + + // must start with get or is + String verb; + if (methodName.startsWith("get") && methodName.length() > 3 && method.getReturnType() != void.class) { + verb = "get"; + } else if (methodName.startsWith("is") && methodName.length() > 2 && method.getReturnType() == boolean.class) { + verb = "is"; + } else { + continue; + } + + // must only throw Remote or Runtime Exceptions + boolean exceptionsValid = true; + Class[] exceptionTypes = method.getExceptionTypes(); + for (int j = 0; j < exceptionTypes.length; j++) { + Class exceptionType = exceptionTypes[j]; + if (!RemoteException.class.isAssignableFrom(exceptionType) && + !RuntimeException.class.isAssignableFrom(exceptionType) && + !Error.class.isAssignableFrom(exceptionType)) { + exceptionsValid = false; + break; + } + } + if (!exceptionsValid) { + continue; + } + + String propertyName; + if (methodName.length() > verb.length() + 1 && Character.isUpperCase(methodName.charAt(verb.length() + 1))) { + propertyName = methodName.substring(verb.length()); + } else { + propertyName = Character.toLowerCase(methodName.charAt(verb.length())) + methodName.substring(verb.length() + 1); + } + getterByMethod.put(method, propertyName); + getterByName.put(propertyName, method); + } + + Map setterByMethod = new HashMap(methods.length); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + String methodName = method.getName(); + + // must have exactally one arg + if (method.getParameterTypes().length != 1) { + continue; + } + + // must return non void + if (method.getReturnType() != void.class) { + continue; + } + + // must start with set + if (!methodName.startsWith("set") || methodName.length() <= 3) { + continue; + } + + // must only throw Remote or Runtime Exceptions + boolean exceptionsValid = true; + Class[] exceptionTypes = method.getExceptionTypes(); + for (int j = 0; j < exceptionTypes.length; j++) { + Class exceptionType = exceptionTypes[j]; + if (!RemoteException.class.isAssignableFrom(exceptionType) && + !RuntimeException.class.isAssignableFrom(exceptionType) && + !Error.class.isAssignableFrom(exceptionType)) { + exceptionsValid = false; + break; + } + } + if (!exceptionsValid) { + continue; + } + + String propertyName; + if (methodName.length() > 4 && Character.isUpperCase(methodName.charAt(4))) { + propertyName = methodName.substring(3); + } else { + propertyName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); + } + + // must have a matching getter + Method getter = (Method) getterByName.get(propertyName); + if (getter == null) { + continue; + } + + // setter property must match getter return value + if (!method.getParameterTypes()[0].equals(getter.getReturnType())) { + continue; + } + setterByMethod.put(method, propertyName); + } + + // index the methods by name... used to determine which methods are overloaded + HashMap> overloadedMethods = new HashMap>(methods.length); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + if (getterByMethod.containsKey(method) || setterByMethod.containsKey(method)) { + continue; + } + String methodName = method.getName(); + List methodList = overloadedMethods.get(methodName); + if (methodList == null) { + methodList = new LinkedList(); + overloadedMethods.put(methodName, methodList); + } + methodList.add(method); + } + + // index the methods by lower case name... used to determine which methods differ only by case + Map> caseCollisionMethods = new HashMap>(methods.length); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + if (getterByMethod.containsKey(method) || setterByMethod.containsKey(method)) { + continue; + } + String lowerCaseMethodName = method.getName().toLowerCase(); + Set methodSet = caseCollisionMethods.get(lowerCaseMethodName); + if (methodSet == null) { + methodSet = new HashSet(); + caseCollisionMethods.put(lowerCaseMethodName, methodSet); + } + methodSet.add(method.getName()); + } + + String className = getClassName(intfClass); + Map iiopMap = new HashMap(methods.length); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + + String iiopName = (String) getterByMethod.get(method); + if (iiopName != null) { + // if we have a leading underscore prepend with J + if (iiopName.charAt(0) == '_') { + iiopName = "J_get_" + iiopName.substring(1); + } else { + iiopName = "_get_" + iiopName; + } + } else { + iiopName = (String) setterByMethod.get(method); + if (iiopName != null) { + // if we have a leading underscore prepend with J + if (iiopName.charAt(0) == '_') { + iiopName = "J_set_" + iiopName.substring(1); + } else { + iiopName = "_set_" + iiopName; + } + } else { + iiopName = method.getName(); + + // if we have a leading underscore prepend with J + if (iiopName.charAt(0) == '_') { + iiopName = "J" + iiopName; + } + } + } + + // if this name only differs by case add the case index to the end + Set caseCollisions = caseCollisionMethods.get(method.getName().toLowerCase()); + if (caseCollisions != null && caseCollisions.size() > 1) { + iiopName += upperCaseIndexString(iiopName); + } + + // if this is an overloaded method append the parameter string + List overloads = overloadedMethods.get(method.getName()); + if (overloads != null && overloads.size() > 1) { + iiopName += buildOverloadParameterString(method.getParameterTypes()); + } + + // if we have a leading underscore prepend with J + iiopName = replace(iiopName, '$', "U0024"); + + // if we have matched a keyword prepend with an underscore + if (keywords.contains(iiopName.toLowerCase())) { + iiopName = "_" + iiopName; + } + + // if the name is the same as the class name, append an underscore + if (iiopName.equalsIgnoreCase(className)) { + iiopName += "_"; + } + + if (operationToMethod) { + iiopMap.put(iiopName, method); + } else { + iiopMap.put(method, iiopName); + } + } + + return iiopMap; + } + + private static Method[] getAllMethods(Class intfClass) { + List methods = new LinkedList(); + for (Iterator> iterator = getAllInterfaces(intfClass).iterator(); iterator.hasNext();) { + Class intf = iterator.next(); + methods.addAll(Arrays.asList(intf.getDeclaredMethods())); + } + + return (Method[]) methods.toArray(new Method[methods.size()]); + } + + /** + * Return the a string containing an underscore '_' index of each uppercase + * character in the IIOP name. This is used for distinction of names that + * only differ by case, since CORBA does not support case sensitive names. + */ + private static String upperCaseIndexString(String iiopName) { + StringBuffer stringBuffer = new StringBuffer(); + for (int i = 0; i < iiopName.length(); i++) { + char c = iiopName.charAt(i); + if (Character.isUpperCase(c)) { + stringBuffer.append('_').append(i); + } + } + return stringBuffer.toString(); + } + + /** + * Replaces any occurances of the specified "oldChar" with the new string. + * This is used to replace occurances if '$' in CORBA names since '$' is a + * special character + */ + private static String replace(String source, char oldChar, String newString) { + StringBuffer stringBuffer = new StringBuffer(source.length()); + for (int i = 0; i < source.length(); i++) { + char c = source.charAt(i); + if (c == oldChar) { + stringBuffer.append(newString); + } else { + stringBuffer.append(c); + } + } + return stringBuffer.toString(); + } + + /** + * Return the a string containing a double underscore '__' list of parameter + * types encoded using the Java to IDL rules. This is used for distinction + * of methods that only differ by parameter lists. + */ + private static String buildOverloadParameterString(Class[] parameterTypes) { + String name = ""; + if (parameterTypes.length == 0) { + name += "__"; + } else { + for (int i = 0; i < parameterTypes.length; i++) { + Class parameterType = parameterTypes[i]; + name += buildOverloadParameterString(parameterType); + } + } + return name.replace('.', '_'); + } + + /** + * Returns a single parameter type encoded using the Java to IDL rules. + */ + private static String buildOverloadParameterString(Class parameterType) { + String name = "_"; + + int arrayDimensions = 0; + while (parameterType.isArray()) { + arrayDimensions++; + parameterType = parameterType.getComponentType(); + } + + // arrays start with org_omg_boxedRMI_ + if (arrayDimensions > 0) { + name += "_org_omg_boxedRMI"; + } + + // IDLEntity types must be prefixed with org_omg_boxedIDL_ + if (IDLEntity.class.isAssignableFrom(parameterType)) { + name += "_org_omg_boxedIDL"; + } + + // add package... some types have special mappings in corba + String packageName = (String)specialTypePackages.get(parameterType.getName()); + if (packageName == null) { + packageName = getPackageName(parameterType.getName()); + } + if (packageName.length() > 0) { + name += "_" + packageName; + } + + // arrays now contain a dimension indicator + if (arrayDimensions > 0) { + name += "_" + "seq" + arrayDimensions; + } + + // add the class name + String className = (String)specialTypeNames.get(parameterType.getName()); + if (className == null) { + className = buildClassName(parameterType); + } + name += "_" + className; + + return name; + } + + /** + * Returns a string containing an encoded class name. + */ + private static String buildClassName(Class type) { + if (type.isArray()) { + throw new IllegalArgumentException("type is an array: " + type); + } + + // get the classname + String typeName = type.getName(); + int endIndex = typeName.lastIndexOf('.'); + if (endIndex < 0) { + return typeName; + } + StringBuffer className = new StringBuffer(typeName.substring(endIndex + 1)); + + // for innerclasses replace the $ separator with two underscores + // we can't just blindly replace all $ characters since class names can + // contain the $ character + if (type.getDeclaringClass() != null) { + String declaringClassName = getClassName(type.getDeclaringClass()); + assert className.toString().startsWith(declaringClassName + "$"); + className.replace(declaringClassName.length(), declaringClassName.length() + 1, "__"); + } + + // if we have a leading underscore prepend with J + if (className.charAt(0) == '_') { + className.insert(0, "J"); + } + return className.toString(); + } + + private static String getClassName(Class type) { + if (type.isArray()) { + throw new IllegalArgumentException("type is an array: " + type); + } + + // get the classname + String typeName = type.getName(); + int endIndex = typeName.lastIndexOf('.'); + if (endIndex < 0) { + return typeName; + } + return typeName.substring(endIndex + 1); + } + + private static String getPackageName(String interfaceName) { + int endIndex = interfaceName.lastIndexOf('.'); + if (endIndex < 0) { + return ""; + } + return interfaceName.substring(0, endIndex); + } + + private static final Map specialTypeNames; + private static final Map specialTypePackages; + private static final Set keywords; + + static { + specialTypeNames = new HashMap(); + specialTypeNames.put("boolean", "boolean"); + specialTypeNames.put("char", "wchar"); + specialTypeNames.put("byte", "octet"); + specialTypeNames.put("short", "short"); + specialTypeNames.put("int", "long"); + specialTypeNames.put("long", "long_long"); + specialTypeNames.put("float", "float"); + specialTypeNames.put("double", "double"); + specialTypeNames.put("java.lang.Class", "ClassDesc"); + specialTypeNames.put("java.lang.String", "WStringValue"); + specialTypeNames.put("org.omg.CORBA.Object", "Object"); + + specialTypePackages = new HashMap(); + specialTypePackages.put("boolean", ""); + specialTypePackages.put("char", ""); + specialTypePackages.put("byte", ""); + specialTypePackages.put("short", ""); + specialTypePackages.put("int", ""); + specialTypePackages.put("long", ""); + specialTypePackages.put("float", ""); + specialTypePackages.put("double", ""); + specialTypePackages.put("java.lang.Class", "javax.rmi.CORBA"); + specialTypePackages.put("java.lang.String", "CORBA"); + specialTypePackages.put("org.omg.CORBA.Object", ""); + + keywords = new HashSet(); + keywords.add("abstract"); + keywords.add("any"); + keywords.add("attribute"); + keywords.add("boolean"); + keywords.add("case"); + keywords.add("char"); + keywords.add("const"); + keywords.add("context"); + keywords.add("custom"); + keywords.add("default"); + keywords.add("double"); + keywords.add("enum"); + keywords.add("exception"); + keywords.add("factory"); + keywords.add("false"); + keywords.add("fixed"); + keywords.add("float"); + keywords.add("in"); + keywords.add("inout"); + keywords.add("interface"); + keywords.add("long"); + keywords.add("module"); + keywords.add("native"); + keywords.add("object"); + keywords.add("octet"); + keywords.add("oneway"); + keywords.add("out"); + keywords.add("private"); + keywords.add("public"); + keywords.add("raises"); + keywords.add("readonly"); + keywords.add("sequence"); + keywords.add("short"); + keywords.add("string"); + keywords.add("struct"); + keywords.add("supports"); + keywords.add("switch"); + keywords.add("true"); + keywords.add("truncatable"); + keywords.add("typedef"); + keywords.add("union"); + keywords.add("unsigned"); + keywords.add("valuebase"); + keywords.add("valuetype"); + keywords.add("void"); + keywords.add("wchar"); + keywords.add("wstring"); + } + + @SuppressWarnings("unchecked") + public static Map mapOperationToMethod(List operations, Class forClass) { + return (Map)createMethod2OperationMapping(operations, forClass, false); + } + + @SuppressWarnings("unchecked") + public static Map mapMethodToOperation(List operations, Class forClass) { + return (Map)createMethod2OperationMapping(operations, forClass, true); + } + + /** + * Maps Java methods to Tuscany operations + */ + @SuppressWarnings("unchecked") + private static Map createMethod2OperationMapping(List operations, Class forClass, boolean method2operation) { + // for every operation find all methods with the same name, then + // compare operations and methods parameters + Map mapping = new HashMap(); + for (Operation operation : operations) { + List inputTypes = operation.getInputType().getLogical(); + Method[] methods = forClass.getMethods(); + for (int i = 0; i < methods.length; i++) { + if (methods[i].getName().equals(operation.getName()) && inputTypes.size() == methods[i] + .getParameterTypes().length) { + Class[] parameterTypes = methods[i].getParameterTypes(); + int j = 0; + boolean parameterMatch = true; + for (DataType dataType : inputTypes) { + if (!dataType.getPhysical().equals(parameterTypes[j])) { + parameterMatch = false; + break; + } + j++; + } + if (parameterMatch) { + // match found + if (method2operation) { + mapping.put(methods[i], operation); + } else { + mapping.put(operation, methods[i]); + } + break; + } + } + } + } + return mapping; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaArray.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaArray.java new file mode 100644 index 0000000000..24661323be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaArray.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.sca.binding.corba.meta; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * @version $Rev$ $Date$ + * Declares CORBA arrays lengths + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface CorbaArray { + + int[] value(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaUnionElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaUnionElement.java new file mode 100644 index 0000000000..101bda1ba2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaUnionElement.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.sca.binding.corba.meta; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * @version $Rev$ $Date$ Declares CORBA union object + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface CorbaUnionElement { + + // number of option in switch clause + int optionNumber() default -1; + + // type of element + CorbaUnionElementType type(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaUnionElementType.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaUnionElementType.java new file mode 100644 index 0000000000..3a46fc2b5f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/meta/CorbaUnionElementType.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.sca.binding.corba.meta; + +/** + * @version $Rev$ $Date$ + * Types for union element + */ +public enum CorbaUnionElementType { + discriminator, defaultOption, option; +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..394e7bbd05 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.corba.impl.CorbaBindingProviderFactory;model=org.apache.tuscany.sca.binding.corba.CorbaBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java new file mode 100644 index 0000000000..7fc58c9b96 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java @@ -0,0 +1,564 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing; + +import static junit.framework.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.Array; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.binding.corba.impl.exceptions.CorbaException; +import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; +import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaRequest; +import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaResponse; +import org.apache.tuscany.sca.binding.corba.impl.service.ComponentInvocationProxy; +import org.apache.tuscany.sca.binding.corba.impl.service.DynaCorbaServant; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationProxy; +import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils; +import org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests; +import org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTestsHelper; +import org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct; +import org.apache.tuscany.sca.binding.corba.testing.enums.Color; +import org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager; +import org.apache.tuscany.sca.binding.corba.testing.enums.EnumManagerHelper; +import org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc; +import org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcHelper; +import org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero; +import org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported; +import org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter; +import org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetterHelper; +import org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter; +import org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetterHelper; +import org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct; +import org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct; +import org.apache.tuscany.sca.binding.corba.testing.generated.TestObject; +import org.apache.tuscany.sca.binding.corba.testing.generated.TestObjectHelper; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.NonCorbaException; +import org.apache.tuscany.sca.binding.corba.testing.servants.ArraysSetterServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.ArraysUnionsTuscanyServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.CalcServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.EnumManagerServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.InvalidTestObjectServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.InvalidTypesServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.NonCorbaServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.PrimitivesSetterServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.TestObjectServant; +import org.apache.tuscany.sca.binding.corba.testing.service.mocks.TestRuntimeComponentService; +import org.apache.tuscany.sca.host.corba.naming.TransientNameServer; +import org.apache.tuscany.sca.host.corba.naming.TransientNameService; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; +import org.omg.CosNaming.NameComponent; +import org.omg.CosNaming.NamingContext; +import org.omg.CosNaming.NamingContextHelper; + +/** + * @version $Rev$ $Date$ + * Tests API for dynamic CORBA servants + */ +public class CorbaServantTestCase { + + private static ORB orb; + private static TransientNameServer server; + + @BeforeClass + public static void start() { + try { + server = + new TransientNameServer(TestConstants.TEST2_HOST, TestConstants.TEST2_PORT, + TransientNameService.DEFAULT_SERVICE_NAME); + Thread t = server.start(); + if (t == null) { + Assert.fail("The naming server cannot be started"); + } + orb = server.getORB(); + } catch (Throwable e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + } + + @AfterClass + public static void stop() { + server.stop(); + } + + /** + * Binds servant implementation to name + */ + private void bindServant(DynaCorbaServant servant, String name) { + try { + Object nameService = orb.resolve_initial_references("NameService"); + NamingContext namingContext = NamingContextHelper.narrow(nameService); + + NameComponent nc = new NameComponent(name, ""); + NameComponent[] path = new NameComponent[] {nc}; + namingContext.rebind(path, servant); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Returns object reference which is binded to given name + * + * @param name + * @return + */ + private org.omg.CORBA.Object bindReference(String name) { + try { + org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); + NamingContext ncRef = NamingContextHelper.narrow(objRef); + NameComponent nc = new NameComponent(name, ""); + NameComponent path[] = {nc}; + return ncRef.resolve(path); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * Tests primitives (arguments, return types) + */ + @Test + public void test_primitivesSetter() { + try { + PrimitivesSetter primitivesSetter = new PrimitivesSetterServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(primitivesSetter); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + String[] ids = + new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter:1.0"}; + servant.setIds(ids); + bindServant(servant, "PrimitivesSetter"); + PrimitivesSetter psClient = PrimitivesSetterHelper.narrow(bindReference("PrimitivesSetter")); + assertTrue(psClient.setBoolean(true) == true); + assertTrue(psClient.setChar('A') == 'A'); + assertTrue(psClient.setString("SomeTest").equals("SomeTest")); + assertTrue(psClient.setDouble(2d) == 2d); + assertTrue(psClient.setFloat(3f) == 3f); + assertTrue(psClient.setLong(1) == 1); + assertTrue(psClient.setLongLong(0L) == 0L); + assertTrue(psClient.setOctet((byte)8) == (byte)8); + assertTrue(psClient.setShort((short)6) == (short)6); + assertTrue(psClient.setUnsignedLong(9) == 9); + assertTrue(psClient.setUnsignedLongLong(11L) == 11L); + assertTrue(psClient.setUnsignedShort((short)15) == (short)15); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + /** + * Tests if array values are equal + */ + private boolean areArraysEqual(java.lang.Object arr1, java.lang.Object arr2, int arrLen) { + try { + for (int i = 0; i < arrLen; i++) { + if (!Array.get(arr1, i).equals(Array.get(arr2, i))) { + return false; + } + } + return true; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + /** + * Tests arrays (arguments, return types) + */ + @Test + public void test_arraysSetter() { + try { + ArraysSetter arraysSetter = new ArraysSetterServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(arraysSetter); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter:1.0"}; + servant.setIds(ids); + java.lang.Object result = null; + bindServant(servant, "ArraysSetter"); + ArraysSetter asClient = ArraysSetterHelper.narrow(bindReference("ArraysSetter")); + + boolean[] bArr = new boolean[] {true, false}; + result = (java.lang.Object)asClient.setBoolean(bArr); + assertTrue(areArraysEqual(bArr, result, bArr.length)); + + byte[] byArr = new byte[] {1, 2}; + result = (java.lang.Object)asClient.setOctet(byArr); + assertTrue(areArraysEqual(byArr, result, byArr.length)); + + short[] shArr = new short[] {1, 2}; + result = (java.lang.Object)asClient.setShort(shArr); + assertTrue(areArraysEqual(shArr, result, shArr.length)); + + int[] iArr = new int[] {1, 2}; + result = (java.lang.Object)asClient.setLong(iArr); + assertTrue(areArraysEqual(iArr, result, iArr.length)); + + long[] lArr = new long[] {1, 2}; + result = (java.lang.Object)asClient.setLongLong(lArr); + assertTrue(areArraysEqual(lArr, result, lArr.length)); + + String[] strArr = new String[] {"Some", "Test"}; + result = (java.lang.Object)asClient.setString(strArr); + assertTrue(areArraysEqual(strArr, result, strArr.length)); + + char[] chArr = new char[] {'A', 'B'}; + result = (java.lang.Object)asClient.setChar(chArr); + assertTrue(areArraysEqual(chArr, result, chArr.length)); + + float[] flArr = new float[] {1, 2}; + result = (java.lang.Object)asClient.setFloat(flArr); + assertTrue(areArraysEqual(flArr, result, flArr.length)); + + double[] dbArr = new double[] {1, 2}; + result = (java.lang.Object)asClient.setDouble(dbArr); + assertTrue(areArraysEqual(dbArr, result, dbArr.length)); + + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + /** + * Tests structures (arguments, return types) + */ + @Test + public void test_TestObject_setStruct() { + try { + TestObject to = new TestObjectServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(to); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; + servant.setIds(ids); + bindServant(servant, "TestObject"); + TestObject testObject = TestObjectHelper.narrow(bindReference("TestObject")); + SomeStruct ss = new SomeStruct(); + SimpleStruct inner = new SimpleStruct(); + inner.field1 = TestConstants.STR_1; + inner.field2 = TestConstants.INT_1; + ss.innerStruct = inner; + ss.str = TestConstants.STR_2; + ss.str_list = TestConstants.STR_ARR_1; + ss.threeDimSeq = TestConstants.INT_ARRAY_3_DIM; + ss.twoDimSeq = TestConstants.INT_ARRAY_2_DIM; + SomeStruct result = testObject.setStruct(ss); + assertTrue(TestConstants.are2DimArraysEqual(result.twoDimSeq, TestConstants.INT_ARRAY_2_DIM)); + assertTrue(TestConstants.are3DimArraysEqual(result.threeDimSeq, TestConstants.INT_ARRAY_3_DIM)); + assertTrue(result.str.equals(ss.str)); + assertTrue(result.innerStruct.field1.equals(ss.innerStruct.field1)); + assertTrue(result.innerStruct.field2 == ss.innerStruct.field2); + assertTrue(areArraysEqual(result.str_list, ss.str_list, ss.str_list.length)); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + /** + * Tests handling BAD_OPERATION system exception + */ + @Test + public void test_systemException_BAD_OPERATION() { + try { + TestObjectServant tos = new TestObjectServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(tos); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; + servant.setIds(ids); + bindServant(servant, "TestObject"); + DynaCorbaRequest request = + new DynaCorbaRequest(bindReference("TestObject"), "methodThatSurelyDoesNotExist"); + request.invoke(); + fail(); + } catch (Exception e) { + if (e instanceof CorbaException) { + assertTrue(true); + } else { + e.printStackTrace(); + } + } + + try { + InvalidTestObjectServant tos = new InvalidTestObjectServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(tos); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; + servant.setIds(ids); + bindServant(servant, "InvalidTestObject"); + TestObject to = TestObjectHelper.narrow(bindReference("InvalidTestObject")); + SomeStruct str = new SomeStruct(); + str.innerStruct = new SimpleStruct(); + str.innerStruct.field1 = "Whatever"; + str.str = "Whatever"; + str.str_list = new String[] {}; + str.threeDimSeq = new int[][][] {}; + str.twoDimSeq = new int[][] {}; + to.setStruct(str); + } catch (Exception e) { + if (e instanceof BAD_OPERATION) { + assertTrue(true); + } else { + e.printStackTrace(); + } + } + } + + /** + * Tests handling user exceptions + */ + @Test + public void test_userExceptions() { + try { + CalcServant calc = new CalcServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(calc); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + String[] ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc:1.0"}; + servant.setIds(ids); + bindServant(servant, "Calc"); + Calc calcClient = CalcHelper.narrow(bindReference("Calc")); + calcClient.div(1, 0); + fail(); + } catch (Exception e) { + if (e instanceof DivByZero) { + assertTrue(true); + } else { + e.printStackTrace(); + fail(); + } + } + + try { + CalcServant calc = new CalcServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(calc); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + String[] ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc:1.0"}; + servant.setIds(ids); + bindServant(servant, "Calc"); + Calc calcClient = CalcHelper.narrow(bindReference("Calc")); + calcClient.divForSmallArgs(255, 255); + fail(); + } catch (Exception e) { + if (e instanceof NotSupported) { + assertTrue(true); + } else { + e.printStackTrace(); + fail(); + } + } + } + + /** + * Tests enums (arguments, return types) + */ + @Test + public void test_enums() { + try { + EnumManagerServant ems = new EnumManagerServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(ems); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + String[] ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager:1.0"}; + servant.setIds(ids); + bindServant(servant, "Enum"); + EnumManager em = EnumManagerHelper.narrow(bindReference("Enum")); + Color color = Color.red; + assertTrue(em.getColor(color).value() == color.value()); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void test_nonCorbaServants() { + try { + NonCorbaServant ncs = new NonCorbaServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(ncs); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + bindServant(servant, "NonCorbaServant"); + // it's non corba servant so we don't have stubs to test them + DynaCorbaRequest request = new DynaCorbaRequest(bindReference("NonCorbaServant"), "setString"); + request.addArgument(TestConstants.STR_1); + request.setOutputType(String.class); + DynaCorbaResponse response = request.invoke(); + assertTrue(response.getContent().equals(TestConstants.STR_1)); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + try { + NonCorbaServant ncs = new NonCorbaServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(ncs); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + bindServant(servant, "NonCorbaServant"); + // it's non corba servant so we don't have stubs to test them + DynaCorbaRequest request = new DynaCorbaRequest(bindReference("NonCorbaServant"), "throwException"); + request.addExceptionType(NonCorbaException.class); + request.invoke(); + fail(); + } catch (Exception e) { + if (e instanceof NonCorbaException) { + assertTrue(true); + } else { + e.printStackTrace(); + fail(); + } + } + } + + /** + * Tests handling BAD_PARAM system exception + */ + @Test + public void test_systemException_BAD_PARAM() { + try { + CalcServant calc = new CalcServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(calc); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; + servant.setIds(ids); + bindServant(servant, "Calc"); + DynaCorbaRequest request = new DynaCorbaRequest(bindReference("Calc"), "div"); + request.addArgument(2d); + request.setOutputType(double.class); + request.invoke(); + fail(); + } catch (Exception e) { + if (e instanceof CorbaException) { + assertTrue(true); + } else { + e.printStackTrace(); + fail(); + } + } + } + + /** + * Tests handling BAD_PARAM system exception + */ + @Test + public void test_invalidServantConfiguraion() { + try { + InvalidTypesServant its = new InvalidTypesServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(its); + //expecting exception... + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + fail(); + } catch (Exception e) { + if (e instanceof RequestConfigurationException) { + assertTrue(true); + } else { + e.printStackTrace(); + fail(); + } + } + } + + /** + * Tests serving CORBA arrays by Tuscany CORBA servants + */ + @Test + public void test_arraysPassing() { + try { + ArraysUnionsTuscanyServant arraysUnions = new ArraysUnionsTuscanyServant(); + TestRuntimeComponentService service = new TestRuntimeComponentService(arraysUnions); + Class javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); + String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests:1.0"}; + servant.setIds(ids); + bindServant(servant, "ArraysUnions"); + Object reference = bindReference("ArraysUnions"); + ArraysUnionsTests objRef = ArraysUnionsTestsHelper.narrow(reference); + String[][] stringArray = {{"Hello", "World"}, {"Hi", "Again"}}; + String[][] result = objRef.passStringArray(stringArray); + for (int i = 0; i < stringArray.length; i++) { + for (int j = 0; j < stringArray[i].length; j++) { + assertEquals(stringArray[i][j], result[i][j]); + } + } + TestStruct struct = new TestStruct(); + String[] field1 = {"Hello", "World"}; + int[][] field2 = { {4, 2, 2, 5}, {6, 12, 5, 8}}; + float[][][] field3 = { { {2, 6}, {2, 7}, {9, 3}, {4, 6}}, { {3, 7}, {6, 6}, {3, 5}, {6, 2}}}; + struct.oneDimArray = field1; + struct.twoDimArray = field2; + struct.threeDimArray = field3; + + TestStruct structResult = objRef.passTestStruct(struct); + for (int i = 0; i < struct.oneDimArray.length; i++) { + assertEquals(struct.oneDimArray[i], structResult.oneDimArray[i]); + } + for (int i = 0; i < struct.twoDimArray.length; i++) { + for (int j = 0; j < struct.twoDimArray[i].length; j++) { + assertEquals(struct.twoDimArray[i][j], structResult.twoDimArray[i][j]); + } + } + for (int i = 0; i < struct.threeDimArray.length; i++) { + for (int j = 0; j < struct.threeDimArray[i].length; j++) { + for (int k = 0; k < struct.threeDimArray[i][j].length; k++) { + assertEquals(struct.threeDimArray[i][j][k], structResult.threeDimArray[i][j][k], 0.0); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java new file mode 100644 index 0000000000..6521255d3b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java @@ -0,0 +1,841 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Array; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.binding.corba.impl.exceptions.CorbaException; +import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; +import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaRequest; +import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaResponse; +import org.apache.tuscany.sca.binding.corba.testing.enums.Color; +import org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero; +import org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported; +import org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct; +import org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.ArraysTestStruct; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.DummyObject; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InnerUnion; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidCorbaArray; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidEnum1; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidEnum2; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidEnum3; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidStruct1; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidStruct2; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidStruct3; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidUnion1; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidUnion2; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidUnion3; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidUnion4; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidUnion5; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.RichUnion; +import org.apache.tuscany.sca.binding.corba.testing.servants.ArraysSetterServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.ArraysUnionsServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.ArraysUnionsTuscanyServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.CalcServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.EnumManagerServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.ObjectManagerServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.PrimitivesSetterServant; +import org.apache.tuscany.sca.binding.corba.testing.servants.TestObjectServant; +import org.apache.tuscany.sca.host.corba.naming.TransientNameServer; +import org.apache.tuscany.sca.host.corba.naming.TransientNameService; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; +import org.omg.CosNaming.NameComponent; +import org.omg.CosNaming.NamingContext; +import org.omg.CosNaming.NamingContextExt; +import org.omg.CosNaming.NamingContextExtHelper; +import org.omg.CosNaming.NamingContextHelper; + +/** + * @version $Rev$ $Date$ + * Tests API for dynamic CORBA requests. Tests handling various Java + * types. + */ +public class CorbaTypesTestCase { + private static TransientNameServer server; + private static ORB orb; + + private static Object refPrimitivesSetter; + private static Object refArraysSetter; + private static Object refTestObject; + private static Object refCalcObject; + private static Object refObjectManager; + private static Object refEnumManager; + private static Object refArraysUnions; + + /** + * Spawns tnameserv process (must be in PATH). Initializes test servants and + * stores it's references so tests can use it. + */ + @BeforeClass + public static void setUp() { + try { + try { + server = + new TransientNameServer(TestConstants.TEST1_HOST, TestConstants.TEST1_PORT, + TransientNameService.DEFAULT_SERVICE_NAME); + Thread t = server.start(); + if (t == null) { + Assert.fail("The naming server cannot be started"); + } + orb = server.getORB(); + } catch (Throwable e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + + Object nameService = orb.resolve_initial_references("NameService"); + NamingContext namingContext = NamingContextHelper.narrow(nameService); + + PrimitivesSetterServant singleSetter = new PrimitivesSetterServant(); + ArraysSetterServant arraysSetter = new ArraysSetterServant(); + TestObjectServant complexObject = new TestObjectServant(); + CalcServant calcObject = new CalcServant(); + ObjectManagerServant objectManager = new ObjectManagerServant(); + EnumManagerServant enumManager = new EnumManagerServant(); + ArraysUnionsServant arraysUnions = new ArraysUnionsServant(); + + orb.connect(singleSetter); + orb.connect(arraysSetter); + + NameComponent nc; + NameComponent[] path; + + nc = new NameComponent("PrimitivesSetter", ""); + path = new NameComponent[] {nc}; + namingContext.rebind(path, singleSetter); + + nc = new NameComponent("ArraysSetter", ""); + path = new NameComponent[] {nc}; + namingContext.rebind(path, arraysSetter); + + nc = new NameComponent("TestObject", ""); + path = new NameComponent[] {nc}; + namingContext.rebind(path, complexObject); + + nc = new NameComponent("CalcObject", ""); + path = new NameComponent[] {nc}; + namingContext.rebind(path, calcObject); + + nc = new NameComponent("ObjectManager", ""); + path = new NameComponent[] {nc}; + namingContext.rebind(path, objectManager); + + nc = new NameComponent("EnumManager", ""); + path = new NameComponent[] {nc}; + namingContext.rebind(path, enumManager); + + nc = new NameComponent("ArraysUnions", ""); + path = new NameComponent[] {nc}; + namingContext.rebind(path, arraysUnions); + + NamingContextExt nce = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService")); + + refArraysSetter = nce.resolve(nce.to_name("ArraysSetter")); + refPrimitivesSetter = nce.resolve(nce.to_name("PrimitivesSetter")); + refTestObject = nce.resolve(nce.to_name("TestObject")); + refCalcObject = nce.resolve(nce.to_name("CalcObject")); + refObjectManager = nce.resolve(nce.to_name("ObjectManager")); + refEnumManager = nce.resolve(nce.to_name("EnumManager")); + refArraysUnions = nce.resolve(nce.to_name("ArraysUnions")); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void stop() { + server.stop(); + } + + /** + * Tests remote operation, basing on given reference, operation name, + * arguments, expected return type and content + * + * @param ref remote object + * @param operationName operation to invoke + * @param clazz expected return type + * @param arguments array of operation arguments + * @param equalTo expected return content + */ + private void dynaTestInvoker(Object ref, + String operationName, + Class clazz, + java.lang.Object[] arguments, + java.lang.Object equalTo) { + + try { + DynaCorbaRequest request = new DynaCorbaRequest(ref, operationName); + request.setOutputType(clazz); + for (int i = 0; arguments != null && i < arguments.length; i++) { + request.addArgument(arguments[i]); + } + + DynaCorbaResponse response = request.invoke(); + java.lang.Object content = (java.lang.Object)response.getContent(); + assertTrue(content.getClass().equals(clazz)); + if (equalTo != null && equalTo.getClass().isArray()) { + for (int i = 0; i < Array.getLength(equalTo); i++) { + assertTrue(Array.get(content, i).equals(Array.get(equalTo, i))); + } + } else { + assertTrue(content.equals(equalTo)); + } + } catch (Exception e) { + e.printStackTrace(); + fail("Error while invoking " + operationName); + } + } + + /** + * Tests passing (and getting as result) varied primitives + */ + @Test + public void test_setPrimitives() { + + dynaTestInvoker(refPrimitivesSetter, "setBoolean", Boolean.class, new Boolean[] {true}, true); + dynaTestInvoker(refPrimitivesSetter, "setOctet", Byte.class, new Byte[] {1}, (byte)1); + dynaTestInvoker(refPrimitivesSetter, "setChar", Character.class, new Character[] {'A'}, 'A'); + dynaTestInvoker(refPrimitivesSetter, "setShort", Short.class, new Short[] {1}, (short)1); + dynaTestInvoker(refPrimitivesSetter, "setLong", Integer.class, new Integer[] {1}, (int)1); + dynaTestInvoker(refPrimitivesSetter, "setLongLong", Long.class, new Long[] {(long)1}, (long)1); + dynaTestInvoker(refPrimitivesSetter, "setFloat", Float.class, new Float[] {(float)1}, (float)1); + dynaTestInvoker(refPrimitivesSetter, "setDouble", Double.class, new Double[] {(double)1}, (double)1); + dynaTestInvoker(refPrimitivesSetter, "setString", String.class, new String[] {"1"}, "1"); + + } + + /** + * Tests passing (and getting as result) varied types sequences + */ + @Test + public void test_setArrays() { + + dynaTestInvoker(refArraysSetter, + "setBoolean", + Boolean[].class, + new Boolean[][] {new Boolean[] {false, true}}, + new Boolean[] {false, true}); + + dynaTestInvoker(refArraysSetter, + "setChar", + Character[].class, + new Character[][] {new Character[] {'A', 'B'}}, + new Character[] {'A', 'B'}); + + dynaTestInvoker(refArraysSetter, "setOctet", Byte[].class, new Byte[][] {new Byte[] {1, 2}}, new Byte[] {1, 2}); + + dynaTestInvoker(refArraysSetter, "setShort", Short[].class, new Short[][] {new Short[] {1, 2}}, new Short[] {1, + 2}); + + dynaTestInvoker(refArraysSetter, + "setLong", + Integer[].class, + new Integer[][] {new Integer[] {1, 2}}, + new Integer[] {1, 2}); + + dynaTestInvoker(refArraysSetter, + "setLongLong", + Long[].class, + new Long[][] {new Long[] {new Long(1), new Long(2)}}, + new Long[] {new Long(1), new Long(2)}); + + dynaTestInvoker(refArraysSetter, + "setFloat", + Float[].class, + new Float[][] {new Float[] {new Float(1.0), new Float(2.0)}}, + new Float[] {new Float(1.0), new Float(2.0)}); + + dynaTestInvoker(refArraysSetter, + "setDouble", + Double[].class, + new Double[][] {new Double[] {new Double(1.0), new Double(2.0)}}, + new Double[] {new Double(1.0), new Double(2.0)}); + + dynaTestInvoker(refArraysSetter, + "setString", + String[].class, + new String[][] {new String[] {"A", "B"}}, + new String[] {"A", "B"}); + + } + + /** + * Tests passing (and getting as result) complex structure + */ + @Test + public void test_TestObject_setStruct() { + DynaCorbaRequest request = new DynaCorbaRequest(refTestObject, "setStruct"); + + SomeStruct struct = new SomeStruct(); + SimpleStruct inner = new SimpleStruct(); + inner.field1 = TestConstants.STR_1; + inner.field2 = TestConstants.INT_1; + struct.innerStruct = inner; + struct.str_list = TestConstants.STR_ARR_2; + struct.twoDimSeq = TestConstants.INT_ARRAY_2_DIM; + struct.threeDimSeq = TestConstants.INT_ARRAY_3_DIM; + struct.str = TestConstants.STR_1; + + try { + request.addArgument(struct); + request.setOutputType(SomeStruct.class); + DynaCorbaResponse response = request.invoke(); + SomeStruct result = (SomeStruct)response.getContent(); + assertTrue(TestConstants.are2DimArraysEqual(result.twoDimSeq, TestConstants.INT_ARRAY_2_DIM)); + assertTrue(TestConstants.are3DimArraysEqual(result.threeDimSeq, TestConstants.INT_ARRAY_3_DIM)); + assertEquals(TestConstants.STR_1, result.str); + assertEquals(TestConstants.STR_ARR_2[0], result.str_list[0]); + assertEquals(TestConstants.STR_ARR_2[1], result.str_list[1]); + assertEquals(TestConstants.STR_1, result.innerStruct.field1); + assertEquals(TestConstants.INT_1, result.innerStruct.field2); + } catch (Exception e) { + e.printStackTrace(); + fail("Exception occured during tests: " + e); + } + } + + /** + * Test passing (and getting as result) simple two-field structure + */ + @Test + public void test_TestObject_setSimpleStruct() { + SimpleStruct struct = new SimpleStruct(); + struct.field1 = TestConstants.STR_1; + struct.field2 = TestConstants.INT_1; + DynaCorbaRequest request = new DynaCorbaRequest(refTestObject, "setSimpleStruct"); + try { + request.setOutputType(SimpleStruct.class); + request.addArgument(struct); + DynaCorbaResponse response = request.invoke(); + SimpleStruct retStruct = (SimpleStruct)response.getContent(); + assertTrue(retStruct.field1.equals(struct.field1) && retStruct.field2 == struct.field2); + } catch (Exception e) { + e.printStackTrace(); + fail("Exception occured during tests: " + e); + } + } + + /** + * Tests passing (and getting as result) two dim. sequence of long. + */ + @Test + public void test_TestObject_setLongSeq2() { + int[][] arr1 = new int[2][2]; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + arr1[i][j] = (int)(Math.random() * 1000); + } + } + DynaCorbaRequest request = new DynaCorbaRequest(refTestObject, "setLongSeq2"); + try { + request.setOutputType(arr1.getClass()); + request.addArgument(arr1); + DynaCorbaResponse response = request.invoke(); + int[][] arr2 = (int[][])response.getContent(); + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + assertEquals(arr1[i][j], arr2[i][j]); + } + } + } catch (Exception e) { + e.printStackTrace(); + fail("Exception occured during tests: " + e); + } + } + + /** + * Tests passing multiple complex attributes. + */ + @Test + public void test_TestObject_pickStructFromArgs() { + SomeStruct arg1 = new SomeStruct(); + SomeStruct arg2 = new SomeStruct(); + SomeStruct arg3 = new SomeStruct(); + + SimpleStruct inner = new SimpleStruct(); + inner.field1 = TestConstants.STR_1; + inner.field2 = TestConstants.INT_1; + + arg1.innerStruct = inner; + arg2.innerStruct = inner; + arg3.innerStruct = inner; + + arg1.str = TestConstants.STR_1; + arg2.str = TestConstants.STR_2; + arg3.str = TestConstants.STR_3; + + arg1.str_list = TestConstants.STR_ARR_1; + arg2.str_list = TestConstants.STR_ARR_2; + arg3.str_list = TestConstants.STR_ARR_2; + + arg1.threeDimSeq = TestConstants.INT_ARRAY_3_DIM; + arg2.threeDimSeq = TestConstants.INT_ARRAY_3_DIM; + arg3.threeDimSeq = TestConstants.INT_ARRAY_3_DIM; + + arg1.twoDimSeq = TestConstants.INT_ARRAY_2_DIM; + arg2.twoDimSeq = TestConstants.INT_ARRAY_2_DIM; + arg3.twoDimSeq = TestConstants.INT_ARRAY_2_DIM; + + DynaCorbaRequest request = new DynaCorbaRequest(refTestObject, "pickStructFromArgs"); + try { + + request.setOutputType(SomeStruct.class); + request.addArgument(arg1); + request.addArgument(arg2); + request.addArgument(arg3); + request.addArgument(1); + DynaCorbaResponse response = request.invoke(); + SomeStruct result = (SomeStruct)response.getContent(); + + // just make sure that servant returned right structure + assertTrue(result.str.equals(TestConstants.STR_1)); + } catch (Exception e) { + fail("Exception occured during tests " + e); + e.printStackTrace(); + } + + } + + /** + * Tests handling user defined remote exception (single declared) + */ + @Test + public void test_singleException() { + DynaCorbaRequest request1 = new DynaCorbaRequest(refCalcObject, "div"); + try { + request1.addArgument(2d); + request1.addArgument(2d); + request1.setOutputType(Double.class); + request1.addExceptionType(DivByZero.class); + request1.invoke(); + } catch (Exception e) { + fail(); + } + + DynaCorbaRequest request2 = new DynaCorbaRequest(refCalcObject, "div"); + try { + request2.addArgument(2d); + request2.addArgument(0d); + request2.setOutputType(Double.class); + request2.addExceptionType(DivByZero.class); + request2.invoke(); + } catch (DivByZero e) { + assertTrue(e.info != null && e.arguments != null && e.arguments.arg1 == 2 && e.arguments.arg2 == 0); + } catch (Exception exc) { + exc.printStackTrace(); + fail(); + } + } + + /** + * Tests handling user defined multiple exceptions + */ + @Test + public void test_multipleExceptions() { + DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "divForSmallArgs"); + try { + request.addArgument(101d); + request.addArgument(101d); + request.setOutputType(Double.class); + request.addExceptionType(DivByZero.class); + request.addExceptionType(NotSupported.class); + request.invoke(); + } catch (Exception e) { + assertTrue(e instanceof NotSupported); + } + } + + /** + * Tests handling exceptions while user defined no exceptions + */ + @Test + public void test_noExceptionsDeclared() { + DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "div"); + try { + request.addArgument(1d); + request.addArgument(0d); + request.setOutputType(Double.class); + request.invoke(); + fail(); + } catch (Exception e) { + assertTrue(e instanceof RequestConfigurationException); + } + } + + /** + * Tests handling exceptions while user defined no such exception + */ + @Test + public void test_noSuchExceptionDeclared() { + DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "div"); + try { + request.addArgument(1d); + request.addArgument(0d); + request.addExceptionType(NotSupported.class); + request.setOutputType(Double.class); + request.invoke(); + fail(); + } catch (Exception e) { + assertTrue(e instanceof RequestConfigurationException); + } + } + + /** + * Tests handling non existing operation situation + */ + @Test + public void test_systemException_BAD_OPERATION() { + DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "thisOperationSurelyDoesNotExist"); + try { + request.invoke(); + fail(); + } catch (Exception e) { + assertTrue(e instanceof CorbaException); + } + } + + /** + * Tests obtaining references to other objects and using them with specified + * user interface + */ + @Test + @Ignore("Cause of tnameservice hang on stop") + public void test_enchancedReferences() { + DynaCorbaRequest request = null; + try { + request = new DynaCorbaRequest(refObjectManager, "getDummyObject"); + request.setOutputType(DummyObject.class); + DynaCorbaResponse response = request.invoke(); + DummyObject dummy = (DummyObject)response.getContent(); + DummyObject dummy2 = dummy.cloneObject(); + dummy2.cloneObject(); + assertNotSame(dummy.getLong(), dummy2.getLong()); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + /** + * Test passing enums as arguments and retrieving them as a result + */ + @Test + public void test_enums() { + try { + DynaCorbaRequest request = new DynaCorbaRequest(refEnumManager, "getColor"); + Color color = Color.green; + request.addArgument(color); + request.setOutputType(Color.class); + DynaCorbaResponse response = request.invoke(); + Color result = (Color)response.getContent(); + assertEquals(color.value(), result.value()); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + /** + * Tests recognizing structures + */ + @Test + public void test_structValidation() { + DynaCorbaRequest request = null; + try { + request = new DynaCorbaRequest(refArraysSetter, "whatever"); + request.setOutputType(InvalidStruct1.class); + fail(); + } catch (Exception e) { + assertTrue(e instanceof RequestConfigurationException); + } + + try { + request = new DynaCorbaRequest(refArraysSetter, "whatever"); + request.setOutputType(InvalidStruct2.class); + fail(); + } catch (Exception e) { + assertTrue(e instanceof RequestConfigurationException); + } + + try { + request = new DynaCorbaRequest(refArraysSetter, "whatever"); + request.setOutputType(InvalidStruct3.class); + fail(); + } catch (Exception e) { + assertTrue(e instanceof RequestConfigurationException); + } + + try { + request = new DynaCorbaRequest(refArraysSetter, "whatever"); + request.setOutputType(SomeStruct.class); + } catch (Exception e) { + fail(); + } + } + + /** + * Tests recognizing enums + */ + @Test + public void test_enumValidation() { + DynaCorbaRequest request = null; + try { + request = new DynaCorbaRequest(refArraysSetter, "whatever"); + request.setOutputType(InvalidEnum1.class); + fail(); + } catch (Exception e) { + assertTrue(e instanceof RequestConfigurationException); + } + + try { + request = new DynaCorbaRequest(refArraysSetter, "whatever"); + request.setOutputType(InvalidEnum2.class); + fail(); + } catch (Exception e) { + assertTrue(e instanceof RequestConfigurationException); + } + + try { + request = new DynaCorbaRequest(refArraysSetter, "whatever"); + request.setOutputType(InvalidEnum3.class); + fail(); + } catch (Exception e) { + assertTrue(e instanceof RequestConfigurationException); + } + + try { + request = new DynaCorbaRequest(refArraysSetter, "whatever"); + request.setOutputType(Color.class); + } catch (Exception e) { + fail(); + } + } + + /** + * Tests handling passing wrong params + */ + @Test + public void test_systemException_BAD_PARAM() { + try { + DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "div"); + request.setOutputType(Double.class); + request.addArgument(3d); + request.invoke(); + fail(); + } catch (Exception e) { + if (e instanceof CorbaException) { + assertTrue(true); + } else { + e.printStackTrace(); + fail(); + } + } + } + + /** + * Tests passing CORBA arrays + */ + @Test + public void test_arraysPassing() { + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "passStringArray"); + Annotation[] notes = + ArraysUnionsTuscanyServant.class.getMethod("passStringArray", new Class[] {String[][].class}) + .getAnnotations(); + request.setOutputType(String[][].class, notes); + String[][] argument = { {"Hello", "World"}, {"Hi", "again"}}; + request.addArgument(argument, notes); + DynaCorbaResponse response = request.invoke(); + String[][] result = (String[][])response.getContent(); + for (int i = 0; i < argument.length; i++) { + for (int j = 0; j < argument[i].length; j++) { + assertEquals(argument[i][j], result[i][j]); + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "passTestStruct"); + ArraysTestStruct arg = new ArraysTestStruct(); + String[] field1 = {"Hello", "World"}; + arg.field1 = field1; + int[][] field2 = { {4, 2, 2, 5}, {6, 12, 5, 8}}; + arg.field2 = field2; + float[][][] field3 = { { {2, 6}, {2, 7}, {9, 3}, {4, 6}}, { {3, 7}, {6, 6}, {3, 5}, {6, 2}}}; + arg.field3 = field3; + request.addArgument(arg); + request.setOutputType(ArraysTestStruct.class); + DynaCorbaResponse response = request.invoke(); + ArraysTestStruct result = (ArraysTestStruct)response.getContent(); + for (int i = 0; i < arg.field1.length; i++) { + assertEquals(arg.field1[i], result.field1[i]); + } + for (int i = 0; i < arg.field2.length; i++) { + for (int j = 0; j < arg.field2[i].length; j++) { + assertEquals(arg.field2[i][j], result.field2[i][j]); + } + } + for (int i = 0; i < arg.field2.length; i++) { + for (int j = 0; j < arg.field2[i].length; j++) { + for (int k = 0; k < arg.field3[i][j].length; k++) { + assertEquals(arg.field3[i][j][k], result.field3[i][j][k], 0.0); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + /** + * Tests situation when CORBA array dimension size doesn't match + * CORBA array annotation arguments (which sets dimension lengths) + */ + @Test + public void test_invalidArrayAnnotationSize() { + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "passStringArray"); + Annotation[] notes = + ArraysUnionsTuscanyServant.class.getMethod("passStringArray", new Class[] {String[][].class}) + .getAnnotations(); + request.setOutputType(String[][][].class, notes); + fail(); + } catch (RequestConfigurationException e) { + // expected + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "passStringArray"); + Annotation[] notes = + ArraysUnionsTuscanyServant.class.getMethod("passStringArray", new Class[] {String[][].class}) + .getAnnotations(); + request.addArgument(new String[0][0][0], notes); + fail(); + } catch (RequestConfigurationException e) { + // expected + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "passStringArray"); + request.addArgument(new InvalidCorbaArray(), null); + fail(); + } catch (RequestConfigurationException e) { + // expected + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + /** + * Tests passing CORBA unions + */ + @Test + public void test_passingUnions() { + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "passRichUnion"); + request.setOutputType(RichUnion.class); + RichUnion arg = new RichUnion(); + InnerUnion argIu = new InnerUnion(); + argIu.setX(10); + arg.setIu(argIu); + request.addArgument(arg); + DynaCorbaResponse response = request.invoke(); + RichUnion result = (RichUnion)response.getContent(); + assertEquals(arg.getIu().getX(), result.getIu().getX()); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "passRichUnion"); + request.setOutputType(RichUnion.class); + RichUnion arg = new RichUnion(); + arg.setDef(true); + request.addArgument(arg); + DynaCorbaResponse response = request.invoke(); + RichUnion result = (RichUnion)response.getContent(); + assertEquals(arg.isDef(), result.isDef()); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + /** + * Tests handling invalid union declarations + */ + @Test + public void test_testInvalidUnionClasses() { + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "whatever"); + request.setOutputType(InvalidUnion1.class); + } catch (Exception e) { + assertEquals(RequestConfigurationException.class, e.getClass()); + } + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "whatever"); + request.setOutputType(InvalidUnion2.class); + } catch (Exception e) { + assertEquals(RequestConfigurationException.class, e.getClass()); + } + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "whatever"); + request.setOutputType(InvalidUnion3.class); + } catch (Exception e) { + assertEquals(RequestConfigurationException.class, e.getClass()); + } + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "whatever"); + request.setOutputType(InvalidUnion4.class); + } catch (Exception e) { + assertEquals(RequestConfigurationException.class, e.getClass()); + } + try { + DynaCorbaRequest request = new DynaCorbaRequest(refArraysUnions, "whatever"); + request.setOutputType(InvalidUnion5.class); + } catch (Exception e) { + assertEquals(RequestConfigurationException.class, e.getClass()); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/MappingTestInterface.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/MappingTestInterface.java new file mode 100644 index 0000000000..f0dccd9e7e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/MappingTestInterface.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.sca.binding.corba.testing; + +/** + * @version $Rev$ $Date$ + * Interface that can be tested for operations mapping + */ +public interface MappingTestInterface { + + int getIntField(); + + void setIntField(int intField); + + boolean isBoolField(); + + void setBoolField(boolean boolField); + + void overloadedName(); + + void overloadedName(String arg1); + + void overloadedName(String arg1, int arg2); + + void caseCollision(); + + void CaseCollision(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/MethodFinderTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/MethodFinderTestCase.java new file mode 100644 index 0000000000..725ce0ec41 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/MethodFinderTestCase.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.sca.binding.corba.testing; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.binding.corba.impl.util.MethodFinder; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + * Various tests for MethodFinder + */ +public class MethodFinderTestCase { + + /** + * Tests finding existing methods + */ + @Test + public void test_findExistingMethod() { + try { + String methodName = "rotateLeft"; + Method sample = Integer.class.getMethod(methodName, new Class[] {int.class, int.class}); + Method m1 = MethodFinder.findMethod(Integer.class, methodName, new Class[] {int.class, int.class}); + Method m2 = + MethodFinder.findMethod(Integer.class, methodName, new Class[] {Integer.class, Integer.class}); + assertEquals(sample, m1); + assertEquals(sample, m2); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + /** + * Tests null result value for not existing method + */ + @Test + public void test_findNotExistingMethod() { + try { + String methodName = "rotateLeft"; + Method method = MethodFinder.findMethod(Integer.class, methodName, new Class[] {}); + assertEquals(null, method); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/OperationMappingTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/OperationMappingTestCase.java new file mode 100644 index 0000000000..0dd34c26e8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/OperationMappingTestCase.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.sca.binding.corba.testing; + +import static org.junit.Assert.assertEquals; + +import java.lang.reflect.Method; +import java.util.Map; + +import org.apache.tuscany.sca.binding.corba.impl.util.OperationMapper; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + * Various tests for OperationsMapping + */ +public class OperationMappingTestCase { + + /** + * Tests if Java2IDLUtil maps methods to operations correctly + */ + @Test + public void test_mappingRules() { + Map met2op = OperationMapper.mapMethodToOperationName(MappingTestInterface.class); + for (Method method : met2op.keySet()) { + String name = method.getName(); + String translatedName = met2op.get(method); + if (name.equals("getIntField")) { + assertEquals("_get_intField", translatedName); + } else if (name.equals("setIntField")) { + assertEquals("_set_intField", translatedName); + } else if (name.equals("isBoolField")) { + assertEquals("_get_boolField", translatedName); + } else if (name.equals("setBoolField")) { + assertEquals("_set_boolField", translatedName); + } else if (name.equals("overloadedName") && method.getParameterTypes().length == 0) { + assertEquals("overloadedName__", translatedName); + } else if (name.equals("overloadedName") && method.getParameterTypes().length == 1) { + assertEquals("overloadedName__CORBA_WStringValue", translatedName); + } else if (name.equals("overloadedName") && method.getParameterTypes().length == 2) { + assertEquals("overloadedName__CORBA_WStringValue__long", translatedName); + } else if (name.equals("caseCollision")) { + assertEquals("caseCollision_4", translatedName); + } else if (name.equals("CaseCollision")) { + assertEquals("CaseCollision_0_4", translatedName); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/TestConstants.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/TestConstants.java new file mode 100644 index 0000000000..962a00d002 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/TestConstants.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.sca.binding.corba.testing; + +/** + * Some constants and utilities for module tests + * @version $Rev$ $Date$ + */ +public class TestConstants { + + public static final String STR_1 = "Hello world!"; + public static final String STR_2 = "2nd string"; + public static final String STR_3 = "Other string"; + public static final String[] STR_ARR_1 = {"Hello", "World"}; + public static final String[] STR_ARR_2 = {"Another", "string", "array"}; + public static final int INT_1 = 0; + + public static final int TEST1_PORT = 11100; + public static final String TEST1_HOST = "localhost"; + + public static final int TEST2_PORT = 11101; + public static final String TEST2_HOST = "localhost"; + + public static final int[][] INT_ARRAY_2_DIM = { {1, 2}, {3, 4}}; + public static final int[][][] INT_ARRAY_3_DIM = { { {1, 2}, {3, 4}}, { {5, 6}, {7, 8}}}; + + public static final long TNAMESERV_SPAWN_WAIT = 300; + + /** + * Tests if given 2D arrays values are equal + * @param arr1 + * @param arr2 + * @return + */ + public static boolean are2DimArraysEqual(int[][] arr1, int[][] arr2) { + int sum = 0; + int expSum = 0; + for (int i = 0; i < arr1.length; i++) { + for (int j = 0; j < arr1[i].length; j++) { + expSum++; + if (arr1[i][j] == arr2[i][j]) { + sum++; + } + } + } + return sum == expSum; + } + + /** + * Tests if given 3D arrays values are equal + * @param arr1 + * @param arr2 + * @return + */ + public static boolean are3DimArraysEqual(int[][][] arr1, int[][][] arr2) { + int sum = 0; + int expSum = 0; + for (int i = 0; i < arr1.length; i++) { + for (int j = 0; j < arr1[i].length; j++) { + for (int k = 0; k < arr1[i][j].length; k++) { + expSum++; + if (arr1[i][j][k] == arr2[i][j][k]) { + sum++; + } + } + } + } + return sum == expSum; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests.java new file mode 100644 index 0000000000..154ca31645 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests.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.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public interface ArraysUnionsTests extends ArraysUnionsTestsOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity +{ +} // interface ArraysUnionsTests diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsHelper.java new file mode 100644 index 0000000000..9f97a6075a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsHelper.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +abstract public class ArraysUnionsTestsHelper +{ + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests:1.0"; + + public static void insert (org.omg.CORBA.Any a, org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests that) + { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream (); + a.type (type ()); + write (out, that); + a.read_value (out.create_input_stream (), type ()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests extract (org.omg.CORBA.Any a) + { + return read (a.create_input_stream ()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + synchronized public static org.omg.CORBA.TypeCode type () + { + if (__typeCode == null) + { + __typeCode = org.omg.CORBA.ORB.init ().create_interface_tc (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTestsHelper.id (), "ArraysUnionsTests"); + } + return __typeCode; + } + + public static String id () + { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests read (org.omg.CORBA.portable.InputStream istream) + { + return narrow (istream.read_Object (_ArraysUnionsTestsStub.class)); + } + + public static void write (org.omg.CORBA.portable.OutputStream ostream, org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests value) + { + ostream.write_Object ((org.omg.CORBA.Object) value); + } + + public static org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests narrow (org.omg.CORBA.Object obj) + { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests) + return (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests)obj; + else if (!obj._is_a (id ())) + throw new org.omg.CORBA.BAD_PARAM (); + else + { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate (); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions._ArraysUnionsTestsStub stub = new org.apache.tuscany.sca.binding.corba.testing.arrays_unions._ArraysUnionsTestsStub (); + stub._set_delegate(delegate); + return stub; + } + } + + public static org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests unchecked_narrow (org.omg.CORBA.Object obj) + { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests) + return (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests)obj; + else + { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate (); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions._ArraysUnionsTestsStub stub = new org.apache.tuscany.sca.binding.corba.testing.arrays_unions._ArraysUnionsTestsStub (); + stub._set_delegate(delegate); + return stub; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsHolder.java new file mode 100644 index 0000000000..e0afdde639 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsHolder.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.sca.binding.corba.testing.arrays_unions; + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public final class ArraysUnionsTestsHolder implements org.omg.CORBA.portable.Streamable +{ + public org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests value = null; + + public ArraysUnionsTestsHolder () + { + } + + public ArraysUnionsTestsHolder (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests initialValue) + { + value = initialValue; + } + + public void _read (org.omg.CORBA.portable.InputStream i) + { + value = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTestsHelper.read (i); + } + + public void _write (org.omg.CORBA.portable.OutputStream o) + { + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTestsHelper.write (o, value); + } + + public org.omg.CORBA.TypeCode _type () + { + return org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTestsHelper.type (); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsOperations.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsOperations.java new file mode 100644 index 0000000000..1a515b613a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsOperations.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.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTestsOperations.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public interface ArraysUnionsTestsOperations +{ + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct passTestStruct (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct arg); + String[][] passStringArray (String[][] arg); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion passRichUnion (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion arg); +} // interface ArraysUnionsTestsOperations diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnion.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnion.java new file mode 100644 index 0000000000..c590ebb082 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnion.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnion.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public final class InnerUnion implements org.omg.CORBA.portable.IDLEntity +{ + private int ___x; + private float ___y; + private int __discriminator; + private boolean __uninitialized = true; + + public InnerUnion () + { + } + + public int discriminator () + { + if (__uninitialized) + throw new org.omg.CORBA.BAD_OPERATION (); + return __discriminator; + } + + public int x () + { + if (__uninitialized) + throw new org.omg.CORBA.BAD_OPERATION (); + verifyx (__discriminator); + return ___x; + } + + public void x (int value) + { + __discriminator = 1; + ___x = value; + __uninitialized = false; + } + + public void x (int discriminator, int value) + { + verifyx (discriminator); + __discriminator = discriminator; + ___x = value; + __uninitialized = false; + } + + private void verifyx (int discriminator) + { + if (discriminator != 1) + throw new org.omg.CORBA.BAD_OPERATION (); + } + + public float y () + { + if (__uninitialized) + throw new org.omg.CORBA.BAD_OPERATION (); + verifyy (__discriminator); + return ___y; + } + + public void y (float value) + { + __discriminator = 2; + ___y = value; + __uninitialized = false; + } + + public void y (int discriminator, float value) + { + verifyy (discriminator); + __discriminator = discriminator; + ___y = value; + __uninitialized = false; + } + + private void verifyy (int discriminator) + { + if (discriminator != 2) + throw new org.omg.CORBA.BAD_OPERATION (); + } + + public void _default () + { + __discriminator = -2147483648; + __uninitialized = false; + } + + public void _default (int discriminator) + { + verifyDefault( discriminator ) ; + __discriminator = discriminator ; + __uninitialized = false; + } + + private void verifyDefault( int value ) + { + switch (value) { + case 1: + case 2: + throw new org.omg.CORBA.BAD_OPERATION() ; + + default: + return; + } + } + +} // class InnerUnion diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnionHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnionHelper.java new file mode 100644 index 0000000000..977cd6aa4d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnionHelper.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.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnionHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +abstract public class InnerUnionHelper +{ + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnion/InnerUnion:1.0"; + + public static void insert (org.omg.CORBA.Any a, org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion that) + { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream (); + a.type (type ()); + write (out, that); + a.read_value (out.create_input_stream (), type ()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion extract (org.omg.CORBA.Any a) + { + return read (a.create_input_stream ()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + synchronized public static org.omg.CORBA.TypeCode type () + { + if (__typeCode == null) + { + org.omg.CORBA.TypeCode _disTypeCode0; + _disTypeCode0 = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_long); + org.omg.CORBA.UnionMember[] _members0 = new org.omg.CORBA.UnionMember [2]; + org.omg.CORBA.TypeCode _tcOf_members0; + org.omg.CORBA.Any _anyOf_members0; + + // Branch for x (case label 1) + _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any (); + _anyOf_members0.insert_long ((int)1); + _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_long); + _members0[0] = new org.omg.CORBA.UnionMember ( + "x", + _anyOf_members0, + _tcOf_members0, + null); + + // Branch for y (case label 2) + _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any (); + _anyOf_members0.insert_long ((int)2); + _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_float); + _members0[1] = new org.omg.CORBA.UnionMember ( + "y", + _anyOf_members0, + _tcOf_members0, + null); + __typeCode = org.omg.CORBA.ORB.init ().create_union_tc (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnionHelper.id (), "InnerUnion", _disTypeCode0, _members0); + } + return __typeCode; + } + + public static String id () + { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion read (org.omg.CORBA.portable.InputStream istream) + { + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion value = new org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion (); + int _dis0 = (int)0; + _dis0 = istream.read_long (); + switch (_dis0) + { + case 1: + int _x = (int)0; + _x = istream.read_long (); + value.x (_x); + break; + case 2: + float _y = (float)0; + _y = istream.read_float (); + value.y (_y); + break; + default: + value._default( _dis0 ) ; + break; + } + return value; + } + + public static void write (org.omg.CORBA.portable.OutputStream ostream, org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion value) + { + ostream.write_long (value.discriminator ()); + switch (value.discriminator ()) + { + case 1: + ostream.write_long (value.x ()); + break; + case 2: + ostream.write_float (value.y ()); + break; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnionHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnionHolder.java new file mode 100644 index 0000000000..a5f65930a9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnionHolder.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.sca.binding.corba.testing.arrays_unions; + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/InnerUnionHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public final class InnerUnionHolder implements org.omg.CORBA.portable.Streamable +{ + public org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion value = null; + + public InnerUnionHolder () + { + } + + public InnerUnionHolder (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion initialValue) + { + value = initialValue; + } + + public void _read (org.omg.CORBA.portable.InputStream i) + { + value = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnionHelper.read (i); + } + + public void _write (org.omg.CORBA.portable.OutputStream o) + { + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnionHelper.write (o, value); + } + + public org.omg.CORBA.TypeCode _type () + { + return org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnionHelper.type (); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnion.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnion.java new file mode 100644 index 0000000000..c1742b4ae3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnion.java @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnion.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public final class RichUnion implements org.omg.CORBA.portable.IDLEntity +{ + private int ___x; + private float ___y; + private String ___z; + private org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion ___iu; + private boolean ___a; + private int __discriminator; + private boolean __uninitialized = true; + + public RichUnion () + { + } + + public int discriminator () + { + if (__uninitialized) + throw new org.omg.CORBA.BAD_OPERATION (); + return __discriminator; + } + + public int x () + { + if (__uninitialized) + throw new org.omg.CORBA.BAD_OPERATION (); + verifyx (__discriminator); + return ___x; + } + + public void x (int value) + { + __discriminator = 1; + ___x = value; + __uninitialized = false; + } + + public void x (int discriminator, int value) + { + verifyx (discriminator); + __discriminator = discriminator; + ___x = value; + __uninitialized = false; + } + + private void verifyx (int discriminator) + { + if (discriminator != 1) + throw new org.omg.CORBA.BAD_OPERATION (); + } + + public float y () + { + if (__uninitialized) + throw new org.omg.CORBA.BAD_OPERATION (); + verifyy (__discriminator); + return ___y; + } + + public void y (float value) + { + __discriminator = 2; + ___y = value; + __uninitialized = false; + } + + public void y (int discriminator, float value) + { + verifyy (discriminator); + __discriminator = discriminator; + ___y = value; + __uninitialized = false; + } + + private void verifyy (int discriminator) + { + if (discriminator != 2) + throw new org.omg.CORBA.BAD_OPERATION (); + } + + public String z () + { + if (__uninitialized) + throw new org.omg.CORBA.BAD_OPERATION (); + verifyz (__discriminator); + return ___z; + } + + public void z (String value) + { + __discriminator = 3; + ___z = value; + __uninitialized = false; + } + + public void z (int discriminator, String value) + { + verifyz (discriminator); + __discriminator = discriminator; + ___z = value; + __uninitialized = false; + } + + private void verifyz (int discriminator) + { + if (discriminator != 3) + throw new org.omg.CORBA.BAD_OPERATION (); + } + + public org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion iu () + { + if (__uninitialized) + throw new org.omg.CORBA.BAD_OPERATION (); + verifyiu (__discriminator); + return ___iu; + } + + public void iu (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion value) + { + __discriminator = 4; + ___iu = value; + __uninitialized = false; + } + + public void iu (int discriminator, org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion value) + { + verifyiu (discriminator); + __discriminator = discriminator; + ___iu = value; + __uninitialized = false; + } + + private void verifyiu (int discriminator) + { + if (discriminator != 4) + throw new org.omg.CORBA.BAD_OPERATION (); + } + + public boolean a () + { + if (__uninitialized) + throw new org.omg.CORBA.BAD_OPERATION (); + verifya (__discriminator); + return ___a; + } + + public void a (boolean value) + { + __discriminator = -2147483648; + ___a = value; + __uninitialized = false; + } + + public void a (int discriminator, boolean value) + { + verifya (discriminator); + __discriminator = discriminator; + ___a = value; + __uninitialized = false; + } + + private void verifya (int discriminator) + { + if (discriminator == 1 || discriminator == 2 || discriminator == 3 || discriminator == 4) + throw new org.omg.CORBA.BAD_OPERATION (); + } + +} // class RichUnion diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnionHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnionHelper.java new file mode 100644 index 0000000000..a6682c6f5f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnionHelper.java @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnionHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +abstract public class RichUnionHelper +{ + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnion/RichUnion:1.0"; + + public static void insert (org.omg.CORBA.Any a, org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion that) + { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream (); + a.type (type ()); + write (out, that); + a.read_value (out.create_input_stream (), type ()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion extract (org.omg.CORBA.Any a) + { + return read (a.create_input_stream ()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + synchronized public static org.omg.CORBA.TypeCode type () + { + if (__typeCode == null) + { + org.omg.CORBA.TypeCode _disTypeCode0; + _disTypeCode0 = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_long); + org.omg.CORBA.UnionMember[] _members0 = new org.omg.CORBA.UnionMember [5]; + org.omg.CORBA.TypeCode _tcOf_members0; + org.omg.CORBA.Any _anyOf_members0; + + // Branch for x (case label 1) + _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any (); + _anyOf_members0.insert_long ((int)1); + _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_long); + _members0[0] = new org.omg.CORBA.UnionMember ( + "x", + _anyOf_members0, + _tcOf_members0, + null); + + // Branch for y (case label 2) + _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any (); + _anyOf_members0.insert_long ((int)2); + _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_float); + _members0[1] = new org.omg.CORBA.UnionMember ( + "y", + _anyOf_members0, + _tcOf_members0, + null); + + // Branch for z (case label 3) + _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any (); + _anyOf_members0.insert_long ((int)3); + _tcOf_members0 = org.omg.CORBA.ORB.init ().create_string_tc (0); + _members0[2] = new org.omg.CORBA.UnionMember ( + "z", + _anyOf_members0, + _tcOf_members0, + null); + + // Branch for iu (case label 4) + _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any (); + _anyOf_members0.insert_long ((int)4); + _tcOf_members0 = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnionHelper.type (); + _members0[3] = new org.omg.CORBA.UnionMember ( + "iu", + _anyOf_members0, + _tcOf_members0, + null); + + // Branch for a (Default case) + _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any (); + _anyOf_members0.insert_octet ((byte)0); // default member label + _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_boolean); + _members0[4] = new org.omg.CORBA.UnionMember ( + "a", + _anyOf_members0, + _tcOf_members0, + null); + __typeCode = org.omg.CORBA.ORB.init ().create_union_tc (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnionHelper.id (), "RichUnion", _disTypeCode0, _members0); + } + return __typeCode; + } + + public static String id () + { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion read (org.omg.CORBA.portable.InputStream istream) + { + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion value = new org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion (); + int _dis0 = (int)0; + _dis0 = istream.read_long (); + switch (_dis0) + { + case 1: + int _x = (int)0; + _x = istream.read_long (); + value.x (_x); + break; + case 2: + float _y = (float)0; + _y = istream.read_float (); + value.y (_y); + break; + case 3: + String _z = null; + _z = istream.read_string (); + value.z (_z); + break; + case 4: + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnion _iu = null; + _iu = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnionHelper.read (istream); + value.iu (_iu); + break; + default: + boolean _a = false; + _a = istream.read_boolean (); + value.a (_dis0, _a); + break; + } + return value; + } + + public static void write (org.omg.CORBA.portable.OutputStream ostream, org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion value) + { + ostream.write_long (value.discriminator ()); + switch (value.discriminator ()) + { + case 1: + ostream.write_long (value.x ()); + break; + case 2: + ostream.write_float (value.y ()); + break; + case 3: + ostream.write_string (value.z ()); + break; + case 4: + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.InnerUnionHelper.write (ostream, value.iu ()); + break; + default: + ostream.write_boolean (value.a ()); + break; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnionHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnionHolder.java new file mode 100644 index 0000000000..c04df97113 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnionHolder.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.sca.binding.corba.testing.arrays_unions; + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/RichUnionHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public final class RichUnionHolder implements org.omg.CORBA.portable.Streamable +{ + public org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion value = null; + + public RichUnionHolder () + { + } + + public RichUnionHolder (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion initialValue) + { + value = initialValue; + } + + public void _read (org.omg.CORBA.portable.InputStream i) + { + value = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnionHelper.read (i); + } + + public void _write (org.omg.CORBA.portable.OutputStream o) + { + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnionHelper.write (o, value); + } + + public org.omg.CORBA.TypeCode _type () + { + return org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnionHelper.type (); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArrayHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArrayHelper.java new file mode 100644 index 0000000000..2ff28612c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArrayHelper.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArrayHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +abstract public class StringArrayHelper +{ + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArray:1.0"; + + public static void insert (org.omg.CORBA.Any a, String[][] that) + { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream (); + a.type (type ()); + write (out, that); + a.read_value (out.create_input_stream (), type ()); + } + + public static String[][] extract (org.omg.CORBA.Any a) + { + return read (a.create_input_stream ()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + synchronized public static org.omg.CORBA.TypeCode type () + { + if (__typeCode == null) + { + __typeCode = org.omg.CORBA.ORB.init ().create_string_tc (0); + __typeCode = org.omg.CORBA.ORB.init ().create_array_tc (2, __typeCode ); + __typeCode = org.omg.CORBA.ORB.init ().create_array_tc (2, __typeCode ); + __typeCode = org.omg.CORBA.ORB.init ().create_alias_tc (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.StringArrayHelper.id (), "StringArray", __typeCode); + } + return __typeCode; + } + + public static String id () + { + return _id; + } + + public static String[][] read (org.omg.CORBA.portable.InputStream istream) + { + String value[][] = null; + value = new String[2][]; + for (int _o0 = 0;_o0 < (2); ++_o0) + { + value[_o0] = new String[2]; + for (int _o1 = 0;_o1 < (2); ++_o1) + { + value[_o0][_o1] = istream.read_string (); + } + } + return value; + } + + public static void write (org.omg.CORBA.portable.OutputStream ostream, String[][] value) + { + if (value.length != (2)) + throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + for (int _i0 = 0;_i0 < (2); ++_i0) + { + if (value[_i0].length != (2)) + throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + for (int _i1 = 0;_i1 < (2); ++_i1) + { + ostream.write_string (value[_i0][_i1]); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArrayHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArrayHolder.java new file mode 100644 index 0000000000..5c95a673b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArrayHolder.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.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/StringArrayHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public final class StringArrayHolder implements org.omg.CORBA.portable.Streamable +{ + public String value[][] = null; + + public StringArrayHolder () + { + } + + public StringArrayHolder (String[][] initialValue) + { + value = initialValue; + } + + public void _read (org.omg.CORBA.portable.InputStream i) + { + value = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.StringArrayHelper.read (i); + } + + public void _write (org.omg.CORBA.portable.OutputStream o) + { + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.StringArrayHelper.write (o, value); + } + + public org.omg.CORBA.TypeCode _type () + { + return org.apache.tuscany.sca.binding.corba.testing.arrays_unions.StringArrayHelper.type (); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStruct.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStruct.java new file mode 100644 index 0000000000..a07079b369 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStruct.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.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStruct.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public final class TestStruct implements org.omg.CORBA.portable.IDLEntity +{ + public String oneDimArray[] = null; + public int twoDimArray[][] = null; + public float threeDimArray[][][] = null; + + public TestStruct () + { + } // ctor + + public TestStruct (String[] _oneDimArray, int[][] _twoDimArray, float[][][] _threeDimArray) + { + oneDimArray = _oneDimArray; + twoDimArray = _twoDimArray; + threeDimArray = _threeDimArray; + } // ctor + +} // class TestStruct diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStructHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStructHelper.java new file mode 100644 index 0000000000..36453797d5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStructHelper.java @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStructHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +abstract public class TestStructHelper +{ + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStruct/TestStruct:1.0"; + + public static void insert (org.omg.CORBA.Any a, org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct that) + { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream (); + a.type (type ()); + write (out, that); + a.read_value (out.create_input_stream (), type ()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct extract (org.omg.CORBA.Any a) + { + return read (a.create_input_stream ()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + private static boolean __active = false; + synchronized public static org.omg.CORBA.TypeCode type () + { + if (__typeCode == null) + { + synchronized (org.omg.CORBA.TypeCode.class) + { + if (__typeCode == null) + { + if (__active) + { + return org.omg.CORBA.ORB.init().create_recursive_tc ( _id ); + } + __active = true; + org.omg.CORBA.StructMember[] _members0 = new org.omg.CORBA.StructMember [3]; + org.omg.CORBA.TypeCode _tcOf_members0 = null; + _tcOf_members0 = org.omg.CORBA.ORB.init ().create_string_tc (0); + _tcOf_members0 = org.omg.CORBA.ORB.init ().create_array_tc (2, _tcOf_members0 ); + _members0[0] = new org.omg.CORBA.StructMember ( + "oneDimArray", + _tcOf_members0, + null); + _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_long); + _tcOf_members0 = org.omg.CORBA.ORB.init ().create_array_tc (2, _tcOf_members0 ); + _tcOf_members0 = org.omg.CORBA.ORB.init ().create_array_tc (4, _tcOf_members0 ); + _members0[1] = new org.omg.CORBA.StructMember ( + "twoDimArray", + _tcOf_members0, + null); + _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_float); + _tcOf_members0 = org.omg.CORBA.ORB.init ().create_array_tc (2, _tcOf_members0 ); + _tcOf_members0 = org.omg.CORBA.ORB.init ().create_array_tc (4, _tcOf_members0 ); + _tcOf_members0 = org.omg.CORBA.ORB.init ().create_array_tc (2, _tcOf_members0 ); + _members0[2] = new org.omg.CORBA.StructMember ( + "threeDimArray", + _tcOf_members0, + null); + __typeCode = org.omg.CORBA.ORB.init ().create_struct_tc (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStructHelper.id (), "TestStruct", _members0); + __active = false; + } + } + } + return __typeCode; + } + + public static String id () + { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct read (org.omg.CORBA.portable.InputStream istream) + { + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct value = new org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct (); + value.oneDimArray = new String[2]; + for (int _o0 = 0;_o0 < (2); ++_o0) + { + value.oneDimArray[_o0] = istream.read_string (); + } + value.twoDimArray = new int[2][]; + for (int _o1 = 0;_o1 < (2); ++_o1) + { + value.twoDimArray[_o1] = new int[4]; + for (int _o2 = 0;_o2 < (4); ++_o2) + { + value.twoDimArray[_o1][_o2] = istream.read_long (); + } + } + value.threeDimArray = new float[2][][]; + for (int _o3 = 0;_o3 < (2); ++_o3) + { + value.threeDimArray[_o3] = new float[4][]; + for (int _o4 = 0;_o4 < (4); ++_o4) + { + value.threeDimArray[_o3][_o4] = new float[2]; + for (int _o5 = 0;_o5 < (2); ++_o5) + { + value.threeDimArray[_o3][_o4][_o5] = istream.read_float (); + } + } + } + return value; + } + + public static void write (org.omg.CORBA.portable.OutputStream ostream, org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct value) + { + if (value.oneDimArray.length != (2)) + throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + for (int _i0 = 0;_i0 < (2); ++_i0) + { + ostream.write_string (value.oneDimArray[_i0]); + } + if (value.twoDimArray.length != (2)) + throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + for (int _i1 = 0;_i1 < (2); ++_i1) + { + if (value.twoDimArray[_i1].length != (4)) + throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + for (int _i2 = 0;_i2 < (4); ++_i2) + { + ostream.write_long (value.twoDimArray[_i1][_i2]); + } + } + if (value.threeDimArray.length != (2)) + throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + for (int _i3 = 0;_i3 < (2); ++_i3) + { + if (value.threeDimArray[_i3].length != (4)) + throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + for (int _i4 = 0;_i4 < (4); ++_i4) + { + if (value.threeDimArray[_i3][_i4].length != (2)) + throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + for (int _i5 = 0;_i5 < (2); ++_i5) + { + ostream.write_float (value.threeDimArray[_i3][_i4][_i5]); + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStructHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStructHolder.java new file mode 100644 index 0000000000..f46ac436be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStructHolder.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.sca.binding.corba.testing.arrays_unions; + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/TestStructHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public final class TestStructHolder implements org.omg.CORBA.portable.Streamable +{ + public org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct value = null; + + public TestStructHolder () + { + } + + public TestStructHolder (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct initialValue) + { + value = initialValue; + } + + public void _read (org.omg.CORBA.portable.InputStream i) + { + value = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStructHelper.read (i); + } + + public void _write (org.omg.CORBA.portable.OutputStream o) + { + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStructHelper.write (o, value); + } + + public org.omg.CORBA.TypeCode _type () + { + return org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStructHelper.type (); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/_ArraysUnionsTestsImplBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/_ArraysUnionsTestsImplBase.java new file mode 100644 index 0000000000..0d25b36786 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/_ArraysUnionsTestsImplBase.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.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/_ArraysUnionsTestsImplBase.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public abstract class _ArraysUnionsTestsImplBase extends org.omg.CORBA.portable.ObjectImpl + implements org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests, org.omg.CORBA.portable.InvokeHandler +{ + + // Constructors + public _ArraysUnionsTestsImplBase () + { + } + + private static java.util.Hashtable _methods = new java.util.Hashtable (); + static + { + _methods.put ("passTestStruct", new java.lang.Integer (0)); + _methods.put ("passStringArray", new java.lang.Integer (1)); + _methods.put ("passRichUnion", new java.lang.Integer (2)); + } + + public org.omg.CORBA.portable.OutputStream _invoke (String $method, + org.omg.CORBA.portable.InputStream in, + org.omg.CORBA.portable.ResponseHandler $rh) + { + org.omg.CORBA.portable.OutputStream out = null; + java.lang.Integer __method = (java.lang.Integer)_methods.get ($method); + if (__method == null) + throw new org.omg.CORBA.BAD_OPERATION (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + + switch (__method.intValue ()) + { + case 0: // org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests/passTestStruct + { + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct arg = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStructHelper.read (in); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct $result = null; + $result = this.passTestStruct (arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStructHelper.write (out, $result); + break; + } + + case 1: // org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests/passStringArray + { + String arg[][] = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.StringArrayHelper.read (in); + String $result[][] = null; + $result = this.passStringArray (arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.StringArrayHelper.write (out, $result); + break; + } + + case 2: // org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests/passRichUnion + { + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion arg = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnionHelper.read (in); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion $result = null; + $result = this.passRichUnion (arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnionHelper.write (out, $result); + break; + } + + default: + throw new org.omg.CORBA.BAD_OPERATION (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + } + + return out; + } // _invoke + + // Type-specific CORBA::Object operations + private static String[] __ids = { + "IDL:org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests:1.0"}; + + public String[] _ids () + { + return (String[])__ids.clone (); + } + + +} // class _ArraysUnionsTestsImplBase diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/_ArraysUnionsTestsStub.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/_ArraysUnionsTestsStub.java new file mode 100644 index 0000000000..5046e3d450 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/arrays_unions/_ArraysUnionsTestsStub.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.corba.testing.arrays_unions; + + +/** +* org/apache/tuscany/sca/binding/corba/testing/arrays_unions/_ArraysUnionsTestsStub.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from arrays_unions.idl +* niedziela, 17 sierpie 2008 15:45:39 CEST +*/ + +public class _ArraysUnionsTestsStub extends org.omg.CORBA.portable.ObjectImpl implements org.apache.tuscany.sca.binding.corba.testing.arrays_unions.ArraysUnionsTests +{ + + public org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct passTestStruct (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct arg) + { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request ("passTestStruct", true); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStructHelper.write ($out, arg); + $in = _invoke ($out); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct $result = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStructHelper.read ($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream (); + String _id = $ex.getId (); + throw new org.omg.CORBA.MARSHAL (_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return passTestStruct (arg ); + } finally { + _releaseReply ($in); + } + } // passTestStruct + + public String[][] passStringArray (String[][] arg) + { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request ("passStringArray", true); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.StringArrayHelper.write ($out, arg); + $in = _invoke ($out); + String $result[][] = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.StringArrayHelper.read ($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream (); + String _id = $ex.getId (); + throw new org.omg.CORBA.MARSHAL (_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return passStringArray (arg ); + } finally { + _releaseReply ($in); + } + } // passStringArray + + public org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion passRichUnion (org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion arg) + { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request ("passRichUnion", true); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnionHelper.write ($out, arg); + $in = _invoke ($out); + org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion $result = org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnionHelper.read ($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream (); + String _id = $ex.getId (); + throw new org.omg.CORBA.MARSHAL (_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return passRichUnion (arg ); + } finally { + _releaseReply ($in); + } + } // passRichUnion + + // Type-specific CORBA::Object operations + private static String[] __ids = { + "IDL:org/apache/tuscany/sca/binding/corba/testing/arrays_unions/ArraysUnionsTests:1.0"}; + + public String[] _ids () + { + return (String[])__ids.clone (); + } + + private void readObject (java.io.ObjectInputStream s) throws java.io.IOException + { + String str = s.readUTF (); + String[] args = null; + java.util.Properties props = null; + org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init (args, props).string_to_object (str); + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl) obj)._get_delegate (); + _set_delegate (delegate); + } + + private void writeObject (java.io.ObjectOutputStream s) throws java.io.IOException + { + String[] args = null; + java.util.Properties props = null; + String str = org.omg.CORBA.ORB.init (args, props).object_to_string (this); + s.writeUTF (str); + } +} // class _ArraysUnionsTestsStub diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/Color.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/Color.java new file mode 100644 index 0000000000..e3c28f8b91 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/Color.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.sca.binding.corba.testing.enums; + +/** +* org/apache/tuscany/sca/binding/corba/testing/enums/Color.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from enums.idl +* czwartek, 19 czerwiec 2008 15:46:10 CEST +*/ + +public class Color implements org.omg.CORBA.portable.IDLEntity { + private int __value; + private static int __size = 3; + private static org.apache.tuscany.sca.binding.corba.testing.enums.Color[] __array = + new org.apache.tuscany.sca.binding.corba.testing.enums.Color[__size]; + + public static final int _red = 0; + public static final org.apache.tuscany.sca.binding.corba.testing.enums.Color red = + new org.apache.tuscany.sca.binding.corba.testing.enums.Color(_red); + public static final int _yellow = 1; + public static final org.apache.tuscany.sca.binding.corba.testing.enums.Color yellow = + new org.apache.tuscany.sca.binding.corba.testing.enums.Color(_yellow); + public static final int _green = 2; + public static final org.apache.tuscany.sca.binding.corba.testing.enums.Color green = + new org.apache.tuscany.sca.binding.corba.testing.enums.Color(_green); + + public int value() { + return __value; + } + + public static org.apache.tuscany.sca.binding.corba.testing.enums.Color from_int(int value) { + if (value >= 0 && value < __size) + return __array[value]; + else + throw new org.omg.CORBA.BAD_PARAM(); + } + + protected Color(int value) { + __value = value; + __array[__value] = this; + } +} // class Color diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/ColorHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/ColorHelper.java new file mode 100644 index 0000000000..775cac8e16 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/ColorHelper.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.sca.binding.corba.testing.enums; + +/** +* org/apache/tuscany/sca/binding/corba/testing/enums/ColorHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from enums.idl +* czwartek, 19 czerwiec 2008 15:46:10 CEST +*/ + +abstract public class ColorHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/enums/Color:1.0"; + + public static void insert(org.omg.CORBA.Any a, org.apache.tuscany.sca.binding.corba.testing.enums.Color that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.enums.Color extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = + org.omg.CORBA.ORB.init().create_enum_tc(org.apache.tuscany.sca.binding.corba.testing.enums.ColorHelper + .id(), + "Color", + new String[] {"red", "yellow", "green"}); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.enums.Color read(org.omg.CORBA.portable.InputStream istream) { + return org.apache.tuscany.sca.binding.corba.testing.enums.Color.from_int(istream.read_long()); + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.enums.Color value) { + ostream.write_long(value.value()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/ColorHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/ColorHolder.java new file mode 100644 index 0000000000..32cd9c8df6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/ColorHolder.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.sca.binding.corba.testing.enums; + +/** +* org/apache/tuscany/sca/binding/corba/testing/enums/ColorHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from enums.idl +* czwartek, 19 czerwiec 2008 15:46:10 CEST +*/ + +public final class ColorHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.enums.Color value = null; + + public ColorHolder() { + } + + public ColorHolder(org.apache.tuscany.sca.binding.corba.testing.enums.Color initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.enums.ColorHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.enums.ColorHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.enums.ColorHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager.java new file mode 100644 index 0000000000..3f73557952 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager.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.sca.binding.corba.testing.enums; + +/** +* org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from enums.idl +* czwartek, 19 czerwiec 2008 15:46:10 CEST +*/ + +public interface EnumManager extends EnumManagerOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity { +} // interface EnumManager diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerHelper.java new file mode 100644 index 0000000000..a6160a7643 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerHelper.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.enums; + +/** +* org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from enums.idl +* czwartek, 19 czerwiec 2008 15:46:10 CEST +*/ + +abstract public class EnumManagerHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager:1.0"; + + public static void insert(org.omg.CORBA.Any a, org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = + org.omg.CORBA.ORB.init() + .create_interface_tc(org.apache.tuscany.sca.binding.corba.testing.enums.EnumManagerHelper.id(), + "EnumManager"); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager read(org.omg.CORBA.portable.InputStream istream) { + return narrow(istream.read_Object(_EnumManagerStub.class)); + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager value) { + ostream.write_Object((org.omg.CORBA.Object)value); + } + + public static org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager) + return (org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager)obj; + else if (!obj._is_a(id())) + throw new org.omg.CORBA.BAD_PARAM(); + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.enums._EnumManagerStub stub = + new org.apache.tuscany.sca.binding.corba.testing.enums._EnumManagerStub(); + stub._set_delegate(delegate); + return stub; + } + } + + public static org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager unchecked_narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager) + return (org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager)obj; + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.enums._EnumManagerStub stub = + new org.apache.tuscany.sca.binding.corba.testing.enums._EnumManagerStub(); + stub._set_delegate(delegate); + return stub; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerHolder.java new file mode 100644 index 0000000000..6afa6bc806 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerHolder.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.sca.binding.corba.testing.enums; + +/** +* org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from enums.idl +* czwartek, 19 czerwiec 2008 15:46:10 CEST +*/ + +public final class EnumManagerHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager value = null; + + public EnumManagerHolder() { + } + + public EnumManagerHolder(org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.enums.EnumManagerHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.enums.EnumManagerHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.enums.EnumManagerHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerOperations.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerOperations.java new file mode 100644 index 0000000000..bab0c27f77 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerOperations.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.sca.binding.corba.testing.enums; + +/** +* org/apache/tuscany/sca/binding/corba/testing/enums/EnumManagerOperations.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from enums.idl +* czwartek, 19 czerwiec 2008 15:46:10 CEST +*/ + +public interface EnumManagerOperations { + + org.apache.tuscany.sca.binding.corba.testing.enums.Color getColor(org.apache.tuscany.sca.binding.corba.testing.enums.Color color); +} // interface EnumManagerOperations diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/_EnumManagerImplBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/_EnumManagerImplBase.java new file mode 100644 index 0000000000..514627ff4b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/_EnumManagerImplBase.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.sca.binding.corba.testing.enums; + +/** +* org/apache/tuscany/sca/binding/corba/testing/enums/_EnumManagerImplBase.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from enums.idl +* czwartek, 19 czerwiec 2008 15:46:10 CEST +*/ + +public abstract class _EnumManagerImplBase extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager, org.omg.CORBA.portable.InvokeHandler { + + // Constructors + public _EnumManagerImplBase() { + } + + private static java.util.Hashtable _methods = new java.util.Hashtable(); + static { + _methods.put("getColor", new java.lang.Integer(0)); + } + + public org.omg.CORBA.portable.OutputStream _invoke(String $method, + org.omg.CORBA.portable.InputStream in, + org.omg.CORBA.portable.ResponseHandler $rh) { + org.omg.CORBA.portable.OutputStream out = null; + java.lang.Integer __method = (java.lang.Integer)_methods.get($method); + if (__method == null) + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + + switch (__method.intValue()) { + case 0: // org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager/getColor + { + org.apache.tuscany.sca.binding.corba.testing.enums.Color color = + org.apache.tuscany.sca.binding.corba.testing.enums.ColorHelper.read(in); + org.apache.tuscany.sca.binding.corba.testing.enums.Color $result = null; + $result = this.getColor(color); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.enums.ColorHelper.write(out, $result); + break; + } + + default: + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + } + + return out; + } // _invoke + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + +} // class _EnumManagerImplBase diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/_EnumManagerStub.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/_EnumManagerStub.java new file mode 100644 index 0000000000..4629ca9cff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/enums/_EnumManagerStub.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.sca.binding.corba.testing.enums; + +/** +* org/apache/tuscany/sca/binding/corba/testing/enums/_EnumManagerStub.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from enums.idl +* czwartek, 19 czerwiec 2008 15:46:10 CEST +*/ + +public class _EnumManagerStub extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager { + + public org.apache.tuscany.sca.binding.corba.testing.enums.Color getColor(org.apache.tuscany.sca.binding.corba.testing.enums.Color color) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("getColor", true); + org.apache.tuscany.sca.binding.corba.testing.enums.ColorHelper.write($out, color); + $in = _invoke($out); + org.apache.tuscany.sca.binding.corba.testing.enums.Color $result = + org.apache.tuscany.sca.binding.corba.testing.enums.ColorHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return getColor(color); + } finally { + _releaseReply($in); + } + } // getColor + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + + private void readObject(java.io.ObjectInputStream s) throws java.io.IOException { + String str = s.readUTF(); + String[] args = null; + java.util.Properties props = null; + org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init(args, props).string_to_object(str); + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + _set_delegate(delegate); + } + + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + String[] args = null; + java.util.Properties props = null; + String str = org.omg.CORBA.ORB.init(args, props).object_to_string(this); + s.writeUTF(str); + } +} // class _EnumManagerStub diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc.java new file mode 100644 index 0000000000..aa480f93ac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc.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.sca.binding.corba.testing.exceptions; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public interface Calc extends CalcOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity { +} // interface Calc diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcHelper.java new file mode 100644 index 0000000000..5ed36ca19b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcHelper.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.exceptions; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +abstract public class CalcHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc:1.0"; + + public static void insert(org.omg.CORBA.Any a, org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = + org.omg.CORBA.ORB.init() + .create_interface_tc(org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcHelper.id(), + "Calc"); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc read(org.omg.CORBA.portable.InputStream istream) { + return narrow(istream.read_Object(_CalcStub.class)); + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc value) { + ostream.write_Object((org.omg.CORBA.Object)value); + } + + public static org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc) + return (org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc)obj; + else if (!obj._is_a(id())) + throw new org.omg.CORBA.BAD_PARAM(); + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.exceptions._CalcStub stub = + new org.apache.tuscany.sca.binding.corba.testing.exceptions._CalcStub(); + stub._set_delegate(delegate); + return stub; + } + } + + public static org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc unchecked_narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc) + return (org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc)obj; + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.exceptions._CalcStub stub = + new org.apache.tuscany.sca.binding.corba.testing.exceptions._CalcStub(); + stub._set_delegate(delegate); + return stub; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcHolder.java new file mode 100644 index 0000000000..ec1cfadd1e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcHolder.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.sca.binding.corba.testing.exceptions; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public final class CalcHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc value = null; + + public CalcHolder() { + } + + public CalcHolder(org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcOperations.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcOperations.java new file mode 100644 index 0000000000..29865ace06 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcOperations.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.sca.binding.corba.testing.exceptions; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcOperations.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public interface CalcOperations { + double div(double arg1, double arg2) + throws org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero; + + double divForSmallArgs(double arg1, double arg2) + throws org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero, + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported; +} // interface CalcOperations diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/Arguments.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/Arguments.java new file mode 100644 index 0000000000..d7839ec4db --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/Arguments.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.sca.binding.corba.testing.exceptions.CalcPackage; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/Arguments.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public final class Arguments implements org.omg.CORBA.portable.IDLEntity { + public double arg1 = (double)0; + public double arg2 = (double)0; + + public Arguments() { + } // ctor + + public Arguments(double _arg1, double _arg2) { + arg1 = _arg1; + arg2 = _arg2; + } // ctor + +} // class Arguments diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/ArgumentsHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/ArgumentsHelper.java new file mode 100644 index 0000000000..c47d63208f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/ArgumentsHelper.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/ArgumentsHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +abstract public class ArgumentsHelper { + private static String _id = + "IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc/Arguments/Arguments:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + private static boolean __active = false; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + synchronized (org.omg.CORBA.TypeCode.class) { + if (__typeCode == null) { + if (__active) { + return org.omg.CORBA.ORB.init().create_recursive_tc(_id); + } + __active = true; + org.omg.CORBA.StructMember[] _members0 = new org.omg.CORBA.StructMember[2]; + org.omg.CORBA.TypeCode _tcOf_members0 = null; + _tcOf_members0 = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_double); + _members0[0] = new org.omg.CORBA.StructMember("arg1", _tcOf_members0, null); + _tcOf_members0 = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_double); + _members0[1] = new org.omg.CORBA.StructMember("arg2", _tcOf_members0, null); + __typeCode = + org.omg.CORBA.ORB + .init() + .create_struct_tc(org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.ArgumentsHelper + .id(), + "Arguments", + _members0); + __active = false; + } + } + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments read(org.omg.CORBA.portable.InputStream istream) { + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments value = + new org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments(); + value.arg1 = istream.read_double(); + value.arg2 = istream.read_double(); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments value) { + ostream.write_double(value.arg1); + ostream.write_double(value.arg2); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/ArgumentsHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/ArgumentsHolder.java new file mode 100644 index 0000000000..f767e8c11a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/ArgumentsHolder.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.sca.binding.corba.testing.exceptions.CalcPackage; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/ArgumentsHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public final class ArgumentsHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments value = null; + + public ArgumentsHolder() { + } + + public ArgumentsHolder(org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.ArgumentsHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.ArgumentsHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.ArgumentsHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZero.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZero.java new file mode 100644 index 0000000000..e7cbb4b8ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZero.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.sca.binding.corba.testing.exceptions.CalcPackage; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZero.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public final class DivByZero extends org.omg.CORBA.UserException { + public org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments arguments = null; + public String info = null; + + public DivByZero() { + super(DivByZeroHelper.id()); + } // ctor + + public DivByZero(org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments _arguments, + String _info) { + super(DivByZeroHelper.id()); + arguments = _arguments; + info = _info; + } // ctor + + public DivByZero(String $reason, + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments _arguments, + String _info) { + super(DivByZeroHelper.id() + " " + $reason); + arguments = _arguments; + info = _info; + } // ctor + +} // class DivByZero diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZeroHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZeroHelper.java new file mode 100644 index 0000000000..5d27f9969c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZeroHelper.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZeroHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +abstract public class DivByZeroHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc/DivByZero:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + private static boolean __active = false; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + synchronized (org.omg.CORBA.TypeCode.class) { + if (__typeCode == null) { + if (__active) { + return org.omg.CORBA.ORB.init().create_recursive_tc(_id); + } + __active = true; + org.omg.CORBA.StructMember[] _members0 = new org.omg.CORBA.StructMember[2]; + org.omg.CORBA.TypeCode _tcOf_members0 = null; + _tcOf_members0 = + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.ArgumentsHelper.type(); + _members0[0] = new org.omg.CORBA.StructMember("arguments", _tcOf_members0, null); + _tcOf_members0 = org.omg.CORBA.ORB.init().create_string_tc(0); + _members0[1] = new org.omg.CORBA.StructMember("info", _tcOf_members0, null); + __typeCode = + org.omg.CORBA.ORB + .init() + .create_exception_tc(org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZeroHelper + .id(), + "DivByZero", + _members0); + __active = false; + } + } + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero read(org.omg.CORBA.portable.InputStream istream) { + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero value = + new org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero(); + // read and discard the repository ID + istream.read_string(); + value.arguments = + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.ArgumentsHelper.read(istream); + value.info = istream.read_string(); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero value) { + // write the repository ID + ostream.write_string(id()); + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.ArgumentsHelper.write(ostream, + value.arguments); + ostream.write_string(value.info); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZeroHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZeroHolder.java new file mode 100644 index 0000000000..ab01c66675 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZeroHolder.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.sca.binding.corba.testing.exceptions.CalcPackage; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/DivByZeroHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public final class DivByZeroHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero value = null; + + public DivByZeroHolder() { + } + + public DivByZeroHolder(org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZeroHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZeroHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZeroHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupported.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupported.java new file mode 100644 index 0000000000..f4ea58e55e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupported.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.sca.binding.corba.testing.exceptions.CalcPackage; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupported.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public final class NotSupported extends org.omg.CORBA.UserException { + public String info = null; + + public NotSupported() { + super(NotSupportedHelper.id()); + } // ctor + + public NotSupported(String _info) { + super(NotSupportedHelper.id()); + info = _info; + } // ctor + + public NotSupported(String $reason, String _info) { + super(NotSupportedHelper.id() + " " + $reason); + info = _info; + } // ctor + +} // class NotSupported diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupportedHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupportedHelper.java new file mode 100644 index 0000000000..82609a36c1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupportedHelper.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupportedHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +abstract public class NotSupportedHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc/NotSupported:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + private static boolean __active = false; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + synchronized (org.omg.CORBA.TypeCode.class) { + if (__typeCode == null) { + if (__active) { + return org.omg.CORBA.ORB.init().create_recursive_tc(_id); + } + __active = true; + org.omg.CORBA.StructMember[] _members0 = new org.omg.CORBA.StructMember[1]; + org.omg.CORBA.TypeCode _tcOf_members0 = null; + _tcOf_members0 = org.omg.CORBA.ORB.init().create_string_tc(0); + _members0[0] = new org.omg.CORBA.StructMember("info", _tcOf_members0, null); + __typeCode = + org.omg.CORBA.ORB + .init() + .create_exception_tc(org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupportedHelper + .id(), + "NotSupported", + _members0); + __active = false; + } + } + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported read(org.omg.CORBA.portable.InputStream istream) { + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported value = + new org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported(); + // read and discard the repository ID + istream.read_string(); + value.info = istream.read_string(); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported value) { + // write the repository ID + ostream.write_string(id()); + ostream.write_string(value.info); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupportedHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupportedHolder.java new file mode 100644 index 0000000000..1389bd33d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupportedHolder.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.sca.binding.corba.testing.exceptions.CalcPackage; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/CalcPackage/NotSupportedHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public final class NotSupportedHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported value = null; + + public NotSupportedHolder() { + } + + public NotSupportedHolder(org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupportedHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupportedHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupportedHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/_CalcImplBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/_CalcImplBase.java new file mode 100644 index 0000000000..a73e252129 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/_CalcImplBase.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.exceptions; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/_CalcImplBase.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public abstract class _CalcImplBase extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc, org.omg.CORBA.portable.InvokeHandler { + + // Constructors + public _CalcImplBase() { + } + + private static java.util.Hashtable _methods = new java.util.Hashtable(); + static { + _methods.put("div", new java.lang.Integer(0)); + _methods.put("divForSmallArgs", new java.lang.Integer(1)); + } + + public org.omg.CORBA.portable.OutputStream _invoke(String $method, + org.omg.CORBA.portable.InputStream in, + org.omg.CORBA.portable.ResponseHandler $rh) { + org.omg.CORBA.portable.OutputStream out = null; + java.lang.Integer __method = (java.lang.Integer)_methods.get($method); + if (__method == null) + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + + switch (__method.intValue()) { + case 0: // org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc/div + { + try { + double arg1 = in.read_double(); + double arg2 = in.read_double(); + double $result = (double)0; + $result = this.div(arg1, arg2); + out = $rh.createReply(); + out.write_double($result); + } catch (org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero $ex) { + out = $rh.createExceptionReply(); + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZeroHelper.write(out, $ex); + } + break; + } + + case 1: // org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc/divForSmallArgs + { + try { + double arg1 = in.read_double(); + double arg2 = in.read_double(); + double $result = (double)0; + $result = this.divForSmallArgs(arg1, arg2); + out = $rh.createReply(); + out.write_double($result); + } catch (org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero $ex) { + out = $rh.createExceptionReply(); + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZeroHelper.write(out, $ex); + } catch (org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported $ex) { + out = $rh.createExceptionReply(); + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupportedHelper.write(out, + $ex); + } + break; + } + + default: + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + } + + return out; + } // _invoke + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + +} // class _CalcImplBase diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/_CalcStub.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/_CalcStub.java new file mode 100644 index 0000000000..65ce051129 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/exceptions/_CalcStub.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.sca.binding.corba.testing.exceptions; + +/** +* org/apache/tuscany/sca/binding/corba/testing/exceptions/_CalcStub.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from exceptions.idl +* sobota, 7 czerwiec 2008 16:12:31 CEST +*/ + +public class _CalcStub extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.exceptions.Calc { + + public double div(double arg1, double arg2) + throws org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("div", true); + $out.write_double(arg1); + $out.write_double(arg2); + $in = _invoke($out); + double $result = $in.read_double(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + if (_id.equals("IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc/DivByZero:1.0")) + throw org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZeroHelper.read($in); + else + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return div(arg1, arg2); + } finally { + _releaseReply($in); + } + } // div + + public double divForSmallArgs(double arg1, double arg2) + throws org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero, + org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("divForSmallArgs", true); + $out.write_double(arg1); + $out.write_double(arg2); + $in = _invoke($out); + double $result = $in.read_double(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + if (_id.equals("IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc/DivByZero:1.0")) + throw org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZeroHelper.read($in); + else if (_id.equals("IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc/NotSupported:1.0")) + throw org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupportedHelper.read($in); + else + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return divForSmallArgs(arg1, arg2); + } finally { + _releaseReply($in); + } + } // divForSmallArgs + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + + private void readObject(java.io.ObjectInputStream s) throws java.io.IOException { + String str = s.readUTF(); + String[] args = null; + java.util.Properties props = null; + org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init(args, props).string_to_object(str); + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + _set_delegate(delegate); + } + + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + String[] args = null; + java.util.Properties props = null; + String str = org.omg.CORBA.ORB.init(args, props).object_to_string(this); + s.writeUTF(str); + } +} // class _CalcStub diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter.java new file mode 100644 index 0000000000..fde204edf8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public interface ArraysSetter extends ArraysSetterOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity { +} // interface ArraysSetter diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterHelper.java new file mode 100644 index 0000000000..71b4fbbdb6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterHelper.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +abstract public class ArraysSetterHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = + org.omg.CORBA.ORB + .init() + .create_interface_tc(org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetterHelper.id(), + "ArraysSetter"); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter read(org.omg.CORBA.portable.InputStream istream) { + return narrow(istream.read_Object(_ArraysSetterStub.class)); + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter value) { + ostream.write_Object((org.omg.CORBA.Object)value); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter) + return (org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter)obj; + else if (!obj._is_a(id())) + throw new org.omg.CORBA.BAD_PARAM(); + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.generated._ArraysSetterStub stub = + new org.apache.tuscany.sca.binding.corba.testing.generated._ArraysSetterStub(); + stub._set_delegate(delegate); + return stub; + } + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter unchecked_narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter) + return (org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter)obj; + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.generated._ArraysSetterStub stub = + new org.apache.tuscany.sca.binding.corba.testing.generated._ArraysSetterStub(); + stub._set_delegate(delegate); + return stub; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterHolder.java new file mode 100644 index 0000000000..d758a560a9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public final class ArraysSetterHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter value = null; + + public ArraysSetterHolder() { + } + + public ArraysSetterHolder(org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetterHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetterHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetterHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterOperations.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterOperations.java new file mode 100644 index 0000000000..464c2ccbc3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterOperations.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetterOperations.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public interface ArraysSetterOperations { + boolean[] setBoolean(boolean[] arg); + + char[] setChar(char[] arg); + + char[] setWchar(char[] arg); + + byte[] setOctet(byte[] arg); + + short[] setShort(short[] arg); + + short[] setUnsignedShort(short[] arg); + + int[] setLong(int[] arg); + + int[] setUnsignedLong(int[] arg); + + long[] setLongLong(long[] arg); + + long[] setUnsignedLongLong(long[] arg); + + float[] setFloat(float[] arg); + + double[] setDouble(double[] arg); + + String[] setString(String[] arg); + + String[] setWstring(String[] arg); + + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject[] setRemoteObject(org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject[] obj); +} // interface ArraysSetterOperations diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter.java new file mode 100644 index 0000000000..c053f12a02 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public interface PrimitivesSetter extends PrimitivesSetterOperations, org.omg.CORBA.Object, + org.omg.CORBA.portable.IDLEntity { +} // interface PrimitivesSetter diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterHelper.java new file mode 100644 index 0000000000..566689960e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterHelper.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class PrimitivesSetterHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = + org.omg.CORBA.ORB.init() + .create_interface_tc(org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetterHelper + .id(), + "PrimitivesSetter"); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter read(org.omg.CORBA.portable.InputStream istream) { + return narrow(istream.read_Object(_PrimitivesSetterStub.class)); + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter value) { + ostream.write_Object((org.omg.CORBA.Object)value); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter) + return (org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter)obj; + else if (!obj._is_a(id())) + throw new org.omg.CORBA.BAD_PARAM(); + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.generated._PrimitivesSetterStub stub = + new org.apache.tuscany.sca.binding.corba.testing.generated._PrimitivesSetterStub(); + stub._set_delegate(delegate); + return stub; + } + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter unchecked_narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter) + return (org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter)obj; + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.generated._PrimitivesSetterStub stub = + new org.apache.tuscany.sca.binding.corba.testing.generated._PrimitivesSetterStub(); + stub._set_delegate(delegate); + return stub; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterHolder.java new file mode 100644 index 0000000000..6564957081 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class PrimitivesSetterHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter value = null; + + public PrimitivesSetterHolder() { + } + + public PrimitivesSetterHolder(org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetterHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetterHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetterHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterOperations.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterOperations.java new file mode 100644 index 0000000000..26669de95a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterOperations.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetterOperations.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public interface PrimitivesSetterOperations { + boolean setBoolean(boolean arg); + + char setChar(char arg); + + char setWchar(char arg); + + byte setOctet(byte arg); + + short setShort(short arg); + + short setUnsignedShort(short arg); + + int setLong(int arg); + + int setUnsignedLong(int arg); + + long setLongLong(long arg); + + long setUnsignedLongLong(long arg); + + float setFloat(float arg); + + double setDouble(double arg); + + String setString(String arg); + + String setWstring(String arg); + + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject setRemoteObject(org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject obj); +} // interface PrimitivesSetterOperations diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObject.java new file mode 100644 index 0000000000..5a140f5ecc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObject.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObject.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public interface RemoteObject extends RemoteObjectOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity { +} // interface RemoteObject diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectHelper.java new file mode 100644 index 0000000000..2a8fe73417 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectHelper.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class RemoteObjectHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObject:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = + org.omg.CORBA.ORB + .init() + .create_interface_tc(org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.id(), + "RemoteObject"); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject read(org.omg.CORBA.portable.InputStream istream) { + return narrow(istream.read_Object(_RemoteObjectStub.class)); + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject value) { + ostream.write_Object((org.omg.CORBA.Object)value); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject) + return (org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject)obj; + else if (!obj._is_a(id())) + throw new org.omg.CORBA.BAD_PARAM(); + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.generated._RemoteObjectStub stub = + new org.apache.tuscany.sca.binding.corba.testing.generated._RemoteObjectStub(); + stub._set_delegate(delegate); + return stub; + } + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject unchecked_narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject) + return (org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject)obj; + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.generated._RemoteObjectStub stub = + new org.apache.tuscany.sca.binding.corba.testing.generated._RemoteObjectStub(); + stub._set_delegate(delegate); + return stub; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectHolder.java new file mode 100644 index 0000000000..63e3926dd2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class RemoteObjectHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject value = null; + + public RemoteObjectHolder() { + } + + public RemoteObjectHolder(org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectOperations.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectOperations.java new file mode 100644 index 0000000000..a8231236eb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectOperations.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObjectOperations.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public interface RemoteObjectOperations { +} // interface RemoteObjectOperations diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStruct.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStruct.java new file mode 100644 index 0000000000..ca86420240 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStruct.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStruct.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class SimpleStruct implements org.omg.CORBA.portable.IDLEntity { + public String field1 = null; + public int field2 = (int)0; + + public SimpleStruct() { + } // ctor + + public SimpleStruct(String _field1, int _field2) { + field1 = _field1; + field2 = _field2; + } // ctor + +} // class SimpleStruct diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStructHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStructHelper.java new file mode 100644 index 0000000000..2a8898d38f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStructHelper.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStructHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class SimpleStructHelper { + private static String _id = + "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStruct/SimpleStruct:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + private static boolean __active = false; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + synchronized (org.omg.CORBA.TypeCode.class) { + if (__typeCode == null) { + if (__active) { + return org.omg.CORBA.ORB.init().create_recursive_tc(_id); + } + __active = true; + org.omg.CORBA.StructMember[] _members0 = new org.omg.CORBA.StructMember[2]; + org.omg.CORBA.TypeCode _tcOf_members0 = null; + _tcOf_members0 = org.omg.CORBA.ORB.init().create_string_tc(0); + _members0[0] = new org.omg.CORBA.StructMember("field1", _tcOf_members0, null); + _tcOf_members0 = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_long); + _members0[1] = new org.omg.CORBA.StructMember("field2", _tcOf_members0, null); + __typeCode = + org.omg.CORBA.ORB.init() + .create_struct_tc(org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper + .id(), + "SimpleStruct", + _members0); + __active = false; + } + } + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct read(org.omg.CORBA.portable.InputStream istream) { + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct value = + new org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct(); + value.field1 = istream.read_string(); + value.field2 = istream.read_long(); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct value) { + ostream.write_string(value.field1); + ostream.write_long(value.field2); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStructHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStructHolder.java new file mode 100644 index 0000000000..bed30e00ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStructHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/SimpleStructHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class SimpleStructHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct value = null; + + public SimpleStructHolder() { + } + + public SimpleStructHolder(org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStruct.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStruct.java new file mode 100644 index 0000000000..73dbd6c198 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStruct.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/SomeStruct.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class SomeStruct implements org.omg.CORBA.portable.IDLEntity { + public org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct innerStruct = null; + public String str = null; + public String str_list[] = null; + public int twoDimSeq[][] = null; + public int threeDimSeq[][][] = null; + + public SomeStruct() { + } // ctor + + public SomeStruct(org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct _innerStruct, + String _str, + String[] _str_list, + int[][] _twoDimSeq, + int[][][] _threeDimSeq) { + innerStruct = _innerStruct; + str = _str; + str_list = _str_list; + twoDimSeq = _twoDimSeq; + threeDimSeq = _threeDimSeq; + } // ctor + +} // class SomeStruct diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStructHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStructHelper.java new file mode 100644 index 0000000000..8f524ffeb1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStructHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/SomeStructHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class SomeStructHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/SomeStruct/SomeStruct:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + private static boolean __active = false; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + synchronized (org.omg.CORBA.TypeCode.class) { + if (__typeCode == null) { + if (__active) { + return org.omg.CORBA.ORB.init().create_recursive_tc(_id); + } + __active = true; + org.omg.CORBA.StructMember[] _members0 = new org.omg.CORBA.StructMember[5]; + org.omg.CORBA.TypeCode _tcOf_members0 = null; + _tcOf_members0 = org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.type(); + _members0[0] = new org.omg.CORBA.StructMember("innerStruct", _tcOf_members0, null); + _tcOf_members0 = org.omg.CORBA.ORB.init().create_string_tc(0); + _members0[1] = new org.omg.CORBA.StructMember("str", _tcOf_members0, null); + _tcOf_members0 = org.omg.CORBA.ORB.init().create_string_tc(0); + _tcOf_members0 = org.omg.CORBA.ORB.init().create_sequence_tc(0, _tcOf_members0); + _tcOf_members0 = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper + .id(), + "string_list", + _tcOf_members0); + _members0[2] = new org.omg.CORBA.StructMember("str_list", _tcOf_members0, null); + _tcOf_members0 = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_long); + _tcOf_members0 = org.omg.CORBA.ORB.init().create_sequence_tc(0, _tcOf_members0); + _tcOf_members0 = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper + .id(), + "long_seq1", + _tcOf_members0); + _tcOf_members0 = org.omg.CORBA.ORB.init().create_sequence_tc(0, _tcOf_members0); + _tcOf_members0 = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper + .id(), + "long_seq2", + _tcOf_members0); + _members0[3] = new org.omg.CORBA.StructMember("twoDimSeq", _tcOf_members0, null); + _tcOf_members0 = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_long); + _tcOf_members0 = org.omg.CORBA.ORB.init().create_sequence_tc(0, _tcOf_members0); + _tcOf_members0 = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper + .id(), + "long_seq1", + _tcOf_members0); + _tcOf_members0 = org.omg.CORBA.ORB.init().create_sequence_tc(0, _tcOf_members0); + _tcOf_members0 = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper + .id(), + "long_seq2", + _tcOf_members0); + _tcOf_members0 = org.omg.CORBA.ORB.init().create_sequence_tc(0, _tcOf_members0); + _tcOf_members0 = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper + .id(), + "long_seq3", + _tcOf_members0); + _members0[4] = new org.omg.CORBA.StructMember("threeDimSeq", _tcOf_members0, null); + __typeCode = + org.omg.CORBA.ORB.init() + .create_struct_tc(org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper + .id(), + "SomeStruct", + _members0); + __active = false; + } + } + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct read(org.omg.CORBA.portable.InputStream istream) { + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct value = + new org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct(); + value.innerStruct = org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.read(istream); + value.str = istream.read_string(); + value.str_list = org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper.read(istream); + value.twoDimSeq = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.read(istream); + value.threeDimSeq = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.read(istream); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct value) { + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.write(ostream, value.innerStruct); + ostream.write_string(value.str); + org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper.write(ostream, value.str_list); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.write(ostream, value.twoDimSeq); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.write(ostream, value.threeDimSeq); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStructHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStructHolder.java new file mode 100644 index 0000000000..3231a136dc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/SomeStructHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/SomeStructHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class SomeStructHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct value = null; + + public SomeStructHolder() { + } + + public SomeStructHolder(org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObject.java new file mode 100644 index 0000000000..28d3ecdc91 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObject.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/TestObject.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public interface TestObject extends TestObjectOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity { +} // interface TestObject diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectHelper.java new file mode 100644 index 0000000000..29ff2edfd2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class TestObjectHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.generated.TestObject that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.TestObject extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = + org.omg.CORBA.ORB.init() + .create_interface_tc(org.apache.tuscany.sca.binding.corba.testing.generated.TestObjectHelper.id(), + "TestObject"); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.TestObject read(org.omg.CORBA.portable.InputStream istream) { + return narrow(istream.read_Object(_TestObjectStub.class)); + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.generated.TestObject value) { + ostream.write_Object((org.omg.CORBA.Object)value); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.TestObject narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.generated.TestObject) + return (org.apache.tuscany.sca.binding.corba.testing.generated.TestObject)obj; + else if (!obj._is_a(id())) + throw new org.omg.CORBA.BAD_PARAM(); + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.generated._TestObjectStub stub = + new org.apache.tuscany.sca.binding.corba.testing.generated._TestObjectStub(); + stub._set_delegate(delegate); + return stub; + } + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.TestObject unchecked_narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.generated.TestObject) + return (org.apache.tuscany.sca.binding.corba.testing.generated.TestObject)obj; + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.generated._TestObjectStub stub = + new org.apache.tuscany.sca.binding.corba.testing.generated._TestObjectStub(); + stub._set_delegate(delegate); + return stub; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectHolder.java new file mode 100644 index 0000000000..b8aea13c8d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class TestObjectHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.generated.TestObject value = null; + + public TestObjectHolder() { + } + + public TestObjectHolder(org.apache.tuscany.sca.binding.corba.testing.generated.TestObject initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.TestObjectHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.TestObjectHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.TestObjectHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectOperations.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectOperations.java new file mode 100644 index 0000000000..0bacb6746a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectOperations.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/TestObjectOperations.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public interface TestObjectOperations { + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct pickStructFromArgs(org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg1, + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg2, + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg3, + int structNumber); + + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct setStruct(org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg); + + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct setSimpleStruct(org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHolder arg); + + int[] setLongSeq1(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Holder arg); + + int[][] setLongSeq2(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Holder arg); + + int[][][] setLongSeq3(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Holder arg); +} // interface TestObjectOperations diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_ArraysSetterImplBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_ArraysSetterImplBase.java new file mode 100644 index 0000000000..c6e8c2a4e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_ArraysSetterImplBase.java @@ -0,0 +1,232 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/_ArraysSetterImplBase.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public abstract class _ArraysSetterImplBase extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter, org.omg.CORBA.portable.InvokeHandler { + + // Constructors + public _ArraysSetterImplBase() { + } + + private static java.util.Hashtable _methods = new java.util.Hashtable(); + static { + _methods.put("setBoolean", new java.lang.Integer(0)); + _methods.put("setChar", new java.lang.Integer(1)); + _methods.put("setWchar", new java.lang.Integer(2)); + _methods.put("setOctet", new java.lang.Integer(3)); + _methods.put("setShort", new java.lang.Integer(4)); + _methods.put("setUnsignedShort", new java.lang.Integer(5)); + _methods.put("setLong", new java.lang.Integer(6)); + _methods.put("setUnsignedLong", new java.lang.Integer(7)); + _methods.put("setLongLong", new java.lang.Integer(8)); + _methods.put("setUnsignedLongLong", new java.lang.Integer(9)); + _methods.put("setFloat", new java.lang.Integer(10)); + _methods.put("setDouble", new java.lang.Integer(11)); + _methods.put("setString", new java.lang.Integer(12)); + _methods.put("setWstring", new java.lang.Integer(13)); + _methods.put("setRemoteObject", new java.lang.Integer(14)); + } + + public org.omg.CORBA.portable.OutputStream _invoke(String $method, + org.omg.CORBA.portable.InputStream in, + org.omg.CORBA.portable.ResponseHandler $rh) { + org.omg.CORBA.portable.OutputStream out = null; + java.lang.Integer __method = (java.lang.Integer)_methods.get($method); + if (__method == null) + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + + switch (__method.intValue()) { + case 0: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setBoolean + { + boolean arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.boolean_listHelper.read(in); + boolean $result[] = null; + $result = this.setBoolean(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.boolean_listHelper.write(out, $result); + break; + } + + case 1: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setChar + { + char arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.char_listHelper.read(in); + char $result[] = null; + $result = this.setChar(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.char_listHelper.write(out, $result); + break; + } + + case 2: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setWchar + { + char arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.wchar_listHelper.read(in); + char $result[] = null; + $result = this.setWchar(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.wchar_listHelper.write(out, $result); + break; + } + + case 3: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setOctet + { + byte arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.octet_listHelper.read(in); + byte $result[] = null; + $result = this.setOctet(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.octet_listHelper.write(out, $result); + break; + } + + case 4: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setShort + { + short arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.short_listHelper.read(in); + short $result[] = null; + $result = this.setShort(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.short_listHelper.write(out, $result); + break; + } + + case 5: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setUnsignedShort + { + short arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_short_listHelper.read(in); + short $result[] = null; + $result = this.setUnsignedShort(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_short_listHelper.write(out, $result); + break; + } + + case 6: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setLong + { + int arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.long_listHelper.read(in); + int $result[] = null; + $result = this.setLong(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.long_listHelper.write(out, $result); + break; + } + + case 7: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setUnsignedLong + { + int arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_listHelper.read(in); + int $result[] = null; + $result = this.setUnsignedLong(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_listHelper.write(out, $result); + break; + } + + case 8: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setLongLong + { + long arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.long_long_listHelper.read(in); + long $result[] = null; + $result = this.setLongLong(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.long_long_listHelper.write(out, $result); + break; + } + + case 9: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setUnsignedLongLong + { + long arg[] = + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_long_listHelper.read(in); + long $result[] = null; + $result = this.setUnsignedLongLong(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_long_listHelper + .write(out, $result); + break; + } + + case 10: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setFloat + { + float arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.float_listHelper.read(in); + float $result[] = null; + $result = this.setFloat(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.float_listHelper.write(out, $result); + break; + } + + case 11: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setDouble + { + double arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.double_listHelper.read(in); + double $result[] = null; + $result = this.setDouble(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.double_listHelper.write(out, $result); + break; + } + + case 12: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setString + { + String arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper.read(in); + String $result[] = null; + $result = this.setString(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper.write(out, $result); + break; + } + + case 13: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setWstring + { + String arg[] = org.apache.tuscany.sca.binding.corba.testing.generated.wstring_listHelper.read(in); + String $result[] = null; + $result = this.setWstring(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.wstring_listHelper.write(out, $result); + break; + } + + case 14: // org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter/setRemoteObject + { + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject obj[] = + org.apache.tuscany.sca.binding.corba.testing.generated.remote_object_listHelper.read(in); + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject $result[] = null; + $result = this.setRemoteObject(obj); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.remote_object_listHelper.write(out, $result); + break; + } + + default: + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + } + + return out; + } // _invoke + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + +} // class _ArraysSetterImplBase diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_ArraysSetterStub.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_ArraysSetterStub.java new file mode 100644 index 0000000000..079cc6e899 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_ArraysSetterStub.java @@ -0,0 +1,343 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/_ArraysSetterStub.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public class _ArraysSetterStub extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.generated.ArraysSetter { + + public boolean[] setBoolean(boolean[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setBoolean", true); + org.apache.tuscany.sca.binding.corba.testing.generated.boolean_listHelper.write($out, arg); + $in = _invoke($out); + boolean $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.boolean_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setBoolean(arg); + } finally { + _releaseReply($in); + } + } // setBoolean + + public char[] setChar(char[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setChar", true); + org.apache.tuscany.sca.binding.corba.testing.generated.char_listHelper.write($out, arg); + $in = _invoke($out); + char $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.char_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setChar(arg); + } finally { + _releaseReply($in); + } + } // setChar + + public char[] setWchar(char[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setWchar", true); + org.apache.tuscany.sca.binding.corba.testing.generated.wchar_listHelper.write($out, arg); + $in = _invoke($out); + char $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.wchar_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setWchar(arg); + } finally { + _releaseReply($in); + } + } // setWchar + + public byte[] setOctet(byte[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setOctet", true); + org.apache.tuscany.sca.binding.corba.testing.generated.octet_listHelper.write($out, arg); + $in = _invoke($out); + byte $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.octet_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setOctet(arg); + } finally { + _releaseReply($in); + } + } // setOctet + + public short[] setShort(short[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setShort", true); + org.apache.tuscany.sca.binding.corba.testing.generated.short_listHelper.write($out, arg); + $in = _invoke($out); + short $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.short_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setShort(arg); + } finally { + _releaseReply($in); + } + } // setShort + + public short[] setUnsignedShort(short[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setUnsignedShort", true); + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_short_listHelper.write($out, arg); + $in = _invoke($out); + short $result[] = + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_short_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setUnsignedShort(arg); + } finally { + _releaseReply($in); + } + } // setUnsignedShort + + public int[] setLong(int[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setLong", true); + org.apache.tuscany.sca.binding.corba.testing.generated.long_listHelper.write($out, arg); + $in = _invoke($out); + int $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.long_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setLong(arg); + } finally { + _releaseReply($in); + } + } // setLong + + public int[] setUnsignedLong(int[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setUnsignedLong", true); + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_listHelper.write($out, arg); + $in = _invoke($out); + int $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setUnsignedLong(arg); + } finally { + _releaseReply($in); + } + } // setUnsignedLong + + public long[] setLongLong(long[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setLongLong", true); + org.apache.tuscany.sca.binding.corba.testing.generated.long_long_listHelper.write($out, arg); + $in = _invoke($out); + long $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.long_long_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setLongLong(arg); + } finally { + _releaseReply($in); + } + } // setLongLong + + public long[] setUnsignedLongLong(long[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setUnsignedLongLong", true); + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_long_listHelper.write($out, arg); + $in = _invoke($out); + long $result[] = + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_long_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setUnsignedLongLong(arg); + } finally { + _releaseReply($in); + } + } // setUnsignedLongLong + + public float[] setFloat(float[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setFloat", true); + org.apache.tuscany.sca.binding.corba.testing.generated.float_listHelper.write($out, arg); + $in = _invoke($out); + float $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.float_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setFloat(arg); + } finally { + _releaseReply($in); + } + } // setFloat + + public double[] setDouble(double[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setDouble", true); + org.apache.tuscany.sca.binding.corba.testing.generated.double_listHelper.write($out, arg); + $in = _invoke($out); + double $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.double_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setDouble(arg); + } finally { + _releaseReply($in); + } + } // setDouble + + public String[] setString(String[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setString", true); + org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper.write($out, arg); + $in = _invoke($out); + String $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setString(arg); + } finally { + _releaseReply($in); + } + } // setString + + public String[] setWstring(String[] arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setWstring", true); + org.apache.tuscany.sca.binding.corba.testing.generated.wstring_listHelper.write($out, arg); + $in = _invoke($out); + String $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.wstring_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setWstring(arg); + } finally { + _releaseReply($in); + } + } // setWstring + + public org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject[] setRemoteObject(org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject[] obj) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setRemoteObject", true); + org.apache.tuscany.sca.binding.corba.testing.generated.remote_object_listHelper.write($out, obj); + $in = _invoke($out); + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject $result[] = + org.apache.tuscany.sca.binding.corba.testing.generated.remote_object_listHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setRemoteObject(obj); + } finally { + _releaseReply($in); + } + } // setRemoteObject + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + + private void readObject(java.io.ObjectInputStream s) throws java.io.IOException { + String str = s.readUTF(); + String[] args = null; + java.util.Properties props = null; + org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init(args, props).string_to_object(str); + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + _set_delegate(delegate); + } + + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + String[] args = null; + java.util.Properties props = null; + String str = org.omg.CORBA.ORB.init(args, props).object_to_string(this); + s.writeUTF(str); + } +} // class _ArraysSetterStub diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_PrimitivesSetterImplBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_PrimitivesSetterImplBase.java new file mode 100644 index 0000000000..b444ce68d8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_PrimitivesSetterImplBase.java @@ -0,0 +1,230 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/_PrimitivesSetterImplBase.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public abstract class _PrimitivesSetterImplBase extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter, org.omg.CORBA.portable.InvokeHandler { + + // Constructors + public _PrimitivesSetterImplBase() { + } + + private static java.util.Hashtable _methods = new java.util.Hashtable(); + static { + _methods.put("setBoolean", new java.lang.Integer(0)); + _methods.put("setChar", new java.lang.Integer(1)); + _methods.put("setWchar", new java.lang.Integer(2)); + _methods.put("setOctet", new java.lang.Integer(3)); + _methods.put("setShort", new java.lang.Integer(4)); + _methods.put("setUnsignedShort", new java.lang.Integer(5)); + _methods.put("setLong", new java.lang.Integer(6)); + _methods.put("setUnsignedLong", new java.lang.Integer(7)); + _methods.put("setLongLong", new java.lang.Integer(8)); + _methods.put("setUnsignedLongLong", new java.lang.Integer(9)); + _methods.put("setFloat", new java.lang.Integer(10)); + _methods.put("setDouble", new java.lang.Integer(11)); + _methods.put("setString", new java.lang.Integer(12)); + _methods.put("setWstring", new java.lang.Integer(13)); + _methods.put("setRemoteObject", new java.lang.Integer(14)); + } + + public org.omg.CORBA.portable.OutputStream _invoke(String $method, + org.omg.CORBA.portable.InputStream in, + org.omg.CORBA.portable.ResponseHandler $rh) { + org.omg.CORBA.portable.OutputStream out = null; + java.lang.Integer __method = (java.lang.Integer)_methods.get($method); + if (__method == null) + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + + switch (__method.intValue()) { + case 0: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setBoolean + { + boolean arg = in.read_boolean(); + boolean $result = false; + $result = this.setBoolean(arg); + out = $rh.createReply(); + out.write_boolean($result); + break; + } + + case 1: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setChar + { + char arg = in.read_char(); + char $result = (char)0; + $result = this.setChar(arg); + out = $rh.createReply(); + out.write_char($result); + break; + } + + case 2: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setWchar + { + char arg = in.read_wchar(); + char $result = (char)0; + $result = this.setWchar(arg); + out = $rh.createReply(); + out.write_wchar($result); + break; + } + + case 3: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setOctet + { + byte arg = in.read_octet(); + byte $result = (byte)0; + $result = this.setOctet(arg); + out = $rh.createReply(); + out.write_octet($result); + break; + } + + case 4: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setShort + { + short arg = in.read_short(); + short $result = (short)0; + $result = this.setShort(arg); + out = $rh.createReply(); + out.write_short($result); + break; + } + + case 5: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setUnsignedShort + { + short arg = in.read_ushort(); + short $result = (short)0; + $result = this.setUnsignedShort(arg); + out = $rh.createReply(); + out.write_ushort($result); + break; + } + + case 6: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setLong + { + int arg = in.read_long(); + int $result = (int)0; + $result = this.setLong(arg); + out = $rh.createReply(); + out.write_long($result); + break; + } + + case 7: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setUnsignedLong + { + int arg = in.read_ulong(); + int $result = (int)0; + $result = this.setUnsignedLong(arg); + out = $rh.createReply(); + out.write_ulong($result); + break; + } + + case 8: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setLongLong + { + long arg = in.read_longlong(); + long $result = (long)0; + $result = this.setLongLong(arg); + out = $rh.createReply(); + out.write_longlong($result); + break; + } + + case 9: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setUnsignedLongLong + { + long arg = in.read_ulonglong(); + long $result = (long)0; + $result = this.setUnsignedLongLong(arg); + out = $rh.createReply(); + out.write_ulonglong($result); + break; + } + + case 10: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setFloat + { + float arg = in.read_float(); + float $result = (float)0; + $result = this.setFloat(arg); + out = $rh.createReply(); + out.write_float($result); + break; + } + + case 11: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setDouble + { + double arg = in.read_double(); + double $result = (double)0; + $result = this.setDouble(arg); + out = $rh.createReply(); + out.write_double($result); + break; + } + + case 12: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setString + { + String arg = in.read_string(); + String $result = null; + $result = this.setString(arg); + out = $rh.createReply(); + out.write_string($result); + break; + } + + case 13: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setWstring + { + String arg = in.read_wstring(); + String $result = null; + $result = this.setWstring(arg); + out = $rh.createReply(); + out.write_wstring($result); + break; + } + + case 14: // org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter/setRemoteObject + { + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject obj = + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.read(in); + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject $result = null; + $result = this.setRemoteObject(obj); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.write(out, $result); + break; + } + + default: + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + } + + return out; + } // _invoke + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + +} // class _PrimitivesSetterImplBase diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_PrimitivesSetterStub.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_PrimitivesSetterStub.java new file mode 100644 index 0000000000..0b08e1fb67 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_PrimitivesSetterStub.java @@ -0,0 +1,341 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/_PrimitivesSetterStub.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public class _PrimitivesSetterStub extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.generated.PrimitivesSetter { + + public boolean setBoolean(boolean arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setBoolean", true); + $out.write_boolean(arg); + $in = _invoke($out); + boolean $result = $in.read_boolean(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setBoolean(arg); + } finally { + _releaseReply($in); + } + } // setBoolean + + public char setChar(char arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setChar", true); + $out.write_char(arg); + $in = _invoke($out); + char $result = $in.read_char(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setChar(arg); + } finally { + _releaseReply($in); + } + } // setChar + + public char setWchar(char arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setWchar", true); + $out.write_wchar(arg); + $in = _invoke($out); + char $result = $in.read_wchar(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setWchar(arg); + } finally { + _releaseReply($in); + } + } // setWchar + + public byte setOctet(byte arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setOctet", true); + $out.write_octet(arg); + $in = _invoke($out); + byte $result = $in.read_octet(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setOctet(arg); + } finally { + _releaseReply($in); + } + } // setOctet + + public short setShort(short arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setShort", true); + $out.write_short(arg); + $in = _invoke($out); + short $result = $in.read_short(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setShort(arg); + } finally { + _releaseReply($in); + } + } // setShort + + public short setUnsignedShort(short arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setUnsignedShort", true); + $out.write_ushort(arg); + $in = _invoke($out); + short $result = $in.read_ushort(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setUnsignedShort(arg); + } finally { + _releaseReply($in); + } + } // setUnsignedShort + + public int setLong(int arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setLong", true); + $out.write_long(arg); + $in = _invoke($out); + int $result = $in.read_long(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setLong(arg); + } finally { + _releaseReply($in); + } + } // setLong + + public int setUnsignedLong(int arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setUnsignedLong", true); + $out.write_ulong(arg); + $in = _invoke($out); + int $result = $in.read_ulong(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setUnsignedLong(arg); + } finally { + _releaseReply($in); + } + } // setUnsignedLong + + public long setLongLong(long arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setLongLong", true); + $out.write_longlong(arg); + $in = _invoke($out); + long $result = $in.read_longlong(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setLongLong(arg); + } finally { + _releaseReply($in); + } + } // setLongLong + + public long setUnsignedLongLong(long arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setUnsignedLongLong", true); + $out.write_ulonglong(arg); + $in = _invoke($out); + long $result = $in.read_ulonglong(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setUnsignedLongLong(arg); + } finally { + _releaseReply($in); + } + } // setUnsignedLongLong + + public float setFloat(float arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setFloat", true); + $out.write_float(arg); + $in = _invoke($out); + float $result = $in.read_float(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setFloat(arg); + } finally { + _releaseReply($in); + } + } // setFloat + + public double setDouble(double arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setDouble", true); + $out.write_double(arg); + $in = _invoke($out); + double $result = $in.read_double(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setDouble(arg); + } finally { + _releaseReply($in); + } + } // setDouble + + public String setString(String arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setString", true); + $out.write_string(arg); + $in = _invoke($out); + String $result = $in.read_string(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setString(arg); + } finally { + _releaseReply($in); + } + } // setString + + public String setWstring(String arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setWstring", true); + $out.write_wstring(arg); + $in = _invoke($out); + String $result = $in.read_wstring(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setWstring(arg); + } finally { + _releaseReply($in); + } + } // setWstring + + public org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject setRemoteObject(org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject obj) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setRemoteObject", true); + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.write($out, obj); + $in = _invoke($out); + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject $result = + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setRemoteObject(obj); + } finally { + _releaseReply($in); + } + } // setRemoteObject + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + + private void readObject(java.io.ObjectInputStream s) throws java.io.IOException { + String str = s.readUTF(); + String[] args = null; + java.util.Properties props = null; + org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init(args, props).string_to_object(str); + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + _set_delegate(delegate); + } + + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + String[] args = null; + java.util.Properties props = null; + String str = org.omg.CORBA.ORB.init(args, props).object_to_string(this); + s.writeUTF(str); + } +} // class _PrimitivesSetterStub diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_RemoteObjectImplBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_RemoteObjectImplBase.java new file mode 100644 index 0000000000..a87534f88b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_RemoteObjectImplBase.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/_RemoteObjectImplBase.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public abstract class _RemoteObjectImplBase extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject, org.omg.CORBA.portable.InvokeHandler { + + // Constructors + public _RemoteObjectImplBase() { + } + + private static java.util.Hashtable _methods = new java.util.Hashtable(); + static { + } + + public org.omg.CORBA.portable.OutputStream _invoke(String $method, + org.omg.CORBA.portable.InputStream in, + org.omg.CORBA.portable.ResponseHandler $rh) { + org.omg.CORBA.portable.OutputStream out = null; + java.lang.Integer __method = (java.lang.Integer)_methods.get($method); + if (__method == null) + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + + return out; + } // _invoke + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObject:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + +} // class _RemoteObjectImplBase diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_RemoteObjectStub.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_RemoteObjectStub.java new file mode 100644 index 0000000000..e219dfa338 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_RemoteObjectStub.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/_RemoteObjectStub.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public class _RemoteObjectStub extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject { + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/RemoteObject:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + + private void readObject(java.io.ObjectInputStream s) throws java.io.IOException { + String str = s.readUTF(); + String[] args = null; + java.util.Properties props = null; + org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init(args, props).string_to_object(str); + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + _set_delegate(delegate); + } + + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + String[] args = null; + java.util.Properties props = null; + String str = org.omg.CORBA.ORB.init(args, props).object_to_string(this); + s.writeUTF(str); + } +} // class _RemoteObjectStub diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_TestObjectImplBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_TestObjectImplBase.java new file mode 100644 index 0000000000..c0bc0d6ebd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_TestObjectImplBase.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/_TestObjectImplBase.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public abstract class _TestObjectImplBase extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.generated.TestObject, org.omg.CORBA.portable.InvokeHandler { + + // Constructors + public _TestObjectImplBase() { + } + + private static java.util.Hashtable _methods = new java.util.Hashtable(); + static { + _methods.put("pickStructFromArgs", new java.lang.Integer(0)); + _methods.put("setStruct", new java.lang.Integer(1)); + _methods.put("setSimpleStruct", new java.lang.Integer(2)); + _methods.put("setLongSeq1", new java.lang.Integer(3)); + _methods.put("setLongSeq2", new java.lang.Integer(4)); + _methods.put("setLongSeq3", new java.lang.Integer(5)); + } + + public org.omg.CORBA.portable.OutputStream _invoke(String $method, + org.omg.CORBA.portable.InputStream in, + org.omg.CORBA.portable.ResponseHandler $rh) { + org.omg.CORBA.portable.OutputStream out = null; + java.lang.Integer __method = (java.lang.Integer)_methods.get($method); + if (__method == null) + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + + switch (__method.intValue()) { + case 0: // org/apache/tuscany/sca/binding/corba/testing/generated/TestObject/pickStructFromArgs + { + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg1 = + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.read(in); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg2 = + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.read(in); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg3 = + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.read(in); + int structNumber = in.read_long(); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct $result = null; + $result = this.pickStructFromArgs(arg1, arg2, arg3, structNumber); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.write(out, $result); + break; + } + + case 1: // org/apache/tuscany/sca/binding/corba/testing/generated/TestObject/setStruct + { + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg = + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.read(in); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct $result = null; + $result = this.setStruct(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.write(out, $result); + break; + } + + case 2: // org/apache/tuscany/sca/binding/corba/testing/generated/TestObject/setSimpleStruct + { + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHolder arg = + new org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHolder(); + arg.value = org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.read(in); + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct $result = null; + $result = this.setSimpleStruct(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.write(out, $result); + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.write(out, arg.value); + break; + } + + case 3: // org/apache/tuscany/sca/binding/corba/testing/generated/TestObject/setLongSeq1 + { + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Holder arg = + new org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Holder(); + arg.value = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.read(in); + int $result[] = null; + $result = this.setLongSeq1(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.write(out, $result); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.write(out, arg.value); + break; + } + + case 4: // org/apache/tuscany/sca/binding/corba/testing/generated/TestObject/setLongSeq2 + { + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Holder arg = + new org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Holder(); + arg.value = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.read(in); + int $result[][] = null; + $result = this.setLongSeq2(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.write(out, $result); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.write(out, arg.value); + break; + } + + case 5: // org/apache/tuscany/sca/binding/corba/testing/generated/TestObject/setLongSeq3 + { + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Holder arg = + new org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Holder(); + arg.value = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.read(in); + int $result[][][] = null; + $result = this.setLongSeq3(arg); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.write(out, $result); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.write(out, arg.value); + break; + } + + default: + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + } + + return out; + } // _invoke + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + +} // class _TestObjectImplBase diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_TestObjectStub.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_TestObjectStub.java new file mode 100644 index 0000000000..ad47595ddf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/_TestObjectStub.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/_TestObjectStub.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public class _TestObjectStub extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.generated.TestObject { + + public org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct pickStructFromArgs(org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg1, + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg2, + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg3, + int structNumber) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("pickStructFromArgs", true); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.write($out, arg1); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.write($out, arg2); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.write($out, arg3); + $out.write_long(structNumber); + $in = _invoke($out); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct $result = + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return pickStructFromArgs(arg1, arg2, arg3, structNumber); + } finally { + _releaseReply($in); + } + } // pickStructFromArgs + + public org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct setStruct(org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setStruct", true); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.write($out, arg); + $in = _invoke($out); + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct $result = + org.apache.tuscany.sca.binding.corba.testing.generated.SomeStructHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setStruct(arg); + } finally { + _releaseReply($in); + } + } // setStruct + + public org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct setSimpleStruct(org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHolder arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setSimpleStruct", true); + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.write($out, arg.value); + $in = _invoke($out); + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct $result = + org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.read($in); + arg.value = org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setSimpleStruct(arg); + } finally { + _releaseReply($in); + } + } // setSimpleStruct + + public int[] setLongSeq1(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Holder arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setLongSeq1", true); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.write($out, arg.value); + $in = _invoke($out); + int $result[] = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.read($in); + arg.value = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setLongSeq1(arg); + } finally { + _releaseReply($in); + } + } // setLongSeq1 + + public int[][] setLongSeq2(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Holder arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setLongSeq2", true); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.write($out, arg.value); + $in = _invoke($out); + int $result[][] = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.read($in); + arg.value = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setLongSeq2(arg); + } finally { + _releaseReply($in); + } + } // setLongSeq2 + + public int[][][] setLongSeq3(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Holder arg) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("setLongSeq3", true); + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.write($out, arg.value); + $in = _invoke($out); + int $result[][][] = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.read($in); + arg.value = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return setLongSeq3(arg); + } finally { + _releaseReply($in); + } + } // setLongSeq3 + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + + private void readObject(java.io.ObjectInputStream s) throws java.io.IOException { + String str = s.readUTF(); + String[] args = null; + java.util.Properties props = null; + org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init(args, props).string_to_object(str); + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + _set_delegate(delegate); + } + + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + String[] args = null; + java.util.Properties props = null; + String str = org.omg.CORBA.ORB.init(args, props).object_to_string(this); + s.writeUTF(str); + } +} // class _TestObjectStub diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/boolean_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/boolean_listHelper.java new file mode 100644 index 0000000000..f3d96e8fd7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/boolean_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/boolean_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +abstract public class boolean_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/boolean_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, boolean[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static boolean[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_boolean); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.boolean_listHelper.id(), + "boolean_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static boolean[] read(org.omg.CORBA.portable.InputStream istream) { + boolean value[] = null; + int _len0 = istream.read_long(); + value = new boolean[_len0]; + istream.read_boolean_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, boolean[] value) { + ostream.write_long(value.length); + ostream.write_boolean_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/boolean_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/boolean_listHolder.java new file mode 100644 index 0000000000..cb0ab8bcfd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/boolean_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/boolean_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public final class boolean_listHolder implements org.omg.CORBA.portable.Streamable { + public boolean value[] = null; + + public boolean_listHolder() { + } + + public boolean_listHolder(boolean[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.boolean_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.boolean_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.boolean_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/char_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/char_listHelper.java new file mode 100644 index 0000000000..0bde1e701c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/char_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/char_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +abstract public class char_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/char_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, char[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static char[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_char); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.char_listHelper.id(), + "char_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static char[] read(org.omg.CORBA.portable.InputStream istream) { + char value[] = null; + int _len0 = istream.read_long(); + value = new char[_len0]; + istream.read_char_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, char[] value) { + ostream.write_long(value.length); + ostream.write_char_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/char_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/char_listHolder.java new file mode 100644 index 0000000000..19b2942cfe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/char_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/char_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public final class char_listHolder implements org.omg.CORBA.portable.Streamable { + public char value[] = null; + + public char_listHolder() { + } + + public char_listHolder(char[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.char_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.char_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.char_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/double_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/double_listHelper.java new file mode 100644 index 0000000000..8bb5a9c69d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/double_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/double_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +abstract public class double_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/double_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, double[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static double[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_double); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.double_listHelper.id(), + "double_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static double[] read(org.omg.CORBA.portable.InputStream istream) { + double value[] = null; + int _len0 = istream.read_long(); + value = new double[_len0]; + istream.read_double_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, double[] value) { + ostream.write_long(value.length); + ostream.write_double_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/double_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/double_listHolder.java new file mode 100644 index 0000000000..dc89e71092 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/double_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/double_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public final class double_listHolder implements org.omg.CORBA.portable.Streamable { + public double value[] = null; + + public double_listHolder() { + } + + public double_listHolder(double[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.double_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.double_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.double_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/float_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/float_listHelper.java new file mode 100644 index 0000000000..7b71aa0a9f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/float_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/float_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +abstract public class float_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/float_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, float[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static float[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_float); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.float_listHelper.id(), + "float_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static float[] read(org.omg.CORBA.portable.InputStream istream) { + float value[] = null; + int _len0 = istream.read_long(); + value = new float[_len0]; + istream.read_float_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, float[] value) { + ostream.write_long(value.length); + ostream.write_float_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/float_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/float_listHolder.java new file mode 100644 index 0000000000..513bab37cc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/float_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/float_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public final class float_listHolder implements org.omg.CORBA.portable.Streamable { + public float value[] = null; + + public float_listHolder() { + } + + public float_listHolder(float[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.float_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.float_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.float_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_listHelper.java new file mode 100644 index 0000000000..c1d06e2ba9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/long_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +abstract public class long_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/long_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, int[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static int[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_long); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_listHelper.id(), + "long_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static int[] read(org.omg.CORBA.portable.InputStream istream) { + int value[] = null; + int _len0 = istream.read_long(); + value = new int[_len0]; + istream.read_long_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, int[] value) { + ostream.write_long(value.length); + ostream.write_long_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_listHolder.java new file mode 100644 index 0000000000..f9ad7b77ac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/long_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public final class long_listHolder implements org.omg.CORBA.portable.Streamable { + public int value[] = null; + + public long_listHolder() { + } + + public long_listHolder(int[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.long_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.long_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.long_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_long_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_long_listHelper.java new file mode 100644 index 0000000000..cfb292fc01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_long_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/long_long_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +abstract public class long_long_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/long_long_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, long[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static long[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_longlong); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_long_listHelper.id(), + "long_long_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static long[] read(org.omg.CORBA.portable.InputStream istream) { + long value[] = null; + int _len0 = istream.read_long(); + value = new long[_len0]; + istream.read_longlong_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, long[] value) { + ostream.write_long(value.length); + ostream.write_longlong_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_long_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_long_listHolder.java new file mode 100644 index 0000000000..02f46a7d85 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_long_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/long_long_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 14:12:28 CEST +*/ + +public final class long_long_listHolder implements org.omg.CORBA.portable.Streamable { + public long value[] = null; + + public long_long_listHolder() { + } + + public long_long_listHolder(long[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.long_long_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.long_long_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.long_long_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1Helper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1Helper.java new file mode 100644 index 0000000000..505aa3f026 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1Helper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1Helper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class long_seq1Helper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1:1.0"; + + public static void insert(org.omg.CORBA.Any a, int[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static int[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_long); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.id(), + "long_seq1", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static int[] read(org.omg.CORBA.portable.InputStream istream) { + int value[] = null; + int _len0 = istream.read_long(); + value = new int[_len0]; + istream.read_long_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, int[] value) { + ostream.write_long(value.length); + ostream.write_long_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1Holder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1Holder.java new file mode 100644 index 0000000000..5cbaa109ee --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1Holder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/long_seq1Holder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class long_seq1Holder implements org.omg.CORBA.portable.Streamable { + public int value[] = null; + + public long_seq1Holder() { + } + + public long_seq1Holder(int[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2Helper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2Helper.java new file mode 100644 index 0000000000..2f792888fb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2Helper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2Helper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class long_seq2Helper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2:1.0"; + + public static void insert(org.omg.CORBA.Any a, int[][] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static int[][] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_long); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.id(), + "long_seq1", + __typeCode); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.id(), + "long_seq2", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static int[][] read(org.omg.CORBA.portable.InputStream istream) { + int value[][] = null; + int _len0 = istream.read_long(); + value = new int[_len0][]; + for (int _o1 = 0; _o1 < value.length; ++_o1) + value[_o1] = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.read(istream); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, int[][] value) { + ostream.write_long(value.length); + for (int _i0 = 0; _i0 < value.length; ++_i0) + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.write(ostream, value[_i0]); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2Holder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2Holder.java new file mode 100644 index 0000000000..8b2ccc1f73 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2Holder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/long_seq2Holder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class long_seq2Holder implements org.omg.CORBA.portable.Streamable { + public int value[][] = null; + + public long_seq2Holder() { + } + + public long_seq2Holder(int[][] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3Helper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3Helper.java new file mode 100644 index 0000000000..67e224f0be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3Helper.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3Helper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class long_seq3Helper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3:1.0"; + + public static void insert(org.omg.CORBA.Any a, int[][][] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static int[][][] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_long); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Helper.id(), + "long_seq1", + __typeCode); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.id(), + "long_seq2", + __typeCode); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.id(), + "long_seq3", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static int[][][] read(org.omg.CORBA.portable.InputStream istream) { + int value[][][] = null; + int _len0 = istream.read_long(); + value = new int[_len0][][]; + for (int _o1 = 0; _o1 < value.length; ++_o1) + value[_o1] = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.read(istream); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, int[][][] value) { + ostream.write_long(value.length); + for (int _i0 = 0; _i0 < value.length; ++_i0) + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Helper.write(ostream, value[_i0]); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3Holder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3Holder.java new file mode 100644 index 0000000000..5d4adfba2d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3Holder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/long_seq3Holder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class long_seq3Holder implements org.omg.CORBA.portable.Streamable { + public int value[][][] = null; + + public long_seq3Holder() { + } + + public long_seq3Holder(int[][][] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Helper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/octet_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/octet_listHelper.java new file mode 100644 index 0000000000..c7d86d9179 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/octet_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/octet_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class octet_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/octet_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, byte[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static byte[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_octet); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.octet_listHelper.id(), + "octet_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static byte[] read(org.omg.CORBA.portable.InputStream istream) { + byte value[] = null; + int _len0 = istream.read_long(); + value = new byte[_len0]; + istream.read_octet_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, byte[] value) { + ostream.write_long(value.length); + ostream.write_octet_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/octet_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/octet_listHolder.java new file mode 100644 index 0000000000..09b2b85c6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/octet_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/octet_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class octet_listHolder implements org.omg.CORBA.portable.Streamable { + public byte value[] = null; + + public octet_listHolder() { + } + + public octet_listHolder(byte[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.octet_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.octet_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.octet_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_listHelper.java new file mode 100644 index 0000000000..e88b1e06c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class remote_object_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.type(); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.remote_object_listHelper + .id(), + "remote_object_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject[] read(org.omg.CORBA.portable.InputStream istream) { + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject value[] = null; + int _len0 = istream.read_long(); + value = new org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject[_len0]; + for (int _o1 = 0; _o1 < value.length; ++_o1) + value[_o1] = org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.read(istream); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject[] value) { + ostream.write_long(value.length); + for (int _i0 = 0; _i0 < value.length; ++_i0) + org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObjectHelper.write(ostream, value[_i0]); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_listHolder.java new file mode 100644 index 0000000000..d3f996c5b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/remote_object_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class remote_object_listHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject value[] = null; + + public remote_object_listHolder() { + } + + public remote_object_listHolder(org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.remote_object_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.remote_object_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.remote_object_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/short_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/short_listHelper.java new file mode 100644 index 0000000000..7c58d47f7c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/short_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/short_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class short_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/short_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, short[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static short[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_short); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.short_listHelper.id(), + "short_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static short[] read(org.omg.CORBA.portable.InputStream istream) { + short value[] = null; + int _len0 = istream.read_long(); + value = new short[_len0]; + istream.read_short_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, short[] value) { + ostream.write_long(value.length); + ostream.write_short_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/short_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/short_listHolder.java new file mode 100644 index 0000000000..5be5a65c43 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/short_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/short_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class short_listHolder implements org.omg.CORBA.portable.Streamable { + public short value[] = null; + + public short_listHolder() { + } + + public short_listHolder(short[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.short_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.short_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.short_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/string_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/string_listHelper.java new file mode 100644 index 0000000000..a40d5fa8de --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/string_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/string_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class string_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/string_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, String[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static String[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().create_string_tc(0); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper.id(), + "string_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static String[] read(org.omg.CORBA.portable.InputStream istream) { + String value[] = null; + int _len0 = istream.read_long(); + value = new String[_len0]; + for (int _o1 = 0; _o1 < value.length; ++_o1) + value[_o1] = istream.read_string(); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, String[] value) { + ostream.write_long(value.length); + for (int _i0 = 0; _i0 < value.length; ++_i0) + ostream.write_string(value[_i0]); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/string_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/string_listHolder.java new file mode 100644 index 0000000000..76f99408f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/string_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/string_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class string_listHolder implements org.omg.CORBA.portable.Streamable { + public String value[] = null; + + public string_listHolder() { + } + + public string_listHolder(String[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.string_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_listHelper.java new file mode 100644 index 0000000000..d7594b0815 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class unsigned_long_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, int[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static int[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_ulong); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_listHelper + .id(), + "unsigned_long_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static int[] read(org.omg.CORBA.portable.InputStream istream) { + int value[] = null; + int _len0 = istream.read_long(); + value = new int[_len0]; + istream.read_ulong_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, int[] value) { + ostream.write_long(value.length); + ostream.write_ulong_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_listHolder.java new file mode 100644 index 0000000000..e9fbcccc36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class unsigned_long_listHolder implements org.omg.CORBA.portable.Streamable { + public int value[] = null; + + public unsigned_long_listHolder() { + } + + public unsigned_long_listHolder(int[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_listHelper.java new file mode 100644 index 0000000000..6ef187c4e5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class unsigned_long_long_listHelper { + private static String _id = + "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, long[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static long[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_ulonglong); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB + .init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_long_listHelper + .id(), + "unsigned_long_long_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static long[] read(org.omg.CORBA.portable.InputStream istream) { + long value[] = null; + int _len0 = istream.read_long(); + value = new long[_len0]; + istream.read_ulonglong_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, long[] value) { + ostream.write_long(value.length); + ostream.write_ulonglong_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_listHolder.java new file mode 100644 index 0000000000..59bc015c38 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_long_long_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class unsigned_long_long_listHolder implements org.omg.CORBA.portable.Streamable { + public long value[] = null; + + public unsigned_long_long_listHolder() { + } + + public unsigned_long_long_listHolder(long[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_long_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_long_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_long_long_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_listHelper.java new file mode 100644 index 0000000000..ec4526cebf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class unsigned_short_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, short[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static short[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_ushort); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_short_listHelper + .id(), + "unsigned_short_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static short[] read(org.omg.CORBA.portable.InputStream istream) { + short value[] = null; + int _len0 = istream.read_long(); + value = new short[_len0]; + istream.read_ushort_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, short[] value) { + ostream.write_long(value.length); + ostream.write_ushort_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_listHolder.java new file mode 100644 index 0000000000..56ab28f0be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/unsigned_short_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class unsigned_short_listHolder implements org.omg.CORBA.portable.Streamable { + public short value[] = null; + + public unsigned_short_listHolder() { + } + + public unsigned_short_listHolder(short[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_short_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_short_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.unsigned_short_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wchar_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wchar_listHelper.java new file mode 100644 index 0000000000..73a10d3b7f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wchar_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/wchar_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class wchar_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/wchar_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, char[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static char[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.tk_wchar); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.wchar_listHelper.id(), + "wchar_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static char[] read(org.omg.CORBA.portable.InputStream istream) { + char value[] = null; + int _len0 = istream.read_long(); + value = new char[_len0]; + istream.read_wchar_array(value, 0, _len0); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, char[] value) { + ostream.write_long(value.length); + ostream.write_wchar_array(value, 0, value.length); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wchar_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wchar_listHolder.java new file mode 100644 index 0000000000..c5c1e87756 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wchar_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/wchar_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class wchar_listHolder implements org.omg.CORBA.portable.Streamable { + public char value[] = null; + + public wchar_listHolder() { + } + + public wchar_listHolder(char[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.wchar_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.wchar_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.wchar_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wstring_listHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wstring_listHelper.java new file mode 100644 index 0000000000..3e45568f01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wstring_listHelper.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/wstring_listHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +abstract public class wstring_listHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/wstring_list:1.0"; + + public static void insert(org.omg.CORBA.Any a, String[] that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static String[] extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = org.omg.CORBA.ORB.init().create_wstring_tc(0); + __typeCode = org.omg.CORBA.ORB.init().create_sequence_tc(0, __typeCode); + __typeCode = + org.omg.CORBA.ORB.init() + .create_alias_tc(org.apache.tuscany.sca.binding.corba.testing.generated.wstring_listHelper.id(), + "wstring_list", + __typeCode); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static String[] read(org.omg.CORBA.portable.InputStream istream) { + String value[] = null; + int _len0 = istream.read_long(); + value = new String[_len0]; + for (int _o1 = 0; _o1 < value.length; ++_o1) + value[_o1] = istream.read_wstring(); + return value; + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, String[] value) { + ostream.write_long(value.length); + for (int _i0 = 0; _i0 < value.length; ++_i0) + ostream.write_wstring(value[_i0]); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wstring_listHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wstring_listHolder.java new file mode 100644 index 0000000000..bdbf9d995b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/generated/wstring_listHolder.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.sca.binding.corba.testing.generated; + +/** +* org/apache/tuscany/sca/binding/corba/testing/generated/wstring_listHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from general_tests.idl +* monday, 23 june 2008 2008 14:12:28 CEST +*/ + +public final class wstring_listHolder implements org.omg.CORBA.portable.Streamable { + public String value[] = null; + + public wstring_listHolder() { + } + + public wstring_listHolder(String[] initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.generated.wstring_listHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.generated.wstring_listHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.generated.wstring_listHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/ArraysTestStruct.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/ArraysTestStruct.java new file mode 100644 index 0000000000..7f90520d67 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/ArraysTestStruct.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.sca.binding.corba.testing.hierarchy; + +import org.apache.tuscany.sca.binding.corba.meta.CorbaArray; + +public final class ArraysTestStruct { + + public ArraysTestStruct() { + + } + + public ArraysTestStruct(String[] field1, int[][] field2, float[][][] field3) { + this.field1 = field1; + this.field2 = field2; + this.field3 = field3; + } + + @CorbaArray( {2}) + public String[] field1; + + @CorbaArray( {2, 4}) + public int[][] field2; + + @CorbaArray( {2, 4, 2}) + public float[][][] field3; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/Calc.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/Calc.java new file mode 100644 index 0000000000..7c33b1d449 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/Calc.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.sca.binding.corba.testing.hierarchy; + +import org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero; + +public interface Calc { + + public double div(double arg1, double arg2) throws DivByZero; + + public double divForSmallArgs(double arg1, double arg2); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/DummyObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/DummyObject.java new file mode 100644 index 0000000000..d0ebff5fec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/DummyObject.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.sca.binding.corba.testing.hierarchy; + +public interface DummyObject { + + int getLong(); + + DummyObject cloneObject(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InnerUnion.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InnerUnion.java new file mode 100644 index 0000000000..baf5043bc2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InnerUnion.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.sca.binding.corba.testing.hierarchy; + +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElement; +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElementType; + +public final class InnerUnion { + + @CorbaUnionElement(type = CorbaUnionElementType.option, optionNumber = 1) + private int x; + + @CorbaUnionElement(type = CorbaUnionElementType.option, optionNumber = 2) + private float y; + + @CorbaUnionElement(type = CorbaUnionElementType.discriminator) + @SuppressWarnings("unused") + private int discriminator; + + public int getX() { + return x; + } + + public void setX(int x) { + discriminator = 1; + this.x = x; + } + + public float getY() { + return y; + } + + public void setY(float y) { + discriminator = 2; + this.y = y; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidCorbaArray.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidCorbaArray.java new file mode 100644 index 0000000000..9ad637fc55 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidCorbaArray.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.sca.binding.corba.testing.hierarchy; + +import org.apache.tuscany.sca.binding.corba.meta.CorbaArray; + +public final class InvalidCorbaArray { + + // annotation argument array is not equal to declared arrays dimension + @CorbaArray( {1}) + public String[][] array; + + public InvalidCorbaArray() { + + } + + public InvalidCorbaArray(String[][] arg) { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum1.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum1.java new file mode 100644 index 0000000000..0c9de5bb31 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum1.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.sca.binding.corba.testing.hierarchy; + +public class InvalidEnum1 { + + public static final InvalidEnum1 red = new InvalidEnum1(0); + + public int value() { + return 0; + } + + public static InvalidEnum1 from_int(int value) { + return null; + } + + protected InvalidEnum1(int value) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum2.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum2.java new file mode 100644 index 0000000000..8746eb7f9b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum2.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.sca.binding.corba.testing.hierarchy; + +public class InvalidEnum2 { + + public static final int _red = 0; + public static final InvalidEnum2 red = new InvalidEnum2(_red); + + public static InvalidEnum2 from_int(int value) { + return null; + } + + protected InvalidEnum2(int value) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum3.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum3.java new file mode 100644 index 0000000000..6d124b0485 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidEnum3.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.sca.binding.corba.testing.hierarchy; + +public class InvalidEnum3 { + + public static final int _red = 0; + public static final InvalidEnum2 red = new InvalidEnum2(_red); + + public int value() { + return 0; + } + + protected InvalidEnum3(int value) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct1.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct1.java new file mode 100644 index 0000000000..8cf66e2fac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct1.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.sca.binding.corba.testing.hierarchy; + +public final class InvalidStruct1 { + + public InvalidStruct1() { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct2.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct2.java new file mode 100644 index 0000000000..5f361512f0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct2.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.sca.binding.corba.testing.hierarchy; + +public final class InvalidStruct2 { + + public int f1; + public String f2; + + public InvalidStruct2(int f1, String f2) { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct3.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct3.java new file mode 100644 index 0000000000..adc81ea5a2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidStruct3.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.sca.binding.corba.testing.hierarchy; + +public final class InvalidStruct3 { + + public int f1; + public String f2; + public static byte f3; + + public InvalidStruct3() { + + } + + public InvalidStruct3(int f1, String f2, byte f3) { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion1.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion1.java new file mode 100644 index 0000000000..c3fd45d5f4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion1.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.sca.binding.corba.testing.hierarchy; + +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElement; +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElementType; + +/** + * More than one discriminators + */ +public final class InvalidUnion1 { + + @CorbaUnionElement(type = CorbaUnionElementType.discriminator) + @SuppressWarnings("unused") + private int a; + @CorbaUnionElement(type = CorbaUnionElementType.discriminator) + @SuppressWarnings("unused") + private int b; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion2.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion2.java new file mode 100644 index 0000000000..f6d5421a56 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion2.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.sca.binding.corba.testing.hierarchy; + +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElement; +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElementType; + +/** + * Discriminator is missing + */ +public final class InvalidUnion2 { + + @CorbaUnionElement(type=CorbaUnionElementType.defaultOption) + @SuppressWarnings("unused") + private int a; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion3.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion3.java new file mode 100644 index 0000000000..0d1bdd0a13 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion3.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.sca.binding.corba.testing.hierarchy; + +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElement; +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElementType; + +/** + * No option, only discriminator + */ +public final class InvalidUnion3{ + + @CorbaUnionElement(type = CorbaUnionElementType.discriminator) + @SuppressWarnings("unused") + private int a; + +} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion4.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion4.java new file mode 100644 index 0000000000..3afe702f87 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion4.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.sca.binding.corba.testing.hierarchy; + +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElement; +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElementType; + +/** + * Invalid field modifiers + */ +public final class InvalidUnion4{ + + @CorbaUnionElement(type = CorbaUnionElementType.discriminator) + @SuppressWarnings("unused") + private static int a; + + @CorbaUnionElement(type = CorbaUnionElementType.defaultOption) + @SuppressWarnings("unused") + private static int b; + +} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion5.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion5.java new file mode 100644 index 0000000000..9d30e5ced1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/InvalidUnion5.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.sca.binding.corba.testing.hierarchy; + +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElement; +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElementType; + +/** + * Reused option id + */ +public final class InvalidUnion5 { + + @CorbaUnionElement(type = CorbaUnionElementType.discriminator) + @SuppressWarnings("unused") + private int a; + + @CorbaUnionElement(type = CorbaUnionElementType.option, optionNumber = 1) + @SuppressWarnings("unused") + private int b; + + @CorbaUnionElement(type = CorbaUnionElementType.option, optionNumber = 1) + @SuppressWarnings("unused") + private int c; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/NonCorbaException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/NonCorbaException.java new file mode 100644 index 0000000000..a514b5e222 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/NonCorbaException.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.sca.binding.corba.testing.hierarchy; + +public class NonCorbaException extends Exception { + + private static final long serialVersionUID = 1L; + + public String someField; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/RichUnion.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/RichUnion.java new file mode 100644 index 0000000000..2ea40e345f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/RichUnion.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.hierarchy; + +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElement; +import org.apache.tuscany.sca.binding.corba.meta.CorbaUnionElementType; + +public final class RichUnion { + + @CorbaUnionElement(type = CorbaUnionElementType.option, optionNumber = 1) + private int x; + + @CorbaUnionElement(type = CorbaUnionElementType.option, optionNumber = 2) + private float y; + + @CorbaUnionElement(type = CorbaUnionElementType.option, optionNumber = 3) + private String z; + + @CorbaUnionElement(type = CorbaUnionElementType.option, optionNumber = 4) + private InnerUnion iu; + + @CorbaUnionElement(type = CorbaUnionElementType.defaultOption) + private boolean def; + + @CorbaUnionElement(type = CorbaUnionElementType.discriminator) + @SuppressWarnings("unused") + private int discriminator = -1; + + public int getX() { + return x; + } + + public void setX(int x) { + this.discriminator = 1; + this.x = x; + } + + public float getY() { + return y; + } + + public void setY(float y) { + this.discriminator = 2; + this.y = y; + } + + public String getZ() { + return z; + } + + public void setZ(String z) { + this.discriminator = 3; + this.z = z; + } + + public boolean isDef() { + return def; + } + + public void setDef(boolean def) { + this.discriminator = -1; + this.def = def; + } + + public InnerUnion getIu() { + return iu; + } + + public void setIu(InnerUnion iu) { + this.discriminator = 4; + this.iu = iu; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/SimpleStruct.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/SimpleStruct.java new file mode 100644 index 0000000000..85ca3798f4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/SimpleStruct.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.sca.binding.corba.testing.hierarchy; + +/** + * @version $Rev$ $Date$ + */ +public class SimpleStruct { + + public String field1; + public int field2; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/SomeStruct.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/SomeStruct.java new file mode 100644 index 0000000000..d8cdf1835a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/hierarchy/SomeStruct.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.sca.binding.corba.testing.hierarchy; + +/** + * @version $Rev$ $Date$ + */ +public class SomeStruct { + + public SimpleStruct innerStruct; + public String str; + public String[] str_list; + public int[][] twoDimSeq; + public int[][][] threeDimSeq; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObject.java new file mode 100644 index 0000000000..bb72fdbbf3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObject.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.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/DummyObject.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +public interface DummyObject extends DummyObjectOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity { +} // interface DummyObject diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectHelper.java new file mode 100644 index 0000000000..606d333bb3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectHelper.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +abstract public class DummyObjectHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/references/DummyObject:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.references.DummyObject extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = + org.omg.CORBA.ORB + .init() + .create_interface_tc(org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.id(), + "DummyObject"); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.references.DummyObject read(org.omg.CORBA.portable.InputStream istream) { + return narrow(istream.read_Object(_DummyObjectStub.class)); + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject value) { + ostream.write_Object((org.omg.CORBA.Object)value); + } + + public static org.apache.tuscany.sca.binding.corba.testing.references.DummyObject narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.references.DummyObject) + return (org.apache.tuscany.sca.binding.corba.testing.references.DummyObject)obj; + else if (!obj._is_a(id())) + throw new org.omg.CORBA.BAD_PARAM(); + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.references._DummyObjectStub stub = + new org.apache.tuscany.sca.binding.corba.testing.references._DummyObjectStub(); + stub._set_delegate(delegate); + return stub; + } + } + + public static org.apache.tuscany.sca.binding.corba.testing.references.DummyObject unchecked_narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.references.DummyObject) + return (org.apache.tuscany.sca.binding.corba.testing.references.DummyObject)obj; + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.references._DummyObjectStub stub = + new org.apache.tuscany.sca.binding.corba.testing.references._DummyObjectStub(); + stub._set_delegate(delegate); + return stub; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectHolder.java new file mode 100644 index 0000000000..0ff9540502 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectHolder.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.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +public final class DummyObjectHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.references.DummyObject value = null; + + public DummyObjectHolder() { + } + + public DummyObjectHolder(org.apache.tuscany.sca.binding.corba.testing.references.DummyObject initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectOperations.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectOperations.java new file mode 100644 index 0000000000..912bd16f9b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectOperations.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.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/DummyObjectOperations.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +public interface DummyObjectOperations { + int getLong(); + + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject cloneObject(); +} // interface DummyObjectOperations diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManager.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManager.java new file mode 100644 index 0000000000..79f7959c72 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManager.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.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/ObjectManager.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +public interface ObjectManager extends ObjectManagerOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity { +} // interface ObjectManager diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerHelper.java new file mode 100644 index 0000000000..495a614d84 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerHelper.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerHelper.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +abstract public class ObjectManagerHelper { + private static String _id = "IDL:org/apache/tuscany/sca/binding/corba/testing/references/ObjectManager:1.0"; + + public static void insert(org.omg.CORBA.Any a, + org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager that) { + org.omg.CORBA.portable.OutputStream out = a.create_output_stream(); + a.type(type()); + write(out, that); + a.read_value(out.create_input_stream(), type()); + } + + public static org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager extract(org.omg.CORBA.Any a) { + return read(a.create_input_stream()); + } + + private static org.omg.CORBA.TypeCode __typeCode = null; + + synchronized public static org.omg.CORBA.TypeCode type() { + if (__typeCode == null) { + __typeCode = + org.omg.CORBA.ORB.init() + .create_interface_tc(org.apache.tuscany.sca.binding.corba.testing.references.ObjectManagerHelper + .id(), + "ObjectManager"); + } + return __typeCode; + } + + public static String id() { + return _id; + } + + public static org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager read(org.omg.CORBA.portable.InputStream istream) { + return narrow(istream.read_Object(_ObjectManagerStub.class)); + } + + public static void write(org.omg.CORBA.portable.OutputStream ostream, + org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager value) { + ostream.write_Object((org.omg.CORBA.Object)value); + } + + public static org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager) + return (org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager)obj; + else if (!obj._is_a(id())) + throw new org.omg.CORBA.BAD_PARAM(); + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.references._ObjectManagerStub stub = + new org.apache.tuscany.sca.binding.corba.testing.references._ObjectManagerStub(); + stub._set_delegate(delegate); + return stub; + } + } + + public static org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager unchecked_narrow(org.omg.CORBA.Object obj) { + if (obj == null) + return null; + else if (obj instanceof org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager) + return (org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager)obj; + else { + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + org.apache.tuscany.sca.binding.corba.testing.references._ObjectManagerStub stub = + new org.apache.tuscany.sca.binding.corba.testing.references._ObjectManagerStub(); + stub._set_delegate(delegate); + return stub; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerHolder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerHolder.java new file mode 100644 index 0000000000..11cfc82ac2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerHolder.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.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerHolder.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +public final class ObjectManagerHolder implements org.omg.CORBA.portable.Streamable { + public org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager value = null; + + public ObjectManagerHolder() { + } + + public ObjectManagerHolder(org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager initialValue) { + value = initialValue; + } + + public void _read(org.omg.CORBA.portable.InputStream i) { + value = org.apache.tuscany.sca.binding.corba.testing.references.ObjectManagerHelper.read(i); + } + + public void _write(org.omg.CORBA.portable.OutputStream o) { + org.apache.tuscany.sca.binding.corba.testing.references.ObjectManagerHelper.write(o, value); + } + + public org.omg.CORBA.TypeCode _type() { + return org.apache.tuscany.sca.binding.corba.testing.references.ObjectManagerHelper.type(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerOperations.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerOperations.java new file mode 100644 index 0000000000..e0e56d1017 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerOperations.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.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/ObjectManagerOperations.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +public interface ObjectManagerOperations { + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject getDummyObject(); + + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject getObjectByArgument(org.apache.tuscany.sca.binding.corba.testing.references.DummyObject dummy); +} // interface ObjectManagerOperations diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_DummyObjectImplBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_DummyObjectImplBase.java new file mode 100644 index 0000000000..c706661eaa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_DummyObjectImplBase.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.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/_DummyObjectImplBase.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +public abstract class _DummyObjectImplBase extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject, org.omg.CORBA.portable.InvokeHandler { + + // Constructors + public _DummyObjectImplBase() { + } + + private static java.util.Hashtable _methods = new java.util.Hashtable(); + static { + _methods.put("getLong", new java.lang.Integer(0)); + _methods.put("cloneObject", new java.lang.Integer(1)); + } + + public org.omg.CORBA.portable.OutputStream _invoke(String $method, + org.omg.CORBA.portable.InputStream in, + org.omg.CORBA.portable.ResponseHandler $rh) { + org.omg.CORBA.portable.OutputStream out = null; + java.lang.Integer __method = (java.lang.Integer)_methods.get($method); + if (__method == null) + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + + switch (__method.intValue()) { + case 0: // org/apache/tuscany/sca/binding/corba/testing/references/DummyObject/getLong + { + int $result = (int)0; + $result = this.getLong(); + out = $rh.createReply(); + out.write_long($result); + break; + } + + case 1: // org/apache/tuscany/sca/binding/corba/testing/references/DummyObject/cloneObject + { + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject $result = null; + $result = this.cloneObject(); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.write(out, $result); + break; + } + + default: + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + } + + return out; + } // _invoke + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/references/DummyObject:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + +} // class _DummyObjectImplBase diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_DummyObjectStub.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_DummyObjectStub.java new file mode 100644 index 0000000000..c9a31deb27 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_DummyObjectStub.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.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/_DummyObjectStub.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +public class _DummyObjectStub extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject { + + public int getLong() { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("getLong", true); + $in = _invoke($out); + int $result = $in.read_long(); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return getLong(); + } finally { + _releaseReply($in); + } + } // getLong + + public org.apache.tuscany.sca.binding.corba.testing.references.DummyObject cloneObject() { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("cloneObject", true); + $in = _invoke($out); + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject $result = + org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return cloneObject(); + } finally { + _releaseReply($in); + } + } // cloneObject + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/references/DummyObject:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + + private void readObject(java.io.ObjectInputStream s) throws java.io.IOException { + String str = s.readUTF(); + String[] args = null; + java.util.Properties props = null; + org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init(args, props).string_to_object(str); + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + _set_delegate(delegate); + } + + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + String[] args = null; + java.util.Properties props = null; + String str = org.omg.CORBA.ORB.init(args, props).object_to_string(this); + s.writeUTF(str); + } +} // class _DummyObjectStub diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_ObjectManagerImplBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_ObjectManagerImplBase.java new file mode 100644 index 0000000000..a6b55b8bae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_ObjectManagerImplBase.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/_ObjectManagerImplBase.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +public abstract class _ObjectManagerImplBase extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager, org.omg.CORBA.portable.InvokeHandler { + + // Constructors + public _ObjectManagerImplBase() { + } + + private static java.util.Hashtable _methods = new java.util.Hashtable(); + static { + _methods.put("getDummyObject", new java.lang.Integer(0)); + _methods.put("getObjectByArgument", new java.lang.Integer(1)); + } + + public org.omg.CORBA.portable.OutputStream _invoke(String $method, + org.omg.CORBA.portable.InputStream in, + org.omg.CORBA.portable.ResponseHandler $rh) { + org.omg.CORBA.portable.OutputStream out = null; + java.lang.Integer __method = (java.lang.Integer)_methods.get($method); + if (__method == null) + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + + switch (__method.intValue()) { + case 0: // org/apache/tuscany/sca/binding/corba/testing/references/ObjectManager/getDummyObject + { + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject $result = null; + $result = this.getDummyObject(); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.write(out, $result); + break; + } + + case 1: // org/apache/tuscany/sca/binding/corba/testing/references/ObjectManager/getObjectByArgument + { + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject dummy = + org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.read(in); + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject $result = null; + $result = this.getObjectByArgument(dummy); + out = $rh.createReply(); + org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.write(out, $result); + break; + } + + default: + throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); + } + + return out; + } // _invoke + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/references/ObjectManager:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + +} // class _ObjectManagerImplBase diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_ObjectManagerStub.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_ObjectManagerStub.java new file mode 100644 index 0000000000..e06a078a93 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/references/_ObjectManagerStub.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.references; + +/** +* org/apache/tuscany/sca/binding/corba/testing/references/_ObjectManagerStub.java . +* Generated by the IDL-to-Java compiler (portable), version "3.2" +* from remote_objects.idl +* niedziela, 8 czerwiec 2008 16:43:12 CEST +*/ + +public class _ObjectManagerStub extends org.omg.CORBA.portable.ObjectImpl implements + org.apache.tuscany.sca.binding.corba.testing.references.ObjectManager { + + public org.apache.tuscany.sca.binding.corba.testing.references.DummyObject getDummyObject() { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("getDummyObject", true); + $in = _invoke($out); + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject $result = + org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return getDummyObject(); + } finally { + _releaseReply($in); + } + } // getDummyObject + + public org.apache.tuscany.sca.binding.corba.testing.references.DummyObject getObjectByArgument(org.apache.tuscany.sca.binding.corba.testing.references.DummyObject dummy) { + org.omg.CORBA.portable.InputStream $in = null; + try { + org.omg.CORBA.portable.OutputStream $out = _request("getObjectByArgument", true); + org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.write($out, dummy); + $in = _invoke($out); + org.apache.tuscany.sca.binding.corba.testing.references.DummyObject $result = + org.apache.tuscany.sca.binding.corba.testing.references.DummyObjectHelper.read($in); + return $result; + } catch (org.omg.CORBA.portable.ApplicationException $ex) { + $in = $ex.getInputStream(); + String _id = $ex.getId(); + throw new org.omg.CORBA.MARSHAL(_id); + } catch (org.omg.CORBA.portable.RemarshalException $rm) { + return getObjectByArgument(dummy); + } finally { + _releaseReply($in); + } + } // getObjectByArgument + + // Type-specific CORBA::Object operations + private static String[] __ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/references/ObjectManager:1.0"}; + + @Override + public String[] _ids() { + return (String[])__ids.clone(); + } + + private void readObject(java.io.ObjectInputStream s) throws java.io.IOException { + String str = s.readUTF(); + String[] args = null; + java.util.Properties props = null; + org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init(args, props).string_to_object(str); + org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate(); + _set_delegate(delegate); + } + + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + String[] args = null; + java.util.Properties props = null; + String str = org.omg.CORBA.ORB.init(args, props).object_to_string(this); + s.writeUTF(str); + } +} // class _ObjectManagerStub diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysSetterServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysSetterServant.java new file mode 100644 index 0000000000..0aec4d278d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysSetterServant.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject; +import org.apache.tuscany.sca.binding.corba.testing.generated._ArraysSetterImplBase; + +public class ArraysSetterServant extends _ArraysSetterImplBase { + + private static final long serialVersionUID = 1L; + + public boolean[] setBoolean(boolean[] arg) { + return arg; + } + + public char[] setChar(char[] arg) { + return arg; + } + + public double[] setDouble(double[] arg) { + return arg; + } + + public float[] setFloat(float[] arg) { + return arg; + } + + public int[] setLong(int[] arg) { + return arg; + } + + public long[] setLongLong(long[] arg) { + return arg; + } + + public byte[] setOctet(byte[] arg) { + return arg; + } + + public RemoteObject[] setRemoteObject(RemoteObject[] obj) { + return obj; + } + + public short[] setShort(short[] arg) { + return arg; + } + + public String[] setString(String[] arg) { + return arg; + } + + public int[] setUnsignedLong(int[] arg) { + return arg; + } + + public long[] setUnsignedLongLong(long[] arg) { + return arg; + } + + public short[] setUnsignedShort(short[] arg) { + return arg; + } + + public char[] setWchar(char[] arg) { + return arg; + } + + public String[] setWstring(String[] arg) { + return arg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysUnionsServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysUnionsServant.java new file mode 100644 index 0000000000..d9bde48a5a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysUnionsServant.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.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.testing.arrays_unions.RichUnion; +import org.apache.tuscany.sca.binding.corba.testing.arrays_unions.TestStruct; +import org.apache.tuscany.sca.binding.corba.testing.arrays_unions._ArraysUnionsTestsImplBase; + +public class ArraysUnionsServant extends _ArraysUnionsTestsImplBase { + + private static final long serialVersionUID = 1L; + + public TestStruct passTestStruct(TestStruct arg) { + return arg; + } + + public String[][] passStringArray(String[][] arg) { + return arg; + } + + public RichUnion passRichUnion(RichUnion arg) { + return arg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysUnionsTuscanyServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysUnionsTuscanyServant.java new file mode 100644 index 0000000000..cd78588363 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ArraysUnionsTuscanyServant.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.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.meta.CorbaArray; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.ArraysTestStruct; +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.RichUnion; + +public class ArraysUnionsTuscanyServant { + + private static final long serialVersionUID = 1L; + + public ArraysTestStruct passTestStruct(ArraysTestStruct arg) { + return arg; + } + + @CorbaArray( {2, 2}) + public String[][] passStringArray(@CorbaArray( {2, 2})String[][] arg) { + return arg; + } + + public RichUnion passRichUnion(RichUnion arg) { + return arg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/CalcServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/CalcServant.java new file mode 100644 index 0000000000..fd789e19cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/CalcServant.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.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.testing.exceptions._CalcImplBase; +import org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.Arguments; +import org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.DivByZero; +import org.apache.tuscany.sca.binding.corba.testing.exceptions.CalcPackage.NotSupported; + +public class CalcServant extends _CalcImplBase { + + private static final long serialVersionUID = 1L; + + public double div(double arg1, double arg2) throws DivByZero { + if (arg2 == 0) { + DivByZero exception = new DivByZero(); + exception.arguments = new Arguments(arg1, arg2); + exception.info = "Error occured during div: div by zero"; + throw exception; + } else { + return arg1 / arg2; + } + } + + public double divForSmallArgs(double arg1, double arg2) throws DivByZero, NotSupported { + if (arg1 > 100 || arg2 > 100) { + NotSupported exception = new NotSupported(); + exception.info = "arg1: " + arg1 + ", arg2: " + arg2; + throw exception; + } else { + return div(arg1, arg2); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/DummyObjectServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/DummyObjectServant.java new file mode 100644 index 0000000000..2e205f1d0f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/DummyObjectServant.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.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.testing.references.DummyObject; +import org.apache.tuscany.sca.binding.corba.testing.references._DummyObjectImplBase; + +public class DummyObjectServant extends _DummyObjectImplBase { + + private static final long serialVersionUID = 1L; + private int retVal; + + public DummyObjectServant() { + retVal = (int)System.currentTimeMillis(); + } + + public int getLong() { + return retVal; + } + + public DummyObject cloneObject() { + return new DummyObjectServant(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/EnumManagerServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/EnumManagerServant.java new file mode 100644 index 0000000000..52386aeef7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/EnumManagerServant.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.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.testing.enums.Color; +import org.apache.tuscany.sca.binding.corba.testing.enums._EnumManagerImplBase; + +public class EnumManagerServant extends _EnumManagerImplBase { + + private static final long serialVersionUID = 1L; + + public Color getColor(Color color) { + return color; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTestObjectServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTestObjectServant.java new file mode 100644 index 0000000000..b7fbb69627 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTestObjectServant.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.servants; + +public class InvalidTestObjectServant { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java new file mode 100644 index 0000000000..dda8203f79 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.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.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidStruct1; + +public class InvalidTypesServant { + + public InvalidStruct1 firstMethodWithInvalidArg() { + return null; + } + + public void secondMethodWithInvalidArg(InvalidStruct1 arg) { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/NonCorbaServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/NonCorbaServant.java new file mode 100644 index 0000000000..20700a0392 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/NonCorbaServant.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.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.testing.hierarchy.NonCorbaException; + +public class NonCorbaServant { + + public String setString(String arg) { + return arg; + } + + public void throwException() throws NonCorbaException { + NonCorbaException e = new NonCorbaException(); + e.someField = "test"; + throw e; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ObjectManagerServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ObjectManagerServant.java new file mode 100644 index 0000000000..213c7fbd7c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/ObjectManagerServant.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.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.testing.references.DummyObject; +import org.apache.tuscany.sca.binding.corba.testing.references._ObjectManagerImplBase; + +public class ObjectManagerServant extends _ObjectManagerImplBase { + + private static final long serialVersionUID = 1L; + + public DummyObject getObjectByArgument(DummyObject arg) { + return arg; + } + + public DummyObject getDummyObject() { + return new DummyObjectServant(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/PrimitivesSetterServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/PrimitivesSetterServant.java new file mode 100644 index 0000000000..92e18741ae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/PrimitivesSetterServant.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.testing.generated.RemoteObject; +import org.apache.tuscany.sca.binding.corba.testing.generated._PrimitivesSetterImplBase; + +public class PrimitivesSetterServant extends _PrimitivesSetterImplBase { + + private static final long serialVersionUID = 1L; + + public boolean setBoolean(boolean arg) { + return arg; + } + + public char setChar(char arg) { + return arg; + } + + public double setDouble(double arg) { + return arg; + } + + public float setFloat(float arg) { + return arg; + } + + public int setLong(int arg) { + return arg; + } + + public long setLongLong(long arg) { + return arg; + } + + public byte setOctet(byte arg) { + return arg; + } + + public RemoteObject setRemoteObject(RemoteObject obj) { + return obj; + } + + public short setShort(short arg) { + return arg; + } + + public String setString(String arg) { + return arg; + } + + public int setUnsignedLong(int arg) { + return arg; + } + + public long setUnsignedLongLong(long arg) { + return arg; + } + + public short setUnsignedShort(short arg) { + return arg; + } + + public char setWchar(char arg) { + return arg; + } + + public String setWstring(String arg) { + return arg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/TestObjectServant.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/TestObjectServant.java new file mode 100644 index 0000000000..153268983f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/TestObjectServant.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.sca.binding.corba.testing.servants; + +import org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStruct; +import org.apache.tuscany.sca.binding.corba.testing.generated.SimpleStructHolder; +import org.apache.tuscany.sca.binding.corba.testing.generated.SomeStruct; +import org.apache.tuscany.sca.binding.corba.testing.generated._TestObjectImplBase; +import org.apache.tuscany.sca.binding.corba.testing.generated.long_seq1Holder; +import org.apache.tuscany.sca.binding.corba.testing.generated.long_seq2Holder; +import org.apache.tuscany.sca.binding.corba.testing.generated.long_seq3Holder; + +/** + * @version $Rev$ $Date$ + */ +public class TestObjectServant extends _TestObjectImplBase { + + private static final long serialVersionUID = 1L; + + public int[] setLongSeq1(long_seq1Holder arg) { + return arg.value; + } + + public int[][] setLongSeq2(long_seq2Holder arg) { + + return arg.value; + } + + public int[][][] setLongSeq3(long_seq3Holder arg) { + return arg.value; + } + + public SimpleStruct setSimpleStruct(SimpleStructHolder arg) { + return arg.value; + } + + public SomeStruct setStruct(SomeStruct arg) { + return arg; + } + + public SomeStruct pickStructFromArgs(SomeStruct arg1, SomeStruct arg2, SomeStruct arg3, int structNumber) { + switch (structNumber) { + case 1: + return arg1; + case 2: + return arg2; + case 3: + return arg3; + default: + return arg1; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestDataType.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestDataType.java new file mode 100644 index 0000000000..7ebc3fce85 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestDataType.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.service.mocks; + +import java.lang.reflect.Type; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * Mock DataType implementation. Only few methods needs to be implemented. + */ +public class TestDataType implements DataType { + + public Class typeClass; + public L logical; + + public TestDataType(Class typeClass) { + this.typeClass = typeClass; + } + + public TestDataType(Class typeClass, L logical) { + this.typeClass = typeClass; + this.logical = logical; + } + + public String getDataBinding() { + return null; + } + + public Type getGenericType() { + return null; + } + + public L getLogical() { + return logical; + } + + public T getMetaData(Class arg0) { + return null; + } + + public Class getPhysical() { + return typeClass; + } + + public void setDataBinding(String arg0) { + + } + + public void setGenericType(Type arg0) { + + } + + public void setLogical(L arg0) { + + } + + public void setMetaData(Class arg0, T arg1) { + + } + + public void setPhysical(Class arg0) { + + } + + @Override + public Object clone() { + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestInterface.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestInterface.java new file mode 100644 index 0000000000..296fa0a454 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestInterface.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.sca.binding.corba.testing.service.mocks; + +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Mock TestInterface implementation. Only few methods needs to be implemented. + */ +public class TestInterface implements JavaInterface { + + private List operations; + private Class javaClass; + + public TestInterface(List opearations, Class javaClass) { + this.operations = opearations; + this.javaClass = javaClass; + } + + public List getOperations() { + return operations; + } + + public boolean isConversational() { + return false; + } + + public boolean isDynamic() { + return false; + } + + public boolean isRemotable() { + return false; + } + + public void resetDataBinding(String dataBinding) { + + } + + public void resetInterfaceInputTypes(Interface newInterface) { + + } + + public void resetInterfaceOutputTypes(Interface newInterface) { + + } + + public void setConversational(boolean conversational) { + + } + + public void setDefaultDataBinding(String dataBinding) { + + } + + public void setRemotable(boolean remotable) { + + } + + public List getApplicablePolicySets() { + return null; + } + + public List getPolicySets() { + return null; + } + + public List getRequiredIntents() { + return null; + } + + public IntentAttachPointType getType() { + return null; + } + + public void setType(IntentAttachPointType type) { + + } + + @Override + public Object clone() { + return null; + } + + public Class getCallbackClass() { + return null; + } + + public Class getJavaClass() { + return javaClass; + } + + public String getName() { + return null; + } + + public QName getQName() { + return null; + } + + public void setCallbackClass(Class arg0) { + } + + public void setJavaClass(Class javaClass) { + this.javaClass = javaClass; + } + + public void setName(String arg0) { + } + + public void setQName(QName arg0) { + + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean arg0) { + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestInterfaceContract.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestInterfaceContract.java new file mode 100644 index 0000000000..d691705955 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestInterfaceContract.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.sca.binding.corba.testing.service.mocks; + +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +/** + * Mock InterfaceContract implementation. Only few methods needs to be + * implemented. + */ +public class TestInterfaceContract implements InterfaceContract { + + private Interface iface; + + public Interface getCallbackInterface() { + return null; + } + + public Interface getInterface() { + return iface; + } + + public InterfaceContract makeUnidirectional(boolean isCallback) { + return null; + } + + public void setCallbackInterface(Interface callbackInterface) { + + } + + public void setInterface(Interface callInterface) { + this.iface = callInterface; + } + + @Override + public Object clone() { + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestOperation.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestOperation.java new file mode 100644 index 0000000000..07a9119afb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestOperation.java @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.service.mocks; + +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.ParameterMode; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Mock Operation implementation. Only few methods needs to be implemented. + */ +public class TestOperation implements Operation { + + private DataType> inputType; + private DataType outputType; + private String name; + + public ConversationSequence getConversationSequence() { + return null; + } + + public String getDataBinding() { + return null; + } + + public Map>> getFaultBeans() { + return null; + } + + public List getFaultTypes() { + return null; + } + + public DataType> getInputType() { + return inputType; + } + + public Interface getInterface() { + return null; + } + + public String getName() { + return name; + } + + public DataType getOutputType() { + return outputType; + } + + public WrapperInfo getInputWrapper() { + return null; + } + + public WrapperInfo getOutputWrapper() { + return null; + } + + public boolean isDynamic() { + return false; + } + + public boolean isNonBlocking() { + return false; + } + + public boolean isUnresolved() { + return false; + } + + public boolean isInputWrapperStyle() { + return false; + } + + public boolean isOutputWrapperStyle() { + return false; + } + + public void setConversationSequence(ConversationSequence sequence) { + + } + + public void setDataBinding(String dataBinding) { + + } + + public void setDynamic(boolean b) { + + } + + public void setFaultBeans(Map>> faultBeans) { + + } + + public void setFaultTypes(List faultTypes) { + + } + + public void setInputType(DataType> inputType) { + this.inputType = inputType; + } + + public void setInterface(Interface interfaze) { + + } + + public void setName(String name) { + this.name = name; + } + + public void setNonBlocking(boolean nonBlocking) { + + } + + public void setOutputType(DataType outputType) { + this.outputType = outputType; + } + + public void setUnresolved(boolean unresolved) { + + } + + public void setInputWrapper(WrapperInfo wrapperInfo) { + + } + + public void setOutputWrapper(WrapperInfo wrapperInfo) { + + } + + public void setInputWrapperStyle(boolean wrapperStyle) { + + } + + public void setOutputWrapperStyle(boolean wrapperStyle) { + + } + + public List getApplicablePolicySets() { + return null; + } + + public List getPolicySets() { + return null; + } + + @Override + public Object clone() { + return null; + } + + public List getRequiredIntents() { + return null; + } + + public IntentAttachPointType getType() { + return null; + } + + public void setType(IntentAttachPointType type) { + } + + public List getParameterModes() { + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java new file mode 100644 index 0000000000..a99b829e9c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java @@ -0,0 +1,239 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.service.mocks; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Mock RuntimeComponentService implementation. Only few methods needs to be + * implemented. + */ +public class TestRuntimeComponentService implements RuntimeComponentService { + + private InterfaceContract interfaceContract; + private RuntimeWire runtimeWire; + + public TestRuntimeComponentService(Object invocationTarget) { + runtimeWire = new TestRuntimeWire(invocationTarget); + List operations = new ArrayList(); + Method[] methods = invocationTarget.getClass().getMethods(); + for (int i = 0; i < methods.length; i++) { + int mod = methods[i].getModifiers(); + if (methods[i].getDeclaringClass().equals(invocationTarget.getClass()) && Modifier.isPublic(mod) + && !methods[i].getName().startsWith("_")) { + Operation operation = new TestOperation(); + DataType returnType = new TestDataType(methods[i].getReturnType()); + operation.setOutputType(returnType); + Class[] argTypes = methods[i].getParameterTypes(); + List argDataTypes = new ArrayList(); + for (int j = 0; j < argTypes.length; j++) { + argDataTypes.add(new TestDataType(argTypes[j])); + } + TestDataType> inputDataType = new TestDataType>(null, argDataTypes); + operation.setInputType(inputDataType); + operations.add(operation); + operation.setName(methods[i].getName()); + } + } + TestInterface iface = new TestInterface(operations, invocationTarget.getClass()); + interfaceContract = new TestInterfaceContract(); + interfaceContract.setInterface(iface); + } + + public void addPolicyProvider(Binding binding, PolicyProvider policyProvider) { + + } + + public ServiceBindingProvider getBindingProvider(Binding binding) { + return null; + } + + public List getCallbackWires() { + return null; + } + + public InvocationChain getInvocationChain(Binding binding, Operation operation) { + return null; + } + + public InvocationChain getInvocationChain(Binding binding, InterfaceContract interfaceContract, Operation operation) { + return null; + } + + public Invoker getInvoker(Binding binding, Operation operation) { + return null; + } + + public Invoker getInvoker(Binding binding, InterfaceContract interfaceContract, Operation operation) { + return null; + } + + public List getPolicyProviders(Binding binding) { + return null; + } + + public RuntimeWire getRuntimeWire(Binding binding) { + return runtimeWire; + } + + public RuntimeWire getRuntimeWire(Binding binding, InterfaceContract interfaceContract) { + return null; + } + + public List getRuntimeWires() { + return null; + } + + public void setBindingProvider(Binding binding, ServiceBindingProvider bindingProvider) { + + } + + public ComponentReference getCallbackReference() { + return null; + } + + public Service getService() { + return null; + } + + public void setCallbackReference(ComponentReference callbackReference) { + + } + + public void setService(Service service) { + + } + + public InterfaceContract getInterfaceContract() { + return interfaceContract; + } + + public InterfaceContract getInterfaceContract(Binding binding) { + return getInterfaceContract(); + } + + public String getName() { + return null; + } + + public boolean isCallback() { + return false; + } + + public void setInterfaceContract(InterfaceContract interfaceContract) { + this.interfaceContract = interfaceContract; + } + + public void setIsCallback(boolean isCallback) { + + } + + public void setName(String name) { + + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + + } + + public List getExtensions() { + return null; + } + + public List getAttributeExtensions() { + return null; + } + + public List getRequiredIntents() { + return null; + } + + public IntentAttachPointType getType() { + return null; + } + + public void setType(IntentAttachPointType type) { + + } + + public List getConfiguredOperations() { + return null; + } + + public B getBinding(Class bindingClass) { + return null; + } + + public List getBindings() { + return null; + } + + public Callback getCallback() { + return null; + } + + public B getCallbackBinding(Class bindingClass) { + return null; + } + + public void setCallback(Callback callback) { + + } + + public List getApplicablePolicySets() { + return null; + } + + public List getPolicySets() { + return null; + } + + @Override + public Object clone() { + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java new file mode 100644 index 0000000000..5b7caf1010 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.testing.service.mocks; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Mock RuntimeWire implementation. Only few methods needs to be implemented. + */ +public class TestRuntimeWire implements RuntimeWire { + private Object invocationTarget; + + public TestRuntimeWire(Object invocationTarget) { + this.invocationTarget = invocationTarget; + } + + public InvocationChain getInvocationChain(Operation arg0) { + return null; + } + + public List getInvocationChains() { + return null; + } + + public EndpointReference getSource() { + return null; + } + + public EndpointReference getTarget() { + return null; + } + + public Object invoke(Operation operation, Object[] args) throws InvocationTargetException { + Class[] types = new Class[args.length]; + for (int i = 0; i < args.length; i++) { + types[i] = args[i].getClass(); + } + Object result = null; + try { + Method[] methods = invocationTarget.getClass().getMethods(); + for (int i = 0; i < methods.length; i++) { + if (methods[i].getName().equals(operation.getName())) { + result = methods[i].invoke(invocationTarget, args); + break; + } + } + } catch (InvocationTargetException e) { + throw e; + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return result; + } + + public Object invoke(Operation operation, Message arg1) throws InvocationTargetException { + + return null; + } + + public Object invoke(Message arg1) throws InvocationTargetException { + + return null; + } + + public void rebuild() { + + } + + public void setTarget(EndpointReference arg0) { + + } + + @Override + public Object clone() { + return null; + } + + public InvocationChain getBindingInvocationChain() { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/arrays_unions.idl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/arrays_unions.idl new file mode 100644 index 0000000000..0f4ed03b4e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/arrays_unions.idl @@ -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. + */ + +/* + * compile by + * idlj -fall -oldImplBase arrays_unions.idl + */ + +module org { + module apache { + module tuscany { + module sca { + module binding { + module corba { + module testing { + module arrays_unions { + + struct TestStruct { + string oneDimArray[2]; + long twoDimArray[2][4]; + float threeDimArray[2][4][2]; + }; + + typedef string StringArray[2][2]; + + union InnerUnion switch (long) { + case 1: long x; + case 2: float y; + }; + + union RichUnion switch (long) { + case 1: long x; + case 2: float y; + case 3: string z; + case 4: InnerUnion iu; + default: boolean a; + }; + + interface ArraysUnionsTests { + TestStruct passTestStruct(in TestStruct arg); + StringArray passStringArray(in StringArray arg); + RichUnion passRichUnion(in RichUnion arg); + }; + + }; + }; + }; + }; + }; + }; + }; +}; + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/enums.idl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/enums.idl new file mode 100644 index 0000000000..2e4e829b0f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/enums.idl @@ -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. + */ + +/* + * compile by + * idlj -fall -oldImplBase enums.idl + */ + +module org { + module apache { + module tuscany { + module sca { + module binding { + module corba { + module testing { + module enums { + enum Color {red, yellow, green}; + interface EnumManager { + Color getColor(in Color color); + }; + }; + }; + }; + }; + }; + }; + }; +}; diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/exceptions.idl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/exceptions.idl new file mode 100644 index 0000000000..b34ec46458 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/exceptions.idl @@ -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. + */ + +/* + * compile by + * idlj -fall -oldImplBase exceptions.idl + */ + +module org { + module apache { + module tuscany { + module sca { + module binding { + module corba { + module testing { + module exceptions { + interface Calc { + struct Arguments { + double arg1; + double arg2; + }; + + exception DivByZero{ + Arguments arguments; + string info; + }; + + exception NotSupported { + string info; + }; + + double div(in double arg1, in double arg2) raises(DivByZero); + double divForSmallArgs(in double arg1, in double arg2) raises(DivByZero, NotSupported); + }; + }; + }; + }; + }; + }; + }; + }; +}; diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/general_tests.idl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/general_tests.idl new file mode 100644 index 0000000000..db253338c3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/general_tests.idl @@ -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. + */ + +/* + * compile by + * idlj -fall -oldImplBase general_tests.idl + */ + +module org { + module apache { + module tuscany { + module sca { + module binding { + module corba { + module testing { + module generated { + + interface RemoteObject { + + }; + + typedef sequence remote_object_list; + typedef sequence boolean_list; + typedef sequence char_list; + typedef sequence wchar_list; + typedef sequence octet_list; + typedef sequence short_list; + typedef sequence unsigned_short_list; + typedef sequence long_list; + typedef sequence unsigned_long_list; + typedef sequence long_long_list; + typedef sequence unsigned_long_long_list; + typedef sequence float_list; + typedef sequence double_list; + typedef sequence string_list; + typedef sequence wstring_list; + + interface PrimitivesSetter { + boolean setBoolean(in boolean arg); + char setChar(in char arg); + wchar setWchar(in wchar arg); + octet setOctet(in octet arg); + short setShort(in short arg); + unsigned short setUnsignedShort(in unsigned short arg); + long setLong(in long arg); + unsigned long setUnsignedLong(in unsigned long arg); + long long setLongLong(in long long arg); + unsigned long long setUnsignedLongLong(in unsigned long long arg); + float setFloat(in float arg); + double setDouble(in double arg); + string setString(in string arg); + wstring setWstring(in wstring arg); + RemoteObject setRemoteObject(in RemoteObject obj); + }; + + interface ArraysSetter { + boolean_list setBoolean(in boolean_list arg); + char_list setChar(in char_list arg); + wchar_list setWchar(in wchar_list arg); + octet_list setOctet(in octet_list arg); + short_list setShort(in short_list arg); + unsigned_short_list setUnsignedShort(in unsigned_short_list arg); + long_list setLong(in long_list arg); + unsigned_long_list setUnsignedLong(in unsigned_long_list arg); + long_long_list setLongLong(in long_long_list arg); + unsigned_long_long_list setUnsignedLongLong(in unsigned_long_long_list arg); + float_list setFloat(in float_list arg); + double_list setDouble(in double_list arg); + string_list setString(in string_list arg); + wstring_list setWstring(in wstring_list arg); + remote_object_list setRemoteObject(in remote_object_list obj); + }; + + typedef sequence long_seq1; + typedef sequence long_seq2; + typedef sequence long_seq3; + + struct SimpleStruct { + string field1; + long field2; + }; + + + struct SomeStruct { + SimpleStruct innerStruct; + string str; + string_list str_list; + long_seq2 twoDimSeq; + long_seq3 threeDimSeq; + }; + + interface TestObject { + SomeStruct pickStructFromArgs(in SomeStruct arg1, in SomeStruct arg2, in SomeStruct arg3, in long structNumber); + SomeStruct setStruct(in SomeStruct arg); + SimpleStruct setSimpleStruct(inout SimpleStruct arg); + long_seq1 setLongSeq1(inout long_seq1 arg); + long_seq2 setLongSeq2(inout long_seq2 arg); + long_seq3 setLongSeq3(inout long_seq3 arg); + }; + + }; + }; + }; + }; + }; + }; + }; +}; diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/references.idl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/references.idl new file mode 100644 index 0000000000..72b58806e6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba-runtime/src/test/resources/references.idl @@ -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. + */ + +/* + * compile by + * idlj -fall -oldImplBase remote_objects.idl + */ + +module org { + module apache { + module tuscany { + module sca { + module binding { + module corba { + module testing { + module references { + + interface DummyObject { + long getLong(); + DummyObject cloneObject(); + }; + + interface ObjectManager { + DummyObject getDummyObject(); + DummyObject getObjectByArgument(in DummyObject dummy); + }; + }; + }; + }; + }; + }; + }; + }; +}; diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/pom.xml new file mode 100644 index 0000000000..5279c6003d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/pom.xml @@ -0,0 +1,71 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-corba + Apache Tuscany SCA CORBA Binding Extension + + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-corba + 1.6-SNAPSHOT + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.corba + ${pom.name} + org.apache.tuscany.sca.binding.corba* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBinding.java new file mode 100644 index 0000000000..0b79065cc3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBinding.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.sca.binding.corba; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * @version $Rev$ $Date$ + */ +public interface CorbaBinding extends Binding { + QName BINDING_CORBA_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "binding.corba"); + + String getHost(); + + void setHost(String host); + + int getPort(); + + void setPort(int port); + + String getId(); + + void setId(String id); + + String getCorbaname(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBindingFactory.java new file mode 100644 index 0000000000..67e3bdcf74 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBindingFactory.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.sca.binding.corba; + +/** + * @version $Rev$ $Date$ + */ +public interface CorbaBindingFactory { + /** + * Create a CorbaBinding model + * @return The CorbaBinding model + */ + CorbaBinding createCorbaBinding(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingFactoryImpl.java new file mode 100644 index 0000000000..cecb4fb567 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingFactoryImpl.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.sca.binding.corba.impl; + +import org.apache.tuscany.sca.binding.corba.CorbaBinding; +import org.apache.tuscany.sca.binding.corba.CorbaBindingFactory; + +/** + * @version $Rev$ $Date$ + */ +public class CorbaBindingFactoryImpl implements CorbaBindingFactory { + + /** + * @see org.apache.tuscany.sca.binding.corba.CorbaBindingFactory#createCorbaBinding() + */ + public CorbaBinding createCorbaBinding() { + return new CorbaBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingImpl.java new file mode 100644 index 0000000000..54e98d4117 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingImpl.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.sca.binding.corba.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.corba.CorbaBinding; +import org.apache.tuscany.sca.host.corba.CorbaHostUtils; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * @version $Rev$ $Date$ + */ +public class CorbaBindingImpl implements CorbaBinding, PolicySetAttachPoint { + private String name; + private String uri; + private String host; + private int port; + private String id; + + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + + } + + public void setURI(String uri) { + this.uri = uri; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getCorbaname() { + return CorbaHostUtils.isValidCorbanameURI(getURI()) ? getURI(): CorbaHostUtils.createCorbanameURI(getHost(), getPort(), getName()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingProcessor.java new file mode 100644 index 0000000000..0bb38d3682 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingProcessor.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.corba.impl; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; +import org.apache.tuscany.sca.binding.corba.CorbaBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * @version $Rev$ $Date$ + */ +public class CorbaBindingProcessor implements StAXArtifactProcessor { + private PolicyFactory policyFactory; + private PolicyAttachPointProcessor policyProcessor; + + public CorbaBindingProcessor(ModelFactoryExtensionPoint modelFactories) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#getArtifactType() + */ + public QName getArtifactType() { + return CorbaBinding.BINDING_CORBA_QNAME; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#read(javax.xml.stream.XMLStreamReader) + */ + public CorbaBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + CorbaBinding binding = new CorbaBindingImpl(); + + // Read the policies + policyProcessor.readPolicies(binding, reader); + + binding.setHost(reader.getAttributeValue(null, "host")); + String port = reader.getAttributeValue(null, "port"); + if (port != null) { + binding.setPort(Integer.parseInt(port)); + } + + // Read the name + String name = reader.getAttributeValue(null, "name"); + if (name != null) { + binding.setName(name); + } + + // Read binding URI + String uri = reader.getAttributeValue(null, "uri"); + if (uri != null) { + binding.setURI(uri); + } + + // Read CORBA id + String id = reader.getAttributeValue(null, "id"); + if (id != null) { + binding.setId(id); + } + return binding; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#write(java.lang.Object, javax.xml.stream.XMLStreamWriter) + */ + public void write(CorbaBinding model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + // Write a + writer.writeStartElement(Constants.SCA10_TUSCANY_NS, "binding.corba"); + + if (model.getName() != null) { + writer.writeAttribute("name", model.getName()); + } + + if (model.getURI() != null) { + writer.writeAttribute("uri", model.getURI()); + } + + if (model.getHost() != null) { + writer.writeAttribute("host", model.getHost()); + } + + if (model.getPort() != -1) { + writer.writeAttribute("port", String.valueOf(model.getPort())); + } + + if (model.getId() != null) { + writer.writeAttribute("id", model.getId()); + } + writer.writeEndElement(); + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#getModelType() + */ + public Class getModelType() { + return CorbaBinding.class; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#resolve(java.lang.Object, org.apache.tuscany.sca.contribution.resolver.ModelResolver) + */ + public void resolve(CorbaBinding model, ModelResolver resolver) throws ContributionResolveException { + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.corba.CorbaBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.corba.CorbaBindingFactory new file mode 100644 index 0000000000..57959840d4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.corba.CorbaBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the model factory +org.apache.tuscany.sca.binding.corba.impl.CorbaBindingFactoryImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..71d14bc077 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.corba.impl.CorbaBindingProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.corba,model=org.apache.tuscany.sca.binding.corba.CorbaBinding,factory=org.apache.tuscany.sca.binding.corba.CorbaBindingFactory diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/pom.xml new file mode 100644 index 0000000000..2fc029350d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/pom.xml @@ -0,0 +1,95 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-dwr + Apache Tuscany SCA AJAX DWR Binding Extension + + + + + org.apache.tuscany.sca + tuscany-extension-helper + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + + org.directwebremoting + dwr + 2.0.3 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + junit + junit + 4.5 + test + + + + org.easymock + easymock + 2.2 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.dwr + ${pom.name} + org.apache.tuscany.sca.binding.dwr* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java new file mode 100644 index 0000000000..ae5cf327ab --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.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.sca.binding.dwr; + +/** + * The runtime representation of the SCDL + * + * @version $Rev$ $Date$ + */ +public class DWRBinding { + + // Empty as doesn't use any additional attributes or elements (yet). + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java new file mode 100644 index 0000000000..d14751f235 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.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.sca.binding.dwr; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.extension.helper.BindingActivator; +import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; +import org.apache.tuscany.sca.extension.helper.InvokerFactory; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * The Binding Activator for the DWR Binding. + * + * @version $Rev$ $Date$ + */ +public class DWRBindingActivator implements BindingActivator{ + + private ServletHost servletHost; + + public DWRBindingActivator(ServletHost servletHost) { + this.servletHost = servletHost; + } + + public Class getBindingClass() { + return DWRBinding.class; + } + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, DWRBinding ab) { + return new DWRInvokerFactory(rc, rcr, b, ab, servletHost); + } + + public ComponentLifecycle createService(RuntimeComponent rc, RuntimeComponentService rcs, Binding b, DWRBinding ab) { + return new DWRService(rc, rcs, b, ab, servletHost); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java new file mode 100644 index 0000000000..24e6dbbcd4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.dwr; + +import java.util.Collection; + +import org.apache.tuscany.sca.core.invocation.MessageImpl; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.directwebremoting.ScriptBuffer; +import org.directwebremoting.WebContext; +import org.directwebremoting.WebContextFactory; +import org.directwebremoting.proxy.dwr.Util; + +/** + * The invoker for a DWR Binding. + * + * @version $Rev$ $Date$ + */ +public class DWRInvoker implements Invoker { + + private String referenceFunction; + + public DWRInvoker(String referenceName, Operation operation) { + this.referenceFunction = referenceName + "." + operation.getName(); + } + + public Message invoke(Message requestMsg) { + + invoke((Object[])requestMsg.getBody()); + + // DWR references can not return anything + return new MessageImpl(); + } + + public void invoke(Object[] args) { + + // TODO: this only works if its the same thread as request + WebContext wctx = WebContextFactory.get(); + String currentPage = wctx.getCurrentPage(); + + // Get a DWR Util proxy for all the browsers on the current page: + Collection sessions = wctx.getScriptSessionsByPage(currentPage); + Util utilAll = new Util(sessions); + + ScriptBuffer referenceInvoke = getInvokeFragment(args, wctx); + + // add the reference call to the Util proxy which will cause DWR to + // asynchronously send it to be run on each active browser client + utilAll.addScript(referenceInvoke); + } + + /** + * Creates a fragment of JavaScript code to invoke the reference function + * Eg: ".(arg1, arg2,...);" + */ + protected ScriptBuffer getInvokeFragment(Object[] args, WebContext wctx) { + + ScriptBuffer sb = new ScriptBuffer(); + sb.appendScript(referenceFunction); + sb.appendScript("("); + if (args != null) { + for (int i = 0; i < args.length; i++) { + sb.appendData(args[i]); + if (i < (args.length - 1)) { + sb.appendScript(", "); + } + } + } + sb.appendScript(");"); + + return sb; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java new file mode 100644 index 0000000000..1d073c9ecf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.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.sca.binding.dwr; + +import static org.apache.tuscany.sca.binding.dwr.DWRService.SERVLET_PATH; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; +import org.apache.tuscany.sca.extension.helper.InvokerFactory; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * InvokerFactory for the DWRBinding. + * + * @version $Rev$ $Date$ + */ +public class DWRInvokerFactory implements InvokerFactory, ComponentLifecycle { + + private Binding binding; + private ServletHost servletHost; + + public DWRInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, DWRBinding ab, ServletHost servletHost) { + this.binding = b; + this.servletHost = servletHost; + } + + public Invoker createInvoker(Operation operation) { + return new DWRInvoker(binding.getName(), operation); + } + + public void start() { + + DWRServlet servlet = (DWRServlet) servletHost.getServletMapping(SERVLET_PATH); + if (servlet == null) { + servlet = new DWRServlet(); + servletHost.addServletMapping(SERVLET_PATH, servlet); + } + + servlet.addReference(binding.getName()); + } + + public void stop() { + servletHost.removeServletMapping(SERVLET_PATH); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java new file mode 100644 index 0000000000..7d5a7f1677 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.dwr; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * DWR Service. + * + * @version $Rev$ $Date$ + */ +public class DWRService implements ComponentLifecycle { + + private RuntimeComponent rc; + private RuntimeComponentService rcs; + private Binding binding; + private ServletHost servletHost; + + static final String SERVLET_PATH = "/SCADomain/*"; + + public DWRService(RuntimeComponent rc, RuntimeComponentService rcs, Binding binding, DWRBinding ab, ServletHost servletHost) { + this.rc = rc; + this.rcs = rcs; + this.binding = binding; + this.servletHost = servletHost; + } + + public void start() { + + DWRServlet servlet = (DWRServlet) servletHost.getServletMapping(SERVLET_PATH); + if (servlet == null) { + servlet = new DWRServlet(); + servletHost.addServletMapping(SERVLET_PATH, servlet); + } + + // Create a Java proxy to the target service + Class type = ((JavaInterface)rcs.getInterfaceContract().getInterface()).getJavaClass(); + Object proxy = Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new InvocationHandler() { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + RuntimeWire wire = rcs.getRuntimeWire(binding); + Operation op = JavaInterfaceUtil.findOperation(method, rcs.getInterfaceContract().getInterface().getOperations()); + return wire.invoke(op, args); + }}); + + servlet.addService(binding.getName(), type, proxy); + } + + public void stop() { + servletHost.removeServletMapping(SERVLET_PATH); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java new file mode 100644 index 0000000000..3a2471d8f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java @@ -0,0 +1,247 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.dwr; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.directwebremoting.Container; +import org.directwebremoting.create.AbstractCreator; +import org.directwebremoting.extend.CreatorManager; +import org.directwebremoting.extend.Handler; +import org.directwebremoting.extend.Remoter; +import org.directwebremoting.servlet.DwrServlet; +import org.directwebremoting.servlet.EngineHandler; +import org.directwebremoting.servlet.PathConstants; +import org.directwebremoting.servlet.UrlProcessor; + +/** + * Tuscany customized DWR Servlet to implement support for the DWR binding + * + * Handles requests for SCA services and references that use , + * and also the HTTP GET for the Tuscany DWR system script "scaDomain.js" + * + * @version $Rev$ $Date$ + */ +public class DWRServlet extends DwrServlet { + private static final long serialVersionUID = 1L; + + private transient Map services; + private transient List referenceNames; + private transient boolean initialized; + private transient Map initParams; + + private static final String SCADOMAIN_SCRIPT_PATH = "/scaDomain.js"; + + public DWRServlet() { + this.services = new HashMap(); + this.referenceNames = new ArrayList(); + + this.initParams = new HashMap(); + // maybe use attributes to define the init params + initParams.put("activeReverseAjaxEnabled", "true"); + } + + @Override + public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { + super.service(req, res); + } + + /** + * Initialize the Servlet + * There is a single instance of this Servlet which is registered + * for multiple path mappings, but the init should only run once. + */ + @Override + public void init(ServletConfig servletConfig) throws ServletException { + if (!initialized) { + super.init(patchConfig(servletConfig)); + addScriptHandler(); + initServices(); + initialized = true; + } + } + + /** + * Add in the handler to process the HTTP get for /sca/scaDomain.js + * + * This wrappers the DWR Engine handler which returns the DWR engine.js script, + * this wrappers that handler so as to add Tuscany specific header and footer code + * to the DWR engine.js to define the Tuscany SCADomain control functions and + * functions for each SCA service and reference that use . + */ + private void addScriptHandler() { + + UrlProcessor urlProcessor = (UrlProcessor)getContainer().getBean(UrlProcessor.class.getName()); + + final EngineHandler engineHandler = + (EngineHandler)getContainer().getBean(PathConstants.URL_PREFIX + "/engine.js"); + + final Handler scaDomainScriptHandler = new Handler() { + public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException { + PrintWriter out = response.getWriter(); + out.println("/** Apache Tuscany scaDomain.js Header */"); + + engineHandler.handle(request, response); + + tuscanyFooter(request, out); + } + + }; + + // add the scaDomainScriptHandler to the urlProcessor + // bit of a hack, there's probably cleaner way to get it registered + urlProcessor.afterContainerSetup(new Container() { + public Object getBean(String name) { + return scaDomainScriptHandler; + } + public Collection getBeanNames() { + return Arrays.asList(new String[] {PathConstants.URL_PREFIX + SCADOMAIN_SCRIPT_PATH}); + } + }); + } + + /** + * Adds the JavaScript defining SCADomain, its control functions, + * and functions for all the available SCA services and references. + */ + private void tuscanyFooter(HttpServletRequest request, PrintWriter out) { + out.println("/** Apache Tuscany scaDomain.js Footer */"); + out.println(); + out.println("function scaDomain() { }"); + out.println(); + out.println("// SCA services"); + + // Use the DWR remoter to generate the JavaScipt function for each SCA service + Remoter remoter = (Remoter)getContainer().getBean(Remoter.class.getName()); + + String path = request.getContextPath() + request.getServletPath(); + + for (String serviceName : services.keySet()) { + String serviceScript = remoter.generateInterfaceScript(serviceName, path); + out.println(serviceScript); + } + + if (referenceNames.size() > 0) { + + out.println("// SCA reverse ajax control functions"); + out.println(); + out.println("scaDomain.open = function() { dwr.engine.setActiveReverseAjax(true); };"); + out.println("scaDomain.close = function() { dwr.engine.setActiveReverseAjax(false); };"); + + out.println(); + out.println("// SCA references"); + out.println(); + + // the JavaScript function for SCA references has an + // empty impl as it uses DWR severside "push" + for (String referenceName : referenceNames) { + out.println("function " + referenceName + "() { }"); + } + } + + out.println(); + out.println("/** End of Apache Tuscany scaDomain.js */"); + out.println(); + } + + /** + * Add an SCA reference to be added to the DWR runtime + */ + public void addReference(String name) { + referenceNames.add(name); + } + + /** + * Add an SCA service to be added to the DWR runtime + */ + public void addService(String name, final Class type, final Object instance) { + ServiceHolder holder = new ServiceHolder(); + holder.name = name; + holder.type = type; + holder.instance = instance; + services.put(name, holder); + } + + /** + * Defines each SCA service proxy instance to DWR + */ + private void initServices() { + CreatorManager creatorManager = (CreatorManager)getContainer().getBean(CreatorManager.class.getName()); + + for (final ServiceHolder holder : services.values()) { + creatorManager.addCreator(holder.name, new AbstractCreator() { + public Class getType() { + return holder.type; + } + + public Object getInstance() throws InstantiationException { + return holder.instance; + } + }); + } + } + + // utility class to aid passing around services + private class ServiceHolder { + String name; + Class type; + Object instance; + } + + /** + * Patch the ServletConfig to enable setting init params for DWR + * and so DWR can't see the Tuscany servlet's init params. + */ + private ServletConfig patchConfig(final ServletConfig servletConfig) { + ServletConfig patchedContext = new ServletConfig() { + public String getInitParameter(String name) { + return initParams.get(name); + } + public Enumeration getInitParameterNames() { + return Collections.enumeration(initParams.keySet()); + } + public ServletContext getServletContext() { + return servletConfig.getServletContext(); + } + public String getServletName() { + return servletConfig.getServletName(); + } + }; + return patchedContext; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator new file mode 100644 index 0000000000..1a9f91fab2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.binding.dwr.DWRBindingActivator + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/pom.xml new file mode 100644 index 0000000000..6f78f68190 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/pom.xml @@ -0,0 +1,195 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-ejb-runtime + Apache Tuscany SCA EJB Binding Runtime + + + + org.apache.tuscany.sca + tuscany-binding-ejb + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + cglib + cglib-nodep + 2.2 + compile + + + + backport-util-concurrent + backport-util-concurrent + 3.1 + + + + org.apache.geronimo.specs + geronimo-ejb_3.0_spec + 1.0 + compile + + + + junit + junit + 4.5 + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + org.apache.geronimo.modules + geronimo-openejb + 2.1.4 + test + + + org.apache.geronimo.modules + geronimo-connector + + + org.apache.geronimo.modules + geronimo-persistence-jpa10 + + + org.apache.openejb + openejb-ejbd + + + org.apache.openejb + openejb-server + + + org.apache.openejb + openejb-loader + + + org.apache.openejb + openejb-jee + + + org.apache.openejb + openejb-ejbd + + + org.apache.openejb + openejb-javaagent + + + com.sun.xml.bind + jaxb-impl + + + asm + asm + + + asm + asm-commons + + + + + + asm + asm-all + 3.1 + test + + + + org.apache.geronimo.specs + geronimo-jms_1.1_spec + 1.1 + + + org.apache.geronimo.specs + geronimo-jms_1.1_spec + + + + + + + + + geronimo-repository + Geronimo Repository + http://svn.apache.org/repos/asf/geronimo/server/tags/2.0.2/repository + default + + false + + + true + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.ejb.runtime + ${pom.name} + org.apache.tuscany.sca.binding.ejb* + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ClassLoadingUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ClassLoadingUtil.java new file mode 100644 index 0000000000..c65868c23b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ClassLoadingUtil.java @@ -0,0 +1,365 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ejb.corba; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +/** + * Utility class for loading classes by a variety of name variations. + *

+ * Supported names types are: + *

+ * 1) Fully qualified class name (e.g., "java.lang.String", "org.apache.geronimo.kernel.ClassLoading" + * 2) Method signature encoding ("Ljava.lang.String;", "J", "I", etc.) + * 3) Primitive type names ("int", "boolean", etc.) + * 4) Method array signature strings ("[I", "[Ljava.lang.String") + * 5) Arrays using Java code format ("int[]", "java.lang.String[][]") + *

+ * The classes are loaded using the provided class loader. For the basic types, the primitive + * reflection types are returned. + * + * @version $Rev$ $Date$ + */ +public class ClassLoadingUtil { + + /** + * Table for mapping primitive class names/signatures to the implementing + * class object + */ + private static final HashMap PRIMITIVE_CLASS_MAP = new HashMap(); + + /** + * Table for mapping primitive classes back to their name signature type, which + * allows a reverse mapping to be performed from a class object into a resolvable + * signature. + */ + private static final HashMap CLASS_TO_SIGNATURE_MAP = new HashMap(); + + + /** + * Setup the primitives map. We make any entry for each primitive class using both the + * human readable name and the method signature shorthand type. + */ + static { + PRIMITIVE_CLASS_MAP.put("boolean", boolean.class); + PRIMITIVE_CLASS_MAP.put("Z", boolean.class); + PRIMITIVE_CLASS_MAP.put("byte", byte.class); + PRIMITIVE_CLASS_MAP.put("B", byte.class); + PRIMITIVE_CLASS_MAP.put("char", char.class); + PRIMITIVE_CLASS_MAP.put("C", char.class); + PRIMITIVE_CLASS_MAP.put("short", short.class); + PRIMITIVE_CLASS_MAP.put("S", short.class); + PRIMITIVE_CLASS_MAP.put("int", int.class); + PRIMITIVE_CLASS_MAP.put("I", int.class); + PRIMITIVE_CLASS_MAP.put("long", long.class); + PRIMITIVE_CLASS_MAP.put("J", long.class); + PRIMITIVE_CLASS_MAP.put("float", float.class); + PRIMITIVE_CLASS_MAP.put("F", float.class); + PRIMITIVE_CLASS_MAP.put("double", double.class); + PRIMITIVE_CLASS_MAP.put("D", double.class); + PRIMITIVE_CLASS_MAP.put("void", void.class); + PRIMITIVE_CLASS_MAP.put("V", void.class); + + // Now build a reverse mapping table. The table above has a many-to-one mapping for + // class names. To do the reverse, we need to pick just one. As long as the + // returned name supports "round tripping" of the requests, this will work fine. + + CLASS_TO_SIGNATURE_MAP.put(boolean.class, "Z"); + CLASS_TO_SIGNATURE_MAP.put(byte.class, "B"); + CLASS_TO_SIGNATURE_MAP.put(char.class, "C"); + CLASS_TO_SIGNATURE_MAP.put(short.class, "S"); + CLASS_TO_SIGNATURE_MAP.put(int.class, "I"); + CLASS_TO_SIGNATURE_MAP.put(long.class, "J"); + CLASS_TO_SIGNATURE_MAP.put(float.class, "F"); + CLASS_TO_SIGNATURE_MAP.put(double.class, "D"); + CLASS_TO_SIGNATURE_MAP.put(void.class, "V"); + } + + + /** + * Load a class that matches the requested name, using the provided class loader context. + *

+ * The class name may be a standard class name, the name of a primitive type Java + * reflection class (e.g., "boolean" or "int"), or a type in method type signature + * encoding. Array classes in either encoding form are also processed. + * + * @param className The name of the required class. + * @param classLoader The class loader used to resolve the class object. + * @return The Class object resolved from "className". + * @throws ClassNotFoundException When unable to resolve the class object. + * @throws IllegalArgumentException If either argument is null. + */ + public static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException { + + // the tests require IllegalArgumentExceptions for null values on either of these. + if (className == null) { + throw new IllegalArgumentException("className is null"); + } + + if (classLoader == null) { + throw new IllegalArgumentException("classLoader is null"); + } + // The easiest case is a proper class name. We just have the class loader resolve this. + // If the class loader throws a ClassNotFoundException, then we need to check each of the + // special name encodings we support. + try { + return classLoader.loadClass(className); + } catch (ClassNotFoundException ignore) { + // if not found, continue on to the other name forms. + } + + + // The second easiest version to resolve is a direct map to a primitive type name + // or method signature. Check our name-to-class map for one of those. + Class resolvedClass = (Class) PRIMITIVE_CLASS_MAP.get(className); + if (resolvedClass != null) { + return resolvedClass; + } + + // Class names in method signature have the format "Lfully.resolved.name;", + // so if it ends in a semicolon and begins with an "L", this must be in + // this format. Have the class loader try to load this. There are no other + // options if this fails, so just allow the class loader to throw the + // ClassNotFoundException. + if (className.endsWith(";") && className.startsWith("L")) { + // pick out the name portion + String typeName = className.substring(1, className.length() - 1); + // and delegate the loading to the class loader. + return classLoader.loadClass(typeName); + } + + // All we have left now are the array types. Method signature array types + // have a series of leading "[" characters to specify the number of dimensions. + // The other array type we handle uses trailing "[]" for the dimensions, just + // like the Java language syntax. + + // first check for the signature form ([[[[type). + if (className.charAt(0) == '[') { + // we have at least one array marker, now count how many leading '['s we have + // to get the dimension count. + int count = 0; + int nameLen = className.length(); + + while (count < nameLen && className.charAt(count) == '[') { + count++; + } + + // pull of the name subtype, which is everything after the last '[' + String arrayTypeName = className.substring(count, className.length()); + // resolve the type using a recursive call, which will load any of the primitive signature + // types as well as class names. + Class arrayType = loadClass(arrayTypeName, classLoader); + + // Resolving array types require a little more work. The array classes are + // created dynamically when the first instance of a given dimension and type is + // created. We need to create one using reflection to do this. + return getArrayClass(arrayType, count); + } + + + // ok, last chance. Now check for an array specification in Java language + // syntax. This will be a type name followed by pairs of "[]" to indicate + // the number of dimensions. + if (className.endsWith("[]")) { + // get the base component class name and the arrayDimensions + int count = 0; + int position = className.length(); + + while (position > 1 && className.substring(position - 2, position).equals("[]")) { + // count this dimension + count++; + // and step back the probe position. + position -= 2; + } + + // position now points at the location of the last successful test. This makes it + // easy to pick off the class name. + + String typeName = className.substring(0, position); + + // load the base type, again, doing this recursively + Class arrayType = loadClass(typeName, classLoader); + // and turn this into the class object + return getArrayClass(arrayType, count); + } + + throw new ClassNotFoundException("Could not load class " + className + " from unknown classloader; " + classLoader); + } + + + /** + * Map a class object back to a class name. The returned class object + * must be "round trippable", which means + *

+ * type == ClassLoading.loadClass(ClassLoading.getClassName(type), classLoader) + *

+ * must be true. To ensure this, the class name is always returned in + * method signature format. + * + * @param type The class object we convert into name form. + * @return A string representation of the class name, in method signature + * format. + */ + public static String getClassName(Class type) { + StringBuffer name = new StringBuffer(); + + // we test these in reverse order from the resolution steps, + // first handling arrays, then primitive types, and finally + // "normal" class objects. + + // First handle arrays. If a class is an array, the type is + // element stored at that level. So, for a 2-dimensional array + // of ints, the top-level type will be "[I". We need to loop + // down the hierarchy until we hit a non-array type. + while (type.isArray()) { + // add another array indicator at the front of the name, + // and continue with the next type. + name.append('['); + type = type.getComponentType(); + } + + // we're down to the base type. If this is a primitive, then + // we poke in the single-character type specifier. + if (type.isPrimitive()) { + name.append((String) CLASS_TO_SIGNATURE_MAP.get(type)); + } + // a "normal" class. This gets expressing using the "Lmy.class.name;" syntax. + else { + name.append('L'); + name.append(type.getName()); + name.append(';'); + } + return name.toString(); + } + + private static Class getArrayClass(Class type, int dimension) { + // Array.newInstance() requires an array of the requested number of dimensions + // that gives the size for each dimension. We just request 0 in each of the + // dimensions, which is not unlike a black hole singularity. + int[] dimensions = new int[dimension]; + // create an instance and return the associated class object. + return Array.newInstance(type, dimensions).getClass(); + } + + public static Set getAllTypes(Class type) { + Set allTypes = new LinkedHashSet(); + allTypes.add(type); + allTypes.addAll(getAllSuperClasses(type)); + allTypes.addAll(getAllInterfaces(type)); + return allTypes; + } + + private static Set getAllSuperClasses(Class clazz) { + Set allSuperClasses = new LinkedHashSet(); + for (Class superClass = clazz.getSuperclass(); superClass != null; superClass = superClass.getSuperclass()) { + allSuperClasses.add(superClass); + } + return allSuperClasses; + } + + private static Set getAllInterfaces(Class clazz) { + Set allInterfaces = new LinkedHashSet(); + LinkedList stack = new LinkedList(); + stack.addAll(Arrays.asList(clazz.getInterfaces())); + while (!stack.isEmpty()) { + Class intf = (Class) stack.removeFirst(); + if (!allInterfaces.contains(intf)) { + allInterfaces.add(intf); + stack.addAll(Arrays.asList(intf.getInterfaces())); + } + } + return allInterfaces; + } + + public static Set reduceInterfaces(Set source) { + Class[] classes = (Class[]) source.toArray(new Class[source.size()]); + classes = reduceInterfaces(classes); + return new LinkedHashSet(Arrays.asList(classes)); + } + + /** + * If there are multiple interfaces, and some of them extend each other, + * eliminate the superclass in favor of the subclasses that extend them. + * + * If one of the entries is a class (not an interface), make sure it's + * the first one in the array. If more than one of the entries is a + * class, throws an IllegalArgumentException + * + * @param source the original list of interfaces + * @return the equal or smaller list of interfaces + */ + public static Class[] reduceInterfaces(Class[] source) { + // use a copy of the source array + source = (Class[]) source.clone(); + + for (int leftIndex = 0; leftIndex < source.length-1; leftIndex++) { + Class left = source[leftIndex]; + if(left == null) { + continue; + } + + for (int rightIndex = leftIndex +1; rightIndex < source.length; rightIndex++) { + Class right = source[rightIndex]; + if(right == null) { + continue; + } + + if(left == right || right.isAssignableFrom(left)) { + // right is the same as class or a sub class of left + source[rightIndex] = null; + } else if(left.isAssignableFrom(right)) { + // left is the same as class or a sub class of right + source[leftIndex] = null; + + // the left has been eliminated; move on to the next left + break; + } + } + } + + Class clazz = null; + for (int i = 0; i < source.length; i++) { + if (source[i] != null && !source[i].isInterface()) { + if (clazz != null) { + throw new IllegalArgumentException("Source contains two classes which are not subclasses of each other: " + clazz.getName() + ", " + source[i].getName()); + } + clazz = source[i]; + source[i] = null; + } + } + + List list = new ArrayList(source.length); + if (clazz != null) list.add(clazz); + for (int i = 0; i < source.length; i++) { + if(source[i] != null) { + list.add(source[i]); + } + } + return (Class[]) list.toArray(new Class[list.size()]); + } +} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/DynamicStubClassLoader.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/DynamicStubClassLoader.java new file mode 100644 index 0000000000..82554a1c8f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/DynamicStubClassLoader.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.sca.binding.ejb.corba; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import javax.rmi.CORBA.Stub; + +import net.sf.cglib.core.NamingPolicy; +import net.sf.cglib.core.Predicate; +import net.sf.cglib.proxy.Callback; +import net.sf.cglib.proxy.CallbackFilter; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.FixedValue; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.NoOp; + +/** + * @version $Revision$ $Date$ + */ +public class DynamicStubClassLoader extends ClassLoader { + private static final String PACKAGE_PREFIX = "org.omg.stub."; + + @Override + public synchronized Class loadClass(final String name) throws ClassNotFoundException { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + + // check if the stub already exists first + try { + return classLoader.loadClass(name); + } catch (ClassNotFoundException e) { + } + + // if this is not a class from the org.omg.stub name space don't attempt to generate + if (!name.startsWith(PACKAGE_PREFIX)) { + throw new ClassNotFoundException("Could not load class: " + name); + } + + // load the interfaces class we are attempting to create a stub for + Class iface = loadStubInterfaceClass(name, classLoader); + + // create the stub builder + try { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(Stub.class); + enhancer.setInterfaces(new Class[] {iface}); + enhancer.setCallbackFilter(FILTER); + enhancer.setCallbackTypes(new Class[] {NoOp.class, MethodInterceptor.class, FixedValue.class}); + enhancer.setUseFactory(false); + enhancer.setClassLoader(classLoader); + enhancer.setNamingPolicy(new NamingPolicy() { + public String getClassName(String s, String s1, Object o, Predicate predicate) { + return name; + } + }); + + // generate the class + Class result = enhancer.createClass(); + assert result != null; + + StubMethodInterceptor interceptor = new StubMethodInterceptor(iface); + Ids ids = new Ids(iface); + Enhancer.registerStaticCallbacks(result, new Callback[] {NoOp.INSTANCE, interceptor, ids}); + + return result; + } catch (RuntimeException e) { + throw e; + } catch (Error e) { + throw e; + } + } + + private Class loadStubInterfaceClass(String name, ClassLoader classLoader) throws ClassNotFoundException { + try { + int begin = name.lastIndexOf('.') + 1; + String iPackage = name.substring(13, begin); + String iName = iPackage + name.substring(begin + 1, name.length() - 5); + + return classLoader.loadClass(iName); + } catch (ClassNotFoundException e) { + // don't log exceptions from CosNaming because it attempts to load every + // class bound into the name server + + //FIXME this variable is never read, can we remove the + // whole block of code?? + //boolean shouldLog = true; + StackTraceElement[] stackTrace = e.getStackTrace(); + for (int i = 0; i < stackTrace.length; i++) { + StackTraceElement stackTraceElement = stackTrace[i]; + if (stackTraceElement.getClassName().equals("org.omg.CosNaming.NamingContextExtPOA") && stackTraceElement + .getMethodName().equals("_invoke")) { + //shouldLog = false; + break; + } + } + + throw new ClassNotFoundException("Unable to generate stub", e); + } + } + + private static final CallbackFilter FILTER = new CallbackFilter() { + public int accept(Method method) { + // we don't intercept non-public methods like finalize + if (!Modifier.isPublic(method.getModifiers())) { + return 0; + } + + if (method.getReturnType().equals(String[].class) && method.getParameterTypes().length == 0 + && method.getName().equals("_ids")) { + return 2; + } + + if (Modifier.isAbstract(method.getModifiers())) { + return 1; + } + + return 0; + } + }; + + private static final class Ids implements FixedValue { + private final String[] typeIds; + + public Ids(Class type) { + typeIds = Java2IDLUtil.createCorbaIds(type); + } + + public Object loadObject() throws Exception { + return typeIds; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/Java2IDLUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/Java2IDLUtil.java new file mode 100644 index 0000000000..de8090c45b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/Java2IDLUtil.java @@ -0,0 +1,811 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.corba; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Method; +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.UnexpectedException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.ejb.spi.HandleDelegate; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.rmi.PortableRemoteObject; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.UserException; +import org.omg.CORBA.portable.IDLEntity; +import org.omg.CORBA.portable.ResponseHandler; +import org.omg.CORBA.portable.UnknownException; +import org.omg.CORBA_2_3.portable.InputStream; +import org.omg.CORBA_2_3.portable.OutputStream; +import org.omg.IOP.Codec; +import org.omg.IOP.CodecFactory; +import org.omg.IOP.ENCODING_CDR_ENCAPS; +import org.omg.IOP.Encoding; + +/** + * Various utility functions. + *

+ * Note: #getORB() and #getCodec() rely on UtilInitializer to initialize the ORB and codec. + * + * @version $Rev$ $Date$ + * @see UtilInitializer + */ +public final class Java2IDLUtil { + private static ORB orb; + private static Codec codec; + private static HandleDelegate handleDelegate; + + public static ORB getORB() { + assert orb != null; + return orb; + } + + + + public static void setORB(ORB orb) throws UserException { + if (Java2IDLUtil.orb == null) { + Java2IDLUtil.orb = orb; + CodecFactory factory = (CodecFactory) Java2IDLUtil.orb.resolve_initial_references("CodecFactory"); + codec = factory.create_codec(new Encoding(ENCODING_CDR_ENCAPS.value, (byte) 1, (byte) 2)); + } + } + + public static Codec getCodec() { + assert codec != null; + return codec; + } + + public static HandleDelegate getHandleDelegate() throws NamingException { + if (handleDelegate == null) { + InitialContext ic = new InitialContext(); + handleDelegate = (HandleDelegate) ic.lookup("java:comp/HandleDelegate"); + } + return handleDelegate; + } + + private static final Pattern SCOPED_NAME_EXTRACTION_PATTERN = Pattern.compile("(\\\\\\\\)|(\\\\@)|(@)|(\\z)"); + + /** + * See csiv2 Specification 16.2.5 par. 63-64. We extract the username if any and un-escape any + * escaped \ and @ characters. + * + * @param scopedNameBytes + * @return + * @throws UnsupportedEncodingException + */ + public static String extractUserNameFromScopedName(byte[] scopedNameBytes) throws UnsupportedEncodingException { + String scopedUserName = new String(scopedNameBytes, "UTF8"); + return extractUserNameFromScopedName(scopedUserName); + } + + public static String extractUserNameFromScopedName(String scopedUserName) { + Matcher m = SCOPED_NAME_EXTRACTION_PATTERN.matcher(scopedUserName); + StringBuffer buf = new StringBuffer(); + while (m.find()) { + m.appendReplacement(buf, ""); + if (m.group(1) != null) { + buf.append('\\'); + } else if (m.group(2) != null) { + buf.append("@"); + } else if (m.group(3) != null) { + break; + } + } + return buf.toString(); + } + + private static final Pattern SCOPED_NAME_ESCAPE_PATTERN = Pattern.compile("(\\\\)|(@)"); + + public static String buildScopedUserName(String user, String domain) { + StringBuffer buf = new StringBuffer(); + if (user != null) { + escape(user, buf); + } + if (domain != null) { + buf.append('@'); + escape(domain, buf); + } + return buf.toString(); + } + + private static void escape(String s, StringBuffer buf) { + Matcher m = SCOPED_NAME_ESCAPE_PATTERN.matcher(s); + while (m.find()) { + m.appendReplacement(buf, ""); + if (m.group(1) != null) { + buf.append("\\\\"); + } else if (m.group(2) != null) { + buf.append("\\@"); + } + } + m.appendTail(buf); + } + + + public static String byteToString(byte[] data) { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < data.length; i++) { + buffer.append(HEXCHAR[(data[i] >>> 4) & 0x0F]); + buffer.append(HEXCHAR[(data[i]) & 0x0F]); + } + return buffer.toString(); + + } + + private static final char[] HEXCHAR = { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' + }; + + public static void writeObject(Class type, Object object, OutputStream out) { + if (type == Void.TYPE) { + // do nothing for a void + } else if (type == Boolean.TYPE) { + out.write_boolean(((Boolean) object).booleanValue()); + } else if (type == Byte.TYPE) { + out.write_octet(((Byte) object).byteValue()); + } else if (type == Character.TYPE) { + out.write_wchar(((Character) object).charValue()); + } else if (type == Double.TYPE) { + out.write_double(((Double) object).doubleValue()); + } else if (type == Float.TYPE) { + out.write_float(((Float) object).floatValue()); + } else if (type == Integer.TYPE) { + out.write_long(((Integer) object).intValue()); + } else if (type == Long.TYPE) { + out.write_longlong(((Long) object).longValue()); + } else if (type == Short.TYPE) { + out.write_short(((Short) object).shortValue()); + } else { + // object types must be written in the context of the CORBA application server + // which properly write replaces our objects for CORBA + // ApplicationServer oldApplicationServer = ServerFederation.getApplicationServer(); + try { + // ServerFederation.setApplicationServer(corbaApplicationServer); + + // todo check if + // copy the result to force replacement + // CORBA does not call writeReplace on remote proxies + // + // HOWEVER, if this is an array, then we don't want to do the replacement + // because we can end up with a replacement element that's not compatible with the + // original array type, which results in an ArrayStoreException. Fortunately, + // the Yoko RMI support appears to be able to sort this out for us correctly. + if (object instanceof Serializable && !object.getClass().isArray()) { + try { + object = copyObj(Thread.currentThread().getContextClassLoader(), object); + } catch (Exception e) { + throw new UnknownException(e); + } + } + + if (type == Object.class || type == Serializable.class) { + javax.rmi.CORBA.Util.writeAny(out, object); + } else if (org.omg.CORBA.Object.class.isAssignableFrom(type)) { + out.write_Object((org.omg.CORBA.Object) object); + } else if (Remote.class.isAssignableFrom(type)) { + javax.rmi.CORBA.Util.writeRemoteObject(out, object); + } else if (type.isInterface() && Serializable.class.isAssignableFrom(type)) { + javax.rmi.CORBA.Util.writeAbstractObject(out, object); + } else { + out.write_value((Serializable) object, type); + } + } finally { + // ServerFederation.setApplicationServer(oldApplicationServer); + } + } + } + + private static Object copyObj(ClassLoader classLoader, Object object) throws IOException, ClassNotFoundException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(object); + oos.flush(); + oos.close(); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStreamExt ois = new ObjectInputStreamExt(bais, classLoader); + return ois.readObject(); + } + + public static Object readObject(Class type, InputStream in) { + if (type == Void.TYPE) { + return null; + } else if (type == Boolean.TYPE) { + return new Boolean(in.read_boolean()); + } else if (type == Byte.TYPE) { + return new Byte(in.read_octet()); + } else if (type == Character.TYPE) { + return new Character(in.read_wchar()); + } else if (type == Double.TYPE) { + return new Double(in.read_double()); + } else if (type == Float.TYPE) { + return new Float(in.read_float()); + } else if (type == Integer.TYPE) { + return new Integer(in.read_long()); + } else if (type == Long.TYPE) { + return new Long(in.read_longlong()); + } else if (type == Short.TYPE) { + return new Short(in.read_short()); + } else if (type == Object.class || type == Serializable.class) { + return javax.rmi.CORBA.Util.readAny(in); + } else if (org.omg.CORBA.Object.class.isAssignableFrom(type)) { + return in.read_Object(type); + } else if (Remote.class.isAssignableFrom(type)) { + return PortableRemoteObject.narrow(in.read_Object(), type); + } else if (type.isInterface() && Serializable.class.isAssignableFrom(type)) { + return in.read_abstract_interface(); + } else { + return in.read_value(type); + } + } + + public static void throwException(Method method, InputStream in) throws Throwable { + // read the exception id + final String id = in.read_string(); + + // get the class name from the id + if (!id.startsWith("IDL:")) { + return; + } + + Class[] exceptionTypes = method.getExceptionTypes(); + for (int i = 0; i < exceptionTypes.length; i++) { + Class exceptionType = exceptionTypes[i]; + + String exceptionId = getExceptionId(exceptionType); + if (id.equals(exceptionId)) { + throw (Throwable) in.read_value(exceptionType); + } + } + throw new UnexpectedException(id); + } + + public static OutputStream writeUserException(Method method, ResponseHandler reply, Exception exception) throws Exception { + if (exception instanceof RuntimeException || exception instanceof RemoteException) { + throw exception; + } + + Class[] exceptionTypes = method.getExceptionTypes(); + for (int i = 0; i < exceptionTypes.length; i++) { + Class exceptionType = exceptionTypes[i]; + if (!exceptionType.isInstance(exception)) { + continue; + } + + OutputStream out = (OutputStream) reply.createExceptionReply(); + String exceptionId = getExceptionId(exceptionType); + out.write_string(exceptionId); + out.write_value(exception); + return out; + } + throw exception; + } + + public static String getExceptionId(Class exceptionType) { + String exceptionName = exceptionType.getName().replace('.', '/'); + if (exceptionName.endsWith("Exception")) { + exceptionName = exceptionName.substring(0, exceptionName.length() - "Exception".length()); + } + exceptionName += "Ex"; + String exceptionId = "IDL:" + exceptionName + ":1.0"; + return exceptionId; + } + + public static String[] createCorbaIds(Class type) { + List ids = new LinkedList(); + for (Iterator iterator = getAllInterfaces(type).iterator(); iterator.hasNext();) { + Class superInterface = (Class) iterator.next(); + if (Remote.class.isAssignableFrom(superInterface) && superInterface != Remote.class) { + ids.add("RMI:" + superInterface.getName() + ":0000000000000000"); + } + } + return (String[]) ids.toArray(new String[ids.size()]); + } + + private static Set getAllInterfaces(Class intfClass) { + Set allInterfaces = new LinkedHashSet(); + + LinkedList stack = new LinkedList(); + stack.addFirst(intfClass); + + while (!stack.isEmpty()) { + Class intf = (Class) stack.removeFirst(); + allInterfaces.add(intf); + stack.addAll(0, Arrays.asList(intf.getInterfaces())); + } + + return allInterfaces; + } + + public static Map mapMethodToOperation(Class intfClass) { + return iiopMap(intfClass, false); + } + + public static Map mapOperationToMethod(Class intfClass) { + return iiopMap(intfClass, true); + } + + private static Map iiopMap(Class intfClass, boolean operationToMethod) { + Method[] methods = getAllMethods(intfClass); + + // find every valid getter + HashMap getterByMethod = new HashMap(methods.length); + HashMap getterByName = new HashMap(methods.length); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + String methodName = method.getName(); + + // no arguments allowed + if (method.getParameterTypes().length != 0) { + continue; + } + + // must start with get or is + String verb; + if (methodName.startsWith("get") && methodName.length() > 3 && method.getReturnType() != void.class) { + verb = "get"; + } else if (methodName.startsWith("is") && methodName.length() > 2 && method.getReturnType() == boolean.class) { + verb = "is"; + } else { + continue; + } + + // must only throw Remote or Runtime Exceptions + boolean exceptionsValid = true; + Class[] exceptionTypes = method.getExceptionTypes(); + for (int j = 0; j < exceptionTypes.length; j++) { + Class exceptionType = exceptionTypes[j]; + if (!RemoteException.class.isAssignableFrom(exceptionType) && + !RuntimeException.class.isAssignableFrom(exceptionType) && + !Error.class.isAssignableFrom(exceptionType)) { + exceptionsValid = false; + break; + } + } + if (!exceptionsValid) { + continue; + } + + String propertyName; + if (methodName.length() > verb.length() + 1 && Character.isUpperCase(methodName.charAt(verb.length() + 1))) { + propertyName = methodName.substring(verb.length()); + } else { + propertyName = Character.toLowerCase(methodName.charAt(verb.length())) + methodName.substring(verb.length() + 1); + } + getterByMethod.put(method, propertyName); + getterByName.put(propertyName, method); + } + + HashMap setterByMethod = new HashMap(methods.length); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + String methodName = method.getName(); + + // must have exactally one arg + if (method.getParameterTypes().length != 1) { + continue; + } + + // must return non void + if (method.getReturnType() != void.class) { + continue; + } + + // must start with set + if (!methodName.startsWith("set") || methodName.length() <= 3) { + continue; + } + + // must only throw Remote or Runtime Exceptions + boolean exceptionsValid = true; + Class[] exceptionTypes = method.getExceptionTypes(); + for (int j = 0; j < exceptionTypes.length; j++) { + Class exceptionType = exceptionTypes[j]; + if (!RemoteException.class.isAssignableFrom(exceptionType) && + !RuntimeException.class.isAssignableFrom(exceptionType) && + !Error.class.isAssignableFrom(exceptionType)) { + exceptionsValid = false; + break; + } + } + if (!exceptionsValid) { + continue; + } + + String propertyName; + if (methodName.length() > 4 && Character.isUpperCase(methodName.charAt(4))) { + propertyName = methodName.substring(3); + } else { + propertyName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); + } + + // must have a matching getter + Method getter = (Method) getterByName.get(propertyName); + if (getter == null) { + continue; + } + + // setter property must match getter return value + if (!method.getParameterTypes()[0].equals(getter.getReturnType())) { + continue; + } + setterByMethod.put(method, propertyName); + } + + // index the methods by name... used to determine which methods are overloaded + HashMap overloadedMethods = new HashMap(methods.length); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + if (getterByMethod.containsKey(method) || setterByMethod.containsKey(method)) { + continue; + } + String methodName = method.getName(); + List methodList = (List) overloadedMethods.get(methodName); + if (methodList == null) { + methodList = new LinkedList(); + overloadedMethods.put(methodName, methodList); + } + methodList.add(method); + } + + // index the methods by lower case name... used to determine which methods differ only by case + HashMap caseCollisionMethods = new HashMap(methods.length); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + if (getterByMethod.containsKey(method) || setterByMethod.containsKey(method)) { + continue; + } + String lowerCaseMethodName = method.getName().toLowerCase(); + Set methodSet = (Set) caseCollisionMethods.get(lowerCaseMethodName); + if (methodSet == null) { + methodSet = new HashSet(); + caseCollisionMethods.put(lowerCaseMethodName, methodSet); + } + methodSet.add(method.getName()); + } + + String className = getClassName(intfClass); + Map iiopMap = new HashMap(methods.length); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + + String iiopName = (String) getterByMethod.get(method); + if (iiopName != null) { + // if we have a leading underscore prepend with J + if (iiopName.charAt(0) == '_') { + iiopName = "J_get_" + iiopName.substring(1); + } else { + iiopName = "_get_" + iiopName; + } + } else { + iiopName = (String) setterByMethod.get(method); + if (iiopName != null) { + // if we have a leading underscore prepend with J + if (iiopName.charAt(0) == '_') { + iiopName = "J_set_" + iiopName.substring(1); + } else { + iiopName = "_set_" + iiopName; + } + } else { + iiopName = method.getName(); + + // if we have a leading underscore prepend with J + if (iiopName.charAt(0) == '_') { + iiopName = "J" + iiopName; + } + } + } + + // if this name only differs by case add the case index to the end + Set caseCollisions = (Set) caseCollisionMethods.get(method.getName().toLowerCase()); + if (caseCollisions != null && caseCollisions.size() > 1) { + iiopName += upperCaseIndexString(iiopName); + } + + // if this is an overloaded method append the parameter string + List overloads = (List) overloadedMethods.get(method.getName()); + if (overloads != null && overloads.size() > 1) { + iiopName += buildOverloadParameterString(method.getParameterTypes()); + } + + // if we have a leading underscore prepend with J + iiopName = replace(iiopName, '$', "U0024"); + + // if we have matched a keyword prepend with an underscore + if (keywords.contains(iiopName.toLowerCase())) { + iiopName = "_" + iiopName; + } + + // if the name is the same as the class name, append an underscore + if (iiopName.equalsIgnoreCase(className)) { + iiopName += "_"; + } + + if (operationToMethod) { + iiopMap.put(iiopName, method); + } else { + iiopMap.put(method, iiopName); + } + } + + return iiopMap; + } + + private static Method[] getAllMethods(Class intfClass) { + LinkedList methods = new LinkedList(); + for (Iterator iterator = getAllInterfaces(intfClass).iterator(); iterator.hasNext();) { + Class intf = (Class) iterator.next(); + methods.addAll(Arrays.asList(intf.getDeclaredMethods())); + } + + return (Method[]) methods.toArray(new Method[methods.size()]); + } + + /** + * Return the a string containing an underscore '_' index of each uppercase character in the IIOP name. + * + * This is used for distinction of names that only differ by case, since CORBA does not support case sensitive names. + */ + private static String upperCaseIndexString(String iiopName) { + StringBuffer stringBuffer = new StringBuffer(); + for (int i = 0; i < iiopName.length(); i++) { + char c = iiopName.charAt(i); + if (Character.isUpperCase(c)) { + stringBuffer.append('_').append(i); + } + } + return stringBuffer.toString(); + } + + /** + * Replaces any occurances of the specified "oldChar" with the new string. + * + * This is used to replace occurances if '$' in CORBA names since '$' is a special character + */ + private static String replace(String source, char oldChar, String newString) { + StringBuffer stringBuffer = new StringBuffer(source.length()); + for (int i = 0; i < source.length(); i++) { + char c = source.charAt(i); + if (c == oldChar) { + stringBuffer.append(newString); + } else { + stringBuffer.append(c); + } + } + return stringBuffer.toString(); + } + + /** + * Return the a string containing a double underscore '__' list of parameter types encoded using the Java to IDL rules. + * + * This is used for distinction of methods that only differ by parameter lists. + */ + private static String buildOverloadParameterString(Class[] parameterTypes) { + String name = ""; + if (parameterTypes.length ==0) { + name += "__"; + } else { + for (int i = 0; i < parameterTypes.length; i++) { + Class parameterType = parameterTypes[i]; + name += buildOverloadParameterString(parameterType); + } + } + return name.replace('.', '_'); + } + + /** + * Returns a single parameter type encoded using the Java to IDL rules. + */ + private static String buildOverloadParameterString(Class parameterType) { + String name = "_"; + + int arrayDimensions = 0; + while (parameterType.isArray()) { + arrayDimensions++; + parameterType = parameterType.getComponentType(); + } + + // arrays start with org_omg_boxedRMI_ + if (arrayDimensions > 0) { + name += "_org_omg_boxedRMI"; + } + + // IDLEntity types must be prefixed with org_omg_boxedIDL_ + if (IDLEntity.class.isAssignableFrom(parameterType)) { + name += "_org_omg_boxedIDL"; + } + + // add package... some types have special mappings in corba + String packageName = (String) specialTypePackages.get(parameterType.getName()); + if (packageName == null) { + packageName = getPackageName(parameterType.getName()); + } + if (packageName.length() > 0) { + name += "_" + packageName; + } + + // arrays now contain a dimension indicator + if (arrayDimensions > 0) { + name += "_" + "seq" + arrayDimensions; + } + + // add the class name + String className = (String) specialTypeNames.get(parameterType.getName()); + if (className == null) { + className = buildClassName(parameterType); + } + name += "_" + className; + + return name; + } + + /** + * Returns a string containing an encoded class name. + */ + private static String buildClassName(Class type) { + if (type.isArray()) { + throw new IllegalArgumentException("type is an array: " + type); + } + + // get the classname + String typeName = type.getName(); + int endIndex = typeName.lastIndexOf('.'); + if (endIndex < 0) { + return typeName; + } + StringBuffer className = new StringBuffer(typeName.substring(endIndex + 1)); + + // for innerclasses replace the $ separator with two underscores + // we can't just blindly replace all $ characters since class names can contain the $ character + if (type.getDeclaringClass() != null) { + String declaringClassName = getClassName(type.getDeclaringClass()); + assert className.toString().startsWith(declaringClassName + "$"); + className.replace(declaringClassName.length(), declaringClassName.length() + 1, "__"); + } + + // if we have a leading underscore prepend with J + if (className.charAt(0) == '_') { + className.insert(0, "J"); + } + return className.toString(); + } + + private static String getClassName(Class type) { + if (type.isArray()) { + throw new IllegalArgumentException("type is an array: " + type); + } + + // get the classname + String typeName = type.getName(); + int endIndex = typeName.lastIndexOf('.'); + if (endIndex < 0) { + return typeName; + } + return typeName.substring(endIndex + 1); + } + + private static String getPackageName(String interfaceName) { + int endIndex = interfaceName.lastIndexOf('.'); + if (endIndex < 0) { + return ""; + } + return interfaceName.substring(0, endIndex); + } + + private static final Map specialTypeNames; + private static final Map specialTypePackages; + private static final Set keywords; + + static { + specialTypeNames = new HashMap(); + specialTypeNames.put("boolean", "boolean"); + specialTypeNames.put("char", "wchar"); + specialTypeNames.put("byte", "octet"); + specialTypeNames.put("short", "short"); + specialTypeNames.put("int", "long"); + specialTypeNames.put("long", "long_long"); + specialTypeNames.put("float", "float"); + specialTypeNames.put("double", "double"); + specialTypeNames.put("java.lang.Class", "ClassDesc"); + specialTypeNames.put("java.lang.String", "WStringValue"); + specialTypeNames.put("org.omg.CORBA.Object", "Object"); + + specialTypePackages = new HashMap(); + specialTypePackages.put("boolean", ""); + specialTypePackages.put("char", ""); + specialTypePackages.put("byte", ""); + specialTypePackages.put("short", ""); + specialTypePackages.put("int", ""); + specialTypePackages.put("long", ""); + specialTypePackages.put("float", ""); + specialTypePackages.put("double", ""); + specialTypePackages.put("java.lang.Class", "javax.rmi.CORBA"); + specialTypePackages.put("java.lang.String", "CORBA"); + specialTypePackages.put("org.omg.CORBA.Object", ""); + + keywords = new HashSet(); + keywords.add("abstract"); + keywords.add("any"); + keywords.add("attribute"); + keywords.add("boolean"); + keywords.add("case"); + keywords.add("char"); + keywords.add("const"); + keywords.add("context"); + keywords.add("custom"); + keywords.add("default"); + keywords.add("double"); + keywords.add("enum"); + keywords.add("exception"); + keywords.add("factory"); + keywords.add("false"); + keywords.add("fixed"); + keywords.add("float"); + keywords.add("in"); + keywords.add("inout"); + keywords.add("interface"); + keywords.add("long"); + keywords.add("module"); + keywords.add("native"); + keywords.add("object"); + keywords.add("octet"); + keywords.add("oneway"); + keywords.add("out"); + keywords.add("private"); + keywords.add("public"); + keywords.add("raises"); + keywords.add("readonly"); + keywords.add("sequence"); + keywords.add("short"); + keywords.add("string"); + keywords.add("struct"); + keywords.add("supports"); + keywords.add("switch"); + keywords.add("true"); + keywords.add("truncatable"); + keywords.add("typedef"); + keywords.add("union"); + keywords.add("unsigned"); + keywords.add("valuebase"); + keywords.add("valuetype"); + keywords.add("void"); + keywords.add("wchar"); + keywords.add("wstring"); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ObjectInputStreamExt.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ObjectInputStreamExt.java new file mode 100644 index 0000000000..1be4a98a48 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ObjectInputStreamExt.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.sca.binding.ejb.corba; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectStreamClass; +import java.lang.reflect.Proxy; + +/** + * @version $Rev$ $Date$ + */ +public class ObjectInputStreamExt extends ObjectInputStream { + + private ClassLoader classloader; + + public ObjectInputStreamExt(InputStream in, ClassLoader loader) throws IOException { + super(in); + this.classloader = loader; + } + + @Override + protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException { + return ClassLoadingUtil.loadClass(classDesc.getName(), classloader); + } + + @Override + protected Class resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { + Class[] cinterfaces = new Class[interfaces.length]; + for (int i = 0; i < interfaces.length; i++) + cinterfaces[i] = classloader.loadClass(interfaces[i]); + + try { + return Proxy.getProxyClass(classloader, cinterfaces); + } catch (IllegalArgumentException e) { + throw new ClassNotFoundException(null, e); + } + } + + ClassLoader getClassloader() { + return classloader; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/StubMethodInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/StubMethodInterceptor.java new file mode 100644 index 0000000000..3ff0ed552a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/StubMethodInterceptor.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.corba; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.Map; + +import javax.ejb.EJBObject; +import javax.rmi.CORBA.Stub; +import javax.rmi.CORBA.Util; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.RemarshalException; +import org.omg.CORBA.portable.ServantObject; +import org.omg.CORBA_2_3.portable.InputStream; +import org.omg.CORBA_2_3.portable.OutputStream; + +/** + * @version $Revision$ $Date$ + */ +public class StubMethodInterceptor implements MethodInterceptor { + private static final Method ISIDENTICAL; + + static { + try { + ISIDENTICAL = EJBObject.class.getMethod("isIdentical", new Class[]{EJBObject.class}); + } catch (NoSuchMethodException e) { + throw new ExceptionInInitializerError(e); + } + } + + private final Class type; + private final Map operations; + + public StubMethodInterceptor(Class type) { + this.type = type; + this.operations = Collections.unmodifiableMap(org.apache.tuscany.sca.binding.ejb.corba.Java2IDLUtil.mapMethodToOperation(type)); + } + + public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + Stub stub = (Stub) proxy; + + // handle is identical in stub to avoid unnecessary round trip + if (method.equals(ISIDENTICAL)) { + org.omg.CORBA.Object otherObject = (org.omg.CORBA.Object) args[0]; + return new Boolean(stub._is_equivalent(otherObject)); + } + + // get the operation name object + String operationName = (String) operations.get(method); + if (operationName == null) { + throw new IllegalStateException("Unknown method: " + method); + } + + while (true) { + // if this is a stub to a remote object we invoke over the wire + if (!Util.isLocal(stub)) { + + InputStream in = null; + try { + // create the request output stream + OutputStream out = (OutputStream) stub._request(operationName, true); + + // write the arguments + Class[] parameterTypes = method.getParameterTypes(); + for (int i = 0; i < parameterTypes.length; i++) { + Class parameterType = parameterTypes[i]; + org.apache.tuscany.sca.binding.ejb.corba.Java2IDLUtil.writeObject(parameterType, args[i], out); + } + + // send the invocation + in = (InputStream) stub._invoke(out); + + // read the result + Object result = org.apache.tuscany.sca.binding.ejb.corba.Java2IDLUtil.readObject(method.getReturnType(), in); + return result; + } catch (RemarshalException exception) { + continue; + } catch (ApplicationException exception) { + org.apache.tuscany.sca.binding.ejb.corba.Java2IDLUtil.throwException(method, (InputStream) exception.getInputStream()); + } catch (SystemException e) { + throw Util.mapSystemException(e); + } finally { + stub._releaseReply(in); + } + } else { + // get the servant + ServantObject servantObject = stub._servant_preinvoke(operationName, type); + if (servantObject == null) { + continue; + } + + try { + // copy the arguments + Object[] argsCopy = Util.copyObjects(args, stub._orb()); + + // invoke the servant + Object result = null; + try { + result = method.invoke(servantObject.servant, argsCopy); + } catch (InvocationTargetException e) { + if (e.getCause() != null) { + throw e.getCause(); + } + throw e; + } + + // copy the result + result = Util.copyObject(result, stub._orb()); + + return result; + } catch (Throwable throwable) { + // copy the exception + Throwable throwableCopy = (Throwable) Util.copyObject(throwable, stub._orb()); + + // if it is one of my exception rethrow it + Class[] exceptionTypes = method.getExceptionTypes(); + for (int i = 0; i < exceptionTypes.length; i++) { + Class exceptionType = exceptionTypes[i]; + if (exceptionType.isInstance(throwableCopy)) { + throw throwableCopy; + } + } + + throw Util.wrapException(throwableCopy); + } finally { + stub._servant_postinvoke(servantObject); + } + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/UtilInitializer.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/UtilInitializer.java new file mode 100644 index 0000000000..f9aa9ffa22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/UtilInitializer.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.sca.binding.ejb.corba; + +import org.omg.CORBA.LocalObject; +import org.omg.PortableInterceptor.ORBInitInfo; +import org.omg.PortableInterceptor.ORBInitializer; + +/** + * The sole purpose of this initializer is to register a non-singleton ORB + * with the class Util. + * + * @version $Revision$ $Date$ + * @see Java2IDLUtil + */ +public class UtilInitializer extends LocalObject implements ORBInitializer { + + private static final long serialVersionUID = 4901857563505370955L; + + /** + * Called during ORB initialization. If it is expected that initial + * services registered by an interceptor will be used by other + * interceptors, then those initial services shall be registered at + * this point via calls to + * ORBInitInfo.register_initial_reference. + * + * @param info provides initialization attributes and operations by + * which Interceptors can be registered. + */ + public void pre_init(ORBInitInfo info) { + } + + /** + * Called during ORB initialization. If a service must resolve initial + * references as part of its initialization, it can assume that all + * initial references will be available at this point. + *

+ * Calling the post_init operations is not the final + * task of ORB initialization. The final task, following the + * post_init calls, is attaching the lists of registered + * interceptors to the ORB. Therefore, the ORB does not contain the + * interceptors during calls to post_init. If an + * ORB-mediated call is made from within post_init, no + * request interceptors will be invoked on that call. + * Likewise, if an operation is performed which causes an IOR to be + * created, no IOR interceptors will be invoked. + * + * @param info provides initialization attributes and + * operations by which Interceptors can be registered. + */ + public void post_init(ORBInitInfo info) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingInvoker.java new file mode 100644 index 0000000000..9247c1d3db --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingInvoker.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.sca.binding.ejb.provider; + +import org.apache.tuscany.sca.binding.ejb.EJBBinding; +import org.apache.tuscany.sca.binding.ejb.util.EJBHandler; +import org.apache.tuscany.sca.binding.ejb.util.NamingEndpoint; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; + +/** + * EJBTargetInvoker + * + * @version $Rev$ $Date$ + */ +public class EJBBindingInvoker implements Invoker, DataExchangeSemantics { + + private Operation operation; + private String location; + private Class serviceInterface; + + public EJBBindingInvoker(EJBBinding ejbBinding, Class serviceInterface, Operation operation) { + this.serviceInterface = serviceInterface; + this.location = ejbBinding.getURI(); + this.operation = operation; + } + + public Message invoke(Message msg) { + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(serviceInterface.getClassLoader()); + Object resp = doInvoke(msg.getBody()); + msg.setBody(resp); + } catch (Throwable e) { + e.printStackTrace(); + msg.setFaultBody(e); + } finally { + Thread.currentThread().setContextClassLoader(tccl); + } + return msg; + } + + /** + * Invoke a EJB operation + * + * @param payload + * @return + */ + public Object doInvoke(final Object payload) { + + // construct NamingendPoint + NamingEndpoint endpoint = getNamingEndpoint(); + + // lookup home and ejb stub + EJBHandler ejbHandler = new EJBHandler(endpoint, serviceInterface); + + String methodName = operation.getName(); + + // invoke business method on ejb + Object response = ejbHandler.invoke(methodName, (Object[])payload); + + return response; + } + + protected NamingEndpoint getNamingEndpoint() { + return new NamingEndpoint(location); + } + + public boolean allowsPassByReference() { + // EJB RMI/IIOP always pass by value + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingProviderFactory.java new file mode 100644 index 0000000000..a6ea583d0b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingProviderFactory.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.sca.binding.ejb.provider; + +import org.apache.tuscany.sca.binding.ejb.EJBBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * A factory from creating the EJB binding provider. + * + * @version $Rev$ $Date$ + */ +public class EJBBindingProviderFactory implements BindingProviderFactory { + + public EJBBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + EJBBinding binding) { + return new EJBBindingReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + EJBBinding binding) { + return null; + //throw new EJBBindingException("Service Binding not supported for EJB Binding"); + } + + public Class getModelType() { + return EJBBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingReferenceBindingProvider.java new file mode 100644 index 0000000000..2a02bf0d08 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/provider/EJBBindingReferenceBindingProvider.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.provider; + +import org.apache.tuscany.sca.binding.ejb.EJBBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the ReferenceBindingProvider for the EJBBinding. + * + * @version $Rev$ $Date$ + */ +public class EJBBindingReferenceBindingProvider implements ReferenceBindingProvider { + private EJBBinding ejbBinding; + private RuntimeComponentReference reference; + + /** + * Constructor + * + * @param component + * @param reference + * @param binding + */ + public EJBBindingReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + EJBBinding binding) { + this.reference = reference; + this.ejbBinding = binding; + } + + /** + * {@inheritDoc} + */ + public Invoker createInvoker(Operation operation) { + return new EJBBindingInvoker(ejbBinding, ((JavaInterface)reference.getInterfaceContract().getInterface()) + .getJavaClass(), operation); + } + + /** + * {@inheritDoc} + */ + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + /** + * {@inheritDoc} + */ + public void start() { + } + + /** + * {@inheritDoc} + */ + public void stop() { + } + + /** + * {@inheritDoc} + */ + public boolean supportsOneWayInvocation() { + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java new file mode 100644 index 0000000000..d41dbd0a0f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java @@ -0,0 +1,338 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.RemoteException; +import java.util.HashMap; +import java.util.Map; + +import javax.ejb.EJBObject; +import javax.rmi.CORBA.Util; + +import org.apache.tuscany.sca.binding.ejb.corba.ClassLoadingUtil; +import org.omg.CORBA.ORB; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.RemarshalException; +import org.omg.CORBA.portable.ServantObject; +import org.omg.CORBA_2_3.portable.InputStream; +import org.omg.CORBA_2_3.portable.OutputStream; +import org.osoa.sca.ServiceRuntimeException; + +/** + * EJBMessageHandler + * + * @version $Rev$ $Date$ + */ +public class EJBHandler { + private static final Map PRIMITIVE_TYPES = new HashMap(); + static { + PRIMITIVE_TYPES.put("boolean", boolean.class); + PRIMITIVE_TYPES.put("byte", byte.class); + PRIMITIVE_TYPES.put("char", char.class); + PRIMITIVE_TYPES.put("short", short.class); + PRIMITIVE_TYPES.put("int", int.class); + PRIMITIVE_TYPES.put("long", long.class); + PRIMITIVE_TYPES.put("float", float.class); + PRIMITIVE_TYPES.put("double", double.class); + PRIMITIVE_TYPES.put("void", void.class); + } + + private Object ejbStub; + + private InterfaceInfo interfaceInfo; + private Class ejbInterface; + + public EJBHandler(NamingEndpoint namingEndpoint, Class ejbInterface) { + this(namingEndpoint, InterfaceInfo.getInstance(ejbInterface)); + this.ejbInterface = ejbInterface; + } + + // locates the stub + private EJBHandler(NamingEndpoint namingEndpoint, InterfaceInfo ejbInterface) { + try { + this.ejbStub = EJBStubHelper.lookup(namingEndpoint, ejbInterface); + this.interfaceInfo = ejbInterface; + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + private static Class loadClass(final String name) { + try { + return ClassLoadingUtil.loadClass(name, Thread.currentThread().getContextClassLoader()); + } catch (ClassNotFoundException e) { + throw new ServiceRuntimeException(e); + } + } + + // invokes EJB method + public Object invoke(String methodName, Object[] args) { + Object response = null; + try { + if (ejbStub instanceof ObjectImpl) { + ObjectImpl objectImpl = (ObjectImpl)ejbStub; + // TODO: If the Java 2 security is turned on, then + // the ORB will try to create proxy + // from the interfaces defined on the stub + if (System.getSecurityManager() == null && objectImpl._is_local()) { + /* + * CORBA.Stub is what the object from JNDI will be for a + * remote EJB in the same JVM as the client, but with no + * stub classes available on the client + */ + response = invokeLocalCORBACall(objectImpl, methodName, args); + } else { + /* + * _EJBObject_Stub is what the object from JNDI will be for + * a remote EJB with no stub classes available on the client + */ + response = invokeRemoteCORBACall(objectImpl, methodName, args); + } + } else { + /* + * A generated ejb stub or it must be an EJB in the same ear as + * the client or an AppServer with a single ClassLoader, so + * reflection can be used directly on the JNDI + */ + JavaReflectionAdapter reflectionAdapter = + JavaReflectionAdapter.createJavaReflectionAdapter(ejbStub.getClass()); + try { + Method method = reflectionAdapter.getMethod(methodName); + response = method.invoke(ejbStub, args); + } catch (InvocationTargetException e) { + Throwable t = e.getTargetException(); + // FIXME need to throw really a business exception. + // ServiceBusinessException? + // Tuscany core doesn't have ServiceBusinessException + throw new ServiceRuntimeException(t); + } + } + + return response; + } catch (Exception e) { + // FIXME this be business exception? Tuscany core doesn't have + // ServiceBusinessException + throw new ServiceRuntimeException(e); + + } catch (Throwable e) { + throw new ServiceRuntimeException(e); + } + } + + /** + * Get the IDL operation name for a java method + * + * @param methodName java method name + * @return The IDL operation name + */ + private String getOperation(String methodName) { + if (interfaceInfo == null) { + return methodName; + } + MethodInfo methodInfo = interfaceInfo.getMethod(methodName); + if (methodInfo != null) { + return methodInfo.getIDLName(); + } else { + return null; + } + } + + /* + * Derive the EJB interface name from the Stub When loading a stub class + * corresponding to an interface or class ., the + * class .__Stub shall be used if it exists; + * otherwise, the class org.omg.stub..__Stub shall + * be used. + */ + private static String getInterface(String stubName) { + int index = stubName.lastIndexOf('.'); + String packageName = null; + String typeName = stubName; + if (index != -1) { + packageName = stubName.substring(0, index); + if (packageName.startsWith("org.omg.stub.")) { + packageName = packageName.substring("org.omg.stub.".length()); + } + typeName = stubName.substring(index + 1); + } + if (typeName.startsWith("_") && typeName.endsWith("_Stub")) { + typeName = typeName.substring(1, typeName.length() - "_Stub".length()); + } + if (packageName != null) + return packageName + "." + typeName; + else + return typeName; + } + + /** + * Invoke a method on the local CORBA object + * + * @param stub + * @param methodName + * @param args + * @return + * @throws RemoteException + * @throws ServiceBusinessException + */ + private Object invokeLocalCORBACall(final ObjectImpl stub, String methodName, Object[] args) + throws RemoteException { + + final String operation = getOperation(methodName); + + Class type = loadClass(getInterface(stub.getClass().getName())); + if (type == null) + type = (ejbInterface != null) ? ejbInterface : EJBObject.class; + + ServantObject so = stub._servant_preinvoke(operation, type); + if (so == null) { + // The Servant is not local any more + return invokeRemoteCORBACall(stub, methodName, args); + } + Object[] newArgs = null; + ORB orb = stub._orb(); + try { + if (args != null) + newArgs = Util.copyObjects(args, orb); + JavaReflectionAdapter reflectionAdapter = + JavaReflectionAdapter.createJavaReflectionAdapter(so.servant.getClass()); + Method method = reflectionAdapter.getMethod(methodName); + Object obj = reflectionAdapter.invoke(method, so.servant, newArgs); + Object result = Util.copyObject(obj, orb); + return result; + + } catch (InvocationTargetException e) { + Throwable exCopy = (Throwable)Util.copyObject(e.getTargetException(), orb); + MethodInfo methodInfo = interfaceInfo.getMethod(methodName); + String[] exceptionTypes = methodInfo.getExceptionTypes(); + for (int i = 0; i < exceptionTypes.length; i++) { + Class exceptionType = + methodInfo.getMethod() != null ? methodInfo.getMethod().getExceptionTypes()[i] + : loadClass(exceptionTypes[i]); + if (exceptionType.isAssignableFrom(exCopy.getClass())) + throw new ServiceRuntimeException(exCopy); // FIXME should + // be business + // exception? + } + throw Util.wrapException(exCopy); + } catch (Throwable e) { + // Other exceptions thrown from "invoke" + throw new ServiceRuntimeException(e); + } finally { + stub._servant_postinvoke(so); + } + } + + /** + * Invoke a method on a remote CORBA object + * + * @param stub The remote stub + * @param methodName The name of the method + * @param args Argument list + * @return + * @throws RemoteException + * @throws ServiceBusinessException + */ + private Object invokeRemoteCORBACall(ObjectImpl stub, String methodName, Object[] args) throws RemoteException { + + try { + String operation = getOperation(methodName); + + MethodInfo methodInfo = interfaceInfo.getMethod(methodName); + if (methodInfo == null) { + throw new ServiceRuntimeException("Invalid Method " + methodName); + } + Class[] parameterTypes = null; + Class returnType = null; + if (methodInfo.getMethod() != null) { + parameterTypes = methodInfo.getMethod().getParameterTypes(); + returnType = methodInfo.getMethod().getReturnType(); + } else { + String[] types = methodInfo.getParameterTypes(); + if (args != null) { + if (types.length != args.length) + throw new ServiceRuntimeException( + "The argument list doesn't match the method signature of " + methodName); + } + + parameterTypes = new Class[types.length]; + for (int i = 0; i < types.length; i++) { + parameterTypes[i] = loadClass(types[i]); + } + returnType = loadClass(methodInfo.getReturnType()); + } + + InputStream in = null; + try { + OutputStream out = (OutputStream)stub._request(operation, true); + + for (int i = 0; i < parameterTypes.length; i++) { + // Object arg = (args.length < i) ? null : args[i]; + writeValue(out, args[i], parameterTypes[i]); + } + if (returnType == void.class) { + // void return + stub._invoke(out); + return null; + } else { + // read the return value + in = (InputStream)stub._invoke(out); + Object response = readValue(in, returnType); + return response; + } + + } catch (ApplicationException ex) { + in = (InputStream)ex.getInputStream(); + try { + org.apache.tuscany.sca.binding.ejb.corba.Java2IDLUtil.throwException(methodInfo.getMethod(), in); + return null; + } catch (Throwable e) { + throw new RemoteException(e.getMessage(), e); + } + } catch (RemarshalException ex) { + return invokeRemoteCORBACall(stub, methodName, args); + } finally { + stub._releaseReply(in); + } + } catch (SystemException ex) { + throw Util.mapSystemException(ex); + } + } + + /** + * @param out + * @param value + * @param type + */ + private void writeValue(OutputStream out, Object value, Class type) { + org.apache.tuscany.sca.binding.ejb.corba.Java2IDLUtil.writeObject(type, value, out); + } + + /** + * @param in + * @param type + * @return + */ + private Object readValue(InputStream in, Class type) { + return org.apache.tuscany.sca.binding.ejb.corba.Java2IDLUtil.readObject(type, in); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java new file mode 100644 index 0000000000..0b97f42746 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java @@ -0,0 +1,483 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.omg.CORBA.ORB; +import org.omg.CosNaming.NamingContextExt; + +/** + * CosNaming utility + * + * @version $Rev$ $Date$ + */ +class EJBLocator { + + /* + * Root Context Initial Reference Key ------------ + * ----------------------------------- Server Root NameServiceServerRoot + * Cell Persistent Root NameServiceCellPersistentRoot Cell Root + * NameServiceCellRoot, NameService Node Root NameServiceNodeRoot + */ + public static final String SERVER_ROOT = "NameServiceServerRoot"; + public static final String CELL_PERSISTENT_ROOT = "NameServiceCellPersistentRoot"; + public static final String CELL_ROOT = "NameServiceCellRoot"; + public static final String NODE_ROOT = "NameServiceNodeRoot"; + public static final String DEFAULT_ROOT = "NameService"; // Same as + // CELL_ROOT + + public static final String DEFAULT_HOST = "127.0.0.1"; // Default host name + // or IP address for + // WebSphere + public static final int DEFAULT_NAMING_PORT = 2809; // Default port + public static final String NAMING_SERVICE = "NameService"; // The name of + // the naming + // service + private static final Set ROOTS = + new HashSet(Arrays.asList(new String[] {SERVER_ROOT, CELL_PERSISTENT_ROOT, CELL_ROOT, DEFAULT_ROOT, + NODE_ROOT})); + + // private static final String CHARS_TO_ESCAPE = "\\/."; + private static final String RFC2396 = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789;/:?@&=+$,-_.!~*'()"; + private static final String HEX = "0123456789ABCDEF"; + + private String hostName = DEFAULT_HOST; + private int port = DEFAULT_NAMING_PORT; + private String root = SERVER_ROOT; + + private ORB orb = null; + private ObjectLocator locator = null; + private boolean managed = true; + + EJBLocator(boolean managed) { + this.managed = managed; + if (!managed) { + String url = AccessController.doPrivileged(new PrivilegedAction() { + public String run() { + return System.getProperty(Context.PROVIDER_URL); + } + }); + processCorbaURL(url); + } + } + + EJBLocator(String hostName, int port) { + this.hostName = (hostName == null) ? DEFAULT_HOST : hostName; + this.port = port > 0 ? port : DEFAULT_NAMING_PORT; + this.root = SERVER_ROOT; + } + + EJBLocator(String hostName, int port, String root) { + this(hostName, port); + if (ROOTS.contains(root)) { + this.root = root; + } else { + throw new IllegalArgumentException(root + " is not a legal root"); + } + } + + EJBLocator(String corbaName, boolean managed) { + this.managed = managed; + if (corbaName.startsWith("corbaname:iiop:")) { + processCorbaURL(corbaName); + } else { + throw new IllegalArgumentException(corbaName + " is not a legal corbaname"); + } + } + + private void processCorbaURL(String url) { + if (url != null && (url.startsWith("corbaname:iiop:") || url.startsWith("corbaloc:iiop:"))) { + /** + * corbaname:iiop::/#name corbaloc:iiop::/ + * For example, + * "corbaname:iiop:localhost:2809/NameServiceServerRoot#ejb/MyEJBHome"; + * or "corbaloc:iiop:myhost:2809/NameServiceServerRoot" + */ + String[] parts = url.split("(:|/|#)"); + if (parts.length > 2 && parts[2].length() > 0) { + hostName = parts[2]; // The host name + int index = hostName.lastIndexOf('@'); // version@hostname + if (index != -1) { + hostName = hostName.substring(index + 1); + } + } + if (parts.length > 3 && parts[3].length() > 0) { + port = Integer.parseInt(parts[3]); // The port number + } + if (parts.length > 4 && parts[4].length() > 0) { + root = parts[4]; // The root of naming + } + } + } + + /** + * The corbaloc and corbaname formats enable you to provide a URL to access + * CORBA objects. Use the corbaloc format for resolving to a particular + * CORBAservice without going through a naming service. Use the corbaname + * format to resolve a stringified name from a specific naming context. + */ + + /** + * corbaname Syntax The full corbaname BNF is: <corbaname> = + * "corbaname:"<corbaloc_obj>["#"<string_name>] + * <corbaloc_obj> = <obj_addr_list> ["/"<key_string>] + * <obj_addr_list> = as defined in a corbaloc URL <key_string> = + * as defined in a corbaloc URL <string_name>= stringified Name + * empty_string Where: + *

    + *
  • corbaloc_obj: portion of a corbaname URL that identifies the naming + * context. The syntax is identical to its use in a corbaloc URL. + *
  • obj_addr_list: as defined in a corbaloc URL + *
  • key_string: as defined in a corbaloc URL. + *
  • string_name: a stringified Name with URL escapes as defined below. + *
+ * + * @param hostName The host name or IP address of the naming server + * @param port The port number of the naming service + * @param root The root of the namespace + * @param name The JNDI name + */ + private static String getCorbaname(String hostName, int port, String root, String name) { + if (name == null) { + return "corbaname:iiop:" + hostName + ":" + port + "/" + root; + } else { + return "corbaname:iiop:" + hostName + ":" + port + "/" + root + "#" + toCorbaname(name); + } + } + + String getCorbaname(String name) { + return getCorbaname(hostName, port, root, name); + } + + /** + * Connect to the ORB. + */ + + // FIXME. May need to change the IBM classes if this binding is contributed + // to Tuscany + public ORB connect() { + if (orb == null) { + Properties props = new Properties(); + /* + * This code is for IBM JVM props.put("org.omg.CORBA.ORBClass", + * "com.ibm.CORBA.iiop.ORB"); + * props.put("com.ibm.CORBA.ORBInitRef.NameService", + * getCorbaloc(NAMING_SERVICE)); + * props.put("com.ibm.CORBA.ORBInitRef.NameServiceServerRoot", + * getCorbaloc("NameServiceServerRoot")); + */ + orb = ORB.init((String[])null, props); + } + return orb; + } + + /** + * Replace substrings + * + * @param source The source string. + * @param match The string to search for within the source string. + * @param replace The replacement for any matching components. + * @return + */ + private static String replace(String source, String match, String replace) { + int index = source.indexOf(match, 0); + if (index >= 0) { + + // We have at least one match, so got to do the + // work... + + StringBuffer result = new StringBuffer(source.length() + 16); + int matchLength = match.length(); + int startIndex = 0; + + while (index >= 0) { + result.append(source.substring(startIndex, index)); + result.append(replace); + startIndex = index + matchLength; + index = source.indexOf(match, startIndex); + } + + // Grab the last piece, if any... + if (startIndex < source.length()) { + result.append(source.substring(startIndex)); + } + + return result.toString(); + + } else { + // No matches, just return the source... + return source; + } + } + + /** + * Resolved the JNDI name from the initial CosNaming context + * + * @param jndiName + * @return resolved CORBA object + * @throws NamingException + */ + private static org.omg.CORBA.Object resovleString(NamingContextExt initCtx, String jndiName) throws NamingException { + try { + String name = stringify(jndiName); + return initCtx.resolve_str(name); + } catch (Exception e) { + NamingException ne = new NamingException(e.getMessage()); + ne.setRootCause(e); + throw ne; + } + } + + /** + * Look up a CORBA object by its JNDI name + * + * @param jndiName + * @return + * @throws NamingException + */ + org.omg.CORBA.Object stringToObject(String jndiName) throws NamingException { + /* + * Using an existing ORB and invoking string_to_object with a CORBA + * object URL with multiple name server addresses to get an initial + * context CORBA object URLs can contain more than one bootstrap server + * address. Use this feature when attempting to obtain an initial + * context from a server cluster. You can specify the bootstrap server + * addresses for all servers in the cluster in the URL. The operation + * will succeed if at least one of the servers is running, eliminating a + * single point of failure. There is no guarantee of any particular + * order in which the address list will be processed. For example, the + * second bootstrap server address may be used to obtain the initial + * context even though the first bootstrap server in the list is + * available. An example of a corbaloc URL with multiple addresses + * follows. obj = + * orb.string_to_object("corbaloc::myhost1:9810,:myhost1:9811,:myhost2:9810/NameService"); + */ + String corbaName = null; + if (jndiName.startsWith("corbaloc:") || jndiName.startsWith("corbaname:")) { + // Keep the qualified URL + corbaName = jndiName; + } else { + // Create a corbaname URL + corbaName = getCorbaname(jndiName); + } + + connect(); + org.omg.CORBA.Object obj = orb.string_to_object(corbaName); + return obj; + } + + private boolean isJndiConfigured() { + if (managed) + return true; + Boolean provided = AccessController.doPrivileged(new PrivilegedAction() { + public Boolean run() { + String initCtxFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); + if (initCtxFactory == null) { + URL file = Thread.currentThread().getContextClassLoader().getResource("jndi.properties"); + if (file != null) { + return Boolean.TRUE; + } else { + return Boolean.FALSE; + } + } else { + return Boolean.TRUE; + } + } + }); + return provided.booleanValue(); + } + + /** + * The character escape rules for the stringified name portion of an + * corbaname are: US-ASCII alphanumeric characters are not escaped. + * Characters outside this range are escaped, except for the following: ; / : ? @ & = + $ , - _ . ! ~ * ' ( ) + * corbaname Escape Mechanism The percent '%' character is used as an + * escape. If a character that requires escaping is present in a name + * component it is encoded as two hexadecimal digits following a "%" + * character to represent the octet. (The first hexadecimal character + * represent the highorder nibble of the octet, the second hexadecimal + * character represents the low-order nibble.) If a '%' is not followed by + * two hex digits, the stringified name is syntactically invalid. + * @param s + * @return RFC2396-encoded stringified name + */ + static String encode2396(String s) { + if (s == null) { + return null; + } + StringBuffer encoded = new StringBuffer(s); + for (int i = 0; i < encoded.length(); i++) { + char c = encoded.charAt(i); + if (RFC2396.indexOf(c) == -1) { + encoded.setCharAt(i, '%'); + char[] ac = Integer.toHexString(c).toCharArray(); + if (ac.length == 2) { + encoded.insert(i + 1, ac); + } else if (ac.length == 1) { + encoded.insert(i + 1, '0'); + encoded.insert(i + 2, ac[0]); + } else { + throw new IllegalArgumentException("Invalid character '" + c + "' in \"" + s + "\""); + } + i += 2; // NOPMD + } + } + return encoded.toString(); + } + + /** + * Decode an RFC2396-encoded string + * + * @param s + * @return Plain string + */ + static String decode2396(String s) { + if (s == null) { + return null; + } + StringBuffer decoded = new StringBuffer(s); + for (int i = 0; i < decoded.length(); i++) { + char c = decoded.charAt(i); + if (c == '%') { + if (i + 2 >= decoded.length()) { + throw new IllegalArgumentException("Incomplete key_string escape sequence"); + } + int j; + j = HEX.indexOf(decoded.charAt(i + 1)) * 16 + HEX.indexOf(decoded.charAt(i + 2)); + decoded.setCharAt(i, (char)j); + decoded.delete(i + 1, i + 3); + } else if (RFC2396.indexOf(c) == -1) { + throw new IllegalArgumentException("Invalid key_string character '" + c + "'"); + } + } + return decoded.toString(); + } + + /** + * The backslash '\' character escapes the reserved meaning of '/', '.', and + * '\' in a stringified name. + * + * @param jndiName + * @return Escaped stringified name for CosNaming + */ + private static String stringify(String jndiName) { + // Escape . into \. since it's an INS naming delimiter + return replace(encode2396(jndiName), ".", "\\."); + } + + /** + * Escape the "." into "%5C%2E" + * + * @param jndiName + * @return corbaname treating "." as a literal + */ + private static String toCorbaname(String jndiName) { + // Escape . into %5C%2E (\.) since it's an INS naming delimiter + // For example, sca.sample.StockQuote ---> + // sca%5C%2Esample%5C%2EStockQuote/StockQuote + return replace(encode2396(jndiName), ".", "%5C%2E"); + } + + private ObjectLocator getObjectLocator() throws NamingException { + if (locator != null) { + return locator; + } + /* + * For managed env, JNDI is assumed to be configured by default For + * unmanaged environment, JNDI could have configured through + * jndi.properties file + */ + if (isJndiConfigured()) { + locator = new JndiLocator(); + } else { // this is definitely JSE env without JNDI configured. Use + // CORBA. + locator = new CosNamingLocator(); + } + return locator; + } + + public Object locate(String jndiName) throws NamingException { + + Object result = getObjectLocator().locate(jndiName); + return result; + } + + private static interface ObjectLocator { + Object locate(String name) throws NamingException; + } + + private final class JndiLocator implements ObjectLocator { + private Context context; + + private JndiLocator() throws NamingException { + /* + final Properties props = AccessController.doPrivileged(new PrivilegedAction() { + public Properties run() { + return System.getProperties(); + } + }); + Properties properties = new Properties(); + for (Map.Entry e : props.entrySet()) { + String name = (String)e.getKey(); + if (name.startsWith("java.naming.")) { + properties.setProperty(name, (String)e.getValue()); + } + } + // System.out.println(properties); + this.context = new InitialContext(properties); + */ + this.context = new InitialContext(); + } + + public Object locate(String name) throws NamingException { + return context.lookup(name); + } + } + + private final class CosNamingLocator implements ObjectLocator { + private NamingContextExt context; + + private CosNamingLocator() { + } + + public Object locate(String name) throws NamingException { + if (context != null) { + return resovleString(context, name); + } else { + return stringToObject(name); + } + } + } + + public void setHostEnv(boolean managed) { + this.managed = managed; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java new file mode 100644 index 0000000000..d34cfe1b16 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.RemoteException; +import java.rmi.UnexpectedException; + +import javax.ejb.CreateException; +import javax.ejb.EJBLocalHome; +import javax.naming.NamingException; +import javax.rmi.CORBA.Util; + +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.RemarshalException; +import org.omg.stub.java.rmi._Remote_Stub; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Factor class that is used to create EJB Proxies. + * + * @version $Rev$ $Date$ + */ +final class EJBObjectFactory { + + private EJBObjectFactory() { + } + + /** + * Get either a generated of dynamic EJB stub using the specified JNDI + * properties. + *

+ * The returned stub will implement the specified stubInterface Interface. + * If the underlying EJB stub is not assignable from the specified + * stubInterface then a proxy is used to convert between the two. + *

+ * The returned EJB stub may be either the pregenerated EJB stub or a + * dynamic stub. This allows a client to invoke an EJB without requiring any + * of the pregenerated EJB stub classes be available in the classpath. + *

+ */ + static Object createStub(NamingEndpoint namingEndpoint, InterfaceInfo ejbInterface) throws NamingException, + RemoteException, CreateException { + + EJBLocator locator = namingEndpoint.getLocator(); + Object homeObject = locator.locate(namingEndpoint.getJndiName()); + /* + * The type of the object returned from the lookup is as follows: If the + * generated stub exists on the classpath, it's an instance of that + * type, otherwise, "org.omg.stub.java.rmi._Remote_Stub" or + * "org.omg.stub.javax.ejb._EJBHome_Stub" + */ + Object stub = getEJBStub(homeObject, ejbInterface); + // Cache dynamic stub only + return stub; + } + + /** + * @param homeObject + * @param ejbHomeClass + * @return + * @throws RemoteException + */ + private static Object getEJBStub(Object homeObject, InterfaceInfo ejbInterface) throws RemoteException, + CreateException { + + Object stub = null; + + // Get the business interface of the EJB + Class ejbInterfaceClass = null; + try { + ejbInterfaceClass = Thread.currentThread().getContextClassLoader().loadClass(ejbInterface.getName()); + } catch (ClassNotFoundException e) { + // ignore + } + + if (ejbInterfaceClass != null && ejbInterfaceClass.isInstance(homeObject)) { + // EJB 3 + stub = homeObject; + } else if (homeObject instanceof EJBLocalHome) { + // Local EJB + stub = createEJBLocalObject(homeObject); + } else { + // Handle dynamic stub + if (homeObject instanceof ObjectImpl) { + ObjectImpl objectImpl = (ObjectImpl)homeObject; + stub = createEJBObject(objectImpl); + }/** + * Above checks will be satisfied if Bean is running on servers like WebSphere. With this + * logic, client (SCA composite with EJB ref binding) doesn't need to include home class or + * client stubs. + * + * Below check is needed SCA composite with EJB ref binding is accessing openEJB implementation. + * For e.g if the bean is running on Geronimo. + */ + else if ((javax.rmi.PortableRemoteObject.narrow(homeObject, javax.ejb.EJBHome.class)) instanceof javax.ejb.EJBHome) { + stub = createEJBObjectFromHome(homeObject); + } else + throw new ServiceRuntimeException("Invalid stub type: " + homeObject.getClass()); + } + return stub; + } + + /** + * Create a pre-generated EJB stub + * + * @param homeObject + * @return + * @throws RemoteException + */ + static private Object createEJBLocalObject(Object homeObject) throws RemoteException { + + Object stub = null; + try { + // Find the "create()" method + Method createMethod = homeObject.getClass().getMethod("create", null); + // Create an EJB object + stub = createMethod.invoke(homeObject, null); + } catch (NoSuchMethodException e) { + // "create()" method not found, it's still a dynamic stub + stub = null; + } catch (InvocationTargetException e) { + throw new RemoteException(e.getTargetException().toString()); + } catch (Exception e) { + throw new RemoteException(e.toString()); + } + return stub; + } + + /** + * Here homeObject is instance of EJBHome + * + * @param homeObject + * @return + * @throws RemoteException + */ + private static Object createEJBObjectFromHome(Object homeObject) throws RemoteException { + + Object stub = null; + try { + // Find the "create()" method + Method createMethod = homeObject.getClass().getMethod("create", null); + // Create an EJB object + stub = createMethod.invoke(homeObject, null); + } catch (NoSuchMethodException e) { + // "create()" method not found, it's still a dynamic stub + stub = null; + } catch (InvocationTargetException e) { + throw new RemoteException(e.getTargetException().toString()); + } catch (Exception e) { + throw new RemoteException(e.toString()); + } + return stub; + } + + /** + * Create an EJBObject using RMI/IIOP APIs + * + * @param ejbHomeObject + * @return The EJBObject remote stub + * @throws CreateException + * @throws RemoteException + */ + private static Object createEJBObject(ObjectImpl ejbHomeObject) throws CreateException, RemoteException { + + try { + org.omg.CORBA_2_3.portable.InputStream in = null; + try { + org.omg.CORBA.portable.OutputStream out = ejbHomeObject._request("create", true); + in = (org.omg.CORBA_2_3.portable.InputStream)ejbHomeObject._invoke(out); + // The Remote stub should be available in JDK + // TODO: [rfeng] Work around an issue in Apache Yoko which doesn't understand the org.omg.stub.* + return in.read_Object(_Remote_Stub.class); + } catch (ApplicationException ex) { + in = (org.omg.CORBA_2_3.portable.InputStream)ex.getInputStream(); + String id = in.read_string(); + if (id.equals("IDL:javax/ejb/CreateEx:1.0")) { + throw (CreateException)in.read_value(CreateException.class); + } + throw new UnexpectedException(id); + } catch (RemarshalException ex) { + return createEJBObject(ejbHomeObject); + } finally { + ejbHomeObject._releaseReply(in); + } + } catch (SystemException ex) { + throw Util.mapSystemException(ex); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java new file mode 100644 index 0000000000..b699a02d1d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.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.sca.binding.ejb.util; + +import java.rmi.RemoteException; + +import javax.ejb.CreateException; +import javax.naming.NamingException; + +import org.osoa.sca.ServiceRuntimeException; +import org.osoa.sca.ServiceUnavailableException; + +final class EJBStubHelper { + + private static Object stub; + private static ServiceRuntimeException exception; + + private EJBStubHelper() { + } + + /** + * @param owner + * @param jndiName + * @return + */ + + static Object lookup(NamingEndpoint endpoint, InterfaceInfo ejbInterface) { + return getStub(endpoint, ejbInterface); + } + + private static Object getStub(NamingEndpoint namingEndpoint, InterfaceInfo ejbInterface) { + try { + stub = EJBObjectFactory.createStub(namingEndpoint, ejbInterface); + } catch (NamingException e) { + exception = new ServiceUnavailableException(e); + e.printStackTrace(); + throw (ServiceUnavailableException)exception; + } catch (CreateException e) { + exception = new ServiceUnavailableException(e); + throw (ServiceUnavailableException)exception; + } catch (RemoteException e) { + exception = new ServiceRuntimeException(e); + throw (ServiceRuntimeException)exception; + } + + if (exception == null) { + return stub; // Normal result + } else { + throw exception; // Throw the exception + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.java new file mode 100644 index 0000000000..e60e526e01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.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.sca.binding.ejb.util; + +import java.io.Serializable; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.WeakHashMap; + +import org.apache.tuscany.sca.binding.ejb.corba.Java2IDLUtil; + +/** + * The signature for a java interface + * + * @version $Rev$ $Date$ + */ +class InterfaceInfo implements Serializable { + + private static final Map INTERFACES = + Collections.synchronizedMap(new WeakHashMap()); + + private static final long serialVersionUID = 2314533906465094860L; + private String name; + + private Map methods = new HashMap(); + + InterfaceInfo(final Class iface) { + super(); + if (iface == null) { + throw new IllegalArgumentException("The interface cannot be null"); + } + this.name = iface.getName(); + // SECURITY + /* + * Permission: accessDeclaredMembers : Access denied + * (java.lang.RuntimePermission accessDeclaredMembers) + */ + Map idlNames = AccessController.doPrivileged(new PrivilegedAction() { + public Map run() { + return Java2IDLUtil.mapMethodToOperation(iface); + } + }); + Iterator i = idlNames.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry entry = (Map.Entry)i.next(); + Method method = (Method)entry.getKey(); + MethodInfo methodInfo = new MethodInfo(method); + methodInfo.setIDLName((String) entry.getValue()); + methods.put(method.getName(), methodInfo); + methods.put(methodInfo.getIDLName(), methodInfo); + } + } + + static final synchronized InterfaceInfo getInstance(final Class iface) { + InterfaceInfo info = (InterfaceInfo)INTERFACES.get(iface); + if (info == null) { + info = new InterfaceInfo(iface); + INTERFACES.put(iface, info); + } + return info; + } + + /** + * @return + */ + Map getMethods() { + return methods; + } + + /** + * @return + */ + MethodInfo getMethod(String name) { + return (MethodInfo)methods.get(name); + } + + /** + * @return + */ + String getName() { + return name; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("interface ").append(name).append("{ \n"); + Iterator i = methods.values().iterator(); + while (i.hasNext()) { + MethodInfo methodInfo = (MethodInfo)i.next(); + sb.append("\t").append(methodInfo).append("\n"); + } + sb.append("};\n"); + return sb.toString(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java new file mode 100644 index 0000000000..5e7d6761d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.WeakHashMap; + +import org.osoa.sca.ServiceRuntimeException; + +/** + * An adapter for java classes, indexes the methods by name and provides an + * invoke method that takes a method name. + * + * @version $Rev$ $Date$ + */ +final class JavaReflectionAdapter { + + private static Map adapters = + Collections.synchronizedMap(new WeakHashMap()); + + private static final Map DEFAULT_VALUES = new HashMap(); + static { + DEFAULT_VALUES.put(boolean.class, Boolean.FALSE); + DEFAULT_VALUES.put(byte.class, new Byte((byte)0)); + DEFAULT_VALUES.put(char.class, new Character((char)0)); + DEFAULT_VALUES.put(short.class, new Short((short)0)); + DEFAULT_VALUES.put(int.class, Integer.valueOf(0)); + DEFAULT_VALUES.put(long.class, new Long(0)); + DEFAULT_VALUES.put(float.class, new Float(0.0)); + DEFAULT_VALUES.put(double.class, new Double(0.0)); + } + + private Map methodMap = new HashMap(); + + /** + * Constructor + * + * @param clazz + */ + private JavaReflectionAdapter(final Class clazz) { + // Index the methods on the implementation class + // FIXME J2 Security - promote this to callers of this method + Method[] methods = AccessController.doPrivileged(new PrivilegedAction() { + public Method[] run() { + return clazz.getMethods(); + } + }); + for (int i = 0; i < methods.length; i++) { + methodMap.put(methods[i].getName(), methods[i]); + } + } + + /** + * Create a java reflection adapter + * + * @param clazz + */ + static synchronized JavaReflectionAdapter createJavaReflectionAdapter(Class clazz) { + JavaReflectionAdapter adapter = (JavaReflectionAdapter)adapters.get(clazz); + if (adapter == null) { + adapter = new JavaReflectionAdapter(clazz); + adapters.put(clazz, adapter); + } + return adapter; + } + + /** + * Return the specified method + * + * @param methodName + * @return + * @throws NoSuchMethodException + */ + Method getMethod(String methodName) throws NoSuchMethodException { + + Method method = (Method)methodMap.get(methodName); + if (method == null) { + throw new NoSuchMethodException(methodName); + } + return method; + } + + /** + * Returns a map containing the methods on the class, keyed by name + * + * @return + */ + Map getMethods() { + return methodMap; + } + + /** + * Invoke a method using Java reflection. + * + * @param method + * @param object + * @param args + * @return + * @throws InvocationTargetException + * @throws IllegalAccessException + */ + Object invoke(Method method, Object object, Object[] args) throws InvocationTargetException, + IllegalAccessException { + Class[] parameterTypes = method.getParameterTypes(); + for (int i = 0; i < parameterTypes.length; i++) { + Class parameterType = parameterTypes[i]; + if (args[i] == null && parameterType.isPrimitive()) { + args[i] = DEFAULT_VALUES.get(parameterType); + } + } + return method.invoke(object, args); + } + + /** + * Set the java bean property + * + * @param bean + * @param propertyName + * @param value + * @return + */ + boolean setProperty(Object bean, String propertyName, Object value) { + try { + PropertyDescriptor propertyDescriptor = new PropertyDescriptor(propertyName, bean.getClass()); + Method writeMethod = propertyDescriptor.getWriteMethod(); + writeMethod.invoke(bean, new Object[] {value}); + return true; + } catch (InvocationTargetException e) { + throw new ServiceRuntimeException(e.getTargetException()); + } catch (Exception e) { + return false; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java new file mode 100644 index 0000000000..e7ea7c9077 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.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.sca.binding.ejb.util; + +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +/** + * MetaData for a java method + * + * @version $Rev$ $Date$ + */ +class MethodInfo implements Serializable { + + /** Automatically generated javadoc for: serialVersionUID */ + private static final long serialVersionUID = -5557260979514687514L; + private String name; + private String returnType; + private String[] parameterTypes; + private String[] exceptionTypes; + + private String IDLName; + + private transient Method method; + + /** + * Type Signature Java Type -------------- --------- Z boolean B byte C char + * S short I int J long F float D double L fully-qualified-class ; + * fully-qualified-class [ type type[] ( arg-types ) ret-type method type + */ + private static final Map signatures = new HashMap(); + static { + signatures.put("Z", boolean.class); + signatures.put("B", byte.class); + signatures.put("C", char.class); + signatures.put("S", short.class); + signatures.put("I", int.class); + signatures.put("J", long.class); + signatures.put("F", float.class); + signatures.put("D", double.class); + signatures.put("V", void.class); + } + + MethodInfo(Method method) { + this.method = method; + this.name = method.getName(); + // this.declaringClass = method.getDeclaringClass().getName(); + this.returnType = method.getReturnType().getName(); + Class[] types = method.getParameterTypes(); + this.parameterTypes = new String[types.length]; + for (int i = 0; i < types.length; i++) { + this.parameterTypes[i] = types[i].getName(); + } + types = method.getExceptionTypes(); + this.exceptionTypes = new String[types.length]; + for (int i = 0; i < types.length; i++) { + this.exceptionTypes[i] = types[i].getName(); + } + IDLName = this.name; + } + + MethodInfo(String name, String returnType, String[] parameterTypes, String[] exceptionTypes) { + this.name = name; + this.returnType = returnType; + this.parameterTypes = parameterTypes; + this.exceptionTypes = exceptionTypes; + this.IDLName = name; + } + + /** + * Parse the class name from the internal signature Sample signatures: int + * ---> I; int[] ---> [I Object ---> java/lang/Object Object[] ---> + * [Ljava/lang/Object; + * + * @param value + * @return + */ + private static String getName(String signature) { + String name = signature; + // Remove leading ARRAY ([) signatures + int index = name.lastIndexOf('['); + if (index != -1) + name = name.substring(index + 1); + + // Remove L<...>; + if (name.charAt(0) == 'L' && name.charAt(name.length() - 1) == ';') + name = name.substring(1, name.length() - 1); + + // Primitive types + Class primitiveClass = (Class)signatures.get(name); + if (primitiveClass != null) { + name = primitiveClass.getName(); + } + + for (int i = 0; i < index + 1; i++) { + name = name + "[]"; + } + return name; + } + + /** + * @return + */ + String getName() { + return name; + } + + /** + * @return + */ + String[] getParameterTypes() { + return parameterTypes; + } + + /** + * @return + */ + String getReturnType() { + return returnType; + } + + /** + * @return + */ + String[] getExceptionTypes() { + return exceptionTypes; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(getName(returnType)).append(" ").append(name).append("("); + for (int j = 0; j < parameterTypes.length; j++) { + sb.append(getName(parameterTypes[j])).append(" ").append("arg" + j); + if (j < (parameterTypes.length - 1)) + sb.append(", "); + } + sb.append(")"); + if (exceptionTypes.length > 0) { + sb.append(" throws "); + for (int k = 0; k < exceptionTypes.length; k++) { + sb.append(exceptionTypes[k]); + if (k < (exceptionTypes.length - 1)) + sb.append(", "); + } + } + sb.append(";"); + return sb.toString(); + } + + /** + * @return Returns the iDLName. + */ + String getIDLName() { + return IDLName; + } + + /** + * @param name The iDLName to set. + */ + void setIDLName(String name) { + IDLName = name; + } + + /** + * @return the method + */ + Method getMethod() { + return method; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java new file mode 100644 index 0000000000..346b7c5cf6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.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.sca.binding.ejb.util; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +public class NamingEndpoint { + private String jndiName; + private EJBLocator locator; + private boolean managed = true; + + public NamingEndpoint(String hostName, int port, String jndiName) { + this.jndiName = jndiName; + this.locator = new EJBLocator(hostName, port); + } + + public NamingEndpoint(String name) { + + /** + * by default it's a managed environment means SCA composite with ref + * binding is running on an AppServer. If running on J2SE, pass + * -Dmanaged=false for the VM + */ + final String managedEnv = AccessController.doPrivileged(new PrivilegedAction() { + public String run() { + return System.getProperty("managed"); + } + }); + + if (managedEnv != null) { + managed = Boolean.valueOf(managedEnv); + } + + if ((!managed) && name.startsWith("corbaname:iiop:")) { + /** + * if (name.startsWith("corbaname:iiop:")) { corbaname:iiop::/#name + * For example, + * "corbaname:iiop:localhost:2809/NameServiceServerRoot#ejb/MyEJBHome"; + */ + + String[] parts = split(name, '#'); + if (parts.length != 2) { + throw new IllegalArgumentException("Invalid corbaname: " + name); + } + + this.jndiName = name; // The logical JNDI name + this.locator = new EJBLocator(parts[0], managed); + + } else { + this.jndiName = name; + this.locator = new EJBLocator(managed); + } + + } + + private static String[] split(String str, char ch) { + int index = str.lastIndexOf(ch); + if (index == -1) { + return new String[] {str, ""}; + } else { + return new String[] {str.substring(0, index), str.substring(index + 1)}; + } + } + + /** + * @return Returns the jndiName. + */ + public String getJndiName() { + return jndiName; + } + + public EJBLocator getLocator() { + return locator; + } + + public String getCorbaname() { + return locator.getCorbaname(jndiName); + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof NamingEndpoint) { + NamingEndpoint endpoint = (NamingEndpoint)obj; + return jndiName.equals(endpoint.jndiName); + } + return false; + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return jndiName.hashCode(); + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return jndiName; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..a89f711da9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.ejb.provider.EJBBindingProviderFactory;model=org.apache.tuscany.sca.binding.ejb.EJBBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/resources/binding-ejb-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/resources/binding-ejb-validation-messages.properties new file mode 100644 index 0000000000..28477dd3ac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/main/resources/binding-ejb-validation-messages.properties @@ -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. +# +# +UnknownEJBSessionType = Unknown EJB Session Type of {0} for {1} +UnknownEJBVersion = Unknown EJB Version of {0} for {1} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/BankManagerFacade.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/BankManagerFacade.java new file mode 100644 index 0000000000..28dafedaeb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/BankManagerFacade.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 account; + +import org.osoa.sca.annotations.Remotable; + +/** + * + * Compatible EJB interface + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface BankManagerFacade { + Double getAccountBalance( String accountNo ); + void changeAccountBalance( String accountNo, Double balance ); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/Customer.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/Customer.java new file mode 100644 index 0000000000..49ece71f7a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/Customer.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 account; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Customer { + + /** + * This method deposits the amount. method accesses external EJB to get the + * current balance and add the amount to existing balance. + * + * @param accountNo The number of the account into which to deposit the money + * @param amount The amount to be deposited + * @return total amount in customer account after deposit + */ + Double depositAmount(java.lang.String accountNo, Double amount); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/CustomerImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/CustomerImpl.java new file mode 100644 index 0000000000..ed2b403f2d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/account/CustomerImpl.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 account; + +import org.osoa.sca.ServiceRuntimeException; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +import calculator.AddServiceRemote; + +@Service(Customer.class) +public class CustomerImpl implements Customer { + + private AddServiceRemote extEJBService = null; + + public AddServiceRemote getExtEJBService() { + return extEJBService; + } + + @Reference + public void setExtEJBService(AddServiceRemote extEJBService) { + this.extEJBService = extEJBService; + } + + // this method invokes external EJB through EJB reference binding + public Double depositAmount(java.lang.String accountNo, Double amount) { + + Double total = null; + + System.out.println("In component implementation. Invoking external EJB through EJB reference binding "); + + try { + Double balance = extEJBService.add(amount.doubleValue(), 1000); //invoke external ejb through ejb reference binding + total = balance + amount; + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + return total; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/calculator/AddServiceRemote.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/calculator/AddServiceRemote.java new file mode 100644 index 0000000000..b0d1c8f6e5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/calculator/AddServiceRemote.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import javax.ejb.Remote; + +@Remote +public interface AddServiceRemote { + double add(double n1, double n2); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java new file mode 100644 index 0000000000..e480e648d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.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. + */ + +/* + * Generated by XDoclet - Do not edit! + */ +package org.apache.geronimo.samples.bank.ejb; + +// copied from the Geronimo Bank sample: http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html#EJBsampleapplication-overview + +/** + * Remote interface for BankManagerFacadeBean. + * @xdoclet-generated at ${TODAY} + * @copyright The XDoclet Team + * + * @version $Rev$ $Date$ + */ +public interface BankManagerFacade + extends javax.ejb.EJBObject +{ + + void changeAccountBalance( java.lang.String accountNo,java.lang.Double balance ) + throws java.rmi.RemoteException; + + java.lang.Double getAccountBalance( java.lang.String accountNo ) + throws java.rmi.RemoteException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java new file mode 100644 index 0000000000..0d02be3b95 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.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. + */ + +/* + * Generated by XDoclet - Do not edit! + */ + +// copied from the Geronimo Bank sample: http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html#EJBsampleapplication-overview + +package org.apache.geronimo.samples.bank.ejb; + +/** + * Home interface for BankManagerFacadeBean. + * @xdoclet-generated at ${TODAY} + * @copyright The XDoclet Team + * + * @version $Rev$ $Date$ + */ +public interface BankManagerFacadeHome + extends javax.ejb.EJBHome +{ + String COMP_NAME="java:comp/env/ejb/BankManagerFacadeBean"; + String JNDI_NAME="org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean"; + + org.apache.geronimo.samples.bank.ejb.BankManagerFacade create() + throws javax.ejb.CreateException,java.rmi.RemoteException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java new file mode 100644 index 0000000000..83bf9c8673 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.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.sca.binding.ejb.tests; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import account.Customer; + +/** + * Invokes the component which calls the reference using the EJB binding + * + * @version $Rev$ $Date$ + */ +public class EJBReferenceTestCase { + private static final int MOCK_PORT = 8085; + private SCADomain scaDomain; + + @Before + public void setUp() throws Exception { + System.setProperty("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory"); + System.setProperty("java.naming.provider.url", "ejbd://localhost:" + MOCK_PORT); + System.setProperty("managed", "false"); + + scaDomain = SCADomain.newInstance("account/account.composite"); + + // To capture the network traffic for the MockServer, uncomment the next two lines (A) and comment out B + // int OPENEJB_PORT = 4201; // A + // new Thread(new SocketTracer(MOCK_PORT, OPENEJB_PORT)).start(); // A + + // Start the mock server to simulate the remote EJB + new Thread(new MockServer(MOCK_PORT)).start(); // B + + // Wait enough for the server to be started + Thread.sleep(500); + } + + @After + public void tearDown() throws Exception { + scaDomain.close(); + } + + @Test + public void testCalculator() throws Exception { + Customer customer = scaDomain.getService(Customer.class, "CustomerComponent"); + // This is one of the customer numbers in bank application running on Geronimo + String accountNo = "1234567890"; + Double balance = customer.depositAmount(accountNo, new Double(100)); + // System.out.println("Balance amount for account " + accountNo + " is $" + balance); + Assert.assertEquals(1200.0, balance, 0.0); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java new file mode 100644 index 0000000000..e0cce4bae6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.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.sca.binding.ejb.tests; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.ServerSocket; +import java.net.Socket; + +public class MockServer implements Runnable { + + private int listen; + byte[][] seq = + { + {79, 69, 74, 80, 47, 51, 46, 48, 1, -84, -19, 0, 5, 119, 21, 1, 27, 0, 17, 47, 65, 100, 100, 83, 101, 114, + 118, 105, 99, 101, 82, 101, 109, 111, 116, 101, 112, 119, 4, -63, -5, 13, 59}, + {79, 69, 74, 80, 47, 51, 46, 48, -84, -19, 0, 5, 119, 3, 1, 0, 21, 115, 114, 0, 41, 111, 114, 103, 46, 97, + 112, 97, 99, 104, 101, 46, 111, 112, 101, 110, 101, 106, 98, 46, 99, 108, 105, 101, 110, 116, 46, 69, 74, 66, + 77, 101, 116, 97, 68, 97, 116, 97, 73, 109, 112, 108, 29, -120, -127, 52, 16, -56, 15, 77, 12, 0, 0, 120, + 112, 119, 1, 1, 112, 112, 112, 112, 119, 28, 7, 0, 21, 67, 97, 108, 99, 117, 108, 97, 116, 111, 114, 47, 65, + 100, 100, 83, 101, 114, 118, 105, 99, 101, -1, -1, 0, 1, 118, 114, 0, 27, 99, 97, 108, 99, 117, 108, 97, 116, + 111, 114, 46, 65, 100, 100, 83, 101, 114, 118, 105, 99, 101, 82, 101, 109, 111, 116, 101, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 120, 112, 112, 120}, + {79, 69, 74, 80, 47, 51, 46, 48, 0, -84, -19, 0, 5, 119, 1, 23, 116, 0, 21, 67, 97, 108, 99, 117, 108, 97, + 116, 111, 114, 47, 65, 100, 100, 83, 101, 114, 118, 105, 99, 101, 119, 2, -1, -1, 112, 119, 5, -63, -5, 13, + 59, 1, 112, 118, 114, 0, 27, 99, 97, 108, 99, 117, 108, 97, 116, 111, 114, 46, 65, 100, 100, 83, 101, 114, + 118, 105, 99, 101, 82, 101, 109, 111, 116, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 112, 119, 24, 0, 3, 97, + 100, 100, 2, 4, 64, 89, 0, 0, 0, 0, 0, 0, 4, 64, -113, 64, 0, 0, 0, 0, 0}, + {79, 69, 74, 80, 47, 51, 46, 48, -84, -19, 0, 5, 119, 3, 1, 0, 4, 115, 114, 0, 16, 106, 97, 118, 97, 46, 108, + 97, 110, 103, 46, 68, 111, 117, 98, 108, 101, -128, -77, -62, 74, 41, 107, -5, 4, 2, 0, 1, 68, 0, 5, 118, 97, + 108, 117, 101, 120, 114, 0, 16, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 78, 117, 109, 98, 101, 114, + -122, -84, -107, 29, 11, -108, -32, -117, 2, 0, 0, 120, 112, 64, -111, 48, 0, 0, 0, 0, 0} + }; + + public MockServer(int listen) { + this.listen = listen; + } + + public void run() { + try { + ServerSocket ss = new ServerSocket(listen); + for (int i = 0; i < seq.length; i += 2) { + // System.out.println("Processing request[" + i/2 + "]"); + doExchange(ss.accept(), seq[i], seq[i + 1]); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void doExchange(Socket socket, byte[] read, byte[] write) throws IOException, InterruptedException { + Thread t2 = readBytes(socket, read.length); + Thread t1 = writeBytes(socket, write); + t1.join(); + t2.join(); + socket.close(); + } + + private Thread readBytes(Socket socket, int x) throws IOException, InterruptedException { + byte[] buf = new byte[x]; + Thread t = new Reader(socket, buf); + t.start(); + return t; + } + + private Thread writeBytes(Socket socket, byte[] bs) throws IOException, InterruptedException { + Thread t = new Writer(socket, bs); + t.start(); + return t; + } + + private static class Reader extends Thread { + + private InputStream is; + private byte[] buf; + + Reader(Socket socket, byte[] buf) throws IOException { + this.is = socket.getInputStream(); + this.buf = buf; + } + + @Override + public void run() { + try { + int totalSize = buf.length; + int readSize = 0; + int offset = 0; + while (totalSize > 0 && (readSize = is.read(buf, offset, totalSize)) != -1) { + offset += readSize; + totalSize -= readSize; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + } + + private static class Writer extends Thread { + + private OutputStream os; + private byte[] buf; + + Writer(Socket socket, byte[] buf) throws IOException { + this.os = socket.getOutputStream(); + this.buf = buf; + } + + @Override + public void run() { + try { + os.write(buf); + os.flush(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java new file mode 100644 index 0000000000..66b3feb458 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.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.sca.binding.ejb.tests; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * Displays the bytes flowing across a Socket connection. + * Used to get the read count and reply data for the MockServer + * + * @version $Rev$ $Date$ + */ +public class SocketTracer implements Runnable { + + private int listen; + private int send; + + SocketTracer(int listen, int send) { + this.listen = listen; + this.send = send; + } + + public void run() { + try { + ServerSocket ss = new ServerSocket(listen); + while (true) { + Socket sin = ss.accept(); + + Socket sout = new Socket("localhost", send); + + Thread st = new Thread(new Send(sin, sout)); + st.start(); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * @param buf + * @param count + */ + static synchronized void dump(String str, byte[] buf, int count) { + // System.out.println(Thread.currentThread()); + System.out.print(str+"{"); + for (int j = 0; j < count; j++) { + if (j == count - 1) { + System.out.println(buf[j] + "}, "); + } else { + System.out.print(buf[j] + ", "); + } + } + } +} + + +class Send implements Runnable { + + Socket sin; + Socket sout; + + Send(Socket sin, Socket sout) { + this.sin = sin; + this.sout = sout; + } + + public void run() { + try { + + Reply rr = new Reply(sout.getInputStream(), sin.getOutputStream()); + Thread rt = new Thread(rr); + rt.start(); + + OutputStream outout = sout.getOutputStream(); + InputStream is = sin.getInputStream(); + byte[] buf = new byte[4096]; + int i = 0; + int count = 0; + while ((i = is.read()) != -1) { + buf[count++] = (byte)i; + outout.write(i); + } + SocketTracer.dump("Req: ", buf, count); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} + +class Reply implements Runnable { + + InputStream is; + OutputStream outout; + + Reply(InputStream is, OutputStream outout) { + this.is = is; + this.outout = outout; + } + + public void run() { + try { + byte[] buf = new byte[4096]; + int i = 0; + int count = 0; + while ((i = is.read()) != -1) { + buf[count++] = (byte)i; + outout.write(i); + } + SocketTracer.dump("Res: ", buf, count); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/resources/account/account.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/resources/account/account.composite new file mode 100644 index 0000000000..701b989659 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/resources/account/account.composite @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/resources/calculator-ejb/calculator-ejb.jar b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/resources/calculator-ejb/calculator-ejb.jar new file mode 100644 index 0000000000..d9afb9027f Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb-runtime/src/test/resources/calculator-ejb/calculator-ejb.jar differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/pom.xml new file mode 100644 index 0000000000..a8cf5be26a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/pom.xml @@ -0,0 +1,91 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-ejb + Apache Tuscany SCA EJB Binding Model + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution-xml + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.ejb + ${pom.name} + org.apache.tuscany.sca.binding.ejb* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java new file mode 100644 index 0000000000..ae9d11d112 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * An implementation of EJBBinding. + * + * @version $Rev$ $Date$ + */ +public interface EJBBinding extends Binding, Extensible, Base { + // Constants used when describing the EJB binding + // model and for setting up defaults + String BINDING_EJB = "binding.ejb"; + QName BINDING_EJB_QNAME = new QName(Constants.SCA10_NS, BINDING_EJB); + + // Constants for the XML describing the EJB Binding + String HOME_INTERFACE = "homeInterface"; + String EJB_LINK_NAME = "ejb-link-name"; + String SESSION_TYPE = "session-type"; + String EJB_VERSION = "ejb-version"; + String NAME = "name"; + String POLICY_SETS = "policySets"; + String REQUIRES = "requires"; + String URI = "uri"; + + // Enums for the EJB Binding + enum EJBVersion { + EJB2, EJB3 + }; + + enum SessionType { + STATEFUL, STATELESS + }; + + /** + * Gets the homeInterface. + * + * @return home interface of the service binding + */ + String getHomeInterface(); + + /** + * Set homeInterface + * + * @param homeInterface + */ + void setHomeInterface(String homeInterface); + + /** + * get ejb-link-name + * + * @return ejb-link-name + */ + String getEjbLinkName(); + + /** + * Set ejb-link-name + * + * @param ejb-link-name + */ + void setEjbLinkName(String ejbLinkName); + + SessionType getSessionType(); + void setSessionType(SessionType sessionType); + + EJBVersion getEjbVersion(); + void setEjbVersion(EJBVersion ejbVersion); + + // FIXME: Should use Intent instead of String + String getRequires(); + void setRequires(String requires); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingException.java new file mode 100644 index 0000000000..6e2c8d358f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingException.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.sca.binding.ejb; + +/** + * Exception for the EJB Binding + * + * @version $Rev$ $Date$ + */ +public class EJBBindingException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** + * {@inheritDoc} + */ + public EJBBindingException() { + super(); + } + + /** + * {@inheritDoc} + */ + public EJBBindingException(String message, Throwable cause) { + super(message, cause); + } + + /** + * {@inheritDoc} + */ + public EJBBindingException(String message) { + super(message); + } + + /** + * {@inheritDoc} + */ + public EJBBindingException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingFactory.java new file mode 100644 index 0000000000..13b069a6bb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingFactory.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.sca.binding.ejb; + +/** + * Factory for the EJB binding + * + * @version $Rev$ $Date$ + */ +public interface EJBBindingFactory { + + /** + * Creates a new EJB binding. + * @return the new EJB binding + */ + EJBBinding createEJBBinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingFactoryImpl.java new file mode 100644 index 0000000000..e84de86eca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingFactoryImpl.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.sca.binding.ejb.impl; + +import org.apache.tuscany.sca.binding.ejb.EJBBinding; +import org.apache.tuscany.sca.binding.ejb.EJBBindingFactory; + +/** + * Factory class for building EJBBindings. + * + * @version $Rev$ $Date$ + * + */ +public class EJBBindingFactoryImpl implements EJBBindingFactory { + + public EJBBinding createEJBBinding() { + return new EJBBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingImpl.java new file mode 100644 index 0000000000..4a8d751608 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingImpl.java @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.impl; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.binding.ejb.EJBBinding; + +/** + * An implementation of EJBBinding. + * + * @version $Rev$ $Date$ + */ +public class EJBBindingImpl extends ExtensibleImpl implements EJBBinding { + + /** + * CORBA location For example, + * "corbaname:iiop:localhost:2809/NameServiceServerRoot#ejb/MyEJBHome" + */ + private String uri; + + /** + * homeInterface. remote or local + */ + private String homeInterface; + + /** + * The ejb-link-name attribute allows a SCA client to bind to an EJB that is + * packaged in the same JEE EAR file as the SCA client. This is functionally + * equivalent to using the subelement of the element + * in s EJB deployment descriptor. Used only for Service binding + */ + private String ejbLinkName; + + /** + * The name of this binding + */ + private String name; + + /** + * Whether the binding is unresolved + */ + private boolean unresolved; + + /** + * Clone the binding + */ + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + /** + * The type of session for this EJB Binding + */ + private SessionType sessionType; + + /** + * The EJB version for this EJB Binding + */ + private EJBVersion ejbVersion; + + private String requires; + + /** + * Constructor + */ + public EJBBindingImpl() { + super(); + unresolved = true; + } + + /** + * Gets the homeInterface. + * + * @return home interface of the service binding + */ + public String getHomeInterface() { + return homeInterface; + } + + /** + * Set homeInterface + * + * @param homeInterface + */ + public void setHomeInterface(String homeInterface) { + this.homeInterface = homeInterface; + } + + /** + * get ejb-link-name + * + * @return ejb-link-name + */ + public String getEjbLinkName() { + return ejbLinkName; + } + + /** + * Set ejb-link-name + * + * @param ejb-link-name + */ + public void setEjbLinkName(String ejbLinkName) { + this.ejbLinkName = ejbLinkName; + } + + /** + * {@inheritDoc} + */ + public String getName() { + return this.name; + } + + /** + * {@inheritDoc} + */ + public String getURI() { + return uri; + } + + /** + * {@inheritDoc} + */ + public void setName(String name) { + this.name = name; + } + + /** + * {@inheritDoc} + */ + public void setURI(String uri) { + this.uri = uri; + } + + public boolean isUnresolved() { + return this.unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public void setSessionType(SessionType ejb_version_enum) { + this.sessionType = ejb_version_enum; + } + + public void setEjbVersion(EJBVersion ejb_version_enum) { + this.ejbVersion = ejb_version_enum; + } + + public void setRequires(String requires) { + this.requires = requires; + + } + + public SessionType getSessionType() { + return sessionType; + } + + public EJBVersion getEjbVersion() { + return ejbVersion; + } + + public String getRequires() { + return requires; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingProcessor.java new file mode 100644 index 0000000000..305cd2a742 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingProcessor.java @@ -0,0 +1,231 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.impl; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; +import org.apache.tuscany.sca.binding.ejb.EJBBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * A processor to read the XML that describes the EJB binding... + * + * + * + * + * + * + * + * @version $Rev$ $Date$ + */ +public class EJBBindingProcessor implements StAXArtifactProcessor { + private PolicyFactory policyFactory; + private ExtensionFactory extensionFactory; + private PolicyAttachPointProcessor policyProcessor; + private StAXAttributeProcessor extensionAttributeProcessor; + private Monitor monitor; + + public EJBBindingProcessor(ExtensionPointRegistry extensionPoints) { + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + StAXAttributeProcessorExtensionPoint attributeExtensionPoint = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + this.extensionAttributeProcessor = new ExtensibleStAXAttributeProcessor(attributeExtensionPoint ,inputFactory, outputFactory, this.monitor); + + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + if (monitorFactory != null) { + this.monitor = monitorFactory.createMonitor(); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "binding-ejb-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * {@inheritDoc} + */ + public QName getArtifactType() { + return EJBBinding.BINDING_EJB_QNAME; + } + + /** + * {@inheritDoc} + */ + public EJBBindingImpl read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + EJBBindingImpl ejbBinding = new EJBBindingImpl(); + + // Read the policies + policyProcessor.readPolicies(ejbBinding, reader); + + // Read the name + String name = reader.getAttributeValue(null, EJBBinding.NAME); + if (name != null) { + ejbBinding.setName(name); + } + + // Read binding URI + String uri = reader.getAttributeValue(null, EJBBinding.URI); + if (uri != null) { + ejbBinding.setURI(uri); + } + + String homeInterface = reader.getAttributeValue(null, EJBBinding.HOME_INTERFACE); + if (homeInterface != null) { + ejbBinding.setHomeInterface(homeInterface); + } + + String ejbLinkName = reader.getAttributeValue(null, EJBBinding.EJB_LINK_NAME); + if (ejbLinkName != null) { + ejbBinding.setEjbLinkName(ejbLinkName); + } + + String sessionType = reader.getAttributeValue(null, EJBBinding.SESSION_TYPE); + if (sessionType != null) { + if (sessionType.equals("stateless")) { + ejbBinding.setSessionType(EJBBinding.SessionType.STATELESS); + } else if (sessionType.equals("stateful")) { + ejbBinding.setSessionType(EJBBinding.SessionType.STATEFUL); + } else { + error("UnknownEJBSessionType", reader, sessionType, name); + //throw new ContributionReadException("Unknown EJB Session Type of " + sessionType + " for " + name); + } + } + + String ejbVersion = reader.getAttributeValue(null, EJBBinding.EJB_VERSION); + if (ejbVersion != null) { + if (ejbVersion.equals("EJB2")) { + ejbBinding.setEjbVersion(EJBBinding.EJBVersion.EJB2); + } else if (ejbVersion.equals("EJB3")) { + ejbBinding.setEjbVersion(EJBBinding.EJBVersion.EJB3); + } else { + error("UnknownEJBVersion", reader, ejbVersion, name); + //throw new ContributionReadException("Unknown EJB Version of " + ejbVersion + " for " + name); + } + } + + // TODO: Read requires + String requires = reader.getAttributeValue(null, EJBBinding.REQUIRES); + if (requires != null) { + ejbBinding.setRequires(requires); + } + + // Handle extended attributes + QName elementName = reader.getName(); + for (int a = 0; a < reader.getAttributeCount(); a++) { + QName attributeName = reader.getAttributeName(a); + if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { + if( ! elementName.getNamespaceURI().equals(attributeName.getNamespaceURI()) ) { + Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); + Extension attributeExtension; + if (attributeValue instanceof Extension) { + attributeExtension = (Extension) attributeValue; + } else { + attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true); + } + ejbBinding.getAttributeExtensions().add(attributeExtension); + } + } + } + + return ejbBinding; + } + + public void write(EJBBindingImpl ejbBinding, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + // Write a + writer.writeStartElement(Constants.SCA10_NS, EJBBinding.BINDING_EJB); + + if (ejbBinding.getName() != null){ + writer.writeAttribute(EJBBinding.NAME, ejbBinding.getName()); + } + + if (ejbBinding.getURI() != null){ + writer.writeAttribute(EJBBinding.URI, ejbBinding.getURI()); + } + + for(Extension extension : ejbBinding.getAttributeExtensions()) { + if(extension.isAttribute()) { + extensionAttributeProcessor.write(extension, writer); + } + } + + // FIXME Implement the rest + + writer.writeEndElement(); + } + + public Class getModelType() { + return EJBBindingImpl.class; + } + + public void resolve(EJBBindingImpl ejbBinding, ModelResolver modelResolver) throws ContributionResolveException { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ejb.EJBBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ejb.EJBBindingFactory new file mode 100644 index 0000000000..c445a82ecb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ejb.EJBBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for model factory +org.apache.tuscany.sca.binding.ejb.impl.EJBBindingFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..82e85ef067 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.ejb.impl.EJBBindingProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#binding.ejb,model=org.apache.tuscany.sca.binding.ejb.EJBBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/binding-ejb-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/binding-ejb-validation-messages.properties new file mode 100644 index 0000000000..28477dd3ac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/main/resources/binding-ejb-validation-messages.properties @@ -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. +# +# +UnknownEJBSessionType = Unknown EJB Session Type of {0} for {1} +UnknownEJBVersion = Unknown EJB Version of {0} for {1} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/impl/ReadWriteAnyAttributeTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/impl/ReadWriteAnyAttributeTestCase.java new file mode 100644 index 0000000000..9797c8b490 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/impl/ReadWriteAnyAttributeTestCase.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ejb.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.xml.AnyAttributeProcessor; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadWriteAnyAttributeTestCase { + + private static final QName EXTENDED_ATTRIBUTE = new QName("http://test", "customAttribute"); + + private static final String XML = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + + /** + * Initialize the test environment + * This takes care to register attribute processors when provided + * + * @param attributeProcessor + * @throws Exception + */ + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + + inputFactory = XMLInputFactory.newInstance(); + + StAXAttributeProcessor attributeProcessor = new AnyAttributeProcessor(modelFactories,null); + + StAXAttributeProcessorExtensionPoint staxAttributeProcessors = new DefaultStAXAttributeProcessorExtensionPoint(extensionPoints); + staxAttributeProcessors.addArtifactProcessor(attributeProcessor); + extensionPoints.addExtensionPoint(staxAttributeProcessors); + + EJBBindingProcessor wsbp = new EJBBindingProcessor(extensionPoints); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessors.addArtifactProcessor(wsbp); + + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + @After + public void tearDown() throws Exception { + + } + + + @Test + //@Ignore() + public void testReadWriteCompositeWithBindings() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML); + // System.out.println(bos.toString()); + + assertEquals(XML, bos.toString()); + bos.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/pom.xml new file mode 100644 index 0000000000..f3a2a4c3d2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/pom.xml @@ -0,0 +1,91 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-erlang-runtime + Apache Tuscany SCA Erlang Binding Runtime + + + + wjaniszewski-jinterface + http://people.apache.org/~wjaniszewski/jinterface-repo + + + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-erlang + 1.6-SNAPSHOT + + + + com.ericsson + otperlang + 1.4.2 + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.erlang + ${pom.name} + org.apache.tuscany.sca.binding.erlang* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProviderFactory.java new file mode 100644 index 0000000000..f7ea057e56 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProviderFactory.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.impl; + +import java.util.HashSet; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class ErlangBindingProviderFactory implements + BindingProviderFactory { + + private static final Logger logger = Logger + .getLogger(ErlangBindingProviderFactory.class.getName()); + + private Set nodes = new HashSet(); + + public ErlangBindingProviderFactory(ExtensionPointRegistry registry) { + + } + + /** + * @see org.apache.tuscany.sca.provider.BindingProviderFactory#createReferenceBindingProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, + * org.apache.tuscany.sca.runtime.RuntimeComponentReference, + * org.apache.tuscany.sca.assembly.Binding) + */ + public ReferenceBindingProvider createReferenceBindingProvider( + RuntimeComponent component, RuntimeComponentReference reference, + ErlangBinding binding) { + return new ErlangReferenceBindingProvider(binding, reference); + } + + /** + * @see org.apache.tuscany.sca.provider.BindingProviderFactory#createServiceBindingProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, + * org.apache.tuscany.sca.runtime.RuntimeComponentService, + * org.apache.tuscany.sca.assembly.Binding) + */ + public ServiceBindingProvider createServiceBindingProvider( + RuntimeComponent component, RuntimeComponentService service, + ErlangBinding binding) { + ServiceBindingProvider provider = null; + try { + if (nodes.contains(binding.getNode())) { + // TODO: externalize message? + logger.log(Level.WARNING, + "Node name '" + binding.getNode() + "' already registered. This service will not be spawned."); + } else { + provider = new ErlangServiceBindingProvider(binding, service); + nodes.add(binding.getNode()); + } + } catch (Exception e) { + // TODO: externalize message? + logger.log(Level.WARNING, + "Exception during creating ServiceBindingProvider", e); + } + return provider; + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + return ErlangBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java new file mode 100644 index 0000000000..a2cf71a053 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.impl; + +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.binding.erlang.impl.exceptions.ErlangException; +import org.apache.tuscany.sca.binding.erlang.impl.types.TypeHelpersProxy; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +import com.ericsson.otp.erlang.OtpAuthException; +import com.ericsson.otp.erlang.OtpConnection; +import com.ericsson.otp.erlang.OtpEpmd; +import com.ericsson.otp.erlang.OtpErlangList; +import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangTuple; +import com.ericsson.otp.erlang.OtpMbox; +import com.ericsson.otp.erlang.OtpMsg; +import com.ericsson.otp.erlang.OtpNode; +import com.ericsson.otp.erlang.OtpPeer; +import com.ericsson.otp.erlang.OtpSelf; + +/** + * @version $Rev$ $Date$ + */ +public class ErlangInvoker implements Invoker { + + private static final Logger logger = Logger.getLogger(ErlangInvoker.class + .getName()); + + private ErlangBinding binding; + + public ErlangInvoker(ErlangBinding binding) { + this.binding = binding; + } + + private void reportProblem(Message msg, Exception e) { + if (msg.getOperation().getFaultTypes().size() > 0) { + msg.setFaultBody(e); + } else { + // NOTE: don't throw exception if not declared + // TODO: externalize message? + msg.setBody(null); + logger + .log(Level.WARNING, "Problem while sending/receiving data", + e); + } + } + + private String getClientNodeName() { + return "_connector_to_" + binding.getNode() + + System.currentTimeMillis(); + } + + private Message sendMessage(Message msg) { + OtpMbox tmpMbox = null; + OtpNode node = null; + try { + node = new OtpNode(getClientNodeName()); + if (binding.hasCookie()) { + node.setCookie(binding.getCookie()); + } + tmpMbox = node.createMbox(); + // obtain args, make sure they aren't null + // NOTE: sending message with no content (but only with senders PID) + // is possible + Object[] args = (Object[]) (msg.getBody() != null ? msg.getBody() + : new Object[0]); + Method jmethod = ((JavaOperation) msg.getOperation()) + .getJavaMethod(); + // create and send msg with self pid in the beginning + OtpErlangObject[] argsArray = { + tmpMbox.self(), + TypeHelpersProxy.toErlang(args, jmethod + .getParameterAnnotations()) }; + OtpErlangObject otpArgs = new OtpErlangTuple(argsArray); + tmpMbox.send(msg.getOperation().getName(), binding.getNode(), + otpArgs); + if (msg.getOperation().getOutputType() != null) { + OtpMsg resultMsg = null; + if (binding.hasTimeout()) { + resultMsg = tmpMbox.receiveMsg(binding.getTimeout()); + } else { + resultMsg = tmpMbox.receiveMsg(); + } + OtpErlangObject result = resultMsg.getMsg(); + msg.setBody(TypeHelpersProxy.toJava(result, msg.getOperation() + .getOutputType().getPhysical(), jmethod + .getAnnotations())); + } + } catch (InterruptedException e) { + // TODO: externalize message? + ErlangException ee = new ErlangException( + "Timeout while receiving message reply", e); + msg.setBody(null); + reportProblem(msg, ee); + } catch (Exception e) { + reportProblem(msg, e); + } finally { + if (tmpMbox != null) { + tmpMbox.close(); + } + if (node != null) { + OtpEpmd.unPublishPort(node); + node.close(); + } + } + return msg; + } + + private Message invokeOperation(Message msg) { + OtpSelf self = null; + OtpPeer other = null; + OtpConnection connection = null; + try { + self = new OtpSelf(getClientNodeName()); + if (binding.hasCookie()) { + self.setCookie(binding.getCookie()); + } + other = new OtpPeer(binding.getNode()); + connection = self.connect(other); + Method jmethod = ((JavaOperation) msg.getOperation()) + .getJavaMethod(); + OtpErlangList params = TypeHelpersProxy.toErlangAsList(msg + .getBody(), jmethod.getParameterAnnotations()); + OtpErlangTuple message = MessageHelper.rpcMessage(self.pid(), self + .createRef(), binding.getModule(), msg.getOperation() + .getName(), params); + connection.send(MessageHelper.RPC_MBOX, message); + OtpErlangObject rpcResponse = null; + if (binding.hasTimeout()) { + rpcResponse = connection.receive(binding.getTimeout()); + } else { + rpcResponse = connection.receive(); + } + OtpErlangObject result = ((OtpErlangTuple) rpcResponse) + .elementAt(1); + if (MessageHelper.isfunctionUndefMessage(result)) { + // TODO: externalize message? + Exception e = new ErlangException("No '" + binding.getModule() + + ":" + msg.getOperation().getName() + + "' operation defined on remote '" + binding.getNode() + + "' node."); + reportProblem(msg, e); + msg.setBody(null); + } else if (msg.getOperation().getOutputType() != null) { + jmethod.getAnnotations(); + msg.setBody(TypeHelpersProxy.toJava(result, msg.getOperation() + .getOutputType().getPhysical(), jmethod + .getAnnotations())); + } + } catch (OtpAuthException e) { + // TODO: externalize message? + ErlangException ee = new ErlangException( + "Problem while authenticating client - check your cookie", + e); + msg.setBody(null); + reportProblem(msg, ee); + } catch (InterruptedException e) { + // TODO: externalize message? + ErlangException ee = new ErlangException( + "Timeout while receiving RPC reply", e); + msg.setBody(null); + reportProblem(msg, ee); + } catch (Exception e) { + reportProblem(msg, e); + } finally { + if (connection != null) { + connection.close(); + } + } + return msg; + } + + /** + * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message) + */ + public Message invoke(Message msg) { + if (binding.isMbox()) { + return sendMessage(msg); + } else { + return invokeOperation(msg); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java new file mode 100644 index 0000000000..8a2ca44290 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNode.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.impl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.binding.erlang.impl.exceptions.ErlangException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +import com.ericsson.otp.erlang.OtpAuthException; +import com.ericsson.otp.erlang.OtpConnection; +import com.ericsson.otp.erlang.OtpSelf; + +/** + * @version $Rev$ $Date$ + */ +public class ErlangNode implements Runnable { + + private static final Logger logger = Logger.getLogger(ErlangNode.class + .getName()); + + private ErlangNodeElement nodeElement; + private String name; + private OtpSelf self; + private ExecutorService executors; + private boolean stopRequested; + private Map> groupedOperations; + + public ErlangNode(String name, ErlangBinding binding, + RuntimeComponentService service) throws Exception { + this.name = name; + self = new OtpSelf(name); + boolean registered = self.publishPort(); + if (!registered) { + // TODO: externalize message? + throw new ErlangException( + "Problem with publishing service under epmd server."); + } + if (binding.hasCookie()) { + self.setCookie(binding.getCookie()); + } + registerBinding(binding, service); + } + + public void stop() { + stopRequested = true; + executors.shutdownNow(); + } + + public void run() { + executors = Executors.newFixedThreadPool(nodeElement.getBinding().getServiceThreadPool()); + while (!stopRequested) { + try { + OtpConnection connection = self.accept(); + executors.execute(new ServiceExecutor(connection, + groupedOperations, nodeElement, name)); + } catch (IOException e) { + // TODO: externalzie message? + logger.log(Level.WARNING, + "Error occured while accepting connection on '" + name + + "' node", e); + } catch (OtpAuthException e) { + // TODO: externalize message? + logger.log(Level.WARNING, "Error while authenticating client", e); + } + } + executors.shutdownNow(); + } + + private void registerBinding(ErlangBinding binding, + RuntimeComponentService service) throws ErlangException { + if (binding.isMbox()) { + List operations = service.getInterfaceContract() + .getInterface().getOperations(); + groupedOperations = new HashMap>(); + for (Operation operation : operations) { + List operationsGroup = groupedOperations + .get(operation.getName()); + if (operationsGroup == null) { + operationsGroup = new ArrayList(); + groupedOperations.put(operation.getName(), operationsGroup); + } + operationsGroup.add(operation); + } + } + nodeElement = new ErlangNodeElement(); + nodeElement.setService(service); + nodeElement.setBinding(binding); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNodeElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNodeElement.java new file mode 100644 index 0000000000..f945a841ec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangNodeElement.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.sca.binding.erlang.impl; + +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Holds information (RuntimeComponentService, ErlangBindin) for element (program module, mbox) binded on node. + * @version $Rev$ $Date$ + */ +public class ErlangNodeElement { + + private ErlangBinding binding; + private RuntimeComponentService service; + + public void setBinding(ErlangBinding binding) { + this.binding = binding; + } + + public ErlangBinding getBinding() { + return binding; + } + + public void setService(RuntimeComponentService service) { + this.service = service; + } + + public RuntimeComponentService getService() { + return service; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.java new file mode 100644 index 0000000000..b96a4524e1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangReferenceBindingProvider.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.sca.binding.erlang.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class ErlangReferenceBindingProvider implements ReferenceBindingProvider { + + private static final Logger logger = Logger + .getLogger(ErlangReferenceBindingProvider.class.getName()); + private RuntimeComponentReference reference; + private ErlangBinding binding; + + public ErlangReferenceBindingProvider(ErlangBinding binding, + RuntimeComponentReference reference) { + this.reference = reference; + this.binding = binding; + } + + /** + * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#createInvoker(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Invoker createInvoker(Operation operation) { + try { + return new ErlangInvoker(binding); + } catch (Exception e) { + logger.log(Level.WARNING, + "Exception during creating Erlang invoker", e); + } + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#getBindingInterfaceContract() + */ + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + /** + * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#start() + */ + public void start() { + } + + /** + * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#stop() + */ + public void stop() { + } + + /** + * @see org.apache.tuscany.sca.provider.ReferenceBindingProvider#supportsOneWayInvocation() + */ + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.java new file mode 100644 index 0000000000..725c62fca0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangServiceBindingProvider.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.sca.binding.erlang.impl; + +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.osoa.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class ErlangServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private ErlangNode node; + + public ErlangServiceBindingProvider(ErlangBinding binding, + RuntimeComponentService service) throws Exception { + this.service = service; + this.node = new ErlangNode(binding.getNode(), binding, service); + } + + /** + * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#getBindingInterfaceContract() + */ + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + /** + * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#start() + */ + public void start() { + try { + Thread thread = new Thread(node); + // prevents blocking stop procedure by service listener + thread.setDaemon(true); + thread.start(); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + + } + + /** + * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#stop() + */ + public void stop() { + try { + node.stop(); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + + } + + /** + * @see org.apache.tuscany.sca.provider.ServiceBindingProvider#supportsOneWayInvocation() + */ + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.java new file mode 100644 index 0000000000..ee7957406b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/MessageHelper.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.sca.binding.erlang.impl; + +import com.ericsson.otp.erlang.OtpErlangAtom; +import com.ericsson.otp.erlang.OtpErlangList; +import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangPid; +import com.ericsson.otp.erlang.OtpErlangRef; +import com.ericsson.otp.erlang.OtpErlangTuple; + +/** + * @version $Rev$ $Date$ + */ +public class MessageHelper { + + /** + * Mbox name used for Remote Procedure Calls + */ + public static String RPC_MBOX = "rex"; + + public static final OtpErlangAtom ATOM_OK = new OtpErlangAtom("ok"); + public static final OtpErlangAtom ATOM_ERROR = new OtpErlangAtom("error"); + public static final OtpErlangAtom ATOM_BADRPC = new OtpErlangAtom("badrpc"); + private static final OtpErlangAtom ATOM_EXIT = new OtpErlangAtom("EXIT"); + private static final OtpErlangAtom ATOM_UNDEF = new OtpErlangAtom("undef"); + private static final OtpErlangAtom ATOM_CALL = new OtpErlangAtom("call"); + private static final OtpErlangAtom ATOM_GEN_CALL = new OtpErlangAtom( + "$gen_call"); + + public static OtpErlangObject functionUndefMessage(String module, + String function, OtpErlangList args, String tuscanyMsg) { + OtpErlangObject[] args4 = new OtpErlangObject[3]; + args4[0] = new OtpErlangAtom(module); + args4[1] = new OtpErlangAtom(function); + args4[2] = args; + + OtpErlangObject[] args3 = new OtpErlangObject[2]; + args3[0] = new OtpErlangTuple(args4); + args3[1] = new OtpErlangAtom(tuscanyMsg); + + OtpErlangObject[] args2 = new OtpErlangObject[2]; + args2[0] = ATOM_UNDEF; + args2[1] = new OtpErlangList(args3); + + OtpErlangObject[] args1 = new OtpErlangObject[2]; + args1[0] = ATOM_EXIT; + args1[1] = new OtpErlangTuple(args2); + + OtpErlangTuple result = new OtpErlangTuple(args1); + return result; + } + + public static boolean isfunctionUndefMessage(OtpErlangObject msg) { + if (msg.getClass().equals(OtpErlangTuple.class)) { + OtpErlangTuple tupleMsg = (OtpErlangTuple) msg; + if (tupleMsg.arity() == 2 + && tupleMsg.elementAt(0).getClass().equals( + OtpErlangAtom.class) + && tupleMsg.elementAt(1).getClass().equals( + OtpErlangTuple.class) + && ((OtpErlangAtom) tupleMsg.elementAt(0)).atomValue() + .equals(ATOM_BADRPC.atomValue())) { + OtpErlangTuple badrpcTuple = (OtpErlangTuple) tupleMsg + .elementAt(1); + if (badrpcTuple.arity() == 2 + && badrpcTuple.elementAt(0).getClass().equals( + OtpErlangAtom.class) + && badrpcTuple.elementAt(1).getClass().equals( + OtpErlangTuple.class) + && ((OtpErlangAtom) badrpcTuple.elementAt(0)) + .atomValue().equals(ATOM_EXIT.atomValue())) { + OtpErlangTuple exitTuple = (OtpErlangTuple) badrpcTuple + .elementAt(1); + if (exitTuple.arity() == 2 + && exitTuple.elementAt(0).getClass().equals( + OtpErlangAtom.class) + && ((OtpErlangAtom) exitTuple.elementAt(0)) + .atomValue().equals(ATOM_UNDEF.atomValue())) { + return true; + } + } + + } + } + return false; + } + + public static OtpErlangTuple rpcMessage(OtpErlangPid senderPid, + OtpErlangRef ref, String module, String function, OtpErlangList args) { + OtpErlangObject[] args3 = new OtpErlangObject[5]; + args3[0] = ATOM_CALL; + args3[1] = new OtpErlangAtom(module); + args3[2] = new OtpErlangAtom(function); + args3[3] = args; + args3[4] = senderPid; + + OtpErlangObject[] args2 = new OtpErlangObject[2]; + args2[0] = senderPid; + args2[1] = ref; + + OtpErlangObject[] args1 = new OtpErlangObject[3]; + args1[0] = ATOM_GEN_CALL; + args1[1] = new OtpErlangTuple(args2); + args1[2] = new OtpErlangTuple(args3); + + OtpErlangTuple result = new OtpErlangTuple(args1); + return result; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java new file mode 100644 index 0000000000..9e292fe3bb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java @@ -0,0 +1,378 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.impl; + +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.binding.erlang.impl.types.TypeHelpersProxy; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +import com.ericsson.otp.erlang.OtpAuthException; +import com.ericsson.otp.erlang.OtpConnection; +import com.ericsson.otp.erlang.OtpErlangAtom; +import com.ericsson.otp.erlang.OtpErlangDecodeException; +import com.ericsson.otp.erlang.OtpErlangExit; +import com.ericsson.otp.erlang.OtpErlangList; +import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangPid; +import com.ericsson.otp.erlang.OtpErlangRef; +import com.ericsson.otp.erlang.OtpErlangString; +import com.ericsson.otp.erlang.OtpErlangTuple; +import com.ericsson.otp.erlang.OtpMsg; + +/** + * @version $Rev$ $Date$ + */ +public class ServiceExecutor implements Runnable { + + private static final Logger logger = Logger.getLogger(ServiceExecutor.class + .getName()); + + private ErlangNodeElement nodeElement; + private OtpConnection connection; + private Map> groupedOperations; + private String name; + + public ServiceExecutor(OtpConnection connection, + Map> groupedOperations, + ErlangNodeElement nodeElement, String name) { + this.connection = connection; + this.groupedOperations = groupedOperations; + this.nodeElement = nodeElement; + this.name = name; + } + + private void sendMessage(OtpConnection connection, OtpErlangPid pid, + OtpErlangRef ref, OtpErlangAtom head, OtpErlangObject message) + throws IOException { + OtpErlangObject tResult = null; + if (head != null) { + tResult = new OtpErlangTuple( + new OtpErlangObject[] { head, message }); + } else { + tResult = message; + } + OtpErlangObject msg = null; + msg = new OtpErlangTuple(new OtpErlangObject[] { ref, tResult }); + connection.send(pid, msg); + } + + private void handleRpc(OtpMsg msg) { + OtpErlangTuple request = null; + OtpErlangPid senderPid = null; + OtpErlangRef senderRef = null; + try { + OtpErlangTuple call = (OtpErlangTuple) msg.getMsg(); + OtpErlangTuple from = (OtpErlangTuple) call.elementAt(1); + request = (OtpErlangTuple) call.elementAt(2); + senderPid = (OtpErlangPid) from.elementAt(0); + senderRef = (OtpErlangRef) from.elementAt(1); + String module = ((OtpErlangAtom) request.elementAt(1)).atomValue(); + String function = ((OtpErlangAtom) request.elementAt(2)) + .atomValue(); + OtpErlangObject args = request.elementAt(3); + OtpErlangList argsList = null; + // normalize input + if (args instanceof OtpErlangList) { + argsList = (OtpErlangList) args; + } else { + argsList = new OtpErlangList(args); + } + if (!nodeElement.getBinding().getModule().equals(module)) { + // module not found + // TODO: externalize message? + OtpErlangObject errorMsg = MessageHelper.functionUndefMessage( + module, function, argsList, + "Module not found in SCA component."); + sendMessage(connection, senderPid, senderRef, + MessageHelper.ATOM_BADRPC, errorMsg); + } else { + // module found, looking for operation + RuntimeComponentService service = nodeElement.getService(); + ErlangBinding binding = nodeElement.getBinding(); + List operations = service.getInterfaceContract() + .getInterface().getOperations(); + Operation operation = null; + for (Operation o : operations) { + if (o.getName().equals(function)) { + operation = o; + break; + } + } + if (operation != null) { + // operation found + List iTypes = operation.getInputType() + .getLogical(); + Class[] forClasses = new Class[iTypes.size()]; + for (int i = 0; i < iTypes.size(); i++) { + forClasses[i] = iTypes.get(i).getPhysical(); + } + try { + // invoke operation + Method jmethod = ((JavaOperation) operation) + .getJavaMethod(); + Object result = service.getRuntimeWire(binding, + service.getInterfaceContract()).invoke( + operation, + TypeHelpersProxy.toJavaFromList(argsList, + forClasses, jmethod + .getParameterAnnotations())); + OtpErlangObject response = null; + + // send reply + if (operation.getOutputType() != null + && operation.getOutputType().getPhysical() + .isArray()) { + // output type is array + response = TypeHelpersProxy.toErlangAsResultList( + result, jmethod.getAnnotations()); + } else if (operation.getOutputType() == null) { + // output type is void, create empty reply + Object[] arrArg = new Object[] {}; + response = TypeHelpersProxy.toErlang(arrArg, + new Annotation[0][0]); + } else { + // output type is not void and not array + response = TypeHelpersProxy.toErlang(result, + jmethod.getAnnotations()); + } + sendMessage(connection, senderPid, senderRef, null, + response); + } catch (Exception e) { + if ((e.getClass().equals( + InvocationTargetException.class) && e + .getCause().getClass().equals( + IllegalArgumentException.class)) + || e.getClass().equals( + TypeMismatchException.class)) { + // wrong params + // TODO: externalize message? + OtpErlangObject errorMsg = MessageHelper + .functionUndefMessage(module, function, + argsList, + "Operation name found in SCA component, but parameters types didn't match."); + sendMessage(connection, senderPid, senderRef, + MessageHelper.ATOM_BADRPC, errorMsg); + } else { + // unexpected error + throw e; + } + } + } else { + // operation not found + // TODO: externalize message? + OtpErlangObject errorMsg = MessageHelper + .functionUndefMessage(module, function, argsList, + "Operation name not found in SCA component."); + sendMessage(connection, senderPid, senderRef, + MessageHelper.ATOM_BADRPC, errorMsg); + } + } + } catch (ClassCastException e) { + // invalid request + // TODO: externalize message? + try { + logger + .log( + Level.WARNING, + "On node '" + + nodeElement.getBinding().getNode() + + "' received RPC request which is invalid. Request content is: " + + msg.getMsg()); + } catch (OtpErlangDecodeException e1) { + } + } catch (Exception e) { + // unknown error + try { + sendMessage(connection, senderPid, senderRef, + MessageHelper.ATOM_ERROR, new OtpErlangString( + "Unhandled error while processing request: " + + e.getClass().getCanonicalName() + + ", message: " + e.getMessage())); + } catch (Exception e1) { + // error while sending error message. Can't do anything now + logger.log(Level.WARNING, "Error during sending error message", + e); + } + } + } + + private void handleMsg(OtpMsg msg) { + Operation matchedOperation = null; + Object args[] = null; + OtpErlangPid senderPid = null; + OtpErlangObject msgNoSender = null; + List operations = groupedOperations.get(msg + .getRecipientName()); + try { + if (msg.getMsg().getClass().equals(OtpErlangTuple.class) + && (((OtpErlangTuple) msg.getMsg()).elementAt(0)) + .getClass().equals(OtpErlangPid.class)) { + // PID provided by client + senderPid = (OtpErlangPid) ((OtpErlangTuple) msg.getMsg()) + .elementAt(0); + msgNoSender = ((OtpErlangTuple) msg.getMsg()).elementAt(1); + } else { + // PID obtained from jinterface + senderPid = msg.getSenderPid(); + msgNoSender = msg.getMsg(); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Unexpected error", e); + } + + if (operations == null) { + // operation name not found + // TODO: externalize message? + // NOTE: I assume in Erlang sender doesn't get confirmation so + // no message will be send + logger.log(Level.WARNING, "Node '" + name + + "' received message addressed to non exising mbox: " + + msg.getRecipientName()); + } else { + // find proper operation for received parameters + for (Operation operation : operations) { + Method method = ((JavaOperation) operation).getJavaMethod(); + List iTypes = operation.getInputType().getLogical(); + Class[] forClasses = new Class[iTypes.size()]; + for (int i = 0; i < iTypes.size(); i++) { + forClasses[i] = iTypes.get(i).getPhysical(); + } + try { + args = TypeHelpersProxy.toJavaAsArgs(msgNoSender, + forClasses, method.getParameterAnnotations()); + matchedOperation = operation; + break; + } catch (Exception e) { + // this exception is expected while processing operation + // version with mismatched arguments + } + } + if (matchedOperation != null) { + // operation found, invoke it + try { + Method jmethod = ((JavaOperation) matchedOperation) + .getJavaMethod(); + Object result = nodeElement.getService().getRuntimeWire( + nodeElement.getBinding()).invoke(matchedOperation, + args); + OtpErlangObject response = null; + + // create and send send reply + if (matchedOperation.getOutputType() != null + && matchedOperation.getOutputType().getPhysical() + .isArray()) { + // result type is array + response = TypeHelpersProxy.toErlangAsResultList( + result, jmethod.getAnnotations()); + } else if (matchedOperation.getOutputType() != null) { + // result type is not array and not void + response = TypeHelpersProxy.toErlang(result, jmethod + .getAnnotations()); + } + if (response != null && senderPid != null) { + connection.send(senderPid, response); + } else if (response != null && senderPid == null) { + // couldn't send reply - sender pid unavailable + // TODO: externalize message? + // TODO: do we need to send this reply? + logger + .log( + Level.WARNING, + "Cannot send reply - Erlang client didn't provide it's PID and couldn't obtain sender PID from jinterface"); + } + } catch (InvocationTargetException e) { + if (e.getCause() != null + && e.getCause().getClass().equals( + IllegalArgumentException.class)) { + // arguments number or type mismatch + try { + // TODO: externalize message? + connection + .send( + senderPid, + new OtpErlangString( + "Operation name found in SCA component, but parameters types didn't match.")); + } catch (IOException e1) { + e1.printStackTrace(); + } + } else { + logger.log(Level.WARNING, "Unexpected error", e); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Unexpected error", e); + } + } else { + // TODO: externalize message? + // NOTE: don't send error message if mapping not found + logger.log(Level.WARNING, "No mapping for such arguments in '" + + msg.getRecipientName() + "' operation in '" + name + + "' node. Recevied arguments: " + msgNoSender); + } + } + } + + public void run() { + try { + // NOTE: there's also a timeout, like in reference bindings + OtpMsg msg = null; + if (nodeElement.getBinding().hasTimeout()) { + msg = connection.receiveMsg(nodeElement.getBinding() + .getTimeout()); + } else { + msg = connection.receiveMsg(); + } + // check if request is message or RPC + if (msg.getRecipientName().equals(MessageHelper.RPC_MBOX) + && !nodeElement.getBinding().isMbox()) { + handleRpc(msg); + } else if (!msg.getRecipientName().equals(MessageHelper.RPC_MBOX) + && nodeElement.getBinding().isMbox()) { + handleMsg(msg); + } else { + // received wrong message type + } + } catch (IOException e) { + // TODO: externalize message? + logger.log(Level.WARNING, "Problem while receiving message", e); + } catch (OtpErlangExit e) { + // TODO: linking? + } catch (OtpAuthException e) { + // TODO: cookies? does this exception occur sometime? + } catch (InterruptedException e) { + // NOTE: timeout will be logged + // TODO: externalize message? + logger.log(Level.WARNING, "Timeout while waiting for request", e); + } finally { + connection.close(); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.java new file mode 100644 index 0000000000..b3562cc413 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/TypeMismatchException.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.sca.binding.erlang.impl; + +/** + * @version $Rev$ $Date$ + */ +public class TypeMismatchException extends Exception { + + private static final long serialVersionUID = 1L; + private Class expected; + private Class received; + + public TypeMismatchException(Class expected, Class received) { + super("Received " + received + " cannot be mapped to " + + expected.getCanonicalName()); + this.expected = expected; + this.received = received; + } + + public TypeMismatchException() { + super("Arguments don't match"); + } + + public Class getExpected() { + return expected; + } + + public Class getReceived() { + return received; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.java new file mode 100644 index 0000000000..587d7a509c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/exceptions/ErlangException.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.sca.binding.erlang.impl.exceptions; + +/** + * @version $Rev$ $Date$ + */ +public class ErlangException extends Exception { + + private static final long serialVersionUID = 1L; + + public ErlangException(String message) { + super(message); + } + + public ErlangException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/AnnotatedListTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/AnnotatedListTypeHelper.java new file mode 100644 index 0000000000..154f0c27fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/AnnotatedListTypeHelper.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.sca.binding.erlang.impl.types; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; + +import com.ericsson.otp.erlang.OtpErlangList; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class AnnotatedListTypeHelper implements TypeHelper { + + private Annotation[] notes; + + public AnnotatedListTypeHelper(Annotation[] notes) { + this.notes = notes; + } + + public OtpErlangObject toErlang(Object object) { + int i = 0; + List elements = new ArrayList(); + while (true) { + try { + elements.add(TypeHelpersProxy.toErlang(Array.get(object, i), + notes)); + i++; + } catch (ArrayIndexOutOfBoundsException e) { + // expected + break; + } + } + return new OtpErlangList(elements.toArray(new OtpErlangObject[elements + .size()])); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + OtpErlangList erlangList = (OtpErlangList) object; + Object result = Array.newInstance(forClass.getComponentType(), + erlangList.arity()); + for (int i = 0; i < erlangList.arity(); i++) { + Array.set(result, i, TypeHelpersProxy.toJava(erlangList + .elementAt(i), forClass.getComponentType(), + new Annotation[0])); + } + return result; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/AtomTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/AtomTypeHelper.java new file mode 100644 index 0000000000..94285c66bf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/AtomTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangAtom; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class AtomTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangAtom((String) object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + return ((OtpErlangAtom) object).atomValue(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BinaryTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BinaryTypeHelper.java new file mode 100644 index 0000000000..7385fe64e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BinaryTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangBinary; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class BinaryTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangBinary((byte[])object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + return ((OtpErlangBinary)object).binaryValue(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BooleanTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BooleanTypeHelper.java new file mode 100644 index 0000000000..9463b72eb9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/BooleanTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangAtom; +import com.ericsson.otp.erlang.OtpErlangBoolean; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class BooleanTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangBoolean((Boolean) object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + if (object.getClass().equals(OtpErlangAtom.class)) { + return ((OtpErlangAtom) object).booleanValue(); + } else { + return ((OtpErlangBoolean) object).booleanValue(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ByteTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ByteTypeHelper.java new file mode 100644 index 0000000000..c6c8f6690f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ByteTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangByte; +import com.ericsson.otp.erlang.OtpErlangLong; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class ByteTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangByte((Byte) object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + return (byte) ((OtpErlangLong) object).longValue(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/CharTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/CharTypeHelper.java new file mode 100644 index 0000000000..b0479c9b0c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/CharTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangChar; +import com.ericsson.otp.erlang.OtpErlangLong; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class CharTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangChar((Character) object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + return (char) ((OtpErlangLong) object).longValue(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/DoubleTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/DoubleTypeHelper.java new file mode 100644 index 0000000000..92dd4749ac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/DoubleTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangDouble; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class DoubleTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangDouble((Double) object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + return ((OtpErlangDouble) object).doubleValue(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/FloatTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/FloatTypeHelper.java new file mode 100644 index 0000000000..3ee695c3cc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/FloatTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangDouble; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class FloatTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangDouble((Float) object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + return (float) ((OtpErlangDouble) object).doubleValue(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/IntTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/IntTypeHelper.java new file mode 100644 index 0000000000..3ee8e7d9ac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/IntTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangInt; +import com.ericsson.otp.erlang.OtpErlangLong; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class IntTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangInt((Integer) object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + return (int) ((OtpErlangLong) object).longValue(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ListTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ListTypeHelper.java new file mode 100644 index 0000000000..7bb62d4cf8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ListTypeHelper.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.sca.binding.erlang.impl.types; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; + +import com.ericsson.otp.erlang.OtpErlangList; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class ListTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + int i = 0; + List elements = new ArrayList(); + while (true) { + try { + elements.add(TypeHelpersProxy.toErlang(Array.get(object, i), + new Annotation[0])); + i++; + } catch (ArrayIndexOutOfBoundsException e) { + // expected + break; + } + } + return new OtpErlangList(elements.toArray(new OtpErlangObject[elements + .size()])); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + OtpErlangList erlangList = (OtpErlangList) object; + Object result = Array.newInstance(forClass.getComponentType(), + erlangList.arity()); + for (int i = 0; i < erlangList.arity(); i++) { + Array.set(result, i, TypeHelpersProxy.toJava(erlangList + .elementAt(i), forClass.getComponentType(), + new Annotation[0])); + } + return result; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/LongTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/LongTypeHelper.java new file mode 100644 index 0000000000..711057569a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/LongTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangLong; +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public class LongTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangLong((Long) object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + return ((OtpErlangLong) object).longValue(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ShortTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ShortTypeHelper.java new file mode 100644 index 0000000000..73a68691a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/ShortTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangLong; +import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangShort; + +/** + * @version $Rev$ $Date$ + */ +public class ShortTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangShort((Short) object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + return (short) ((OtpErlangLong) object).longValue(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/StringTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/StringTypeHelper.java new file mode 100644 index 0000000000..001ec47655 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/StringTypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangString; + +/** + * @version $Rev$ $Date$ + */ +public class StringTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + return new OtpErlangString((String) object); + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + return ((OtpErlangString) object).stringValue(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TupleTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TupleTypeHelper.java new file mode 100644 index 0000000000..64ea57f836 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TupleTypeHelper.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.sca.binding.erlang.impl.types; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangTuple; + +/** + * @version $Rev$ $Date$ + */ +public class TupleTypeHelper implements TypeHelper { + + public OtpErlangObject toErlang(Object object) { + Class forClass = object.getClass(); + List tupleMembers = new ArrayList(); + Field[] fields = forClass.getFields(); + for (int i = 0; i < fields.length; i++) { + try { + OtpErlangObject member = TypeHelpersProxy.toErlang(fields[i] + .get(object), fields[i].getAnnotations()); + tupleMembers.add(member); + } catch (IllegalArgumentException e) { + // no problem should occur here + } catch (IllegalAccessException e) { + // and here + } + } + OtpErlangObject result = new OtpErlangTuple(tupleMembers + .toArray(new OtpErlangObject[tupleMembers.size()])); + return result; + } + + public Object toJava(OtpErlangObject object, Class forClass) + throws Exception { + Object result = null; + OtpErlangTuple tuple = (OtpErlangTuple) object; + Field[] fields = forClass.getFields(); + result = forClass.newInstance(); + for (int i = 0; i < tuple.arity(); i++) { + OtpErlangObject tupleMember = tuple.elementAt(i); + Object javaMember = TypeHelpersProxy.toJava(tupleMember, fields[i] + .getType(), fields[i].getAnnotations()); + fields[i].setAccessible(true); + fields[i].set(result, javaMember); + } + return result; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelper.java new file mode 100644 index 0000000000..add885ef6e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelper.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.sca.binding.erlang.impl.types; + +import com.ericsson.otp.erlang.OtpErlangObject; + +/** + * @version $Rev$ $Date$ + */ +public interface TypeHelper { + + Object toJava(OtpErlangObject object, Class forClass) throws Exception; + + OtpErlangObject toErlang(Object object); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java new file mode 100644 index 0000000000..2ab29490e3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java @@ -0,0 +1,291 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.impl.types; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.binding.erlang.impl.TypeMismatchException; +import org.apache.tuscany.sca.binding.erlang.meta.ErlangAtom; + +import com.ericsson.otp.erlang.OtpErlangList; +import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangTuple; + +/** + * @version $Rev$ $Date$ + */ +public class TypeHelpersProxy { + + private static Map, TypeHelper> primitiveTypes = null; + + static { + // initiate type helpers + primitiveTypes = new HashMap, TypeHelper>(); + primitiveTypes.put(boolean.class, new BooleanTypeHelper()); + primitiveTypes.put(short.class, new ShortTypeHelper()); + primitiveTypes.put(byte.class, new ByteTypeHelper()); + primitiveTypes.put(char.class, new CharTypeHelper()); + primitiveTypes.put(int.class, new IntTypeHelper()); + primitiveTypes.put(long.class, new LongTypeHelper()); + primitiveTypes.put(float.class, new FloatTypeHelper()); + primitiveTypes.put(double.class, new DoubleTypeHelper()); + primitiveTypes.put(String.class, new StringTypeHelper()); + primitiveTypes.put(Boolean.class, primitiveTypes.get(boolean.class)); + primitiveTypes.put(Character.class, primitiveTypes.get(char.class)); + primitiveTypes.put(Short.class, primitiveTypes.get(char.class)); + primitiveTypes.put(Byte.class, primitiveTypes.get(byte.class)); + primitiveTypes.put(Short.class, primitiveTypes.get(short.class)); + primitiveTypes.put(Integer.class, primitiveTypes.get(int.class)); + primitiveTypes.put(Long.class, primitiveTypes.get(long.class)); + primitiveTypes.put(Float.class, primitiveTypes.get(float.class)); + primitiveTypes.put(Double.class, primitiveTypes.get(double.class)); + primitiveTypes.put(byte[].class, new BinaryTypeHelper()); + primitiveTypes.put(ErlangAtom.class, new AtomTypeHelper()); + } + + private static TypeHelper getTypeHelper(Class forClass, + Annotation[] notes) { + TypeHelper typeHelper = null; + // check for special types marked by annotations + for (int i = 0; i < notes.length; i++) { + typeHelper = primitiveTypes.get(notes[i].annotationType()); + if (typeHelper != null) { + // get type which is annotated, reduce array if needed + Class annotatedType = forClass; + while (annotatedType.isArray()) { + annotatedType = annotatedType.getComponentType(); + } + if (notes[i].annotationType().equals(ErlangAtom.class) + && !annotatedType.equals(String.class)) { + // NOTE: @ErlangAtom atom will be ignored if not annotates + // string + typeHelper = null; + } else { + // check if annotation points to array + if (forClass.isArray()) { + typeHelper = new AnnotatedListTypeHelper(notes); + } + break; + } + } + } + // check for standard types + if (typeHelper == null) { + typeHelper = primitiveTypes.get(forClass); + } + // check for arrays + if (typeHelper == null && forClass.isArray()) { + typeHelper = new ListTypeHelper(); + } + // others would be tuples + if (typeHelper == null) { + typeHelper = new TupleTypeHelper(); + } + return typeHelper; + } + + /** + * Converts single Java object into Erlang + * + * @param object + * @param notes + * @return + */ + public static OtpErlangObject toErlang(Object object, Annotation[] notes) { + TypeHelper helper = getTypeHelper(object.getClass(), notes); + return helper.toErlang(object); + } + + /** + * Converts Java objects arrays to Erlang: 1. single object (if array arity + * == 1) or 2. tuple (if array arity > 1) + * + * @param objects + * @return + */ + public static OtpErlangObject toErlang(Object[] objects, + Annotation[][] notes) { + OtpErlangObject result = null; + if (objects != null) { + TypeHelper helper = null; + switch (objects.length) { + case 0: + result = new OtpErlangList(); + break; + case 1: + helper = getTypeHelper(objects[0].getClass(), notes[0]); + result = helper.toErlang(objects[0]); + break; + default: + OtpErlangObject[] erlObjects = new OtpErlangObject[objects.length]; + for (int i = 0; i < objects.length; i++) { + helper = getTypeHelper(objects[i].getClass(), notes[i]); + erlObjects[i] = helper.toErlang(objects[i]); + } + result = new OtpErlangTuple(erlObjects); + break; + } + } + return result; + } + + /** + * Creates Erlang list basing on unknown Java arrays + * + * @param array + * @param notes + * @return + */ + public static OtpErlangList toErlangAsList(Object array, + Annotation[][] notes) { + return toErlangAsList(array, notes, false); + } + + /** + * Creates Erlang list of result elements + * + * @param array + * @param notes + * @return + */ + public static OtpErlangList toErlangAsResultList(Object array, + Annotation[] notes) { + return toErlangAsList(array, new Annotation[][] { notes }, true); + } + + /** + * + * @param array + * @param notes + * @param isArray + * @return + */ + private static OtpErlangList toErlangAsList(Object array, + Annotation[][] notes, boolean isArray) { + OtpErlangList result = null; + if (array != null) { + List attrsList = new ArrayList(); + int i = 0; + while (true) { + try { + Annotation[] currNotes = isArray ? notes[0] : notes[i]; + TypeHelper helper = getTypeHelper(Array.get(array, i) + .getClass(), currNotes); + attrsList.add(helper.toErlang(Array.get(array, i))); + i++; + } catch (ArrayIndexOutOfBoundsException e) { + break; + } + } + result = new OtpErlangList(attrsList + .toArray(new OtpErlangObject[attrsList.size()])); + } else { + result = new OtpErlangList(); + } + return result; + } + + /** + * Converts single Erlang object to Java + * + * @param object + * @param forClass + * @return + * @throws Exception + */ + public static Object toJava(OtpErlangObject object, Class forClass, + Annotation[] notes) throws Exception { + try { + TypeHelper helper = getTypeHelper(forClass, notes); + return helper.toJava(object, forClass); + } catch (ClassCastException e) { + throw new TypeMismatchException(forClass, object.getClass()); + } + } + + /** + * Creates array of Java objects from Erlang list + * + * @param objects + * @param forClass + * @return + * @throws Exception + */ + public static Object[] toJavaFromList(OtpErlangList objects, + Class[] forClass, Annotation[][] notes) throws Exception { + Object[] result = new Object[objects.arity()]; + try { + for (int i = 0; i < objects.arity(); i++) { + TypeHelper helper = getTypeHelper(forClass[i], notes[i]); + result[i] = helper.toJava(objects.elementAt(i), forClass[i]); + } + } catch (Exception e) { + // type mismatch as mismatch of parameters count or parameters type + if (e.getClass().equals(ClassCastException.class) + || e.getClass() + .equals(ArrayIndexOutOfBoundsException.class)) + throw new TypeMismatchException(); + } + return result; + } + + /** + * Converts incoming Erlang message to operation arguments + * + * @param objects + * @param forClass + * @return + * @throws Exception + */ + public static Object[] toJavaAsArgs(OtpErlangObject objects, + Class[] forClass, Annotation[][] notes) throws Exception { + OtpErlangObject[] args = null; + // normalize input + if (objects.getClass().equals(OtpErlangTuple.class)) { + args = new OtpErlangObject[((OtpErlangTuple) objects).arity()]; + for (int i = 0; i < ((OtpErlangTuple) objects).arity(); i++) { + args[i] = ((OtpErlangTuple) objects).elementAt(i); + } + } else { + args = new OtpErlangObject[1]; + args[0] = objects; + } + Object[] result = new Object[args.length]; + try { + for (int i = 0; i < args.length; i++) { + TypeHelper helper = getTypeHelper(forClass[i], notes[i]); + result[i] = helper.toJava(args[i], forClass[i]); + } + } catch (Exception e) { + // type mismatch as mismatch of parameters count or parameters type + if (e.getClass().equals(ClassCastException.class) + || e.getClass() + .equals(ArrayIndexOutOfBoundsException.class)) + throw new TypeMismatchException(); + } + return result; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/meta/ErlangAtom.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/meta/ErlangAtom.java new file mode 100644 index 0000000000..48037eaa1c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/meta/ErlangAtom.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.sca.binding.erlang.meta; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface ErlangAtom { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..8e1c659797 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.erlang.impl.ErlangBindingProviderFactory;model=org.apache.tuscany.sca.binding.erlang.ErlangBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/AtomTuple.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/AtomTuple.java new file mode 100644 index 0000000000..f0930295a7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/AtomTuple.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.sca.binding.erlang.testing; + +import org.apache.tuscany.sca.binding.erlang.meta.ErlangAtom; + +public class AtomTuple { + + @ErlangAtom + public String field1; + public int field2; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java new file mode 100644 index 0000000000..034abab8f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.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.sca.binding.erlang.testing; + +import org.apache.tuscany.sca.binding.erlang.meta.ErlangAtom; + +/** + * @version $Rev$ $Date$ + */ +public interface MboxInterface { + + String sendArgs(String arg) throws Exception; + + boolean sendArgs(boolean arg) throws Exception; + + float sendArgs(float arg) throws Exception; + + double sendArgs(double arg) throws Exception; + + long sendArgs(long arg) throws Exception; + + int sendArgs(int arg) throws Exception; + + char sendArgs(char arg) throws Exception; + + short sendArgs(short arg) throws Exception; + + byte sendArgs(byte arg) throws Exception; + + void sendArgs(int arg1, String arg2) throws Exception; + + StructuredTuple sendArgs(StructuredTuple arg) throws Exception; + + String[] sendArgs(String[] arg) throws Exception; + + String[][] sendArgs(String[][] arg); + + byte[] sendArgs(byte[] arg); + + @ErlangAtom + String[] sendArgs(@ErlangAtom String arg1, AtomTuple arg2); + + @ErlangAtom + String[][] sendArgs(@ErlangAtom String[][] arg1, int arg2); + + void sendArgs() throws Exception; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java new file mode 100644 index 0000000000..0cab5c0b0e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.testing; + +import java.lang.annotation.Annotation; + +import org.apache.tuscany.sca.binding.erlang.impl.types.TypeHelpersProxy; + +import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangPid; +import com.ericsson.otp.erlang.OtpErlangTuple; +import com.ericsson.otp.erlang.OtpMbox; +import com.ericsson.otp.erlang.OtpMsg; + +/** + * @version $Rev$ $Date$ + */ +public class MboxListener implements Runnable { + + private OtpMbox mbox; + private OtpMsg msg; + private Object response; + private long duration; + + public MboxListener(OtpMbox mbox, Object response) { + this(mbox, response, 0); + } + + public MboxListener(OtpMbox mbox, Object response, long duration) { + this.mbox = mbox; + this.response = response; + this.duration = duration; + } + + public void run() { + try { + msg = mbox.receiveMsg(); + Thread.sleep(duration); + OtpErlangPid senderPid = null; + if (response != null) { + if (msg.getMsg().getClass().equals(OtpErlangTuple.class) + && ((OtpErlangTuple) msg.getMsg()).elementAt(0) + .getClass().equals(OtpErlangPid.class)) { + senderPid = (OtpErlangPid) ((OtpErlangTuple) msg.getMsg()) + .elementAt(0); + } else { + senderPid = msg.getSenderPid(); + } + mbox.send(senderPid, TypeHelpersProxy.toErlang(response, + new Annotation[0])); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public OtpErlangObject getMsg() { + try { + // Sometimes clients tries to get message which isn't fully + // received. + // If so - give it more tries. This sometimes caused + // NullPointerException in + // ReferenceServiceTestCase.testMultipleArguments(). + for (int i = 0; i < 3; i++) { + if (msg != null) { + return ((OtpErlangTuple) msg.getMsg()).elementAt(1); + } else { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + } + } + return ((OtpErlangTuple) msg.getMsg()).elementAt(1); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ModuleInterface.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ModuleInterface.java new file mode 100644 index 0000000000..6fc95ac120 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ModuleInterface.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.sca.binding.erlang.testing; + +/** + * @version $Rev$ $Date$ + */ +public interface ModuleInterface { + + String start(String arg1, String arg2) throws Exception; + + String start() throws Exception; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java new file mode 100644 index 0000000000..2073e4b154 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java @@ -0,0 +1,924 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.testing; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.IOException; + +import org.apache.tuscany.sca.binding.erlang.impl.TypeMismatchException; +import org.apache.tuscany.sca.binding.erlang.impl.exceptions.ErlangException; +import org.apache.tuscany.sca.binding.erlang.testing.dynaignore.IgnorableRunner; +import org.apache.tuscany.sca.binding.erlang.testing.dynaignore.IgnoreTest; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.ericsson.otp.erlang.OtpAuthException; +import com.ericsson.otp.erlang.OtpConnection; +import com.ericsson.otp.erlang.OtpErlangAtom; +import com.ericsson.otp.erlang.OtpErlangBinary; +import com.ericsson.otp.erlang.OtpErlangBoolean; +import com.ericsson.otp.erlang.OtpErlangDouble; +import com.ericsson.otp.erlang.OtpErlangInt; +import com.ericsson.otp.erlang.OtpErlangList; +import com.ericsson.otp.erlang.OtpErlangLong; +import com.ericsson.otp.erlang.OtpErlangObject; +import com.ericsson.otp.erlang.OtpErlangString; +import com.ericsson.otp.erlang.OtpErlangTuple; +import com.ericsson.otp.erlang.OtpMbox; +import com.ericsson.otp.erlang.OtpNode; +import com.ericsson.otp.erlang.OtpPeer; +import com.ericsson.otp.erlang.OtpSelf; + +/** + * Test is annotated with test runner, which will ignore tests if epmd is not + * available + * + * @version $Rev$ $Date$ + */ +@RunWith(IgnorableRunner.class) +public class ReferenceServiceTestCase { + + private static final String EPMD_COMMAND = "epmd"; + + private static MboxInterface mboxReference; + private static MboxInterface timeoutMboxReference; + private static ServiceInterface moduleReference; + private static ServiceInterface cookieModuleReference; + private static ServiceInterface invalidCookieModuleReference; + private static ServiceInterface timeoutModuleReference; + private static OtpNode serNode; + private static OtpMbox serMbox; + private static OtpNode refNode; + private static OtpMbox refMbox; + private static Process epmdProcess; + + @BeforeClass + public static void init() throws IOException { + try { + epmdProcess = Runtime.getRuntime().exec(EPMD_COMMAND); + SCADomain domain = SCADomain + .newInstance("ErlangReference.composite"); + SCADomain.newInstance("ErlangService.composite"); + ReferenceTestComponentImpl component = domain.getService( + ReferenceTestComponentImpl.class, "ReferenceTest"); + + mboxReference = component.getMboxReference(); + timeoutMboxReference = component.getTimeoutMboxReference(); + moduleReference = component.getModuleReference(); + cookieModuleReference = component.getCookieModuleReference(); + invalidCookieModuleReference = component + .getInvalidCookieModuleReference(); + timeoutModuleReference = component.getTimeoutModuleReference(); + + serNode = new OtpNode("MboxServer"); + serMbox = serNode.createMbox("sendArgs"); + refNode = new OtpNode("MboxClient"); + refMbox = refNode.createMbox("connector_to_SCA_mbox"); + } catch (IOException e) { + System.out.println("Problem executing " + EPMD_COMMAND + ": " + + e.getLocalizedMessage() + ". Tests will be IGNORED."); + } + } + + @AfterClass + public static void clean() { + if (epmdProcess != null) { + epmdProcess.destroy(); + } + } + + @Before + public void before() { + if (epmdProcess == null) { + throw new IgnoreTest(); + } + } + + /** + * Tests passing strings + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testStrings() throws Exception { + String strArg = "Test message"; + String strResult = "OK"; + MboxListener mboxListener = new MboxListener(serMbox, strResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String testResult = mboxReference.sendArgs(strArg); + assertEquals(strArg, ((OtpErlangString) mboxListener.getMsg()) + .stringValue()); + assertEquals(strResult, testResult); + } + + /** + * Tests passing booleans + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testBooleans() throws Exception { + boolean booleanArg = true; + boolean booleanResult = false; + MboxListener mboxListener = new MboxListener(serMbox, booleanResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + boolean testResult = mboxReference.sendArgs(booleanArg); + assertEquals(booleanArg, ((OtpErlangAtom) mboxListener.getMsg()) + .booleanValue()); + assertEquals(booleanResult, testResult); + } + + /** + * Tests passing floats + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testFloats() throws Exception { + float floatArg = 1.0f; + float floatResult = 2.0f; + MboxListener mboxListener = new MboxListener(serMbox, floatResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + float testResult = mboxReference.sendArgs(floatArg); + assertEquals(floatArg, ((OtpErlangDouble) mboxListener.getMsg()) + .doubleValue(), 0); + assertEquals(floatResult, testResult, 0); + } + + /** + * Tests passing doubles + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testDoubles() throws Exception { + double doubleArg = 1.0f; + double doubleResult = 2.0f; + MboxListener mboxListener = new MboxListener(serMbox, doubleResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + double testResult = mboxReference.sendArgs(doubleArg); + assertEquals(doubleArg, ((OtpErlangDouble) mboxListener.getMsg()) + .doubleValue(), 0); + assertEquals(doubleResult, testResult, 0); + } + + /** + * Tests passing long values + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testLongs() throws Exception { + long longArg = 1; + long longResult = 2; + MboxListener mboxListener = new MboxListener(serMbox, longResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + long testResult = mboxReference.sendArgs(longArg); + assertEquals(longArg, ((OtpErlangLong) mboxListener.getMsg()) + .longValue(), 0); + assertEquals(longResult, testResult, 0); + } + + /** + * Tests passing integers + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testInts() throws Exception { + int intArg = 1; + int intResult = 2; + MboxListener mboxListener = new MboxListener(serMbox, intResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + int testResult = mboxReference.sendArgs(intArg); + assertEquals(intArg, + ((OtpErlangLong) mboxListener.getMsg()).intValue(), 0); + assertEquals(intResult, testResult, 0); + } + + /** + * Tests passing chars + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testChars() throws Exception { + char charArg = 1; + char charResult = 2; + MboxListener mboxListener = new MboxListener(serMbox, charResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + char testResult = mboxReference.sendArgs(charArg); + assertEquals(charArg, ((OtpErlangLong) mboxListener.getMsg()) + .charValue(), 0); + assertEquals(charResult, testResult, 0); + } + + /** + * Tests passing shorts + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testShorts() throws Exception { + short shortArg = 1; + short shortResult = 2; + MboxListener mboxListener = new MboxListener(serMbox, shortResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + short testResult = mboxReference.sendArgs(shortArg); + assertEquals(shortArg, ((OtpErlangLong) mboxListener.getMsg()) + .shortValue(), 0); + assertEquals(shortResult, testResult, 0); + } + + /** + * Tests passing bytes + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testBytes() throws Exception { + byte byteArg = 1; + byte byteResult = 2; + MboxListener mboxListener = new MboxListener(serMbox, byteResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + byte testResult = mboxReference.sendArgs(byteArg); + assertEquals(byteArg, ((OtpErlangLong) mboxListener.getMsg()) + .byteValue(), 0); + assertEquals(byteResult, testResult, 0); + } + + /** + * Tests passing multiple arguments + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testMultipleArguments() throws Exception { + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String testString = "TupleString"; + int testInt = 10; + mboxReference.sendArgs(testInt, testString); + // FIXME: + // without following sleep an exception occurs: + // com.ericsson.otp.erlang.OtpErlangDecodeException: Cannot read from + // input stream + Thread.sleep(100); + assertEquals(testInt, ((OtpErlangLong) ((OtpErlangTuple) mboxListener + .getMsg()).elementAt(0)).longValue()); + assertEquals(testString, + ((OtpErlangString) ((OtpErlangTuple) mboxListener.getMsg()) + .elementAt(1)).stringValue()); + } + + /** + * Tests passing tuples + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testTuples() throws Exception { + StructuredTuple tupleResult = new StructuredTuple(); + tupleResult.arg1.arg1 = 1; + tupleResult.arg1.arg2 = "Tuple inside tuple"; + tupleResult.arg2 = "Tuple!"; + tupleResult.arg3 = true; + MboxListener mboxListener = new MboxListener(serMbox, tupleResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + StructuredTuple testArg = new StructuredTuple(); + testArg.arg2 = "Arg2a"; + testArg.arg3 = true; + testArg.arg1.arg1 = 10; + testArg.arg1.arg2 = "Arg2b"; + StructuredTuple testResult = mboxReference.sendArgs(testArg); + assertEquals(tupleResult, testResult); + OtpErlangTuple received = (OtpErlangTuple) mboxListener.getMsg(); + assertEquals(testArg.arg1.arg1, + ((OtpErlangLong) ((OtpErlangTuple) received.elementAt(0)) + .elementAt(0)).longValue()); + assertEquals(testArg.arg1.arg2, + ((OtpErlangString) ((OtpErlangTuple) received.elementAt(0)) + .elementAt(1)).stringValue()); + assertEquals(testArg.arg2, ((OtpErlangString) received.elementAt(1)) + .stringValue()); + assertEquals(testArg.arg3, ((OtpErlangAtom) received.elementAt(2)) + .booleanValue()); + } + + /** + * Test passing Erlang binaries + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testBinaries() throws Exception { + byte[] testArg = { 0, 1 }; + MboxListener mboxListener = new MboxListener(serMbox, testArg); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + byte[] testResult = mboxReference.sendArgs(testArg); + assertEquals(testArg.length, testResult.length); + for (int i = 0; i < testArg.length; i++) { + assertEquals(testArg[i], testResult[i]); + } + OtpErlangBinary received = (OtpErlangBinary) mboxListener.getMsg(); + assertEquals(testArg.length, received.size()); + for (int i = 0; i < testArg.length; i++) { + assertEquals(testArg[i], received.binaryValue()[i]); + } + } + + /** + * Tests passing lists + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testLists() throws Exception { + String[] testArg = new String[] { "One", "Two", "Three" }; + MboxListener mboxListener = new MboxListener(serMbox, testArg); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String[] testResult = mboxReference.sendArgs(testArg); + assertEquals(testArg.length, testResult.length); + for (int i = 0; i < testArg.length; i++) { + assertEquals(testArg[i], testResult[i]); + } + OtpErlangList received = (OtpErlangList) mboxListener.getMsg(); + assertEquals(testArg.length, received.arity()); + for (int i = 0; i < testArg.length; i++) { + assertEquals(testArg[i], ((OtpErlangString) received.elementAt(i)) + .stringValue()); + } + } + + /** + * Tests passing multidimensional lists + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testMultiDimLists() throws Exception { + String[][] testArg = new String[][] { { "One", "Two" }, + { "Three", "Four", "Five" }, { "Six" } }; + MboxListener mboxListener = new MboxListener(serMbox, testArg); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String[][] testResult = mboxReference.sendArgs(testArg); + assertEquals(testArg.length, testResult.length); + for (int i = 0; i < testArg.length; i++) { + for (int j = 0; j < testArg[i].length; j++) { + assertEquals(testArg[i][j], testResult[i][j]); + } + } + OtpErlangList received = (OtpErlangList) mboxListener.getMsg(); + assertEquals(testArg.length, received.arity()); + for (int i = 0; i < testArg.length; i++) { + for (int j = 0; j < testArg[i].length; j++) { + assertEquals(testArg[i][j], + (((OtpErlangString) ((OtpErlangList) received + .elementAt(i)).elementAt(j)).stringValue())); + } + } + } + + /** + * Tests passing Erlang atoms. It provides cases for annotating result + * types, parameters and fields in java classes - tuples. + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testAtoms() throws Exception { + AtomTuple arg2 = new AtomTuple(); + arg2.field1 = "test"; + String arg1 = "First arg"; + String[] strResult = { "Hello", "World" }; + MboxListener mboxListener = new MboxListener(serMbox, strResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String[] testResult = mboxReference.sendArgs(arg1, arg2); + assertEquals(strResult[0], testResult[0]); + assertEquals(strResult[1], testResult[1]); + + assertEquals(arg1, ((OtpErlangAtom) ((OtpErlangTuple) mboxListener + .getMsg()).elementAt(0)).atomValue()); + + assertEquals( + arg2.field1, + ((OtpErlangAtom) ((OtpErlangTuple) ((OtpErlangTuple) mboxListener + .getMsg()).elementAt(1)).elementAt(0)).atomValue()); + + // test multi dimensional arrays + String[][] arg = { { "this", "is" }, { "a" }, { "test" } }; + mboxListener = new MboxListener(serMbox, arg); + mboxThread = new Thread(mboxListener); + mboxThread.start(); + String[][] multiDimRes = mboxReference.sendArgs(arg, 1); + for (int i = 0; i < arg.length; i++) { + for (int j = 0; j < arg[i].length; j++) { + assertEquals(arg[i][j], multiDimRes[i][j]); + assertEquals( + arg[i][j], + ((OtpErlangAtom) ((OtpErlangList) ((OtpErlangList) ((OtpErlangTuple) mboxListener + .getMsg()).elementAt(0)).elementAt(i)) + .elementAt(j)).atomValue()); + } + } + + } + + /** + * Tests Erlang Atom types on service side + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testServiceAtoms() throws Exception { + String[] args = { "Say", "Atoms" }; + OtpErlangObject[] toList = new OtpErlangObject[2]; + toList[0] = new OtpErlangString(args[0]); + toList[1] = new OtpErlangString(args[1]); + OtpErlangList list = new OtpErlangList(toList); + OtpErlangObject[] toTuple = new OtpErlangObject[2]; + toTuple[0] = refMbox.self(); + toTuple[1] = list; + refMbox.send("sayAtoms", "RPCServerMbox", new OtpErlangTuple(toTuple)); + OtpErlangObject result = refMbox.receiveMsg().getMsg(); + assertEquals(args.length, ((OtpErlangList) result).arity()); + for (int i = 0; i < args.length; i++) { + assertEquals(args[i], ((OtpErlangAtom) ((OtpErlangList) result) + .elementAt(i)).atomValue()); + } + } + + /** + * Tests mismatched interface + * + * @throws Exception + */ + @Test(timeout = 1000) + public void typeMismatch() throws Exception { + try { + StructuredTuple arg = new StructuredTuple(); + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + String[] arg = new String[] { "test" }; + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + long arg = 1; + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + int arg = 1; + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + short arg = 1; + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + char arg = 1; + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + byte arg = 1; + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + double arg = 1; + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + float arg = 1; + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + String arg = "1"; + MboxListener mboxListener = new MboxListener(serMbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + boolean arg = true; + MboxListener mboxListener = new MboxListener(serMbox, 1); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + } + + /** + * Basic RPC test, without arguments + * + * @throws Exception + */ + @Test(timeout = 10000000) + public void testRPC() throws Exception { + String[] result = moduleReference.sayHellos(); + assertEquals(2, result.length); + assertEquals("1", result[0]); + assertEquals("2", result[1]); + } + + /** + * Tests RPC with arguments + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testRPCWithArgs() throws Exception { + String arg1 = "One"; + String arg2 = "Two"; + String testResult = moduleReference.sayHello(arg1, arg2); + assertEquals("Hello " + arg1 + " " + arg2, testResult); + } + + /** + * Tests RPC with structured arguments + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testRPCWithComplexArgs() throws Exception { + StructuredTuple arg = new StructuredTuple(); + arg.arg1.arg2 = "Not empty"; + arg.arg2 = "Not empty"; + StructuredTuple testResult = moduleReference.passComplexArgs(arg, + new String[] { "some", "array" }); + assertEquals(arg, testResult); + } + + /** + * Tests RPC with no result + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testRPCWithVoidResult() throws Exception { + moduleReference.doNothing(); + } + + /** + * Tests handling requests pointing to unknown functions + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testUnknownFunction() throws Exception { + + // following functions differs by parameters + + try { + moduleReference.sayHello(); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + + try { + moduleReference.sayHello("1"); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + + try { + moduleReference.sayHello(1, 2); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + + // for following ones name not exists + + moduleReference.notExist(); + + try { + moduleReference.notExistWithException(); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + } + + /** + * Tests mbox with retrieving and answering with basic arguments + * + * @throws Exception + */ + @Test(timeout = 2000) + public void testMbox() throws Exception { + OtpErlangObject[] args = new OtpErlangObject[2]; + args[0] = new OtpErlangString("world"); + args[1] = new OtpErlangString("!"); + OtpErlangTuple tuple = new OtpErlangTuple(args); + OtpErlangObject[] argsWithSender = new OtpErlangObject[2]; + argsWithSender[0] = refMbox.self(); + argsWithSender[1] = tuple; + refMbox.send("sayHello", "RPCServerMbox", new OtpErlangTuple( + argsWithSender)); + OtpErlangString result = (OtpErlangString) refMbox.receiveMsg() + .getMsg(); + assertEquals("Hello world !", result.stringValue()); + } + + /** + * Tests receiving reply without sending self PID + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testMsgWithoutPid() throws Exception { + OtpErlangObject[] args = new OtpErlangObject[2]; + args[0] = new OtpErlangString("world"); + args[1] = new OtpErlangString("!"); + refMbox.send("sayHello", "RPCServerMbox", new OtpErlangTuple(args)); + OtpErlangString result = (OtpErlangString) refMbox.receiveMsg() + .getMsg(); + assertEquals("Hello world !", result.stringValue()); + } + + /** + * Tests service mbox receiving complex message + * + * @throws Exception + */ + @Test(timeout = 2000) + public void testMboxWithComplexArgs() throws Exception { + int arg1 = 1; + String arg2 = "arg2"; + String arg3 = "arg3"; + boolean arg4 = true; + + OtpErlangObject[] smallTupleContent = new OtpErlangObject[2]; + smallTupleContent[0] = new OtpErlangInt(arg1); + smallTupleContent[1] = new OtpErlangString(arg2); + OtpErlangTuple smallTuple = new OtpErlangTuple(smallTupleContent); + OtpErlangObject[] structuredTupleContent = new OtpErlangObject[3]; + structuredTupleContent[0] = smallTuple; + structuredTupleContent[1] = new OtpErlangString(arg3); + structuredTupleContent[2] = new OtpErlangBoolean(arg4); + OtpErlangTuple structuredTuple = new OtpErlangTuple( + structuredTupleContent); + OtpErlangObject[] secondArg = new OtpErlangObject[2]; + secondArg[0] = new OtpErlangString("in"); + secondArg[1] = new OtpErlangString("array"); + OtpErlangList list = new OtpErlangList(secondArg); + OtpErlangObject[] argsContent = new OtpErlangObject[2]; + argsContent[0] = structuredTuple; + argsContent[1] = list; + OtpErlangTuple args = new OtpErlangTuple(argsContent); + OtpErlangObject[] withSender = new OtpErlangObject[2]; + withSender[0] = refMbox.self(); + withSender[1] = args; + refMbox.send("passComplexArgs", "RPCServerMbox", new OtpErlangTuple( + withSender)); + OtpErlangObject result = refMbox.receiveMsg().getMsg(); + assertEquals(arg1, + ((OtpErlangLong) ((OtpErlangTuple) ((OtpErlangTuple) result) + .elementAt(0)).elementAt(0)).intValue()); + assertEquals(arg2, + ((OtpErlangString) ((OtpErlangTuple) ((OtpErlangTuple) result) + .elementAt(0)).elementAt(1)).stringValue()); + assertEquals(arg3, ((OtpErlangString) ((OtpErlangTuple) result) + .elementAt(1)).stringValue()); + assertEquals(arg4, ((OtpErlangAtom) ((OtpErlangTuple) result) + .elementAt(2)).booleanValue()); + } + + /** + * Tests timeout feature for reference binding messaging + * + * @throws Exception + */ + @Test(timeout = 4000) + public void testMboxReferenceTimeouts() throws Exception { + long timeBiggerThanTimeout = 1000; + String stringResult = "result"; + + // doing test for response time bigger than declared timeout (500) + MboxListener mboxListener = new MboxListener(serMbox, stringResult, + timeBiggerThanTimeout); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + try { + // timeout exception expected + timeoutMboxReference.sendArgs(""); + fail("Exception expected"); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + assertEquals(e.getCause().getClass(), InterruptedException.class); + } + + // doing test for response time smaller than declared timeout (500) + mboxListener = new MboxListener(serMbox, stringResult, 0); + mboxThread = new Thread(mboxListener); + mboxThread.start(); + // expecting no timeout exception + String testResult = timeoutMboxReference.sendArgs(""); + assertEquals(stringResult, testResult); + + // doing test for response time which will cause timeout. This time + // there is no declared exception in users operation so we expect no + // exception and null result + mboxListener = new MboxListener(serMbox, new byte[1], + timeBiggerThanTimeout); + mboxThread = new Thread(mboxListener); + mboxThread.start(); + // expecting no timeout exception + byte[] result = timeoutMboxReference.sendArgs(new byte[1]); + assertEquals(null, result); + } + + /** + * Tests timeout feature for reference binding RPC + * + * @throws Exception + */ + @Test(timeout = 4000) + public void testRpcReferenceTimeouts() throws Exception { + + // doing test for response time which will cause timeout. Method does + // not + // declare exception so only null value will be returned + String result1 = timeoutModuleReference.sayHello("hello", "world"); + assertEquals(null, result1); + + // doing test for response time which will cause timeout. Method declare + // exception, so expecting one + try { + timeoutModuleReference.sayHellos(); + fail("Exception expected"); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + + // doing test for response time shorter than timeout + timeoutModuleReference.doNothing(); + } + + /** + * Tests timeout feature for service side bindings + * + * @throws Exception + */ + @Test(timeout = 4000) + public void testServiceTimeouts() throws Exception { + OtpSelf self = new OtpSelf("tmp_connector_" + + System.currentTimeMillis()); + OtpPeer peer = new OtpPeer("RPCServerTimeout"); + OtpConnection connection = self.connect(peer); + // delay message sending after connecting + Thread.sleep(1000); + // service binding timeout set to 500 so after that time it will give up + // and close connection + try { + connection.send("rex", new OtpErlangString("test")); + fail("Exception expected"); + } catch (Exception e) { + assertEquals(IOException.class, e.getClass()); + } + + connection = self.connect(peer); + // sending message immediately and encountering no connection close + connection.send("rex", new OtpErlangString("test")); + + } + + /** + * Tests cookie feature for both reference and service bindings RPC + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testReferenceCookies() throws Exception { + // testing wrong cookie + try { + invalidCookieModuleReference.sayHellos(); + fail("Exception expected"); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + assertEquals(OtpAuthException.class, e.getCause().getClass()); + } + + // testing correct cookie + cookieModuleReference.sayHellos(); + } + + /** + * Tests fix which allow to send message with no user specified content (in + * fact always will be some content - senders PID at the content beginning). + * + * @throws Exception + */ + @Test(timeout = 1000) + public void testMboxNoArgs() throws Exception { + mboxReference.sendArgs(); + // no exception should occur + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponent.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponent.java new file mode 100644 index 0000000000..be43820b0b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponent.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.sca.binding.erlang.testing; + +/** + * @version $Rev$ $Date$ + */ +public interface ReferenceTestComponent { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java new file mode 100644 index 0000000000..7bcc378b78 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.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.sca.binding.erlang.testing; + +import org.osoa.sca.annotations.Reference; + +/** + * @version $Rev$ $Date$ + */ +public class ReferenceTestComponentImpl implements ReferenceTestComponent { + + private MboxInterface mboxReference; + private MboxInterface timeoutMboxReference; + private MboxInterface cookieMboxReference; + private ServiceInterface moduleReference; + private ServiceInterface cookieModuleReference; + private ServiceInterface invalidCookieModuleReference; + private ServiceInterface timeoutModuleReference; + private ServiceInterface clonedModuleReference; + + @Reference + public void setMboxReference(MboxInterface mboxReference) { + this.mboxReference = mboxReference; + } + + @Reference + public void setTimeoutMboxReference(MboxInterface timeoutMboxReference) { + this.timeoutMboxReference = timeoutMboxReference; + } + + @Reference + public void setCookieMboxReference(MboxInterface cookieMboxReference) { + this.cookieMboxReference = cookieMboxReference; + } + + @Reference + public void setModuleReference(ServiceInterface timeoutModuleReference) { + this.moduleReference = timeoutModuleReference; + } + + @Reference + public void setCookieModuleReference(ServiceInterface cookieModuleReference) { + this.cookieModuleReference = cookieModuleReference; + } + + @Reference + public void setInvalidCookieModuleReference(ServiceInterface invalidCookieModuleReference) { + this.invalidCookieModuleReference = invalidCookieModuleReference; + } + + @Reference + public void setTimeoutModuleReference(ServiceInterface timeoutModuleReference) { + this.timeoutModuleReference = timeoutModuleReference; + } + + @Reference + public void setClonedModuleReference(ServiceInterface clonedModuleReference) { + this.clonedModuleReference = clonedModuleReference; + } + + public MboxInterface getMboxReference() { + return mboxReference; + } + + public MboxInterface getTimeoutMboxReference() { + return timeoutMboxReference; + } + + public MboxInterface getCookieMboxReference() { + return cookieMboxReference; + } + + public ServiceInterface getModuleReference() { + return moduleReference; + } + + public ServiceInterface getCookieModuleReference() { + return cookieModuleReference; + } + + public ServiceInterface getInvalidCookieModuleReference() { + return invalidCookieModuleReference; + } + + public ServiceInterface getTimeoutModuleReference() { + return timeoutModuleReference; + } + + public ServiceInterface getClonedModuleReference() { + return clonedModuleReference; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java new file mode 100644 index 0000000000..244e6f7f40 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.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.sca.binding.erlang.testing; + +/** + * @version $Rev$ $Date$ + */ +public interface ServiceInterface { + + void doNothing(); + + String sayHello(String arg1, String arg2); + + String[] sayHellos() throws Exception; + + StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2); + + String sayHello() throws Exception; + + String sayHello(String arg) throws Exception; + + String sayHello(int arg1, int arg2); + + void notExistWithException() throws Exception; + + void notExist(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java new file mode 100644 index 0000000000..7cc1fe4dc1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.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.sca.binding.erlang.testing; + +import org.apache.tuscany.sca.binding.erlang.meta.ErlangAtom; + +/** + * @version $Rev$ $Date$ + */ +public interface ServiceTestComponent { + + String sayHello(String arg1, String arg2); + + String[] sayHellos() throws Exception; + + @ErlangAtom + String[] sayAtoms(@ErlangAtom String[] arg); + + StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2); + + void doNothing(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java new file mode 100644 index 0000000000..b3f39fecd4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.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.sca.binding.erlang.testing; + +/** + * @version $Rev$ $Date$ + */ +public class ServiceTestComponentImpl implements ServiceTestComponent { + + public String sayHello(String arg1, String arg2) { + return "Hello " + arg1 + " " + arg2; + } + + public String[] sayHellos() { + String[] result = new String[] { "1", "2" }; + return result; + } + + public StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2) { + return arg1; + } + + public void doNothing() { + // doing nothing + } + + public String[] sayAtoms(String[] arg) { + return arg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java new file mode 100644 index 0000000000..735cefe53d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.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.sca.binding.erlang.testing; + +/** + * @version $Rev$ $Date$ + */ +public class ServiceTestComponentImplClone implements ServiceTestComponent { + + public String sayHello(String arg1, String arg2) { + return "Bye " + arg1 + " " + arg2; + } + + public String[] sayHellos() { + String[] result = new String[] { "-1", "-2" }; + return result; + } + + public StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2) { + return arg1; + } + + public void doNothing() { + + } + + public String[] sayAtoms(String[] arg) { + return arg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java new file mode 100644 index 0000000000..40a9f96769 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.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.sca.binding.erlang.testing; + +/** + * @version $Rev$ $Date$ + */ +public class ServiceTestComponentImplTimeout implements ServiceTestComponent { + + private long duration = 1000; + + public String sayHello(String arg1, String arg2) { + try { + Thread.sleep(duration); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return "Bye " + arg1 + " " + arg2; + } + + public String[] sayHellos() { + try { + Thread.sleep(duration); + } catch (InterruptedException e) { + e.printStackTrace(); + } + String[] result = new String[] { "-1", "-2" }; + return result; + } + + public StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2) { + try { + Thread.sleep(duration); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return arg1; + } + + public void doNothing() { + + } + + public String[] sayAtoms(String[] arg) { + return arg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/SmallTuple.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/SmallTuple.java new file mode 100644 index 0000000000..ac8b9e426a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/SmallTuple.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.sca.binding.erlang.testing; + +/** + * @version $Rev$ $Date$ + */ +public class SmallTuple { + + public int arg1; + public String arg2 = ""; + + public boolean equals(Object o) { + SmallTuple comp = (SmallTuple) o; + return arg1 == comp.arg1 && arg2.equals(arg2); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/StructuredTuple.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/StructuredTuple.java new file mode 100644 index 0000000000..193654172f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/StructuredTuple.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.sca.binding.erlang.testing; + +/** + * @version $Rev$ $Date$ + */ +public class StructuredTuple { + + public SmallTuple arg1 = new SmallTuple(); + public String arg2 = ""; + public boolean arg3; + + public boolean equals(Object o) { + StructuredTuple comp = (StructuredTuple) o; + return arg2.equals(comp.arg2) && arg3 == comp.arg3 + && arg1.equals(comp.arg1); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java new file mode 100644 index 0000000000..33e6d4862b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.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.sca.binding.erlang.testing.dynaignore; + +import org.junit.runner.Description; +import org.junit.runner.Result; +import org.junit.runner.Runner; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunListener; +import org.junit.runner.notification.RunNotifier; +import org.junit.runner.notification.StoppedByUserException; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.InitializationError; + +/** + * @version $Rev$ $Date$ + */ +public class IgnorableRunner extends Runner { + + private static final class Notifier extends RunNotifier { + private final RunNotifier notifier; + + public Notifier(final RunNotifier notifier) { + this.notifier = notifier; + } + + public void addFirstListener(final RunListener listener) { + notifier.addFirstListener(listener); + } + + public void addListener(final RunListener listener) { + notifier.addListener(listener); + } + + @Override + public boolean equals(final Object obj) { + return notifier.equals(obj); + } + + @Override + public void fireTestFailure(final Failure failure) { + if (failure.getException().getClass() == IgnoreTest.class) { + notifier.fireTestIgnored(failure.getDescription()); + } else { + notifier.fireTestFailure(failure); + } + } + + @Override + public void fireTestFinished(final Description description) { + notifier.fireTestFinished(description); + } + + @Override + public void fireTestIgnored(final Description description) { + notifier.fireTestIgnored(description); + } + + @Override + public void fireTestRunFinished(final Result result) { + notifier.fireTestRunFinished(result); + } + + @Override + public void fireTestRunStarted(final Description description) { + notifier.fireTestRunStarted(description); + } + + @Override + public void fireTestStarted(final Description description) + throws StoppedByUserException { + notifier.fireTestStarted(description); + } + + @Override + public int hashCode() { + return notifier.hashCode(); + } + + @Override + public void pleaseStop() { + notifier.pleaseStop(); + } + + @Override + public void removeListener(final RunListener listener) { + notifier.removeListener(listener); + } + + public void testAborted(final Description description, + final Throwable cause) { + ((Notifier) notifier).testAborted(description, cause); + } + + @Override + public String toString() { + return notifier.toString(); + } + + } + + Runner runner = null; + + public IgnorableRunner(Class testClass) { + try { + runner = new BlockJUnit4ClassRunner(testClass); + } catch (InitializationError e) { + e.printStackTrace(); + } + } + + @Override + public Description getDescription() { + return runner.getDescription(); + } + + @Override + public void run(RunNotifier notifier) { + runner.run(new Notifier(notifier)); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java new file mode 100644 index 0000000000..3d736da19d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.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.sca.binding.erlang.testing.dynaignore; + +/** + * @version $Rev$ $Date$ + */ +public final class IgnoreTest extends Error { + + private static final long serialVersionUID = 1L; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/resources/ErlangReference.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/resources/ErlangReference.composite new file mode 100644 index 0000000000..63bce2b3fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/resources/ErlangReference.composite @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/resources/ErlangService.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/resources/ErlangService.composite new file mode 100644 index 0000000000..d48a225481 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang-runtime/src/test/resources/ErlangService.composite @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/pom.xml new file mode 100644 index 0000000000..c5854ce58b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-erlang + Apache Tuscany SCA Erlang Binding Extension + + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.erlang + ${pom.name} + org.apache.tuscany.sca.binding.erlang* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBinding.java new file mode 100644 index 0000000000..a472e88f98 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBinding.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.sca.binding.erlang; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * @version $Rev: $ $Date: $ + */ +public interface ErlangBinding extends Binding { + + final long NO_TIMEOUT = 0; + // NOTE: default thread pool size + final int DEFAULT_THREAD_POOL = 20; + + QName BINDING_ERLANG_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "binding.erlang"); + + String getNode(); + + void setNode(String node); + + String getModule(); + + void setModule(String module); + + boolean isMbox(); + + void setMbox(boolean mbox); + + long getTimeout(); + + void setTimeout(long timeout); + + String getCookie(); + + void setCookie(String cookie); + + boolean hasTimeout(); + + boolean hasCookie(); + + int getServiceThreadPool(); + + void setServiceThreadPool(int threads); + + boolean isDefaultTimeout(); + + boolean isDefaultServiceThreadPool(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBindingFactory.java new file mode 100644 index 0000000000..4c85695dd3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/ErlangBindingFactory.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.sca.binding.erlang; + +/** + * @version $Rev: $ $Date: $ + */ +public interface ErlangBindingFactory { + /** + * Create a ErlangBinding model + * @return The ErlangBinding model + */ + ErlangBinding createErlangBinding(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingFactoryImpl.java new file mode 100644 index 0000000000..1d2e1eefcf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingFactoryImpl.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.sca.binding.erlang.impl; + +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.binding.erlang.ErlangBindingFactory; + +/** + * @version $Rev: $ $Date: $ + */ +public class ErlangBindingFactoryImpl implements ErlangBindingFactory { + + /** + * @see org.apache.tuscany.sca.binding.erlang.ErlangBindingFactory#createErlangBinding() + */ + public ErlangBinding createErlangBinding() { + return new ErlangBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingImpl.java new file mode 100644 index 0000000000..17fd731063 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingImpl.java @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * @version $Rev: $ $Date: $ + */ +public class ErlangBindingImpl implements ErlangBinding, PolicySetAttachPoint { + + private String node; + private String module; + private boolean mbox; + private String cookie; + private int serviceThreadPool = DEFAULT_THREAD_POOL; + + private boolean defaultTimeout = true; + private boolean defaultThreads = true; + + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + private long timeout = NO_TIMEOUT; + + public String getNode() { + return node; + } + + public void setNode(String nodeName) { + this.node = nodeName; + } + + public String getName() { + return null; + } + + public String getURI() { + return null; + } + + public void setName(String arg0) { + } + + public void setURI(String arg0) { + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean arg0) { + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public String getModule() { + return module; + } + + public boolean isMbox() { + return mbox; + } + + public void setMbox(boolean mbox) { + this.mbox = mbox; + } + + public void setModule(String module) { + this.module = module; + } + + public long getTimeout() { + return timeout; + } + + public void setTimeout(long timeout) { + // NOTE: not setting timeout or setting it to 0 will cause no timeout + this.timeout = timeout; + if (timeout != 0) { + defaultTimeout = false; + } + } + + public String getCookie() { + return cookie; + } + + public void setCookie(String cookie) { + this.cookie = cookie; + } + + public boolean hasTimeout() { + return timeout != ErlangBinding.NO_TIMEOUT; + } + + public boolean hasCookie() { + return cookie != null && cookie.length() > 0; + } + + public int getServiceThreadPool() { + return serviceThreadPool; + } + + public void setServiceThreadPool(int threads) { + this.serviceThreadPool = threads; + this.defaultThreads = false; + } + + public boolean isDefaultServiceThreadPool() { + return defaultThreads; + } + + public boolean isDefaultTimeout() { + return defaultTimeout; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProcessor.java new file mode 100644 index 0000000000..07b7533314 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangBindingProcessor.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.impl; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * @version $Rev: $ $Date: $ + */ +public class ErlangBindingProcessor implements + StAXArtifactProcessor { + + private PolicyFactory policyFactory; + private PolicyAttachPointProcessor policyProcessor; + + private static final String ATTR_COOKIE = "cookie"; + private static final String ATTR_MBOX = "mbox"; + private static final String ATTR_MODULE = "module"; + private static final String ATTR_NODE = "node"; + private static final String ATTR_SERVICE_THREAD_POOL = "serviceThreadPool"; + private static final String ATTR_TIMEOUT = "timeout"; + + public ErlangBindingProcessor(ModelFactoryExtensionPoint modelFactories) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#getArtifactType() + */ + public QName getArtifactType() { + return ErlangBinding.BINDING_ERLANG_QNAME; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#read(javax.xml.stream.XMLStreamReader) + */ + public ErlangBinding read(XMLStreamReader reader) + throws ContributionReadException, XMLStreamException { + ErlangBinding binding = new ErlangBindingImpl(); + + // Read the policies + policyProcessor.readPolicies(binding, reader); + + binding.setNode(reader.getAttributeValue(null, ATTR_NODE)); + + String mboxValue = reader.getAttributeValue(null, ATTR_MBOX); + + if (mboxValue != null && mboxValue.length() > 0) { + try { + binding.setMbox(Boolean.parseBoolean(mboxValue)); + } catch (Exception e) { + } + } + + try { + binding.setTimeout(Long.parseLong(reader.getAttributeValue(null, + ATTR_TIMEOUT))); + } catch (NumberFormatException e) { + } + + binding.setModule(reader.getAttributeValue(null, ATTR_MODULE)); + + binding.setCookie(reader.getAttributeValue(null, ATTR_COOKIE)); + + try { + binding.setServiceThreadPool(Integer.parseInt(reader + .getAttributeValue(null, ATTR_SERVICE_THREAD_POOL))); + } catch (NumberFormatException e) { + } + + return binding; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#write(java.lang.Object, + * javax.xml.stream.XMLStreamWriter) + */ + public void write(ErlangBinding model, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + + + writer.writeStartElement(Constants.SCA10_TUSCANY_NS, "binding.erlang"); + + if (model.getCookie() != null && model.getCookie().length() > 0) { + writer.writeAttribute(ATTR_COOKIE, model.getCookie()); + } + + if (model.isMbox()) { + writer.writeAttribute(ATTR_MBOX, Boolean.TRUE.toString()); + } + + if (model.getModule() != null && model.getModule().length() > 0) { + writer.writeAttribute(ATTR_MODULE, model.getModule()); + } + + if (model.getNode() != null && model.getNode().length() > 0) { + writer.writeAttribute(ATTR_NODE, model.getNode()); + } + + if (!model.isDefaultServiceThreadPool()) { + writer.writeAttribute(ATTR_SERVICE_THREAD_POOL, Integer + .toString(model.getServiceThreadPool())); + } + + if (!model.isDefaultTimeout()) { + writer.writeAttribute(ATTR_TIMEOUT, Long.toString(model + .getTimeout())); + } + + writer.writeEndElement(); + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#getModelType() + */ + public Class getModelType() { + return ErlangBinding.class; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#resolve(java.lang.Object, + * org.apache.tuscany.sca.contribution.resolver.ModelResolver) + */ + public void resolve(ErlangBinding model, ModelResolver resolver) + throws ContributionResolveException { + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.erlang.ErlangBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.erlang.ErlangBindingFactory new file mode 100644 index 0000000000..c7872d89c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.erlang.ErlangBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the model factory +org.apache.tuscany.sca.binding.erlang.impl.ErlangBindingFactoryImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..6e614aac3e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.erlang.impl.ErlangBindingProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.erlang,model=org.apache.tuscany.sca.binding.erlang.ErlangBinding,factory=org.apache.tuscany.sca.binding.erlang.ErlangBindingFactory diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ErlangBindingProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ErlangBindingProcessorTestCase.java new file mode 100644 index 0000000000..673c735f1e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-erlang/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ErlangBindingProcessorTestCase.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.testing; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.binding.erlang.ErlangBinding; +import org.apache.tuscany.sca.binding.erlang.impl.ErlangBindingImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * General tests for binding.erlang XML processor + */ +public class ErlangBindingProcessorTestCase { + + private static final String COMPOSITE = "" + + "" + + " " + + " " + + " " + + " " + + " " + " " + ""; + + private static final String COMPOSITE_DEFAULT_TIMEOUT = "" + + "" + + " " + + " " + + " " + + " " + + " " + " " + ""; + + private static XMLInputFactory inputFactory; + private static StAXArtifactProcessor staxProcessor; + private static Monitor monitor; + + @BeforeClass + public static void init() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints + .getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint( + extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, + inputFactory, null, monitor); + } + + /** + * Tests reading "binding.erlang" element + * + * @throws Exception + */ + @Test + public void testLoadValidComposite() throws Exception { + XMLStreamReader reader = inputFactory + .createXMLStreamReader(new StringReader(COMPOSITE)); + Composite composite = (Composite) staxProcessor.read(reader); + ErlangBinding binding = (ErlangBinding) composite.getComponents() + .get(0).getServices().get(0).getBindings().get(0); + assertEquals("SomeNode", binding.getNode()); + assertEquals(1000, binding.getTimeout()); + assertEquals("cookie", binding.getCookie()); + assertEquals(true, binding.hasTimeout()); + assertEquals(true, binding.hasCookie()); + assertEquals(1, binding.getServiceThreadPool()); + assertEquals(false, binding.isDefaultServiceThreadPool()); + assertEquals(false, binding.isDefaultTimeout()); + } + + /** + * Tests using default "resultTimeout", default thread pool, no cookie + * + * @throws Exception + */ + @Test + public void testLoadDefaultTimeout() throws Exception { + XMLStreamReader reader = inputFactory + .createXMLStreamReader(new StringReader( + COMPOSITE_DEFAULT_TIMEOUT)); + Composite composite = (Composite) staxProcessor.read(reader); + ErlangBinding binding = (ErlangBinding) composite.getComponents() + .get(0).getServices().get(0).getBindings().get(0); + assertEquals(ErlangBindingImpl.NO_TIMEOUT, binding.getTimeout()); + assertEquals(null, binding.getCookie()); + assertEquals(false, binding.hasTimeout()); + assertEquals(false, binding.hasCookie()); + assertEquals(ErlangBinding.DEFAULT_THREAD_POOL, binding + .getServiceThreadPool()); + assertEquals(true, binding.isDefaultServiceThreadPool()); + assertEquals(true, binding.isDefaultTimeout()); + } + + @Test + @Ignore("unbound namespace problem") + //FIXME: fix it + public void testWrite() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE)); + Composite composite = (Composite)staxProcessor.read(reader); + ErlangBinding binding1 = (ErlangBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + ErlangBinding binding2 = (ErlangBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + + //compare binding1 to binding2 + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/pom.xml new file mode 100644 index 0000000000..aa7628713a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/pom.xml @@ -0,0 +1,165 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-feed + Apache Tuscany SCA Atom+RSS Feed Binding Extension + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + + commons-httpclient + commons-httpclient + 3.1 + + + + rome + rome + 0.9 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + commons-codec + commons-codec + 1.3 + + + commons-codec + commons-codec + + + + + + commons-logging + commons-logging + 1.1.1 + + + javax.servlet + servlet-api + + + avalon-framework + avalon-framework + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.feed + ${pom.name} + org.apache.tuscany.sca.binding.feed* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.java new file mode 100644 index 0000000000..00aa813af2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.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.sca.binding.feed; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * Atom binding model. + * + * @version $Rev$ $Date$ + */ +public interface AtomBinding extends Binding { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBindingFactory.java new file mode 100644 index 0000000000..050ba9b73c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBindingFactory.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.sca.binding.feed; + +/** + * Factory for the Atom binding + * + * @version $Rev$ $Date$ + */ +public interface AtomBindingFactory { + + /** + * Creates a new Atom binding. + * @return the new Atom binding + */ + AtomBinding createAtomBinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.java new file mode 100644 index 0000000000..81b9fd95ad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.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.sca.binding.feed; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * RSS Feed binding model. + * + * @version $Rev$ $Date$ + */ +public interface RSSBinding extends Binding { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBindingFactory.java new file mode 100644 index 0000000000..c95c8ac012 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBindingFactory.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.sca.binding.feed; + +/** + * Factory for the RSS binding + * + * @version $Rev$ $Date$ + */ +public interface RSSBindingFactory { + + /** + * Creates a new RSS binding. + * @return the new RSS binding + */ + RSSBinding createRSSBinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.java new file mode 100644 index 0000000000..30068afa0a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.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.sca.binding.feed.collection; + +import org.osoa.sca.annotations.Remotable; + +import com.sun.syndication.feed.atom.Entry; + +/** + * Provides access to a collection of resources using Atom. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Collection { + + /** + * Get an RSS or Atom feed for a collection of resources. + * + * @return the RSS or Atom feed + */ + com.sun.syndication.feed.atom.Feed getFeed(); + + /** + * Creates a new entry. + * + * @param entry + * @return + */ + Entry post(Entry entry); + + /** + * Retrieves an entry. + * + * @param id + * @return + */ + Entry get(String id) throws NotFoundException; + + /** + * Update an entry. + * + * @param id + * @param entry + * @return + */ + void put(String id, Entry entry) throws NotFoundException; + + /** + * Delete an entry. + * + * @param id + */ + void delete(String id) throws NotFoundException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.java new file mode 100644 index 0000000000..39a4213a65 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.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.sca.binding.feed.collection; + +import java.io.InputStream; + +import org.osoa.sca.annotations.Remotable; + +import com.sun.syndication.feed.atom.Entry; + +/** + * Provides access to a collection of resources using Atom. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface MediaCollection extends Collection { + + /** + * Creates a new media entry + * + * @param title + * @param slug + * @param contentType + * @param media + */ + Entry postMedia(String title, String slug, String contentType, InputStream media); + + /** + * Update a media entry. + * + * @param id + * @param contentType + * @param media + * @return + */ + void putMedia(String id, String contentType, InputStream media) throws NotFoundException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/NotFoundException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/NotFoundException.java new file mode 100644 index 0000000000..503f30e685 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/NotFoundException.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.sca.binding.feed.collection; + +/** + * Indicates that a resource could not be found. + * + * @version $Rev$ $Date$ + */ +public class NotFoundException extends Exception { + private static final long serialVersionUID = -5046027674128627383L; + + public NotFoundException() { + } + + public NotFoundException(String message) { + super(message); + } + + public NotFoundException(Throwable cause) { + super(cause); + } + + public NotFoundException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingFactoryImpl.java new file mode 100644 index 0000000000..a9a1167544 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingFactoryImpl.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.sca.binding.feed.impl; + +import org.apache.tuscany.sca.binding.feed.AtomBinding; +import org.apache.tuscany.sca.binding.feed.AtomBindingFactory; + +/** + * Factory for the Atom binding model. + * + * @version $Rev$ $Date$ + */ +public class AtomBindingFactoryImpl implements AtomBindingFactory { + + public AtomBinding createAtomBinding() { + return new AtomBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java new file mode 100644 index 0000000000..76551bc412 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.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.sca.binding.feed.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.feed.AtomBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Implementation of the Atom Feed binding model. + * + * @version $Rev$ $Date$ + */ +class AtomBindingImpl implements AtomBinding, PolicySetAttachPoint { + + private String name; + private String uri; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + + public boolean isUnresolved() { + // The binding is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingFactoryImpl.java new file mode 100644 index 0000000000..4d8fb943f0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingFactoryImpl.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.sca.binding.feed.impl; + +import org.apache.tuscany.sca.binding.feed.RSSBinding; +import org.apache.tuscany.sca.binding.feed.RSSBindingFactory; + +/** + * Factory for the RSS binding model. + * + * @version $Rev$ $Date$ + */ +public class RSSBindingFactoryImpl implements RSSBindingFactory { + + public RSSBinding createRSSBinding() { + return new RSSBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.java new file mode 100644 index 0000000000..9df2ec60da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.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.sca.binding.feed.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.feed.RSSBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Implementation of the RSS Feed binding model. + * + * @version $Rev$ $Date$ + */ +class RSSBindingImpl implements RSSBinding, PolicySetAttachPoint { + + private String name; + private String uri; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java new file mode 100644 index 0000000000..45b35d9206 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java @@ -0,0 +1,345 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.feed.provider; + +import java.io.InputStreamReader; +import java.io.StringWriter; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.DeleteMethod; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.tuscany.sca.binding.feed.collection.NotFoundException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.osoa.sca.ServiceRuntimeException; + +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.XmlReader; + +/** + * Invoker for the Atom binding. + * + * @version $Rev$ $Date$ + */ +class AtomBindingInvoker implements Invoker, DataExchangeSemantics { + + Operation operation; + String uri; + HttpClient httpClient; + String authorizationHeader; + + //FIXME Support conversion to/from data api entries + + AtomBindingInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + this.operation = operation; + this.uri = uri; + this.httpClient = httpClient; + this.authorizationHeader = authorizationHeader; + } + + public Message invoke(Message msg) { + // Shouldn't get here, as the only supported methods are + // defined in the ResourceCollection interface, and implemented + // by specific invoker subclasses + throw new UnsupportedOperationException(operation.getName()); + } + + public boolean allowsPassByReference() { + return true; + } + + /** + * Get operation invoker + */ + public static class GetInvoker extends AtomBindingInvoker { + + public GetInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + // Get an entry + String id = (String)((Object[])msg.getBody())[0]; + + // Send an HTTP GET + GetMethod getMethod = new GetMethod(uri + "/" + id); + getMethod.setRequestHeader("Authorization", authorizationHeader); + try { + httpClient.executeMethod(getMethod); + int status = getMethod.getStatusCode(); + + // Read the Atom entry + if (status == 200) { + Entry feedEntry = + AtomFeedEntryUtil.readFeedEntry("atom_1.0", new InputStreamReader(getMethod.getResponseBodyAsStream())); + msg.setBody(feedEntry); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + getMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * Post operation invoker + */ + public static class PostInvoker extends AtomBindingInvoker { + + public PostInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + // Post an entry + Entry feedEntry = (Entry)((Object[])msg.getBody())[0]; + + // Send an HTTP POST + PostMethod postMethod = new PostMethod(uri); + postMethod.setRequestHeader("Authorization", authorizationHeader); + try { + + // Write the Atom entry + StringWriter writer = new StringWriter(); + AtomFeedEntryUtil.writeFeedEntry(feedEntry, "atom_1.0", writer); + postMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8"); + postMethod.setRequestEntity(new StringRequestEntity(writer.toString())); + + httpClient.executeMethod(postMethod); + int status = postMethod.getStatusCode(); + + // Read the Atom entry + if (status == 200 || status == 201) { + Entry createdEntry = + AtomFeedEntryUtil + .readFeedEntry("atom_1.0", new InputStreamReader(postMethod.getResponseBodyAsStream())); + msg.setBody(createdEntry); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + postMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * Put operation invoker + */ + public static class PutInvoker extends AtomBindingInvoker { + + public PutInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + // Put an entry + Object[] args = (Object[])msg.getBody(); + String id = (String)args[0]; + Entry feedEntry = (Entry)args[1]; + + // Send an HTTP PUT + PutMethod putMethod = new PutMethod(uri + "/" + id); + putMethod.setRequestHeader("Authorization", authorizationHeader); + try { + + // Write the Atom entry + StringWriter writer = new StringWriter(); + AtomFeedEntryUtil.writeFeedEntry(feedEntry, "atom_1.0", writer); + putMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8"); + putMethod.setRequestEntity(new StringRequestEntity(writer.toString())); + + httpClient.executeMethod(putMethod); + int status = putMethod.getStatusCode(); + + // Read the Atom entry + if (status == 200 || status == 201) { + try { + Entry updatedEntry = + AtomFeedEntryUtil.readFeedEntry("atom_1.0", new InputStreamReader(putMethod + .getResponseBodyAsStream())); + msg.setBody(updatedEntry); + } catch (Exception e) { + // Returning the updated entry is optional + } + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + putMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * Delete operation invoker + */ + public static class DeleteInvoker extends AtomBindingInvoker { + + public DeleteInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + // Delete an entry + String id = (String)((Object[])msg.getBody())[0]; + + // Send an HTTP DELETE + DeleteMethod deleteMethod = new DeleteMethod(uri + "/" + id); + deleteMethod.setRequestHeader("Authorization", authorizationHeader); + try { + httpClient.executeMethod(deleteMethod); + int status = deleteMethod.getStatusCode(); + + // Read the Atom entry + if (status == 200) { + msg.setBody(null); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + deleteMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * GetAll operation invoker + */ + public static class GetAllInvoker extends AtomBindingInvoker { + + public GetAllInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + // Get a feed + + // Send an HTTP GET + GetMethod getMethod = new GetMethod(uri); + getMethod.setRequestHeader("Authorization", authorizationHeader); + try { + httpClient.executeMethod(getMethod); + int status = getMethod.getStatusCode(); + + // Read the Atom feed + if (status == 200) { + WireFeedInput input = new WireFeedInput(); + Feed feed = (Feed)input.build(new XmlReader(getMethod.getResponseBodyAsStream())); + msg.setBody(feed); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + getMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * PostMedia operation invoker + */ + public static class PostMediaInvoker extends AtomBindingInvoker { + + public PostMediaInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + // TODO implement + return super.invoke(msg); + } + } + + /** + * PutMedia operation invoker + */ + public static class PutMediaInvoker extends AtomBindingInvoker { + + public PutMediaInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + // TODO implement + return super.invoke(msg); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java new file mode 100644 index 0000000000..6e134fd0c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.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.sca.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.AtomBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the Atom binding model. + * + * @version $Rev$ $Date$ + */ +public class AtomBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private Mediator mediator; + private ServletHost servletHost; + + public AtomBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + AtomBinding binding) { + return new AtomReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + AtomBinding binding) { + return new AtomServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator); + } + + public Class getModelType() { + return AtomBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomFeedEntryUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomFeedEntryUtil.java new file mode 100644 index 0000000000..7adbfca6e8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomFeedEntryUtil.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.sca.binding.feed.provider; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.WireFeedOutput; + +/** + * Utility methods to read/write Atom entries. + * + * @version $Rev$ $Date$ + */ +class AtomFeedEntryUtil { + + /** + * Read an Atom entry + * + * @param request + * @return + * @throws IOException + * @throws JDOMException + * @throws FeedException + * @throws IllegalArgumentException + */ + static Entry readFeedEntry(String feedType, Reader reader) throws JDOMException, IOException, IllegalArgumentException, + FeedException { + SAXBuilder builder = new SAXBuilder(); + Document document = builder.build(reader); + Element root = document.getRootElement(); + root.detach(); + Feed feed = new Feed(); + feed.setFeedType(feedType); + WireFeedOutput wireFeedOutput = new WireFeedOutput(); + document = wireFeedOutput.outputJDom(feed); + document.getRootElement().addContent(root); + WireFeedInput input = new WireFeedInput(); + feed = (Feed)input.build(document); + Entry feedEntry = (Entry)feed.getEntries().get(0); + if (feedEntry.getContents().size() != 0) { + Content content = (Content)feedEntry.getContents().get(0); + if ("text/xml".equals(content.getType())) { + Element element = root.getChild("content", root.getNamespace()); + if (!element.getChildren().isEmpty()) { + element = (Element)element.getChildren().get(0); + XMLOutputter outputter = new XMLOutputter(); + StringWriter sw = new StringWriter(); + outputter.output(element, sw); + content.setValue(sw.toString()); + } + } + } + return feedEntry; + } + + /** + * Write an Atom entry. + * + * @param entry + * @param response + * @throws FeedException + * @throws IllegalArgumentException + * @throws IOException + * @throws ServletException + */ + static void writeFeedEntry(Entry feedEntry, String feedType, Writer writer) throws IllegalArgumentException, FeedException, + IOException { + Feed feed = new Feed(); + feed.setFeedType(feedType); + List feedEntries = new ArrayList(); + feedEntries.add(feedEntry); + feed.setEntries(feedEntries); + + WireFeedOutput wireFeedOutput = new WireFeedOutput(); + Document document = wireFeedOutput.outputJDom(feed); + Element root = document.getRootElement(); + Element element = (Element)root.getChildren().get(0); + XMLOutputter outputter = new XMLOutputter(); + outputter.setFormat(Format.getPrettyFormat()); + outputter.output(element, writer); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java new file mode 100644 index 0000000000..d9bda1fb9a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.provider; + +import java.net.URI; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; +import org.apache.tuscany.sca.binding.feed.AtomBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the Atom binding provider. + * + * @version $Rev$ $Date$ + */ +class AtomReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private AtomBinding binding; + private String authorizationHeader; + private HttpClient httpClient; + + /** + * Constructs a new AtomReferenceBindingProvider + * @param component + * @param reference + * @param binding + */ + AtomReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + AtomBinding binding) { + this.reference = reference; + this.binding = binding; + + // Prepare authorization header + String authorization = "admin" + ":" + "admin"; + authorizationHeader = "Basic " + new String(Base64.encodeBase64(authorization.getBytes())); + + // Create an HTTP client + httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); + httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(60000); + } + + public Invoker createInvoker(Operation operation) { + String operationName = operation.getName(); + if (operationName.equals("get")) { + return new AtomBindingInvoker.GetInvoker(operation, binding.getURI(), httpClient, authorizationHeader); + } else if (operationName.equals("post")) { + return new AtomBindingInvoker.PostInvoker(operation, binding.getURI(), httpClient, authorizationHeader); + } else if (operationName.equals("put")) { + return new AtomBindingInvoker.PutInvoker(operation, binding.getURI(), httpClient, authorizationHeader); + } else if (operationName.equals("delete")) { + return new AtomBindingInvoker.DeleteInvoker(operation, binding.getURI(), httpClient, + authorizationHeader); + } else if (operationName.equals("getFeed") || operationName.equals("getAll")) { + return new AtomBindingInvoker.GetAllInvoker(operation, binding.getURI(), httpClient, + authorizationHeader); + } else if (operationName.equals("postMedia")) { + return new AtomBindingInvoker.PostMediaInvoker(operation, binding.getURI(), httpClient, + authorizationHeader); + } else if (operationName.equals("putMedia")) { + return new AtomBindingInvoker.PutMediaInvoker(operation, binding.getURI(), httpClient, + authorizationHeader); + } + + return new AtomBindingInvoker(operation, binding.getURI(), httpClient, authorizationHeader); + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + + // Configure the HTTP client credentials + Credentials credentials = new UsernamePasswordCredentials("admin", "admin"); + httpClient.getParams().setAuthenticationPreemptive(true); + URI uri = URI.create(binding.getURI()); + httpClient.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), credentials); + } + + public void stop() { + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.java new file mode 100644 index 0000000000..23c36f51e3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.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.sca.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.AtomBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the Atom binding provider. + * + * @version $Rev$ $Date$ + */ +class AtomServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private AtomBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private String servletMapping; + private Mediator mediator; + + AtomServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + AtomBinding binding, + ServletHost servletHost, + MessageFactory messageFactory, + Mediator mediator) { + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.mediator = mediator; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + RuntimeComponentService componentService = (RuntimeComponentService)service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + + FeedBindingListenerServlet servlet = + new FeedBindingListenerServlet(wire, messageFactory, mediator, "atom_1.0"); + + servletMapping = binding.getURI(); + if (!servletMapping.endsWith("/")) { + servletMapping += "/"; + } + if (!servletMapping.endsWith("*")) { + servletMapping += "*"; + } + servletHost.addServletMapping(servletMapping, servlet); + } + + public void stop() { + servletHost.removeServletMapping(servletMapping); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java new file mode 100644 index 0000000000..89366456f5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java @@ -0,0 +1,788 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.feed.provider; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.StringTokenizer; +import java.util.logging.Logger; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.commons.codec.binary.Base64; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.Namespace; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.feed.atom.Link; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedOutput; +import com.sun.syndication.io.WireFeedOutput; + +/** + * A resource collection binding listener, implemented as a Servlet and + * registered in a Servlet host provided by the SCA hosting runtime. + * + * @version $Rev$ $Date$ + */ +class FeedBindingListenerServlet extends HttpServlet { + private static final Logger logger = Logger.getLogger(FeedBindingListenerServlet.class.getName()); + private static final long serialVersionUID = 1L; + + private static final Namespace APP_NS = Namespace.getNamespace("app", "http://purl.org/atom/app#"); + private static final Namespace ATOM_NS = Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"); + + private RuntimeWire wire; + private Invoker getFeedInvoker; + private Invoker getAllInvoker; + private Invoker queryInvoker; + private Invoker getInvoker; + private Invoker postInvoker; + private Invoker postMediaInvoker; + private Invoker putInvoker; + private Invoker putMediaInvoker; + private Invoker deleteInvoker; + private MessageFactory messageFactory; + private String feedType; + private Mediator mediator; + private DataType itemClassType; + private DataType itemXMLType; + private boolean supportsFeedEntries; + + /** + * Constructs a new binding listener. + * + * @param wire + * @param messageFactory + * @param feedType + */ + FeedBindingListenerServlet(RuntimeWire wire, MessageFactory messageFactory, Mediator mediator, String feedType) { + this.wire = wire; + this.messageFactory = messageFactory; + this.mediator = mediator; + this.feedType = feedType; + + // Get the invokers for the supported operations + Operation getOperation = null; + for (InvocationChain invocationChain : this.wire.getInvocationChains()) { + invocationChain.setAllowsPassByReference(true); + Operation operation = invocationChain.getTargetOperation(); + String operationName = operation.getName(); + if (operationName.equals("getFeed")) { + getFeedInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("getAll")) { + getAllInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("query")) { + queryInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("get")) { + getInvoker = invocationChain.getHeadInvoker(); + getOperation = operation; + } else if (operationName.equals("put")) { + putInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("putMedia")) { + putMediaInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("post")) { + postInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("postMedia")) { + postMediaInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("delete")) { + deleteInvoker = invocationChain.getHeadInvoker(); + } + } + + // Determine the collection item type + itemXMLType = new DataTypeImpl>(String.class.getName(), String.class, String.class); + Class itemClass = getOperation.getOutputType().getPhysical(); + if (itemClass == Entry.class) { + supportsFeedEntries = true; + } + DataType outputType = getOperation.getOutputType(); + QName qname = outputType.getLogical().getElementName(); + qname = new QName(qname.getNamespaceURI(), itemClass.getSimpleName()); + itemClassType = new DataTypeImpl("java:complexType", itemClass, new XMLType(qname, null)); + + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // No authentication required for a get request + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + // The feedType parameter is used to override what type of feed is going + // to be produced + String requestFeedType = request.getParameter("feedType"); + if (requestFeedType == null) + requestFeedType = feedType; + + logger.info(">>> FeedEndPointServlet (" + requestFeedType + ") " + request.getRequestURI()); + + // Handle an Atom request + if (requestFeedType.startsWith("atom_")) { + + if (path != null && path.equals("/atomsvc")) { + + // Return the Atom service document + response.setContentType("application/atomsvc+xml; charset=utf-8"); + Document document = new Document(); + Element service = new Element("service", APP_NS); + document.setRootElement(service); + + Element workspace = new Element("workspace", APP_NS); + Element title = new Element("title", ATOM_NS); + title.setText("resource"); + workspace.addContent(title); + service.addContent(workspace); + + Element collection = new Element("collection", APP_NS); + String href = request.getRequestURL().toString(); + href = href.substring(0, href.length() - "/atomsvc".length()); + collection.setAttribute("href", href); + Element collectionTitle = new Element("title", ATOM_NS); + collectionTitle.setText("entries"); + collection.addContent(collectionTitle); + workspace.addContent(collection); + + XMLOutputter outputter = new XMLOutputter(); + Format format = Format.getPrettyFormat(); + format.setEncoding("UTF-8"); + outputter.setFormat(format); + outputter.output(document, getWriter(response)); + + } else if (path == null || path.length() == 0 || path.equals("/")) { + + // Return a feed containing the entries in the collection + Feed feed = null; + if (supportsFeedEntries) { + + // The service implementation supports feed entries, invoke its getFeed operation + Message requestMessage = messageFactory.createMessage(); + Message responseMessage = getFeedInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + feed = (Feed)responseMessage.getBody(); + + } else { + + // The service implementation does not support feed entries, + // invoke its getAll operation to get the data item collection, then create + // feed entries from the items + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + requestMessage.setBody(new Object[] {request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + responseMessage = getAllInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + org.apache.tuscany.sca.data.collection.Entry[] collection = + (org.apache.tuscany.sca.data.collection.Entry[])responseMessage.getBody(); + if (collection != null) { + // Create the feed + feed = new Feed(); + feed.setTitle("Feed"); + for (org.apache.tuscany.sca.data.collection.Entry entry: collection) { + Entry feedEntry = createFeedEntry(entry); + feed.getEntries().add(feedEntry); + } + } + } + if (feed != null) { + + // Write the Atom feed + response.setContentType("application/atom+xml; charset=utf-8"); + feed.setFeedType(requestFeedType); + WireFeedOutput feedOutput = new WireFeedOutput(); + try { + feedOutput.output(feed, getWriter(response)); + } catch (FeedException e) { + throw new ServletException(e); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else if (path.startsWith("/")) { + + // Return a specific entry in the collection + Entry feedEntry; + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + String id = path.substring(1); + requestMessage.setBody(new Object[] {id}); + Message responseMessage = getInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + if (supportsFeedEntries) { + + // The service implementation returns a feed entry + feedEntry = responseMessage.getBody(); + + } else { + + // The service implementation only returns a data item, create an entry + // from it + feedEntry = createFeedEntry(new org.apache.tuscany.sca.data.collection.Entry(id, responseMessage.getBody())); + } + + // Write the Atom entry + if (feedEntry != null) { + response.setContentType("application/atom+xml; charset=utf-8"); + try { + AtomFeedEntryUtil.writeFeedEntry(feedEntry, feedType, getWriter(response)); + } catch (FeedException e) { + throw new ServletException(e); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else { + + // Path doesn't match any known pattern + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } else { + + // Handle an RSS request + if (path == null || path.length() == 0 || path.equals("/")) { + + // Return an RSS feed containing the entries in the collection + Feed feed = null; + if (supportsFeedEntries) { + + // The service implementation supports feed entries, invoke its getFeed operation + Message requestMessage = messageFactory.createMessage(); + Message responseMessage = getFeedInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + feed = (Feed)responseMessage.getBody(); + + } else { + + // The service implementation does not support feed entries, invoke its + // getAll operation to get the data item collection. then create feed entries + // from the data items + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + requestMessage.setBody(new Object[] {request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + responseMessage = getAllInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + org.apache.tuscany.sca.data.collection.Entry[] collection = + (org.apache.tuscany.sca.data.collection.Entry[])responseMessage.getBody(); + if (collection != null) { + // Create the feed + feed = new Feed(); + feed.setTitle("Feed"); + for (org.apache.tuscany.sca.data.collection.Entry entry: collection) { + Entry feedEntry = createFeedEntry(entry); + feed.getEntries().add(feedEntry); + } + } + } + + // Convert to an RSS feed + if (feed != null) { + response.setContentType("application/rss+xml; charset=utf-8"); + feed.setFeedType("atom_1.0"); + SyndFeed syndFeed = new SyndFeedImpl(feed); + syndFeed.setFeedType(requestFeedType); + syndFeed.setLink(path); + SyndFeedOutput syndOutput = new SyndFeedOutput(); + try { + syndOutput.output(syndFeed, getWriter(response)); + } catch (FeedException e) { + throw new ServletException(e); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + } + + /** + * Create an Atom entry from a data collection entry. + * @param entry + * @return + */ + private Entry createFeedEntry(org.apache.tuscany.sca.data.collection.Entry entry) { + Object key = entry.getKey(); + Object data = entry.getData(); + if (data instanceof Item) { + Item item = (Item)data; + + Entry feedEntry = new Entry(); + feedEntry.setId(key.toString()); + feedEntry.setTitle(item.getTitle()); + + String value = item.getContents(); + if (value != null) { + Content content = new Content(); + content.setType("text/xml"); + content.setValue(value); + List contents = new ArrayList(); + contents.add(content); + feedEntry.setContents(contents); + } + + String href = item.getLink(); + if (href == null) { + href = key.toString(); + } + Link link = new Link(); + link.setRel("edit"); + link.setHref(href); + feedEntry.getOtherLinks().add(link); + link = new Link(); + link.setRel("alternate"); + link.setHref(href); + feedEntry.getAlternateLinks().add(link); + + Date date = item.getDate(); + if (date == null) { + date = new Date(); + } + feedEntry.setCreated(date); + return feedEntry; + + } else if (data != null) { + Entry feedEntry = new Entry(); + feedEntry.setId(key.toString()); + feedEntry.setTitle("item"); + + // Convert the item to XML + String value = mediator.mediate(data, itemClassType, itemXMLType, null).toString(); + + Content content = new Content(); + content.setType("text/xml"); + content.setValue(value); + List contents = new ArrayList(); + contents.add(content); + feedEntry.setContents(contents); + + Link link = new Link(); + link.setRel("edit"); + link.setHref(key.toString()); + feedEntry.getOtherLinks().add(link); + link = new Link(); + link.setRel("alternate"); + link.setHref(key.toString()); + feedEntry.getAlternateLinks().add(link); + + feedEntry.setCreated(new Date()); + return feedEntry; + } else { + return null; + } + } + + /** + * Create a data collection entry from an Atom entry. + * @param feedEntry + * @return + */ + private org.apache.tuscany.sca.data.collection.Entry createEntry(Entry feedEntry) { + if (feedEntry != null) { + if (itemClassType.getPhysical() == Item.class) { + String key = feedEntry.getId(); + + Item item = new Item(); + item.setTitle(feedEntry.getTitle()); + + List contents = feedEntry.getContents(); + if (!contents.isEmpty()) { + Content content = (Content)contents.get(0); + String value = content.getValue(); + item.setContents(value); + } + + for (Object l : feedEntry.getOtherLinks()) { + Link link = (Link)l; + if (link.getRel() == null || "edit".equals(link.getRel())) { + String href = link.getHref(); + if (href.startsWith("null/")) { + href = href.substring(5); + } + item.setLink(href); + break; + } + } + + item.setDate(feedEntry.getCreated()); + + return new org.apache.tuscany.sca.data.collection.Entry(key, item); + + } else { + String key = feedEntry.getId(); + + // Create the item from XML + List contents = feedEntry.getContents(); + if (contents.isEmpty()) { + return null; + } + Content content = (Content)contents.get(0); + String value = content.getValue(); + Object data = mediator.mediate(value, itemXMLType, itemClassType, null); + + return new org.apache.tuscany.sca.data.collection.Entry(key, data); + } + } else { + return null; + } + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + if (path == null || path.length() == 0 || path.equals("/")) { + Entry createdFeedEntry = null; + + // Create a new Atom entry + String contentType = request.getContentType(); + if (contentType != null && contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + Entry feedEntry; + try { + feedEntry = AtomFeedEntryUtil.readFeedEntry(feedType, request.getReader()); + } catch (JDOMException e) { + throw new ServletException(e); + } catch (FeedException e) { + throw new ServletException(e); + } + + // Let the component implementation create it + if (supportsFeedEntries) { + + // The service implementation supports feed entries, pass the entry to it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {feedEntry}); + Message responseMessage = postInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + createdFeedEntry = responseMessage.getBody(); + } else { + + // The service implementation does not support feed entries, pass the data item to it + Message requestMessage = messageFactory.createMessage(); + org.apache.tuscany.sca.data.collection.Entry entry = createEntry(feedEntry); + requestMessage.setBody(new Object[] {entry.getKey(), entry.getData()}); + Message responseMessage = postInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + entry.setKey(responseMessage.getBody()); + createdFeedEntry = createFeedEntry(entry); + } + + } else if (contentType != null) { + + // Create a new media entry + + // Get incoming headers + String title = request.getHeader("Title"); + String slug = request.getHeader("Slug"); + + // Let the component implementation create the media entry + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {title, slug, contentType, request.getInputStream()}); + Message responseMessage = postMediaInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + createdFeedEntry = responseMessage.getBody(); + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + + // A new entry was created successfully + if (createdFeedEntry != null) { + + // Set location of the created entry in the Location header + for (Object l : createdFeedEntry.getOtherLinks()) { + Link link = (Link)l; + if (link.getRel() == null || "edit".equals(link.getRel())) { + response.addHeader("Location", link.getHref()); + break; + } + } + + // Write the created Atom entry + response.setStatus(HttpServletResponse.SC_CREATED); + response.setContentType("application/atom+xml; charset=utf-8"); + try { + AtomFeedEntryUtil.writeFeedEntry(createdFeedEntry, feedType, getWriter(response)); + } catch (FeedException e) { + throw new ServletException(e); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + private Writer getWriter(HttpServletResponse response) throws UnsupportedEncodingException, IOException { + Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8"); + return writer; + } + + @Override + protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + if (path != null && path.startsWith("/")) { + String id = path.substring(1); + + // Update an Atom entry + String contentType = request.getContentType(); + if (contentType != null && contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + Entry feedEntry; + try { + feedEntry = AtomFeedEntryUtil.readFeedEntry(feedType, request.getReader()); + } catch (JDOMException e) { + throw new ServletException(e); + } catch (FeedException e) { + throw new ServletException(e); + } + + // Let the component implementation create it + if (supportsFeedEntries) { + + // The service implementation supports feed entries, pass the entry to it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id, feedEntry}); + Message responseMessage = putInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } else { + + // The service implementation does not support feed entries, pass the data item to it + Message requestMessage = messageFactory.createMessage(); + org.apache.tuscany.sca.data.collection.Entry entry = createEntry(feedEntry); + requestMessage.setBody(new Object[] {entry.getKey(), entry.getData()}); + Message responseMessage = putInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } + + } else if (contentType != null) { + + // Updated a media entry + + // Let the component implementation create the media entry + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id, contentType, request.getInputStream()}); + Message responseMessage = putMediaInvoker.invoke(requestMessage); + Object body = responseMessage.getBody(); + if (responseMessage.isFault()) { + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + @Override + protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + String id; + if (path != null && path.startsWith("/")) { + id = path.substring(1); + } else { + id = ""; + } + + // Delete a specific entry from the collection + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id}); + Message responseMessage = deleteInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } + + /** + * Process the authorization header + * + * @param request + * @return + * @throws ServletException + */ + private String processAuthorizationHeader(HttpServletRequest request) throws ServletException { + try { + String authorization = request.getHeader("Authorization"); + if (authorization != null) { + StringTokenizer tokens = new StringTokenizer(authorization); + if (tokens.hasMoreTokens()) { + String basic = tokens.nextToken(); + if (basic.equalsIgnoreCase("Basic")) { + String credentials = tokens.nextToken(); + String userAndPassword = new String(Base64.decodeBase64(credentials.getBytes())); + int colon = userAndPassword.indexOf(":"); + if (colon != -1) { + String user = userAndPassword.substring(0, colon); + String password = userAndPassword.substring(colon + 1); + + // Authenticate the User. + if (authenticate(user, password)) { + return user; + } + } + } + } + } + } catch (Exception e) { + throw new ServletException(e); + } + return null; + } + + /** + * Authenticate a user. + * + * @param user + * @param password + * @return + */ + private boolean authenticate(String user, String password) { + + // TODO Handle this using SCA security policies + //FIXME Why are we using endsWith instead of equals here?? + return ("admin".endsWith(user) && "admin".equals(password)); + } + + /** + * Reject an unauthorized request. + * + * @param response + */ + private void unauthorized(HttpServletResponse response) throws IOException { + response.setHeader("WWW-Authenticate", "BASIC realm=\"Tuscany\""); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java new file mode 100644 index 0000000000..c5bd3ec009 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.feed.provider; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; + +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.XmlReader; + +/** + * Invoker for the RSS binding. + * + * @version $Rev$ $Date$ + */ +class RSSBindingInvoker implements Invoker, DataExchangeSemantics { + private static final Logger logger = Logger.getLogger(RSSBindingInvoker.class.getName()); + + private String feedType; + private String uri; + + RSSBindingInvoker(String uri, String feedType) { + this.uri = uri; + this.feedType = feedType; + } + + public Message invoke(Message msg) { + try { + logger.info(">>> RSSBindingInvoker (" + feedType + ") " + uri); + + // Read the configured feed URI into a Feed object + Feed feed; + if (feedType.startsWith("atom_")) { + + // Read an Atom feed + WireFeedInput input = new WireFeedInput(); + feed = (Feed)input.build(new XmlReader(new URL(uri))); + } else { + + // Read an RSS feed and convert it to an Atom feed + SyndFeedInput input = new SyndFeedInput(); + SyndFeed syndFeed = input.build(new XmlReader(new URL(uri))); + feed = (Feed)syndFeed.createWireFeed("atom_1.0"); + } + + //FIXME Support conversion to data-api entries + + msg.setBody(feed); + + } catch (MalformedURLException e) { + msg.setFaultBody(e); + } catch (IllegalArgumentException e) { + msg.setFaultBody(e); + } catch (FeedException e) { + msg.setFaultBody(e); + } catch (IOException e) { + msg.setFaultBody(e); + } + return msg; + } + + public boolean allowsPassByReference() { + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java new file mode 100644 index 0000000000..649af78c5b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.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.sca.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.RSSBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the RSS binding provider factory. + * + * @version $Rev$ $Date$ + */ +public class RSSBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private Mediator mediator; + private ServletHost servletHost; + + public RSSBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + RSSBinding binding) { + return new RSSReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + RSSBinding binding) { + return new RSSServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator); + } + + public Class getModelType() { + return RSSBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.java new file mode 100644 index 0000000000..278ed9cb7e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.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.sca.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.RSSBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the RSS binding provider. + * + * @version $Rev$ $Date$ + */ +class RSSReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private RSSBinding binding; + + RSSReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + RSSBinding binding) { + this.reference = reference; + this.binding = binding; + } + + public Invoker createInvoker(Operation operation) { + return new RSSBindingInvoker(binding.getURI(), "rss_2.0"); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.java new file mode 100644 index 0000000000..779b28cef6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.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.sca.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.RSSBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the RSS binding provider. + * + * @version $Rev$ $Date$ + */ +class RSSServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private RSSBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private String servletMapping; + private Mediator mediator; + + RSSServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + RSSBinding binding, + ServletHost servletHost, + MessageFactory messageFactory, + Mediator mediator) { + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.mediator = mediator; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + RuntimeComponentService componentService = (RuntimeComponentService)service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + + FeedBindingListenerServlet servlet = + new FeedBindingListenerServlet(wire, messageFactory, mediator, "rss_2.0"); + + servletMapping = binding.getURI(); + servletHost.addServletMapping(servletMapping, servlet); + + // Save the actual binding URI in the binding + binding.setURI(servletHost.getURLMapping(binding.getURI()).toString()); + } + + public void stop() { + servletHost.removeServletMapping(servletMapping); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.AtomBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.AtomBindingFactory new file mode 100644 index 0000000000..49478e3db0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.AtomBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the model factory +org.apache.tuscany.sca.binding.feed.impl.AtomBindingFactoryImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.RSSBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.RSSBindingFactory new file mode 100644 index 0000000000..f69b024da9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.RSSBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the model factory +org.apache.tuscany.sca.binding.feed.impl.RSSBindingFactoryImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..3f073b28b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.atom,model=org.apache.tuscany.sca.binding.feed.AtomBinding,factory=org.apache.tuscany.sca.binding.feed.AtomBindingFactory +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.rss,model=org.apache.tuscany.sca.binding.feed.RSSBinding,factory=org.apache.tuscany.sca.binding.feed.RSSBindingFactory diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..f81a0d33ae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.feed.provider.AtomBindingProviderFactory;model=org.apache.tuscany.sca.binding.feed.AtomBinding +org.apache.tuscany.sca.binding.feed.provider.RSSBindingProviderFactory;model=org.apache.tuscany.sca.binding.feed.RSSBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Consumer.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Consumer.java new file mode 100644 index 0000000000..4a33637121 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Consumer.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.sca.binding.feed; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Consumer { + + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/feed/Consumer.composite"); + + CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient"); + testService.testCustomerCollection(); + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClient.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClient.java new file mode 100644 index 0000000000..b7416011ba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClient.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed; + +public interface CustomerClient { + + void testCustomerCollection() throws Exception; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java new file mode 100644 index 0000000000..884e954036 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.feed.collection.Collection; +import org.osoa.sca.annotations.Reference; + +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; + +public class CustomerClientImpl implements CustomerClient { + + @Reference + public Collection resourceCollection; + + public void testCustomerCollection() throws Exception { + + Entry newEntry = newEntry("Sponge Bob"); + System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = resourceCollection.post(newEntry); + System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + newEntry = newEntry("Jane Bond"); + System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = resourceCollection.post(newEntry); + System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + System.out.println(">>> get id=" + newEntry.getId()); + Entry entry = resourceCollection.get(newEntry.getId()); + System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle()); + + System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle()); + resourceCollection.put(entry.getId(), updateEntry(entry, "James Bond")); + System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle()); + + System.out.println(">>> delete id=" + entry.getId()); + resourceCollection.delete(entry.getId()); + System.out.println("<<< delete id=" + entry.getId()); + + System.out.println(">>> get collection"); + Feed feed = resourceCollection.getFeed(); + System.out.println("<<< get collection"); + for (Object o : feed.getEntries()) { + Entry e = (Entry)o; + System.out.println("id = " + e.getId() + " entry = " + e.getTitle()); + } + } + + private Entry newEntry(String value) { + + Entry entry = new Entry(); + entry.setTitle("customer " + value); + + Content content = new Content(); + content.setValue(value); + content.setType(Content.TEXT); + List list = new ArrayList(); + list.add(content); + entry.setContents(list); + + return entry; + } + + private Entry updateEntry(Entry entry, String value) { + + entry.setTitle("customer " + value); + Content content = new Content(); + content.setValue(value); + content.setType(Content.TEXT); + List list = new ArrayList(); + list.add(content); + entry.setContents(list); + + return entry; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java new file mode 100644 index 0000000000..ca4a5a1946 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.tuscany.sca.binding.feed.collection.Collection; +import org.osoa.sca.annotations.Scope; + +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.feed.atom.Link; + +@Scope("COMPOSITE") +public class CustomerCollectionImpl implements Collection { + + private Map entries = new HashMap(); + + public CustomerCollectionImpl() { + + for (int i = 0; i < 4; i++) { + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + + Entry entry = new Entry(); + entry.setTitle("customer " + "Jane Doe_" + String.valueOf(i)); + entry.setId(id); + + Content content = new Content(); + content.setValue("Jane Doe_" + String.valueOf(i)); + content.setType(Content.TEXT); + entry.setContents(Collections.singletonList(content)); + + List links = new ArrayList(); + Link link = new Link(); + link.setRel("edit"); + link.setHref("" + id); + links.add(link); + entry.setOtherLinks(links); + + links = new ArrayList(); + link = new Link(); + link.setRel("alternate"); + link.setHref("" + id); + links.add(link); + entry.setAlternateLinks(links); + + entry.setCreated(new Date()); + + entries.put(id, entry); + System.out.println(">>> id=" + id); + } + } + + public Entry post(Entry entry) { + System.out.println(">>> ResourceCollectionImpl.post entry=" + entry.getTitle()); + + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + entry.setId(id); + + List links = new ArrayList(); + Link link = new Link(); + link.setRel("edit"); + link.setHref("" + id); + links.add(link); + entry.setOtherLinks(links); + + links = new ArrayList(); + link = new Link(); + link.setRel("alternate"); + link.setHref("" + id); + links.add(link); + entry.setAlternateLinks(links); + + entry.setCreated(new Date()); + + entries.put(id, entry); + System.out.println(">>> ResourceCollectionImpl.post return id=" + id); + + return entry; + } + + public Entry get(String id) { + System.out.println(">>> ResourceCollectionImpl.get id=" + id); + return entries.get(id); + } + + public void put(String id, Entry entry) { + System.out.println(">>> ResourceCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); + + entry.setUpdated(new Date()); + entries.put(id, entry); + } + + public void delete(String id) { + System.out.println(">>> ResourceCollectionImpl.delete id=" + id); + entries.remove(id); + } + + @SuppressWarnings("unchecked") + public Feed getFeed() { + System.out.println(">>> ResourceCollectionImpl.get collection"); + + Feed feed = new Feed(); + feed.setTitle("customers"); + Content subtitle = new Content(); + subtitle.setValue("This is a sample feed"); + feed.setSubtitle(subtitle); + feed.getEntries().addAll(entries.values()); + return feed; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Provider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Provider.java new file mode 100644 index 0000000000..a9ddc1a2c8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Provider.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.sca.binding.feed; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Provider { + + public static void main(String[] args) { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/feed/Provider.composite"); + System.out.println("Provider.composite ready..."); + + try { + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite new file mode 100644 index 0000000000..1987c042e6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite new file mode 100644 index 0000000000..9268fbe211 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/pom.xml new file mode 100644 index 0000000000..89c420e9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/pom.xml @@ -0,0 +1,210 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-gdata-runtime + Apache Tuscany SCA Gdata Binding Extension Runtime GSOC + + + + com.google.gdata + http://people.apache.org/~lresende/google-gdata/maven/ + + + + + + org.apache.tuscany.sca + tuscany-binding-gdata + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + + org.apache.abdera + abdera-core + 0.4.0-incubating + + + + commons-httpclient + commons-httpclient + 3.1 + + + + com.google.gdata + gdata-client + 1.0 + + + + com.google.gdata + gdata-client-meta + 1.0 + + + + com.google.gdata + gdata-core + 1.0 + + + + com.google.gdata + gdata-media + 1.0 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + commons-codec + commons-codec + 1.3 + + + commons-codec + commons-codec + + + + + + commons-logging + commons-logging + 1.1.1 + + + javax.servlet + servlet-api + + + avalon-framework + avalon-framework + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + + ${tuscany.version} + + + org.apache.tuscany.sca.binding.gdata.extension + + + ${pom.name} + + + org.apache.tuscany.sca.binding.gdata* + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java new file mode 100644 index 0000000000..8bff8631a6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.collection; + +import com.google.gdata.client.Query; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import org.osoa.sca.annotations.Remotable; + +/** + * Provides access to a collection of resources using Gdata. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Collection { + + /** + * Get a GData feed for a collection of resources. + * + * @return the GData feed + */ + Feed getFeed(); + + /** + * Get a GData feed for a collection of resources resulting from a query. + * + * @param queryString a query string + * @return the GData feed + */ + Feed query(Query query); + + /** + * Creates a new entry. + * + * @param entry + * @return + */ + Entry post(Entry entry); + + /** + * Retrieves an entry. + * + * @param id + * @return + */ + Entry get(String id) throws NotFoundException; + + /** + * Update an entry. + * + * @param id + * @param entry + * @return + */ + void put(String id, Entry entry) throws NotFoundException; + + /** + * Delete an entry. + * + * @param id + */ + void delete(String id) throws NotFoundException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java new file mode 100644 index 0000000000..699e9f0172 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.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.sca.binding.gdata.collection; + +import java.io.InputStream; + +import org.osoa.sca.annotations.Remotable; + +import com.google.gdata.data.Entry; + +/** + * Provides access to a collection of resources using Atom. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface MediaCollection extends Collection { + + /** + * Creates a new media entry + * + * @param title + * @param slug + * @param contentType + * @param media + */ + Entry postMedia(String title, String slug, String contentType, InputStream media); + + /** + * Update a media entry. + * + * @param id + * @param contentType + * @param media + * @return + */ + void putMedia(String id, String contentType, InputStream media) throws NotFoundException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/NotFoundException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/NotFoundException.java new file mode 100644 index 0000000000..4fc32d4d37 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/NotFoundException.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.sca.binding.gdata.collection; + +/** + * Indicates that a resource could not be found. + * + * @version $Rev$ $Date$ + */ +public class NotFoundException extends Exception { + private static final long serialVersionUID = -5046027674128627383L; + + public NotFoundException() { + } + + public NotFoundException(String message) { + super(message); + } + + public NotFoundException(Throwable cause) { + super(cause); + } + + public NotFoundException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingInvoker.java new file mode 100644 index 0000000000..67cf01eca9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingInvoker.java @@ -0,0 +1,419 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.provider; + +import static org.apache.tuscany.sca.binding.gdata.provider.GdataBindingUtil.feedEntry; + +import java.io.IOException; +import java.net.URL; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.DeleteMethod; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.osoa.sca.ServiceRuntimeException; + +import com.google.gdata.client.GoogleService; +import com.google.gdata.client.Query; +import com.google.gdata.data.Feed; +import com.google.gdata.util.ResourceNotFoundException; +import com.google.gdata.util.ServiceException; + +/** + * Invoker for the GData binding. + * + * @version $Rev$ $Date$ + */ +class GdataBindingInvoker implements Invoker, DataExchangeSemantics { + + Operation operation; + String uri; + HttpClient httpClient; + String authorizationHeader; + GdataReferenceBindingProvider provider; + GoogleService googleService; + + GdataBindingInvoker(Operation operation, + String uri, + GoogleService googleService, + HttpClient httpClient, + String authorizationHeader, + GdataReferenceBindingProvider bindingProvider) { + this.operation = operation; + this.uri = uri; + this.googleService = googleService; + this.httpClient = httpClient; + this.authorizationHeader = authorizationHeader; + this.provider = bindingProvider; + + } + + + public boolean allowsPassByReference() { + return true; + } + + public Message invoke(Message msg) { + // Shouldn't get here, as the only supported methods are + // defined in the ResourceCollection interface, and implemented + // by specific invoker subclasses + throw new UnsupportedOperationException(operation.getName()); + } + + + /** + * Get operation invoker + */ + public static class GetInvoker extends GdataBindingInvoker { + + public GetInvoker(Operation operation, + String uri, + GoogleService googleService, + HttpClient httpClient, + String authorizationHeader, + GdataReferenceBindingProvider bindingProvider) { + super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider); + } + + @SuppressWarnings("finally") + @Override + public Message invoke(Message msg) { + + // Get the entry id from the message body + String id = (String)((Object[])msg.getBody())[0]; + + // Send an HTTP GET + GetMethod getMethod = new GetMethod(uri + "/" + id); + getMethod.setRequestHeader("Authorization", authorizationHeader); + + try { + URL entryURL = new URL(uri + "/" + id); + com.google.gdata.data.Entry feedEntry = googleService.getEntry(entryURL, com.google.gdata.data.Entry.class); + msg.setBody(feedEntry); + } catch (IOException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } catch (ServiceException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + return msg; + } + + } + } + + /** + * Post operation invoker + */ + public static class PostInvoker extends GdataBindingInvoker { + + public PostInvoker(Operation operation, + String uri, + GoogleService googleService, + HttpClient httpClient, + String authorizationHeader, + GdataReferenceBindingProvider bindingProvider) { + super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider); + } + + @SuppressWarnings("finally") + @Override + public Message invoke(Message msg) { + // Post an entry + Object[] args = (Object[])msg.getBody(); + com.google.gdata.data.Entry feedEntry = null; + + if (provider.supportsFeedEntries()) { + + // Expect an GData entry + + //System.out.println("[Debug Info]GdataBindingInvoker.PostInvoker --- supportsFeedEntries: " + provider.supportsFeedEntries()); + feedEntry = (com.google.gdata.data.Entry)args[0]; + + //System.out.println("[Debug Info]GdataBindingInvoker.PostInvoker --- feedEntry title: " + feedEntry.getTitle().getPlainText()); + + } else { + // Expect a key and data item + Entry entry = new Entry(args[0], args[1]); + + // FIXME: this needs to be examinated more.... + feedEntry = feedEntry(entry, provider.getItemClassType(), provider.getItemXMLType(), provider.getMediator()); + } + + try { + + com.google.gdata.data.Entry createdEntry = googleService.insert(new URL(uri), feedEntry); + + msg.setBody(createdEntry); + + } catch (IOException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } catch (ServiceException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + return msg; + } + } + } + + + + /** + * Put operation invoker + */ + public static class PutInvoker extends GdataBindingInvoker { + + public PutInvoker(Operation operation, + String uri, + GoogleService googleService, + HttpClient httpClient, + String authorizationHeader, + GdataReferenceBindingProvider bindingProvider) { + super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider); + } + + @SuppressWarnings("finally") + @Override + public Message invoke(Message msg) { + + // Put an entry + Object[] args = (Object[])msg.getBody(); + String id; + com.google.gdata.data.Entry feedEntry = null; + if (provider.supportsFeedEntries()) { + // Expect a key and GData entry + id = (String)args[0]; + feedEntry = (com.google.gdata.data.Entry)args[1]; + } else { + + // Expect a key and data item + id = (String)args[0]; + Entry entry = new Entry(id, args[1]); + + } + + // Send an HTTP PUT + PutMethod putMethod = new PutMethod(uri + "/" + id); + putMethod.setRequestHeader("Authorization", authorizationHeader); + try { + URL entryURL = new URL(uri + "/" + id); + + com.google.gdata.data.Entry toUpdateEntry = googleService.getEntry(entryURL, com.google.gdata.data.Entry.class); + + //System.out.println("EditHtml:" + toUpdateEntry.getEditLink().getHref()); + + URL editURL = new URL(toUpdateEntry.getEditLink().getHref()); + + com.google.gdata.data.Entry updatedEntry = googleService.update(editURL, feedEntry); + + msg.setBody(updatedEntry); + + } catch (IOException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } catch (ServiceException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + return msg; + } } + } + + /** + * Delete operation invoker + */ + public static class DeleteInvoker extends GdataBindingInvoker { + + public DeleteInvoker(Operation operation, + String uri, + GoogleService googleService, + HttpClient httpClient, + String authorizationHeader, + GdataReferenceBindingProvider bindingProvider) { + super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider); + } + + @SuppressWarnings("finally") + @Override + public Message invoke(Message msg) { + + // Delete an entry + String id = (String)((Object[])msg.getBody())[0]; + + // Send an HTTP DELETE(Localhost) + DeleteMethod deleteMethod = new DeleteMethod(uri + "/" + id); + deleteMethod.setRequestHeader("Authorization", authorizationHeader); + + try { + URL entryURL = new URL(uri + "/" + id); + + com.google.gdata.data.Entry toUpdateEntry = googleService.getEntry(entryURL, com.google.gdata.data.Entry.class); + + //System.out.println("EditHtml:" + toUpdateEntry.getEditLink().getHref()); + + URL editURL = new URL(toUpdateEntry.getEditLink().getHref()); + + googleService.delete(editURL); + + } catch (IOException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } catch (ServiceException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + return msg; + } + } + + } + + + /** + * GetAll operation invoker + */ + public static class GetAllInvoker extends GdataBindingInvoker { + + public GetAllInvoker(Operation operation, + String uri, + GoogleService googleService, + HttpClient httpClient, + String authorizationHeader, + GdataReferenceBindingProvider bindingProvider) { + super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider); + } + + @SuppressWarnings("finally") + @Override + public Message invoke(Message msg) { + + // Send an HTTP GET + GetMethod getMethod = new GetMethod(uri); + getMethod.setRequestHeader("Authorization", authorizationHeader); + + //System.out.println("[Debug Info] GdataBindingInvoker.GetAllInvoker.invoke---feedURL: " + uri); + + try { + + Feed feed = googleService.getFeed(new URL(uri), Feed.class); + msg.setBody(feed); + + } catch (ResourceNotFoundException ex) { + msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + uri)); + } catch (ServiceException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } catch (Exception ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + return msg; + } + + } + } + + /** + * Query operation invoker + */ + public static class QueryInvoker extends GdataBindingInvoker { + + public QueryInvoker(Operation operation, + String uri, + GoogleService googleService, + HttpClient httpClient, + String authorizationHeader, + GdataReferenceBindingProvider bindingProvider) { + super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider); + } + + @SuppressWarnings("finally") + @Override + public Message invoke(Message msg) { + + // Send an HTTP GET + GetMethod getMethod = new GetMethod(uri); + getMethod.setRequestHeader("Authorization", authorizationHeader); + + Object[] args = (Object[])msg.getBody(); + Query myQuery = (Query)args[0]; + + //System.out.println("[Debug Info] GdataBindingInvoker.QueryInvoker.invoke---feedURL: " + uri); + + try { + + Feed resultFeed = googleService.query(myQuery, Feed.class); + msg.setBody(resultFeed); + + } catch (ResourceNotFoundException ex) { + msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + uri)); + } catch (ServiceException ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } catch (Exception ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + return msg; + } + + + } + } + + + + /** + * PostMedia operation invoker + */ + public static class PostMediaInvoker extends GdataBindingInvoker { + + public PostMediaInvoker(Operation operation, + String uri, + GoogleService googleService, + HttpClient httpClient, + String authorizationHeader, + GdataReferenceBindingProvider bindingProvider) { + super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider); + } + + @Override + public Message invoke(Message msg) { + // TODO implement + return super.invoke(msg); + } + } + + /** + * PutMedia operation invoker + */ + public static class PutMediaInvoker extends GdataBindingInvoker { + + public PutMediaInvoker(Operation operation, + String uri, + GoogleService googleService, + HttpClient httpClient, + String authorizationHeader, + GdataReferenceBindingProvider bindingProvider) { + super(operation, uri, googleService, httpClient, authorizationHeader, bindingProvider); + } + + @Override + public Message invoke(Message msg) { + // TODO implement + return super.invoke(msg); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingListenerServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingListenerServlet.java new file mode 100644 index 0000000000..facf3bb641 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingListenerServlet.java @@ -0,0 +1,746 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.provider; + +import static org.apache.tuscany.sca.binding.gdata.provider.GdataBindingUtil.entry; +import static org.apache.tuscany.sca.binding.gdata.provider.GdataBindingUtil.feedEntry; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.StringTokenizer; +import java.util.logging.Logger; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.abdera.parser.ParseException; +import org.apache.commons.codec.binary.Base64; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +import com.google.gdata.data.ExtensionProfile; +import com.google.gdata.data.ParseSource; +import com.google.gdata.data.PlainTextConstruct; +import com.google.gdata.util.ServiceException; + +/** + * A resource collection binding listener, implemented as a Servlet and + * registered in a Servlet host provided by the SCA hosting runtime. + * + * @version $Rev$ $Date$ + */ +class GdataBindingListenerServlet extends HttpServlet { + private static final Logger logger = Logger.getLogger(GdataBindingListenerServlet.class.getName()); + private static final long serialVersionUID = 1L; + + private RuntimeWire wire; + private Invoker getFeedInvoker; + private Invoker getAllInvoker; + private Invoker queryInvoker; + private Invoker getInvoker; + private Invoker postInvoker; + private Invoker postMediaInvoker; + private Invoker putInvoker; + private Invoker putMediaInvoker; + private Invoker deleteInvoker; + private MessageFactory messageFactory; + private String title; + private Mediator mediator; + private DataType itemClassType; + private DataType itemXMLType; + private boolean supportsFeedEntries; + + /** + * Constructs a new binding listener. + * + * @param wire + * @param messageFactory + * @param feedType + */ + GdataBindingListenerServlet(RuntimeWire wire, MessageFactory messageFactory, Mediator mediator, String title) { + this.wire = wire; + this.messageFactory = messageFactory; + this.mediator = mediator; + this.title = title; + + // Get the invokers for the supported operations + Operation getOperation = null; + for (InvocationChain invocationChain : this.wire.getInvocationChains()) { + invocationChain.setAllowsPassByReference(true); + Operation operation = invocationChain.getTargetOperation(); + String operationName = operation.getName(); + + if (operationName.equals("getFeed")) { + + //System.out.println("[Debug Info]GdataBindingListenerServlet constructor --- operation: getFeed"); + getFeedInvoker = invocationChain.getHeadInvoker(); + + } else if (operationName.equals("getAll")) { + + getAllInvoker = invocationChain.getHeadInvoker(); + + } else if (operationName.equals("query")) { + + queryInvoker = invocationChain.getHeadInvoker(); + + } else if (operationName.equals("get")) { + + //System.out.println("[Debug Info]GdataBindingListenerServlet Constructor --- opeartion: get"); + getInvoker = invocationChain.getHeadInvoker(); + getOperation = operation; + + } else if (operationName.equals("put")) { + + putInvoker = invocationChain.getHeadInvoker(); + + } else if (operationName.equals("putMedia")) { + + putMediaInvoker = invocationChain.getHeadInvoker(); + + } else if (operationName.equals("post")) { + + //System.out.println("[Debug Info]GdataBindingListenerServlet Constructor --- opeartion: post"); + postInvoker = invocationChain.getHeadInvoker(); + + } else if (operationName.equals("postMedia")) { + postMediaInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("delete")) { + deleteInvoker = invocationChain.getHeadInvoker(); + } + } + + //System.out.println("[Debug Info]GdataBindingListenerServlet constructor --- I am good here 00"); + + // Determine the collection item type + itemXMLType = new DataTypeImpl>(String.class.getName(), String.class, String.class); + Class itemClass = getOperation.getOutputType().getPhysical(); + + if (itemClass == com.google.gdata.data.Entry.class) { + supportsFeedEntries = true; + } + DataType outputType = getOperation.getOutputType(); + QName qname = outputType.getLogical().getElementName(); + qname = new QName(qname.getNamespaceURI(), itemClass.getSimpleName()); + itemClassType = new DataTypeImpl("java:complexType", itemClass, new XMLType(qname, null)); + + //System.out.println("[Debug Info]GdataBindingListenerServlet --- initilized!"); + } + + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // No authentication required for a get request + //System.out.println("[Debug Info]GdataBindingListenerServlet doGet() --- I am good here 00"); + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + //System.out.println("[Debug Info]GdataBindingListenerServlet doGet() --- request.getRequestURI(): " + request.getRequestURI()); + //System.out.println("[Debug Info]GdataBindingListenerServlet doGet()--- path: " + path); + + // FIXME: Log this get http request, commented out for testing + logger.fine("get " + request.getRequestURI()); + + // Handle an Atom request + if (path != null && path.equals("/atomsvc")) { + + //FIXME: This needs to be fixed, for /atomsvc + + /* + System.out.println("GdataBindingListenerServlet doGet(): I am good here brach 01"); + // Return the Atom service document + response.setContentType("application/atomsvc+xml; charset=utf-8"); + Service service = abderaFactory.newService(); + // service.setText("service"); + + Workspace workspace = abderaFactory.newWorkspace(); + workspace.setTitle("resource"); + + String href = request.getRequestURL().toString(); + href = href.substring(0, href.length() - "/atomsvc".length()); + + Collection collection = workspace.addCollection("collection", "atom/feed"); + collection.setTitle("entries"); + collection.setAttributeValue("href", href); + collection.setAccept("entry"); + collection.addCategories().setFixed(false); + + workspace.addCollection(collection); + + service.addWorkspace(workspace); + + // FIXME add prettyPrint support + try { + service.getDocument().writeTo(response.getOutputStream()); + } catch (IOException ioe) { + throw new ServletException(ioe); + } + */ + + } else if (path == null || path.length() == 0 || path.equals("/")) { + + // get HTTP request asking for a feed + + //System.out.println("[Debug Info]GdataBindingListenerServlet doGet() --- I am good here brach 02"); + + // Return a feed containing the entries in the collection + com.google.gdata.data.Feed feed = null; + + if (supportsFeedEntries) { + + //System.out.println("[Debug Info]GdataBindingListenerServlet doGet() --- supportsFeedEntries: " + supportsFeedEntries); + + // The service implementation supports feed entries, invoke its + // getFeed operation + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + //System.out.println("getQueryString != null"); + requestMessage.setBody(new Object[] {request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + //System.out.println("getQueryString == null"); + responseMessage = getFeedInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + + //System.out.println("response msg class:" + responseMessage.getBody().getClass()); + + feed = (com.google.gdata.data.Feed)responseMessage.getBody(); + + //System.out.println("feed title: " + feed.getTitle().getPlainText()); + + } else { + + //System.out.println("GdataBindingListenerServlet doGet(): do not supportsFeedEntries"); + + // The service implementation does not support feed entries, + // invoke its getAll operation to get the data item collection, + // then create + // feed entries from the items + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + requestMessage.setBody(new Object[] {request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + responseMessage = getAllInvoker.invoke(requestMessage); + + //System.out + // .println("GdataBindingListner.doGet(): get msg from getAllInvoker.invoke()" + responseMessage + // .getBody().toString()); + + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + Entry[] collection = (Entry[])responseMessage.getBody(); + if (collection != null) { + + // Create the feed + feed = new com.google.gdata.data.Feed(); + + // Set the feed title + if (title != null) { + feed.setTitle(new PlainTextConstruct(title)); + } else { + feed.setTitle(new PlainTextConstruct("Feed title")); + } + + // Add entries to the feed + ArrayList entries = new ArrayList(); + for (Entry entry : collection) { + com.google.gdata.data.Entry feedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator); + entries.add(feedEntry); + } + feed.setEntries(entries); + + } + } + if (feed != null) { + + // //System.out.println("feed(from the http response)is not + // null"); + + // Write a GData feed using Atom representation + response.setContentType("application/atom+xml; charset=utf-8"); + + // Generate the corresponding Atom representation of the feed + StringWriter stringWriter = new StringWriter(); + com.google.gdata.util.common.xml.XmlWriter w = + new com.google.gdata.util.common.xml.XmlWriter(stringWriter); + feed.generateAtom(w, new ExtensionProfile()); + w.flush(); + + // Write the Atom representation(XML) into Http response content + OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream()); + PrintWriter out = new PrintWriter(response.getOutputStream()); + out.println(stringWriter.toString()); + out.close(); + + //System.out.println("Feed content in plain text:" + stringWriter.toString()); + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else if (path.startsWith("/")) { + + // get HTTP request asking for an entry + + // Return a specific entry in the collection + com.google.gdata.data.Entry feedEntry = null; + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + String id = path.substring(1); + requestMessage.setBody(new Object[] {id}); + Message responseMessage = getInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + + if (supportsFeedEntries) { + // The service implementation returns a feed entry + feedEntry = (com.google.gdata.data.Entry)responseMessage.getBody(); + + //System.out.println("entry title: " + feedEntry.getTitle().getPlainText()); + + } else { + // The service implementation only returns a data item, create + // an entry + // from it + Entry entry = new Entry(id, responseMessage.getBody()); + // FIXME The line below needs to be fixed + // feedEntry = feedEntry(entry, itemClassType, itemXMLType, + // mediator, abderaFactory); + } + + // Write the Gdata entry + if (feedEntry != null) { + + // Write a GData entry using Atom representation + response.setContentType("application/atom+xml; charset=utf-8"); + + // Generate the corresponding Atom representation of the feed + StringWriter stringWriter = new StringWriter(); + com.google.gdata.util.common.xml.XmlWriter w = + new com.google.gdata.util.common.xml.XmlWriter(stringWriter); + feedEntry.generateAtom(w, new ExtensionProfile()); + w.flush(); + + // Write the Atom representation(XML) into Http response content + OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream()); + PrintWriter out = new PrintWriter(response.getOutputStream()); + out.println(stringWriter.toString()); + out.close(); + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } else { + // Path doesn't match any known pattern + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + + //System.out.println("[Debug Info]GdataBindingListenerServlet doPost() --- reached"); + + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + //System.out.println("[Debug Info]GdataBindingListenerServlet path --- " + path); + + if (path == null || path.length() == 0 || path.equals("/")) { + // Create a new Gdata entry + com.google.gdata.data.Entry createdFeedEntry = null; + String contentType = request.getContentType(); + + if (contentType != null && contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + com.google.gdata.data.Entry feedEntry = null; + try { + ParseSource source = new ParseSource(request.getReader()); + feedEntry = com.google.gdata.data.Entry.readEntry(source, com.google.gdata.data.Entry.class, null); + } catch (ParseException pe) { + throw new ServletException(pe); + } catch (com.google.gdata.util.ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ServiceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + // Let the component implementation create it + if (supportsFeedEntries) { + + // The service implementation supports feed entries, pass + // the entry to it + Message requestMessage = messageFactory.createMessage(); + + requestMessage.setBody(new Object[] {feedEntry}); + + Message responseMessage = postInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + createdFeedEntry = responseMessage.getBody(); + } else { + + // The service implementation does not support feed entries, + // pass the data item to it + Message requestMessage = messageFactory.createMessage(); + Entry entry = entry(feedEntry, itemClassType, itemXMLType, mediator); + requestMessage.setBody(new Object[] {entry.getKey(), entry.getData()}); + Message responseMessage = postInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + entry.setKey(responseMessage.getBody()); + + createdFeedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator); + } + + } else if (contentType != null) { + + // Create a new media entry + + // Get incoming headers + String title = request.getHeader("Title"); + String slug = request.getHeader("Slug"); + + // Let the component implementation create the media entry + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {title, slug, contentType, request.getInputStream()}); + Message responseMessage = postMediaInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + createdFeedEntry = responseMessage.getBody(); + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + + // A new entry was created successfully + if (createdFeedEntry != null) { + + // Set location of the created entry in the Location header + // Link link = createdFeedEntry.getSelfLink(); + // if (link != null) { + // response.addHeader("Location", link.getHref().toString()); + // } + + // Write the created Atom entry + response.setStatus(HttpServletResponse.SC_CREATED); + response.setContentType("application/atom+xml; charset=utf-8"); + try { + + // Generate the corresponding Atom representation of the + // feed + StringWriter stringWriter = new StringWriter(); + com.google.gdata.util.common.xml.XmlWriter w = + new com.google.gdata.util.common.xml.XmlWriter(stringWriter); + createdFeedEntry.generateAtom(w, new ExtensionProfile()); + w.flush(); + + // Write the Atom representation(XML) into Http response + // content + OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream()); + PrintWriter out = new PrintWriter(response.getOutputStream()); + out.println(stringWriter.toString()); + out.close(); + + } catch (ParseException pe) { + throw new ServletException(pe); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + private Writer getWriter(HttpServletResponse response) throws UnsupportedEncodingException, IOException { + Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8"); + return writer; + } + + + @Override + protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = request.getRequestURI().substring(request.getServletPath().length()); + + //System.out.println("[Debug Info] localServlet doPut --- path: " + path); + + if (path != null && path.startsWith("/")) { + String id = path.substring(1); + + // Update an Atom entry + String contentType = request.getContentType(); + if (contentType != null && contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + com.google.gdata.data.Entry feedEntry = null; + try { + ParseSource source = new ParseSource(request.getReader()); + feedEntry = com.google.gdata.data.Entry.readEntry(source, com.google.gdata.data.Entry.class, null); + + //System.out.println("[Debug Info] localServlet doPut --- feedEntry title: " + feedEntry.getTitle().getPlainText()); + } catch (ParseException pe) { + throw new ServletException(pe); + } catch (com.google.gdata.util.ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ServiceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + + // Let the component implementation create it + if (supportsFeedEntries) { + + //System.out.println("[Debug Info] localServlet doPut --- supportsFeedEntries: " + supportsFeedEntries); + + // The service implementation supports feed entries, pass + // the entry to it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id, feedEntry}); + Message responseMessage = putInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } else { + + // The service implementation does not support feed entries, + // pass the data item to it + Message requestMessage = messageFactory.createMessage(); + Entry entry = entry(feedEntry, itemClassType, itemXMLType, mediator); + requestMessage.setBody(new Object[] {entry.getKey(), entry.getData()}); + Message responseMessage = putInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } + + // Write the Gdata entry + if (feedEntry != null) { + + // Write a GData entry using Atom representation + response.setContentType("application/atom+xml; charset=utf-8"); + + // Generate the corresponding Atom representation of the feed + StringWriter stringWriter = new StringWriter(); + com.google.gdata.util.common.xml.XmlWriter w = + new com.google.gdata.util.common.xml.XmlWriter(stringWriter); + feedEntry.generateAtom(w, new ExtensionProfile()); + w.flush(); + + // Write the Atom representation(XML) into Http response content + OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream()); + PrintWriter out = new PrintWriter(response.getOutputStream()); + out.println(stringWriter.toString()); + out.close(); + + } + + } else if (contentType != null) { + + // Updated a media entry + + // Let the component implementation create the media entry + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id, contentType, request.getInputStream()}); + Message responseMessage = putMediaInvoker.invoke(requestMessage); + Object body = responseMessage.getBody(); + if (responseMessage.isFault()) { + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + + + + @Override + protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + String id; + if (path != null && path.startsWith("/")) { + id = path.substring(1); + } else { + id = ""; + } + + // Delete a specific entry from the collection + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id}); + Message responseMessage = deleteInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } + + + + /** + * Process the authorization header + * + * @param request + * @return + * @throws ServletException + */ + private String processAuthorizationHeader(HttpServletRequest request) throws ServletException { + + // FIXME temporarily disabling this as it doesn't work with all browsers + if (true) + return "admin"; + + try { + String authorization = request.getHeader("Authorization"); + if (authorization != null) { + StringTokenizer tokens = new StringTokenizer(authorization); + if (tokens.hasMoreTokens()) { + String basic = tokens.nextToken(); + if (basic.equalsIgnoreCase("Basic")) { + String credentials = tokens.nextToken(); + String userAndPassword = new String(Base64.decodeBase64(credentials.getBytes())); + int colon = userAndPassword.indexOf(":"); + if (colon != -1) { + String user = userAndPassword.substring(0, colon); + String password = userAndPassword.substring(colon + 1); + + // Authenticate the User. + if (authenticate(user, password)) { + return user; + } + } + } + } + } + } catch (Exception e) { + throw new ServletException(e); + } + return null; + } + + /** + * Authenticate a user. + * + * @param user + * @param password + * @return + */ + private boolean authenticate(String user, String password) { + // TODO Handle this using SCA security policies + return ("admin".equals(user) && "admin".equals(password)); + } + + /** + * Reject an unauthorized request. + * + * @param response + */ + private void unauthorized(HttpServletResponse response) throws IOException { + response.setHeader("WWW-Authenticate", "BASIC realm=\"Tuscany\""); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java new file mode 100644 index 0000000000..62a05e91d0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.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.sca.binding.gdata.provider; + +import org.apache.tuscany.sca.binding.gdata.GdataBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +import com.google.gdata.util.AuthenticationException; + +/** + * Implementation of a Binding provider factory for the Atom binding. + * + * @version $Rev$ $Date$ + */ +public class GdataBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private Mediator mediator; + private ServletHost servletHost; + + public GdataBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + GdataBinding binding) { + try { + return new GdataReferenceBindingProvider(component, reference, binding, mediator); + } catch (AuthenticationException e) { + e.printStackTrace(); + return null; //Google authentication error! : This exception needs to be handled into a better way + } + + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + GdataBinding binding) { + return new GdataServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator); + } + + public Class getModelType() { + return GdataBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingUtil.java new file mode 100644 index 0000000000..3d476df764 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingUtil.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.sca.binding.gdata.provider; + +import java.util.Date; + +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; + +import com.google.gdata.data.DateTime; +import com.google.gdata.data.PlainTextConstruct; +import com.google.gdata.data.TextContent; + +/** + * Utility methods used in this package. + * + * @version $Rev$ $Date$ + */ +class GdataBindingUtil { + + /** + * Create a data item from an GData entry. + * + * @param feedEntry + * @param itemClassType + * @param itemXMLType + * @param mediator + * @return + */ + static Entry entry(com.google.gdata.data.Entry feedEntry, + DataType itemClassType, + DataType itemXMLType, + Mediator mediator) { + if (feedEntry != null) { + if (itemClassType.getPhysical() == Item.class) { + String key = feedEntry.getId().toString(); + + Item item = new Item(); + item.setTitle(feedEntry.getTitle().toString()); + TextContent content = (TextContent)feedEntry.getContent(); + item.setContents(content.getContent().getPlainText()); + + for (com.google.gdata.data.Link link : feedEntry.getLinks()) { + if (link.getRel() == null || "self".equals(link.getRel())) { + if (item.getLink() == null) { + item.setLink(link.getHref().toString()); + } + } else if ("related".equals(link.getRel())) { + item.setRelated(link.getHref().toString()); + } else if ("alternate".equals(link.getRel())) { + item.setAlternate(link.getHref().toString()); + } + } + + Date date = new Date(feedEntry.getUpdated().getValue()); + item.setDate(date); + return new Entry(key, item); + + } else { + String key = null; + if (feedEntry.getId() != null) { + key = feedEntry.getId(); + } + + // Create the item from XML + if (feedEntry.getContent() == null) { + return null; + } + + TextContent content = (TextContent)feedEntry.getContent(); + String value = content.getContent().getPlainText(); + Object data = mediator.mediate(value, itemXMLType, itemClassType, null); + return new Entry(key, data); + } + } else { + return null; + } + } + + /** + * Create an Gdata entry for a key and item from a collection. + * + * @param entry + * @param itemClassType + * @param itemXMLType + * @param mediator + * @param factory + * @return + */ + static com.google.gdata.data.Entry feedEntry(Entry entry, + DataType itemClassType, + DataType itemXMLType, + Mediator mediator) { + + Object key = entry.getKey(); + Object data = entry.getData(); + if (data instanceof Item) { + Item item = (Item)data; + + com.google.gdata.data.Entry feedEntry = new com.google.gdata.data.Entry(); + if (key != null) { + feedEntry.setId(key.toString()); + } + feedEntry.setTitle(new PlainTextConstruct(item.getTitle())); + feedEntry.setContent(new PlainTextConstruct(item.getContents())); + + String href = item.getLink(); + if (href == null && key != null) { + href = key.toString(); + } + + if (href != null) { + feedEntry.addHtmlLink(href, "", ""); + } + String related = item.getRelated(); + if (related != null) { + feedEntry.addHtmlLink(related, "", "related"); + } + String alternate = item.getAlternate(); + if (alternate != null) { + feedEntry.addHtmlLink(alternate, "", "alternate"); + } + + Date date = item.getDate(); + if (date != null) { + DateTime datetime = new DateTime(date); + feedEntry.setUpdated(datetime); + } + return feedEntry; + + } else if (data != null) { + + com.google.gdata.data.Entry feedEntry = new com.google.gdata.data.Entry(); + feedEntry.setId(key.toString()); + feedEntry.setTitle(new PlainTextConstruct("item")); + + // Convert the item to XML + String value = mediator.mediate(data, itemClassType, itemXMLType, null).toString(); + + // Might be wrong because the example uses XML datatype, I am using + // plainText here + feedEntry.setContent(new PlainTextConstruct(value)); + + feedEntry.addHtmlLink(key.toString(), "", ""); + return feedEntry; + + } else { + return null; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataReferenceBindingProvider.java new file mode 100644 index 0000000000..ac8c298d1a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataReferenceBindingProvider.java @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.gdata.provider; + +import java.net.URI; + +import javax.xml.namespace.QName; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpConnectionManager; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; +import org.apache.tuscany.sca.binding.gdata.GdataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +import com.google.gdata.client.GoogleService; +import com.google.gdata.util.AuthenticationException; + +/** + * Implementation of the Atom binding provider. + * + * @version $Rev$ $Date$ + */ +class GdataReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private GdataBinding binding; + private String authorizationHeader; + private GoogleService googleService; + private HttpClient httpClient; + private Mediator mediator; + private DataType itemClassType; + private DataType itemXMLType; + private boolean supportsFeedEntries; + + /** + * Constructs a new AtomReferenceBindingProvider + * + * @param component + * @param reference + * @param binding + * @param mediator + * @throws AuthenticationException + */ + GdataReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + GdataBinding binding, + Mediator mediator) throws AuthenticationException { + this.reference = reference; + this.binding = binding; + this.mediator = mediator; + + // Prepare authorization header + String authorization = "admin" + ":" + "admin"; + authorizationHeader = "Basic " + new String(Base64.encodeBase64(authorization.getBytes())); + + // Prepare gdata header + String serviceType = binding.getServiceType(); + String usernane = binding.getUsername(); + String password = binding.getPassword(); + + //System.out.println("[Debug Info] binding.getServiceType()" + serviceType); + //System.out.println("[Debug Info] binding.getName()" +usernane); + //System.out.println("[Debug Info] binding.getPassword()" + password); + + googleService = new GoogleService(serviceType, ""); + if(binding.getUsername().equals("admin") == false && binding.getPassword().equals("admin")==false){ + googleService.setUserCredentials(binding.getUsername(),binding.getPassword()); + } + + // Create an HTTP client + HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); + connectionManager.getParams().setDefaultMaxConnectionsPerHost(10); + connectionManager.getParams().setConnectionTimeout(60000); + httpClient = new HttpClient(connectionManager); + } + + public Invoker createInvoker(Operation operation) { + + String operationName = operation.getName(); + + if (operationName.equals("get")) { + + // Determine the collection item type + itemXMLType = new DataTypeImpl>(String.class.getName(), String.class, String.class); + Class itemClass = operation.getOutputType().getPhysical(); + DataType outputType = operation.getOutputType(); + QName qname = outputType.getLogical().getElementName(); + qname = new QName(qname.getNamespaceURI(), itemClass.getSimpleName()); + itemClassType = new DataTypeImpl("java:complexType", itemClass, new XMLType(qname, null)); + + if (itemClassType.getPhysical() == com.google.gdata.data.Entry.class) { + supportsFeedEntries = true; + } + + String entryURI = this.binding.getURI(); + if(entryURI.contains("picasaweb.google.com/data/feed/api/")){ + entryURI = entryURI.replace("picasaweb.google.com/data/feed/api/", "picasaweb.google.com/data/entry/api/"); + } + + return new GdataBindingInvoker.GetInvoker(operation, entryURI, googleService, httpClient, authorizationHeader, this); + + } else if (operationName.equals("post")) { + + return new GdataBindingInvoker.PostInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader, this); + + } else if (operationName.equals("put")) { + + String entryURI = this.binding.getURI(); + if(entryURI.contains("picasaweb.google.com/data/feed/api/")){ + entryURI = entryURI.replace("picasaweb.google.com/data/feed/api/", "picasaweb.google.com/data/entry/api/"); + } + + return new GdataBindingInvoker.PutInvoker(operation, entryURI, googleService, httpClient, authorizationHeader, this); + + } else if (operationName.equals("delete")) { + + String entryURI = this.binding.getURI(); + if(entryURI.contains("picasaweb.google.com/data/feed/api/")){ + entryURI = entryURI.replace("picasaweb.google.com/data/feed/api/", "picasaweb.google.com/data/entry/api/"); + } + return new GdataBindingInvoker.DeleteInvoker(operation, entryURI, googleService, httpClient, authorizationHeader, this); + + } else if (operationName.equals("getFeed") || operationName.equals("getAll")) { + + return new GdataBindingInvoker.GetAllInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader, this); + + } else if (operationName.equals("postMedia")) { + + return new GdataBindingInvoker.PostMediaInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader, this); + + } else if (operationName.equals("putMedia")) { + + return new GdataBindingInvoker.PutMediaInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader, this); + + } else if (operationName.equals("query")) { + + return new GdataBindingInvoker.QueryInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader, this); + } + + return new GdataBindingInvoker(operation, binding.getURI(), googleService, httpClient, authorizationHeader, this); + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + // Configure the HTTP client credentials + Credentials credentials = new UsernamePasswordCredentials("admin", "admin"); + httpClient.getParams().setAuthenticationPreemptive(true); + URI uri = URI.create(binding.getURI()); + httpClient.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), credentials); + } + + public void stop() { + + } + + public boolean supportsOneWayInvocation() { + return false; + } + + /** + * Returns the mediator. + * + * @return + */ + Mediator getMediator() { + return mediator; + } + + /** + * Returns the item class type. + * + * @return + */ + DataType getItemClassType() { + return itemClassType; + } + + /** + * Returns the item XML type. + * + * @return + */ + DataType getItemXMLType() { + return itemXMLType; + } + + /** + * Returns true if the invoker should work with Atom feed entries. + * + * @return + */ + boolean supportsFeedEntries() { + return supportsFeedEntries; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataServiceBindingProvider.java new file mode 100644 index 0000000000..10faf74371 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataServiceBindingProvider.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.gdata.provider; + +import org.apache.tuscany.sca.binding.gdata.GdataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the Atom binding provider. + * + * @version $Rev$ $Date$ + */ +class GdataServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private GdataBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private String servletMapping; + private Mediator mediator; + + GdataServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + GdataBinding binding, + ServletHost servletHost, + MessageFactory messageFactory, + Mediator mediator) { + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.mediator = mediator; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + RuntimeComponentService componentService = (RuntimeComponentService)service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + + GdataBindingListenerServlet servlet = + new GdataBindingListenerServlet(wire, messageFactory, mediator, binding.getTitle()); + + servletMapping = binding.getURI(); + if (!servletMapping.endsWith("/")) { + servletMapping += "/"; + } + if (!servletMapping.endsWith("*")) { + servletMapping += "*"; + } + servletHost.addServletMapping(servletMapping, servlet); + + // Save the actual binding URI in the binding + binding.setURI(servletHost.getURLMapping(binding.getURI()).toString()); + } + + public void stop() { + servletHost.removeServletMapping(servletMapping); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..5e380eb4e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.gdata.provider.GdataBindingProviderFactory;model=org.apache.tuscany.sca.binding.gdata.GdataBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Constants.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Constants.java new file mode 100644 index 0000000000..6b4a6e2509 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Constants.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.gdata; + +public class Constants { + static long SLEEP_INTERVAL = 400L; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java new file mode 100644 index 0000000000..7d723a2883 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.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.sca.binding.gdata; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.PlainTextConstruct; + +public class Consumer { + + public static void main(String[] args) throws Exception { + + //Initialize the GData client service (Reference Binding test) + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite"); + CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient"); + + + Feed feed = testService.clientGetFeed(); + + //System.out.println("#Entries(Before post): "+ testService.clientGetFeed().getEntries().size()); + + /* + String entryID = "tag:blogger.com,1999:blog-4520949313432095990.post-973462497533349425"; + Entry entry = testService.clientGetEntry(entryID); + System.out.println("Entry id: " + entry.getId()); + */ + + Entry myEntry = new Entry(); + myEntry.setTitle(new PlainTextConstruct("titleByConsumer2")); + myEntry.setContent(new PlainTextConstruct("contentByConsmer2")); + testService.clientPost(myEntry); + + //System.out.println("#Entries(After post): "+ testService.clientGetFeed().getEntries().size()); + + String entryID = "tag:blogger.com,1999:blog-4520949313432095990.post-973462497533349425"; + Entry entry = testService.clientGetEntry(entryID); + //System.out.println("Entry id: " + entry.getId()); + + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/ConsumerProviderTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/ConsumerProviderTestCase.java new file mode 100644 index 0000000000..af7027ca90 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/ConsumerProviderTestCase.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.gdata; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.PlainTextConstruct; + +public class ConsumerProviderTestCase { + + private static SCADomain scaDomainProvider = null; + private static SCADomain scaDomainConsumer = null; + private static CustomerClient testService = null; + + @BeforeClass + public static void setUp() throws Exception { + // Setup the local GData servlet (Service Binding test) + scaDomainProvider = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Provider.composite"); + + // Initialize the GData client service (Reference Binding test) + scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Consumer.composite"); + testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient"); + } + + @AfterClass + public static void tearDown() { + scaDomainConsumer.close(); + scaDomainProvider.close(); + } + + + @Test + public void testClientGetFeed() throws Exception { + Feed feed = testService.clientGetFeed(); + //System.out.println(feed.getTitle().getPlainText()); + Assert.assertNotNull(feed); + // Given we are testing on the localhost providing feed, we know the + // feed title is "Feedtitle(LocalHostServlet)" + Assert.assertEquals("Feedtitle(LocalHostServlet)", feed.getTitle().getPlainText()); + } + + @Test + public void testClientGetEntry() throws Exception { + String entryID = "urn:uuid:customer-0"; + Entry entry = testService.clientGetEntry(entryID); + //System.out.println("entryID in testcase: " + entry.getId()); + Assert.assertEquals(entryID, entry.getId()); + } + + @Test + public void testClientPost() throws Exception { + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct("NewEntry title by Post")); + newEntry.setContent(new PlainTextConstruct("NewEntry Content by Post")); + Entry postedEntry = testService.clientPost(newEntry); + Assert.assertEquals("NewEntry title by Post", postedEntry.getTitle().getPlainText()); + } + + + + @Test + public void testClientPut() throws Exception { + String newTitleValue = "newTitleValueByPut"; + String entryID = "urn:uuid:customer-0"; + //System.out.println("Before clientPut"); + testService.clientPut(entryID, newTitleValue); + //System.out.println("After clientPut"); + Entry updatedEntry = testService.clientGetEntry(entryID); + //System.out.println("title: "+ updatedEntry.getTitle().getPlainText()); + Assert.assertEquals(newTitleValue, updatedEntry.getTitle().getPlainText()); + } + + + + @Test + public void testClientDelete() throws Exception { + + // We first create a new entry, then delete it + + // Post a new entry + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct("NewEntry title to be deleted")); + newEntry.setContent(new PlainTextConstruct("NewEntry Content to be delted")); + Entry confirmedNewEntry = testService.clientPost(newEntry); + + Thread.sleep(Constants.SLEEP_INTERVAL); + + Feed feed00 = testService.clientGetFeed(); + int entryNum00 = feed00.getEntries().size(); // The number of entries + // before deleting + //System.out.println("entryNum00:" + entryNum00); + + // Delete this newly created entry + String entryID = confirmedNewEntry.getId(); + Thread.sleep(300); + + //System.out.println("confirmed entry ID: " + confirmedNewEntry.getId()); + //System.out.println("confirmed entry title: " + confirmedNewEntry.getTitle().getPlainText()); + + //System.out.println("Before test clientDelete"); + testService.clientDelete(entryID); + //System.out.println("After test clientDelete"); + + Feed feed01 = testService.clientGetFeed(); + int entryNum01 = feed01.getEntries().size(); + //System.out.println("entryNum01:" + entryNum01); // The number of entries after deleting + + //assertEquals(1, entryNum00 - entryNum01); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java new file mode 100644 index 0000000000..7aa0a8961c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.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.sca.binding.gdata; + +import com.google.gdata.client.Query; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; + +public interface CustomerClient { + + Feed clientGetFeed() throws Exception; + + Entry clientGetEntry(String entryID) throws Exception; + + Entry clientPost(Entry entry) throws Exception; + + void clientDelete(String entryID) throws Exception; + + void clientPut(String entryID, String newTitle) throws Exception; + + Feed clientQuery(Query query) throws Exception; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java new file mode 100644 index 0000000000..5dc9c0079f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.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.sca.binding.gdata; + +import com.google.gdata.client.Query; +import com.google.gdata.data.Feed; +import com.google.gdata.data.Entry; +import com.google.gdata.data.PlainTextConstruct; + +import org.apache.tuscany.sca.binding.gdata.collection.Collection; +import org.apache.tuscany.sca.binding.gdata.collection.NotFoundException; +import org.osoa.sca.annotations.Reference; + +public class CustomerClientImpl implements CustomerClient { + + @Reference + public Collection resourceCollection; + + // Call Collection.getFeed() + public Feed clientGetFeed() throws Exception { + // Get all the entries from the provider, return in a single feed + //System.out.println(">>> get the feed from the provider service"); + Feed feed = resourceCollection.getFeed(); + //System.out.println("\n\n!!! Fetched feed title: " + feed.getTitle().getPlainText()); + int i = 0; + for (Object o : feed.getEntries()) { + com.google.gdata.data.Entry e = (com.google.gdata.data.Entry)o; + //System.out.print("Entry" + i + "\t"); + //System.out.println(" id = " + e.getId() + "\t title = " + e.getTitle().getPlainText()); + i++; + } + return feed; + } + + + // Call Collection.get(entryID) + public Entry clientGetEntry(String entryID) throws Exception { + // Get an existing entry based on its id + //System.out.println(">>> get an existing entry from the provider service"); + Entry entry = resourceCollection.get(entryID); + //System.out.println("\n\n!!! Entry retrieved with id=" + entry.getId() + // + " title=" + // + entry.getTitle().getPlainText()); + return entry; + } + + + // Call Collection.post(newEntry) + public Entry clientPost(Entry newEntry) throws Exception { + // Put a new entry to the provider + //System.out.println(">>> post a new entry to the provider service"); + Entry confirmedNewEntry = resourceCollection.post(newEntry); + //System.out.println("!!! New entry posted with id=" + confirmedNewEntry.getId() + // + " title=" + // + confirmedNewEntry.getTitle().getPlainText()); + return confirmedNewEntry; + } + + + // Call Collection.delete(newEntry) + public void clientDelete(String entryID) throws Exception { + // Put a new entry to the provider + //System.out.println(">>> delete an existing entry from the provider service"); + //System.out.println(">>> delete id=" + "urn:uuid:customer-1"); + resourceCollection.delete(entryID); + //System.out.println("!!! entry with id" + entryID); + } + + + + // Call Collection.put(entry, updatedTitle) + public void clientPut(String entryID, String newTitle) throws Exception { + + //System.out.println("clientPut"); + // Put a new entry to the provider + //System.out.println(">>> put id=" + entryID + " title=" + newTitle); + Entry entry = resourceCollection.get(entryID); + + //change the title of this entry + entry.setTitle(new PlainTextConstruct(newTitle)); + resourceCollection.put(entryID, entry); + //System.out.println("!!! Updated entry with id=" + entry.getId() + " title=" + entry.getTitle()); + } + + + + // Call Collection.getFeed() + public Feed clientQuery(Query query) throws Exception { + // Get all the entries from the provider, return in a single feed + //System.out.println(">>> query the service"); + Feed feed = resourceCollection.query(query); + //System.out.println("\n\n!!! Query result feed title: " + feed.getTitle().getPlainText()); + int i = 0; + for (Object o : feed.getEntries()) { + com.google.gdata.data.Entry e = (com.google.gdata.data.Entry)o; + //System.out.print("Entry" + i + "\t"); + //System.out.println(" id = " + e.getId() + "\t title = " + e.getTitle().getPlainText()); + i++; + } + return feed; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java new file mode 100644 index 0000000000..9c4d118cd6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.gdata; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import com.google.gdata.client.Query; +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.Link; +import com.google.gdata.data.PlainTextConstruct; + +import org.apache.tuscany.sca.binding.gdata.collection.Collection; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class CustomerCollectionImpl implements Collection { + + + private Map entries = new HashMap(); + + /** + * Default constructor that initializes collection with couple customer + * entries + */ + public CustomerCollectionImpl() { + + for (int i = 0; i < 4; i++) { + // id is supposed to be generated in a random way, but for the + // purpose of testing, we just make them as static ids + + // String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + + String id = "urn:uuid:customer-" + String.valueOf(i); + Entry entry = new Entry(); + entry.setId(id); + entry.setTitle(new PlainTextConstruct("EntryTitle_" + i)); + entry.setContent(new PlainTextConstruct("content_" + i)); + entry.setUpdated(DateTime.now()); + // FIXME: The following three lines of code need to be fixed to add + // HTML links. + Link link = new Link(); + link.setType(Link.Type.ATOM); + link.setRel(Link.Rel.ENTRY_EDIT); + link.setHref("http://localhost:8084/customer" + "/" + id); + entry.getLinks().add(link); + + // entry.addHtmlLink(""+id, "", "edit"); + // entry.addHtmlLink(""+id, "", "alternate"); + entries.put(id, entry); + //System.out.println(">>> id=" + id); + } + } + + public Entry post(Entry entry) { + //System.out.println(">>> ResourceCollectionImpl.post entry=" + entry.getTitle()); + + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + entry.setId(id); + + Link link = new Link(); + link.setType(Link.Type.ATOM); + link.setRel(Link.Rel.ENTRY_EDIT); + link.setHref("http://localhost:8084/customer" + "/" + id); + entry.getLinks().add(link); + + //entry.addLink("" + id, "edit"); entry.addLink("" + id, "alternate"); + entry.setUpdated(DateTime.now()); + + // entry.addHtmlLink("http://www.google.com", "languageType", "edit"); + // entry.addHtmlLink("http://www.google.com", "languageType", + // "alternate"); + + entries.put(id, entry); + //System.out.println(">>> ResourceCollectionImpl.post return id=" + id); + return entry; + } + + public Entry get(String id) { + //System.out.println(">>> ResourceCollectionImpl.get id= " + id); + return entries.get(id); + } + + public void put(String id, Entry entry) { + //System.out.println(">>> ResourceCollectionImpl.put id=" + id + " entry=" + entry.getTitle().getPlainText()); + entry.setUpdated(DateTime.now()); + entries.put(id, entry); + } + + + public void delete(String id) { + //System.out.println(">>> ResourceCollectionImpl.delete id=" + id); + entries.remove(id); + } + + + public Feed getFeed() { + //System.out.println(">>> ResourceCollectionImpl.get collection"); + + Feed feed = new Feed(); + feed.setTitle(new PlainTextConstruct("Feedtitle(LocalHostServlet)")); + feed.setSubtitle(new PlainTextConstruct("Subtitle: This is a sample feed")); + feed.setUpdated(DateTime.now()); + // FIXME: The following two lines of code need to be fixed + // feed.addHtmlLink("", "", ""); + // feed.addHtmlLink("", "languageType", "self"); + ArrayList entryList = new ArrayList(); + for (Entry entry : entries.values()) { + entryList.add(entry); + } + feed.setEntries(entryList); + + return feed; + } + + //FIXME: need to be modified + public Feed query(Query query) { + //System.out.println(">>> ResourceCollectionImpl.query collection "); + return getFeed(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleBloggerServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleBloggerServiceTestCase.java new file mode 100644 index 0000000000..a827677fd0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleBloggerServiceTestCase.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.sca.binding.gdata; + +import java.net.URL; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import com.google.gdata.client.Query; +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.PlainTextConstruct; + +public class GoogleBloggerServiceTestCase { + + private static SCADomain scaDomainConsumer = null; + private static CustomerClient testService = null; + + @BeforeClass + public static void setUp() throws Exception { + //Initialize the GData client service (Reference Binding test) + scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite"); + testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient"); + } + + @AfterClass + public static void tearDown(){ + scaDomainConsumer.close(); + } + + @Test + public void testClientGetFeed() throws Exception { + Feed feed = testService.clientGetFeed(); + //System.out.println("feed title: " + feed.getTitle().getPlainText()); + Assert.assertEquals("gdata binding tuscany test", feed.getTitle().getPlainText()); + } + + + @Test + public void testClientGetEntry() throws Exception { + String entryID = "8308734583601887890"; + Entry blogEntry = testService.clientGetEntry(entryID); + //System.out.println("Entry ID: " + blogEntry.getId()); + Assert.assertTrue(blogEntry.getId().endsWith(entryID)); + //System.out.println("------------------------------------------------------------\n\n"); + } + + + @Test + public void testClientPut() throws Exception { + String entryID = "2889832689497686762"; + String newBlogEntryTitle = "updatedTitleByTestCase2"; + testService.clientPut(entryID, newBlogEntryTitle); //update the title + Thread.sleep(Constants.SLEEP_INTERVAL); + Entry updatedEntry = testService.clientGetEntry(entryID); + Assert.assertEquals(newBlogEntryTitle, updatedEntry.getTitle().getPlainText()); + } + + + + @Test + public void testClientPost() throws Exception { + String blogEntryTitle = "titleByBloogerTestcase000"; + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct(blogEntryTitle)); + newEntry.setContent(new PlainTextConstruct("contentByBloggerTestCase000")); + Entry postedEntry = testService.clientPost(newEntry); + Assert.assertEquals(blogEntryTitle, postedEntry.getTitle().getPlainText()); + } + + + @Test + public void testClientDelete() throws Exception { + + //This test case might fail + //because Google blogger service has limitation on new posts allowed everyday/every hour? + + //System.out.println("testClientDelete"); + //We create a new post, and then delete it + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct("blogEntryShouldNotApear")); + newEntry.setContent(new PlainTextConstruct("contentByBloggerShouldNotAppear")); + Entry postedEntry = testService.clientPost(newEntry); + Thread.sleep(Constants.SLEEP_INTERVAL); + int idStartPosition = postedEntry.getId().lastIndexOf("-"); + String postedEntryID = postedEntry.getId().substring(idStartPosition+1); + //System.out.println("postedEntryID: " + postedEntryID ); + + //Before deletion + Entry entry00 = testService.clientGetEntry(postedEntryID); + //System.out.println("Before Deleteion: " + entry00.getId()); + + //Delete this entry + testService.clientDelete(postedEntryID); + + //Worked: this newly posted entry did not appear in the blogspot website, + //But we need a Junit assertion here + //Link: http://haibotuscany.blogspot.com/feeds/posts/default/ + //FIXME: Need an assertion here + //Assert(....); + } + + + @Test + public void testClientQuery() throws Exception { + Query myQuery = new Query(new URL("http://haibotuscany.blogspot.com/feeds/posts/default")); + myQuery.setMaxResults(100); + //myQuery.setUpdatedMin(startTime); + myQuery.setUpdatedMax(DateTime.now()); + Feed resultFeed = testService.clientQuery(myQuery); + //System.out.println("Query result feed title: " + resultFeed.getTitle().getPlainText()); + //System.out.println("Query result entry number: "+ resultFeed.getEntries().size()); + //assertEquals("gdata binding tuscany test", resultFeed.getTitle().getPlainText()); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleCalendarServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleCalendarServiceTestCase.java new file mode 100644 index 0000000000..9c3122e134 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleCalendarServiceTestCase.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.gdata; + +import java.net.URL; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.google.gdata.client.Query; +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.PlainTextConstruct; + +public class GoogleCalendarServiceTestCase { + + private static SCADomain scaDomainConsumer = null; + private static CustomerClient testService = null; + + public GoogleCalendarServiceTestCase() { + + } + + @BeforeClass + public static void setUp() throws Exception { + //Initialize the GData client service (Reference Binding test) + scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleCalendar.composite"); + testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient"); + } + + @AfterClass + public static void tearDown(){ + scaDomainConsumer.close(); + } + + @Test + public void testClientGetFeed() throws Exception { + Feed feed = testService.clientGetFeed(); + //System.out.println("feed title: " + feed.getTitle().getPlainText()); + Assert.assertEquals("gsoc gosc", feed.getTitle().getPlainText()); + } + + + @Test + public void testClientGetEntry() throws Exception { + String entryID = "1c76lcl70jg9r0fm18rcbneea8"; + Entry blogEntry = testService.clientGetEntry(entryID); + //System.out.println("Entry ID: " + blogEntry.getId()); + Assert.assertTrue(blogEntry.getId().endsWith(entryID)); + //System.out.println("------------------------------------------------------------\n\n"); + } + + + @Test + public void testClientPut() throws Exception { + String entryID = "1c76lcl70jg9r0fm18rcbneea8"; + String newBlogEntryTitle = "updatedTitleByGoogleContactsConsumerTestCase"; + testService.clientPut(entryID, newBlogEntryTitle); //update the title + Thread.sleep(Constants.SLEEP_INTERVAL); + Entry updatedEntry = testService.clientGetEntry(entryID); + Assert.assertEquals(newBlogEntryTitle, updatedEntry.getTitle().getPlainText()); + } + + @Test + public void testClientPost() throws Exception { + String blogEntryTitle = "titleByGoogleCalendarTestcase"; + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct(blogEntryTitle)); + newEntry.setContent(new PlainTextConstruct("contentByGoogleCalendarTestCase")); + Entry postedEntry = testService.clientPost(newEntry); + Assert.assertEquals(blogEntryTitle, postedEntry.getTitle().getPlainText()); + } + + @Test + public void testClientDelete() throws Exception { + + //This test case might fail + //because Google blogger service has limitation on new posts allowed everyday/every hour? + + //System.out.println("testClientDelete"); + //We create a new post, and then delete it + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct("calendarEntryShouldNotApear")); + newEntry.setContent(new PlainTextConstruct("calendarByBloggerShouldNotAppear")); + Entry postedEntry = testService.clientPost(newEntry); + Thread.sleep(Constants.SLEEP_INTERVAL); + + //System.out.println("ID: " + postedEntry.getId()); + + int idStartPosition = postedEntry.getId().lastIndexOf("/"); + String postedEntryID = postedEntry.getId().substring(idStartPosition+1); + //System.out.println("postedEntryID: " + postedEntryID ); + + //Before deletion + Entry entry00 = testService.clientGetEntry(postedEntryID); + //System.out.println("Before Deleteion: " + entry00.getId()); + + //Delete this entry + testService.clientDelete(postedEntryID); + + //Worked: this newly posted entry did not appear in the contact list + //But we need a Junit assertion here + //Link: http://haibotuscany.blogspot.com/feeds/posts/default/ + //FIXME: Need an assertion here + //Assert(....); + } + + + @Test + public void testClientQuery() throws Exception { + Query myQuery = new Query(new URL("http://www.google.com/calendar/feeds/haibotuscany@gmail.com/private/full")); + myQuery.setMaxResults(100); + //myQuery.setUpdatedMin(startTime); + myQuery.setUpdatedMax(DateTime.now()); + + //Google Calendar service supports full-text search + String queryString = "event0"; + myQuery.setFullTextQuery(queryString); + + Feed resultFeed = testService.clientQuery(myQuery); + //System.out.println("Query result feed title: " + resultFeed.getTitle().getPlainText()); + //System.out.println("Query result entry number: "+ resultFeed.getEntries().size()); + //assertEquals("gdata binding tuscany test", resultFeed.getTitle().getPlainText()); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleContactsServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleContactsServiceTestCase.java new file mode 100644 index 0000000000..1f261dfc90 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleContactsServiceTestCase.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.gdata; + +import java.net.URL; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.google.gdata.client.Query; +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.PlainTextConstruct; + +public class GoogleContactsServiceTestCase { + + private static SCADomain scaDomainConsumer = null; + private static CustomerClient testService = null; + + public GoogleContactsServiceTestCase(){ + + } + + @BeforeClass + public static void setUp() throws Exception { + //Initialize the GData client service (Reference Binding test) + scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleContacts.composite"); + testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient"); + } + + @AfterClass + public static void tearDown(){ + scaDomainConsumer.close(); + } + + @Test + public void testClientGetFeed() throws Exception { + Feed feed = testService.clientGetFeed(); + System.out.println("feed title: " + feed.getTitle().getPlainText()); + Assert.assertEquals("Haibo Zhao's Contacts", feed.getTitle().getPlainText()); + } + + + @Test + public void testClientGetEntry() throws Exception { + String entryID = "12feeeb38ab87365"; + Entry contactEntry = testService.clientGetEntry(entryID); + //System.out.println("Entry ID: " + contactEntry.getId()); + Assert.assertTrue(contactEntry.getId().endsWith(entryID)); + } + + + @Test + public void testClientPut() throws Exception { + String entryID = "12feeeb38ab87365"; + String newBlogEntryTitle = "updatedTitleByGoogleContactsConsumerTestCase"; + testService.clientPut(entryID, newBlogEntryTitle); //update the title + Thread.sleep(Constants.SLEEP_INTERVAL); + Entry updatedEntry = testService.clientGetEntry(entryID); + Assert.assertEquals(newBlogEntryTitle, updatedEntry.getTitle().getPlainText()); + } + + + + @Test + public void testClientPost() throws Exception { + String blogEntryTitle = "titleByGoogleContactsTestcase"; + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct(blogEntryTitle)); + newEntry.setContent(new PlainTextConstruct("contentByGoogleContactsTestCase")); + Entry postedEntry = testService.clientPost(newEntry); + Assert.assertEquals(blogEntryTitle, postedEntry.getTitle().getPlainText()); + } + + + @Test + public void testClientDelete() throws Exception { + + //This test case might fail + //because Google blogger service has limitation on new posts allowed everyday/every hour? + + //System.out.println("testClientDelete"); + //We create a new post, and then delete it + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct("contactEntryShouldNotApear")); + newEntry.setContent(new PlainTextConstruct("contactByBloggerShouldNotAppear")); + Entry postedEntry = testService.clientPost(newEntry); + Thread.sleep(Constants.SLEEP_INTERVAL); + + //System.out.println("ID: " + postedEntry.getId()); + + int idStartPosition = postedEntry.getId().lastIndexOf("/"); + String postedEntryID = postedEntry.getId().substring(idStartPosition+1); + //System.out.println("postedEntryID: " + postedEntryID ); + + //Before deletion + for (int i = 0; i < 5; i++) { // make 5 attempts because of timing issues + try { + Entry entry00 = testService.clientGetEntry(postedEntryID); + //System.out.println("Before Deletion: " + entry00.getId()); + break; // get was successful + } catch (Exception e) { + if (i < 4) { + System.out.println("Get failed, retrying..."); + } else { + throw e; // final attempt, give up + } + } + } + + //Delete this entry + for (int i = 0; i < 5; i++) { // make 5 attempts because of timing issues + try { + testService.clientDelete(postedEntryID); + break; // delete was successful + } catch (Exception e) { + if (i < 4) { + System.out.println("Delete failed, retrying..."); + } else { + throw e; // final attempt, give up + } + } + } + + //Worked: this newly posted entry did not appear in the contact list + //But we need a Junit assertion here + //Link: http://haibotuscany.blogspot.com/feeds/posts/default/ + //FIXME: Need an assertion here + //Assert(....); + } + + + @Test + public void testClientQuery() throws Exception { + Query myQuery = new Query(new URL("http://www.google.com/m8/feeds/contacts/default/base")); + myQuery.setMaxResults(100); + //myQuery.setUpdatedMin(startTime); + myQuery.setUpdatedMax(DateTime.now()); + Feed resultFeed = testService.clientQuery(myQuery); + //System.out.println("Query result feed title: " + resultFeed.getTitle().getPlainText()); + //System.out.println("Query result entry number: "+ resultFeed.getEntries().size()); + //assertEquals("gdata binding tuscany test", resultFeed.getTitle().getPlainText()); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleWebAlbumServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleWebAlbumServiceTestCase.java new file mode 100644 index 0000000000..459c2f6933 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleWebAlbumServiceTestCase.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.sca.binding.gdata; + +import java.net.URL; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import com.google.gdata.client.Query; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; + +public class GoogleWebAlbumServiceTestCase { + + private static SCADomain scaDomainConsumer = null; + private static CustomerClient testService = null; + + public GoogleWebAlbumServiceTestCase(){ + + } + + @BeforeClass + public static void setUp() throws Exception { + //Initialize the GData client service (Reference Binding test) + scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleWebAlbum.composite"); + testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient"); + } + + @AfterClass + public static void tearDown(){ + scaDomainConsumer.close(); + } + + @Test + public void testClientGetFeed() throws Exception { + Feed feed = testService.clientGetFeed(); + //System.out.println("feed title: " + feed.getTitle().getPlainText()); + Assert.assertEquals("flowers", feed.getTitle().getPlainText()); + } + + + + + @Test + public void testClientGetEntry() throws Exception { + String entryID = "photoid/5233468700029715874"; + Entry contactEntry = testService.clientGetEntry(entryID); + //System.out.println("Entry ID: " + contactEntry.getId()); + Assert.assertTrue(contactEntry.getId().endsWith(entryID)); + //System.out.println("------------------------------------------------------------\n\n"); + } + + + @Test + public void testClientQuery() throws Exception { + String feedUrlString = "http://picasaweb.google.com/data/feed/api/user/haibotuscany/album/flowers"; + URL feedURL = new URL(feedUrlString); + Query myQuery = new Query(feedURL); + myQuery.setMaxResults(100); + myQuery.setFullTextQuery("photo"); + Feed resultFeed = testService.clientQuery(myQuery); + //System.out.println("Query result feed title: " + resultFeed.getTitle().getPlainText()); + //System.out.println("Query result entry number: "+ resultFeed.getEntries().size()); + //assertEquals("gdata binding tuscany test", resultFeed.getTitle().getPlainText()); + } + + + + @Test + public void testClientPut() throws Exception { + String entryID = "photoid/5233468700029715874"; + String newBlogEntryTitle = "updatedTitle:dog"; + testService.clientPut(entryID, newBlogEntryTitle); //update the title + Thread.sleep(Constants.SLEEP_INTERVAL); + Entry updatedEntry = testService.clientGetEntry(entryID); + Assert.assertEquals(newBlogEntryTitle, updatedEntry.getTitle().getPlainText()); + } + + + @Test + @Ignore("Not testing anything") + public void testClientDelete() throws Exception { + + //Tested and it worked, but only once because we can not delete the same entry twice + String entryID = "photoid/5233468698153151618"; + + //Delete this entry + //To test, change the entryID + //testService.clientDelete(entryID); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Provider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Provider.java new file mode 100644 index 0000000000..21bff30256 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/Provider.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.sca.binding.gdata; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Provider { + + public static void main(String[] args) { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Provider.composite"); + System.out.println("Provider.composite ready..."); + + try { + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/StartLocalhostServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/StartLocalhostServlet.java new file mode 100644 index 0000000000..2773398426 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/StartLocalhostServlet.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.sca.binding.gdata; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class StartLocalhostServlet { + + public static void main(String[] args) { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Provider.composite"); + System.out.println("Provider.composite ready..."); + + try { + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/log4j.properties b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/log4j.properties new file mode 100644 index 0000000000..33eaf11c1f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/log4j.properties @@ -0,0 +1,25 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Set root logger level to WARN and its only appender to CONSOLE +log4j.rootLogger=INFO, CONSOLE + + +# Console appender +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%d{ABSOLUTE} %-5p %x - %m\n diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite new file mode 100644 index 0000000000..a7941a2056 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite new file mode 100644 index 0000000000..078873c44f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleCalendar.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleCalendar.composite new file mode 100644 index 0000000000..7e0c925482 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleCalendar.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleContacts.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleContacts.composite new file mode 100644 index 0000000000..bc1ea7a8a9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleContacts.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleWebAlbum.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleWebAlbum.composite new file mode 100644 index 0000000000..99db48cc4e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/ConsumerGoogleWebAlbum.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite new file mode 100644 index 0000000000..a4cf00dc84 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/LICENSE @@ -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, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/NOTICE new file mode 100644 index 0000000000..841fb69681 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/NOTICE @@ -0,0 +1,8 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/pom.xml new file mode 100644 index 0000000000..2dcbef6f7b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/pom.xml @@ -0,0 +1,79 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-gdata + Apache Tuscany SCA Gdata Binding Extension + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.gdata + ${pom.name} + org.apache.tuscany.sca.binding.gdata* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java new file mode 100644 index 0000000000..a3a0b834cd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.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.sca.binding.gdata; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * Gdata binding model. + * + * @version $Rev$ $Date$ + */ +public interface GdataBinding extends Binding { + + /** + * Returns the title of the GData collection. + * @return + */ + String getTitle(); + + /** + * Sets the title of the GData collection. + * @param title + */ + void setTitle(String title); + + /** + * Returns the username to be used when authenticating with GData Services + * @return + */ + String getUsername(); + + /** + * Sets the username to be used when authenticating with GData Services + * @param username + */ + void setUsername(String username); + + /** + * Returns the password to be used when authenticating with GData Services + * @return + */ + String getPassword(); + + /** + * Sets the password to be used when authenticating with GData Services + * @param password + */ + void setPassword(String password); + + /** + * Returns the type os service being used + * @return + */ + String getServiceType(); + + /** + * Sets the type of service being used + * @param serviceType + */ + void setServiceType(String serviceType); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBindingFactory.java new file mode 100644 index 0000000000..5cfc688dcb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBindingFactory.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.sca.binding.gdata; + +/** + * Factory for the GData binding + * + * @version $Rev$ $Date$ + */ +public interface GdataBindingFactory { + + /** + * Creates a new GData binding. + * @return the new GData binding + */ + GdataBinding createGdataBinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingFactoryImpl.java new file mode 100644 index 0000000000..87f3597248 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingFactoryImpl.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.sca.binding.gdata.impl; + +import org.apache.tuscany.sca.binding.gdata.GdataBinding; +import org.apache.tuscany.sca.binding.gdata.GdataBindingFactory; + +/** + * Factory for the GData binding model. + * + * @version $Rev$ $Date$ + */ +public class GdataBindingFactoryImpl implements GdataBindingFactory { + + public GdataBinding createGdataBinding() { + return new GdataBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java new file mode 100644 index 0000000000..b4b0a5f449 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.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.sca.binding.gdata.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.gdata.GdataBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Implementation of the GData binding model. + * + * @version $Rev$ $Date$ + */ +class GdataBindingImpl implements GdataBinding, PolicySetAttachPoint { + + private String name; + private String uri; + private String title; + private String username; + private String password; + private String serviceType; + + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public String getTitle() { + return title; + } + + public String getUsername(){ + return username; + } + + public String getPassword(){ + return password; + } + + public String getServiceType(){ + return serviceType; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + public boolean isUnresolved() { + // The binding is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + //Policy related getters/setters + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java new file mode 100644 index 0000000000..dea035559b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.impl; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.binding.gdata.GdataBinding; +import org.apache.tuscany.sca.binding.gdata.GdataBindingFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + +/** + * A processor for elements. + * + * @version $Rev$ $Date$ + */ +public class GdataBindingProcessor implements StAXArtifactProcessor { + + private QName BINDING_GDATA = new QName("http://tuscany.apache.org/xmlns/sca/1.0", "binding.gdata"); + + private final GdataBindingFactory factory; + + public GdataBindingProcessor(ModelFactoryExtensionPoint modelFactories) { + this.factory = modelFactories.getFactory(GdataBindingFactory.class); + //System.out.println("[Debug Info]GdataBindingProcessor reached"); + } + + public QName getArtifactType() { + return BINDING_GDATA; + } + + public Class getModelType() { + return GdataBinding.class; + } + + public GdataBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + GdataBinding gdataBinding = factory.createGdataBinding(); + + String name = reader.getAttributeValue(null, "name"); + if (name != null) { + gdataBinding.setName(name); + } + + String uri = reader.getAttributeValue(null, "uri"); + if (uri != null) { + gdataBinding.setURI(uri); + } + + String serviceType = reader.getAttributeValue(null, "serviceType"); + if (serviceType != null) { + gdataBinding.setServiceType(serviceType); + } + + String username = reader.getAttributeValue(null, "username"); + if (username != null) { + gdataBinding.setUsername(username); + } + + String password = reader.getAttributeValue(null, "password"); + if (password != null) { + gdataBinding.setPassword(password); + } + + + return gdataBinding; + } + + public void write(GdataBinding gdataBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + writer.writeStartElement(BINDING_GDATA.getNamespaceURI(), BINDING_GDATA.getLocalPart()); + + if (gdataBinding.getName() != null) { + writer.writeAttribute("name", gdataBinding.getName()); + } + + if (gdataBinding.getURI() != null) { + writer.writeAttribute("uri", gdataBinding.getURI()); + } + + if (gdataBinding.getServiceType() != null) { + writer.writeAttribute("serviceType", gdataBinding.getServiceType()); + } + + if (gdataBinding.getUsername() != null) { + writer.writeAttribute("username", gdataBinding.getUsername()); + } + + if (gdataBinding.getPassword() != null) { + writer.writeAttribute("password", gdataBinding.getPassword()); + } + + writer.writeEndElement(); + } + + + public void resolve(GdataBinding gdataBinding, ModelResolver resolver) throws ContributionResolveException { + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.gdata.GdataBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.gdata.GdataBindingFactory new file mode 100644 index 0000000000..21688a62a6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.gdata.GdataBindingFactory @@ -0,0 +1,18 @@ +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the model factory +org.apache.tuscany.sca.binding.gdata.impl.GdataBindingFactoryImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..4e71818f7b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-gdata/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.gdata.impl.GdataBindingProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.gdata,model=org.apache.tuscany.sca.binding.gdata.GdataBinding,factory=org.apache.tuscany.sca.binding.gdata.GdataBindingFactory \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/pom.xml new file mode 100644 index 0000000000..15ed1e5d19 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/pom.xml @@ -0,0 +1,107 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-hessian + Apache Tuscany SCA Hessian Binding Extension + + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + com.caucho + hessian + 3.1.5 + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + + javax.servlet + servlet-api + 2.5 + provided + + + + junit + junit + 4.5 + test + + + + org.apache.tuscany.sca + tuscany-node-impl + 1.6-SNAPSHOT + test + + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.hessian + ${pom.name} + org.apache.tuscany.sca.binding.hessian* + * + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBinding.java new file mode 100644 index 0000000000..7f90d78424 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBinding.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.hessian.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; + +public class HessianBinding implements Binding { + + // properties required to implement the Tuscany + // binding extension SPI + private String uri = null; + private String name = null; + private boolean unresolved = false; + private List extensions = new ArrayList(); + + public HessianBinding() { + super(); + } + + /** + * Returns the binding URI. + * + * @return the binding URI + */ + public String getURI() { + return this.uri; + } + + /** + * Sets the binding URI. + * + * @param uri the binding URI + */ + public void setURI(String uri) { + this.uri = uri; + } + + /** + * Returns the binding name. + * + * @return the binding name + */ + public String getName() { + return this.name; + } + + /** + * Sets the binding name. + * + * @param name the binding name + */ + public void setName(String name) { + this.name = name; + } + + public boolean isUnresolved() { + return this.unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public List getExtensions() { + return extensions; + } + + /** + * Clone the binding + */ + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBindingException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBindingException.java new file mode 100644 index 0000000000..456f0d11ba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBindingException.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.sca.binding.hessian.impl; + +public class HessianBindingException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public HessianBindingException() { + super(); + } + + public HessianBindingException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + + public HessianBindingException(String arg0) { + super(arg0); + } + + public HessianBindingException(Throwable arg0) { + super(arg0); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBindingProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBindingProcessor.java new file mode 100644 index 0000000000..f5564b926b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/impl/HessianBindingProcessor.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.hessian.impl; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; +import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.policy.PolicyFactory; + +public class HessianBindingProcessor implements StAXArtifactProcessor { + + private QName BINDING_HESSIAN = new QName("http://hessian", "binding.hessian"); + + private PolicyFactory policyFactory; + private PolicyAttachPointProcessor policyProcessor; + private Monitor monitor; + + public HessianBindingProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void warning(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + new ProblemImpl(this.getClass().getName(), "binding-hessian-validation-messages", Severity.WARNING, + model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + new ProblemImpl(this.getClass().getName(), "binding-hessian-validation-messages", Severity.ERROR, + model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return BINDING_HESSIAN; + } + + public Class getModelType() { + return HessianBinding.class; + } + + public HessianBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + HessianBinding hessianBinding = new HessianBinding(); + + // Read policies + policyProcessor.readPolicies(hessianBinding, reader); + + // Read binding name + String name = reader.getAttributeValue(null, "name"); + if (name != null) { + hessianBinding.setName(name); + } + + // Read binding URI + String uri = reader.getAttributeValue(null, "uri"); + if (uri != null) { + hessianBinding.setURI(uri); + } + + return hessianBinding; + } + + public void resolve(HessianBinding model, ModelResolver resolver) throws ContributionResolveException { + } + + public void write(HessianBinding hessianBinding, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + policyProcessor.writePolicyPrefixes(hessianBinding, writer); + writer.writeStartElement(BINDING_HESSIAN.getNamespaceURI(), BINDING_HESSIAN.getLocalPart()); + policyProcessor.writePolicyAttributes(hessianBinding, writer); + + if (hessianBinding.getName() != null) { + writer.writeAttribute("name", hessianBinding.getName()); + } + + if (hessianBinding.getURI() != null) { + writer.writeAttribute("uri", hessianBinding.getURI()); + } + + writer.writeEndElement(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianBindingInvoker.java new file mode 100644 index 0000000000..9d6ede2dbc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianBindingInvoker.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.sca.binding.hessian.provider; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.binding.hessian.impl.HessianBinding; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +import com.caucho.hessian.client.HessianProxyFactory; + +public class HessianBindingInvoker implements Invoker { + + private String serviceURL; + private Interface homeImpl; + + HessianBindingInvoker(Interface homeImpl, HessianBinding binding) { + this.serviceURL = binding.getURI(); + this.homeImpl = homeImpl; + } + + public Message invoke(Message msg) { + try { + Method method = ((JavaOperation)msg.getOperation()).getJavaMethod(); + Object[] args = msg.getBody(); + + HessianProxyFactory proxyFactory = new HessianProxyFactory(); + Object service = proxyFactory.create(loadClass(homeImpl.toString()), serviceURL); + Object result = null; + result = method.invoke(service, args); + msg.setBody(result); + } catch (Throwable e) { + e.printStackTrace(); + if (e instanceof InvocationTargetException) + e = ((InvocationTargetException)e).getTargetException(); + msg.setFaultBody(e); + } + return msg; + } + + private Class loadClass(String className) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + try { + if (loader != null) + return Class.forName(className, false, loader); + else + return Class.forName(className); + } catch (Exception e) { + + } + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianBindingProviderFactory.java new file mode 100644 index 0000000000..77a5f6f675 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianBindingProviderFactory.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.sca.binding.hessian.provider; + +import java.util.List; + +import org.apache.tuscany.sca.binding.hessian.impl.HessianBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +public class HessianBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private ServletHost servletHost; + + public HessianBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + List hosts = servletHosts.getServletHosts(); + if (!hosts.isEmpty()) { + this.servletHost = hosts.get(0); + } + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + messageFactory = modelFactories.getFactory(MessageFactory.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + HessianBinding binding) { + return new HessianReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + HessianBinding binding) { + return new HessianServiceBindingProvider(component, service, binding, messageFactory, servletHost); + } + + public Class getModelType() { + return HessianBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianReferenceBindingProvider.java new file mode 100644 index 0000000000..27711932d7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianReferenceBindingProvider.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.sca.binding.hessian.provider; + +import org.apache.tuscany.sca.binding.hessian.impl.HessianBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +public class HessianReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private HessianBinding hessianBinding; + + public HessianReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + HessianBinding binding) { + this.reference = reference; + this.hessianBinding = binding; + } + + public Invoker createInvoker(Operation operation) { + return new HessianBindingInvoker(getBindingInterfaceContract().getInterface(), hessianBinding); + } + + public boolean supportsOneWayInvocation() { + return true; + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + + } + + public void stop() { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianServiceBindingProvider.java new file mode 100644 index 0000000000..3e4922dc13 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianServiceBindingProvider.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.sca.binding.hessian.provider; + +import java.util.logging.Logger; + +import javax.servlet.Servlet; + +import org.apache.tuscany.sca.binding.hessian.impl.HessianBinding; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class HessianServiceBindingProvider implements ServiceBindingProvider { + private static final Logger logger = Logger.getLogger(HessianServiceBindingProvider.class.getName()); + + private RuntimeComponent component; + private RuntimeComponentService service; + private HessianBinding hessianBinding; + private MessageFactory messageFactory; + private ServletHost servletHost; + private String servletMapping; + + public HessianServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + HessianBinding binding, + MessageFactory messageFactory, + ServletHost servletHost) { + this.component = component; + this.service = service; + this.hessianBinding = binding; + this.messageFactory = messageFactory; + this.servletHost = servletHost; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return true; + } + + public void start() { + Servlet servlet = null; + Interface homeImpl = service.getInterfaceContract().getInterface(); + RuntimeWire wire = service.getRuntimeWire(hessianBinding); + servlet = new HessianServiceListenerServlet(homeImpl, wire, messageFactory); + + if (servlet == null) { + throw new IllegalStateException("No get or service method found on the service"); + } + + servletMapping = hessianBinding.getURI(); + servletHost.addServletMapping(servletMapping, servlet); + + // Save the actual binding URI in the binding + hessianBinding.setURI(servletHost.getURLMapping(hessianBinding.getURI()).toString()); + } + + public void stop() { + servletHost.removeServletMapping(servletMapping); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianServiceListenerServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianServiceListenerServlet.java new file mode 100644 index 0000000000..de9b4927c6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/java/org/apache/tuscany/sca/binding/hessian/provider/HessianServiceListenerServlet.java @@ -0,0 +1,335 @@ +/* + * Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved. + * + * The Apache Software License, Version 1.1 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Caucho Technology (http://www.caucho.com/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "Hessian", "Resin", and "Caucho" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * info@caucho.com. + * + * 5. Products derived from this software may not be called "Resin" + * nor may "Resin" appear in their names without prior written + * permission of Caucho Technology. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @author Scott Ferguson + */ + +package org.apache.tuscany.sca.binding.hessian.provider; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +import javax.servlet.GenericServlet; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +import com.caucho.hessian.io.AbstractHessianInput; +import com.caucho.hessian.io.AbstractHessianOutput; +import com.caucho.hessian.io.Hessian2Input; +import com.caucho.hessian.io.Hessian2Output; +import com.caucho.hessian.io.HessianOutput; +import com.caucho.hessian.io.SerializerFactory; +import com.caucho.services.server.ServiceContext; + +/** + * Servlet for serving Hessian services. + */ +public class HessianServiceListenerServlet extends GenericServlet { + + private static final Logger logger = Logger.getLogger(HessianServiceListenerServlet.class.getName()); + + private Interface homeImpl; + private RuntimeWire wire; + private MessageFactory messageFactory; + + private SerializerFactory _serializerFactory; + + private Map _operationMap = new Hashtable(); + + public HessianServiceListenerServlet(Interface homeImpl, RuntimeWire wire, MessageFactory messageFactory) { + this.homeImpl = homeImpl; + this.wire = wire; + this.messageFactory = messageFactory; + + List operations = homeImpl.getOperations(); + for (int i = 0; i < operations.size(); i++) { + JavaOperation op = (JavaOperation)operations.get(i); + Method method = op.getJavaMethod(); + if (_operationMap.get(method.getName()) == null) + _operationMap.put(method.getName(), op); + + Class[] param = method.getParameterTypes(); + String mangledName = method.getName() + "__" + param.length; + _operationMap.put(mangledName, op); + _operationMap.put(mangleName(method, false), op); + } + } + + public String getServletInfo() { + return "Tuscany Binding Hessian Servlet"; + } + + /** + * Sets the serializer factory. + */ + public void setSerializerFactory(SerializerFactory factory) { + _serializerFactory = factory; + } + + /** + * Gets the serializer factory. + */ + public SerializerFactory getSerializerFactory() { + if (_serializerFactory == null) + _serializerFactory = new SerializerFactory(); + + return _serializerFactory; + } + + /** + * Sets the serializer send collection java type. + */ + public void setSendCollectionType(boolean sendType) { + getSerializerFactory().setSendCollectionType(sendType); + } + + /** + * Execute a request. The path-info of the request selects the bean. Once + * the bean's selected, it will be applied. + */ + public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException { + HttpServletRequest req = (HttpServletRequest)request; + HttpServletResponse res = (HttpServletResponse)response; + + if (!req.getMethod().equals("POST")) { + res.setStatus(500, "Hessian Requires POST"); + PrintWriter out = res.getWriter(); + res.setContentType("text/html"); + out.println("

Hessian Requires POST

"); + return; + } + + String serviceId = req.getPathInfo(); + String objectId = req.getParameter("id"); + if (objectId == null) + objectId = req.getParameter("ejbid"); + + ServiceContext.begin(req, serviceId, objectId); + + try { + InputStream is = request.getInputStream(); + OutputStream os = response.getOutputStream(); + + Hessian2Input in = new Hessian2Input(is); + AbstractHessianOutput out; + + SerializerFactory serializerFactory = getSerializerFactory(); + + in.setSerializerFactory(serializerFactory); + + int code = in.read(); + + if (code != 'c') { + // XXX: deflate + throw new IOException("expected 'c' in hessian input at " + code); + } + + int major = in.read(); + int minor = in.read(); + + if (major >= 2) + out = new Hessian2Output(os); + else + out = new HessianOutput(os); + + out.setSerializerFactory(serializerFactory); + + invoke(in, out); + + out.close(); + } catch (RuntimeException e) { + throw e; + } catch (ServletException e) { + throw e; + } catch (Throwable e) { + throw new ServletException(e); + } finally { + ServiceContext.end(); + } + } + + private String mangleName(Method method, boolean isFull) { + StringBuffer sb = new StringBuffer(); + sb.append(method.getName()); + Class[] params = method.getParameterTypes(); + for (int i = 0; i < params.length; i++) { + sb.append('_'); + sb.append(mangleClass(params[i], isFull)); + } + return sb.toString(); + } + + private String mangleClass(Class cl, boolean isFull) { + String name = cl.getName(); + if (name.equals("boolean") || name.equals("java.lang.Boolean")) + return "boolean"; + else if (name.equals("int") || name.equals("java.lang.Integer") + || name.equals("short") + || name.equals("java.lang.Short") + || name.equals("byte") + || name.equals("java.lang.Byte")) + return "int"; + else if (name.equals("long") || name.equals("java.lang.Long")) + return "long"; + else if (name.equals("float") || name.equals("java.lang.Float") + || name.equals("double") + || name.equals("java.lang.Double")) + return "double"; + else if (name.equals("java.lang.String") || name.equals("com.caucho.util.CharBuffer") + || name.equals("char") + || name.equals("java.lang.Character") + || name.equals("java.io.Reader")) + return "string"; + else if (name.equals("java.util.Date") || name.equals("com.caucho.util.QDate")) + return "date"; + else if (InputStream.class.isAssignableFrom(cl) || name.equals("[B")) + return "binary"; + else if (cl.isArray()) { + return "[" + mangleClass(cl.getComponentType(), isFull); + } else if (name.equals("org.w3c.dom.Node") || name.equals("org.w3c.dom.Element") + || name.equals("org.w3c.dom.Document")) + return "xml"; + else if (isFull) + return name; + else { + int p = name.lastIndexOf('.'); + if (p > 0) + return name.substring(p + 1); + else + return name; + } + } + + public void invoke(AbstractHessianInput in, AbstractHessianOutput out) throws Exception { + ServiceContext context = ServiceContext.getContext(); + + // backward compatibility for some frameworks that don't read + // the call type first + in.skipOptionalCall(); + + String header; + while ((header = in.readHeader()) != null) { + Object value = in.readObject(); + context.addHeader(header, value); + } + + String methodName = in.readMethod(); + Method method = null; + JavaOperation operation = _operationMap.get(methodName); + if (operation != null) + method = operation.getJavaMethod(); + + if (method != null) { + } else if ("_hessian_getAttribute".equals(methodName)) { + String attrName = in.readString(); + in.completeCall(); + String value = null; + if ("java.api.class".equals(attrName)) + value = homeImpl.toString(); + else if ("java.home.class".equals(attrName)) + value = homeImpl.toString(); + else if ("java.object.class".equals(attrName)) + value = homeImpl.toString(); + out.startReply(); + out.writeObject(value); + out.completeReply(); + return; + } else if (method == null) { + out.startReply(); + out.writeFault("NoSuchMethodException", "The service has no method named: " + in.getMethod(), null); + out.completeReply(); + return; + } + + Class[] args = method.getParameterTypes(); + Object[] values = new Object[args.length]; + + for (int i = 0; i < args.length; i++) { + values[i] = in.readObject(args[i]); + } + + Object result = null; + try { + Message msg = messageFactory.createMessage(); + msg.setOperation(operation); + msg.setBody(values); + result = wire.invoke(operation, msg); + } catch (Throwable e) { + while (e instanceof InvocationTargetException) + e = ((InvocationTargetException)e).getTargetException(); + out.startReply(); + out.writeFault("ServiceException", e.getMessage(), e); + out.completeReply(); + return; + } + + // The complete call needs to be after the invoke to handle a + // trailing InputStream + in.completeCall(); + out.startReply(); + out.writeObject(result); + out.completeReply(); + out.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..1bbe97e514 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.hessian.impl.HessianBindingProcessor;qname=http://hessian#binding.hessian,model=org.apache.tuscany.sca.binding.hessian.impl.HessianBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema new file mode 100644 index 0000000000..dfd4823a13 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# URI of the XML schema to be used for validation +binding-hessian.xsd diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..244449ddf0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.hessian.provider.HessianBindingProviderFactory;model=org.apache.tuscany.sca.binding.hessian.impl.HessianBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/binding-hessian.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/binding-hessian.xsd new file mode 100644 index 0000000000..01d7437878 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/main/resources/binding-hessian.xsd @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/FirstImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/FirstImpl.java new file mode 100644 index 0000000000..b60c41397b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/FirstImpl.java @@ -0,0 +1,19 @@ +package org.zhulei.test.hessian.first; + +import java.util.ArrayList; +import java.util.List; + +public class FirstImpl implements IFirst { + + public String getString(String str) { + return str + "_first"; + } + + public List getData(String str1, String str2) { + List list = new ArrayList(); + list.add(str1 + "_first"); + list.add(str2 + "_first"); + return list; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/FirstTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/FirstTestCase.java new file mode 100644 index 0000000000..919cbe90ff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/FirstTestCase.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.zhulei.test.hessian.first; + +import java.io.IOException; +import java.util.List; + +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.caucho.hessian.client.HessianProxyFactory; + +/** + * + */ +public class FirstTestCase { + private static SCANode node; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + node = SCANodeFactory.newInstance().createSCANodeFromClassLoader("first_hessian.composite", null); + node.start(); + } + + @Test + public void testServer() throws IOException { + try { + HessianProxyFactory proxyFactory = new HessianProxyFactory(); + IFirst service = (IFirst)proxyFactory.create(IFirst.class, "http://localhost:8085/hessian1"); + List datas = service.getData("123", "ABC"); + for (int i = 0; i < datas.size(); i++) { + System.out.println(datas.get(i)); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + node.stop(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/IFirst.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/IFirst.java new file mode 100644 index 0000000000..a346214ebb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/first/IFirst.java @@ -0,0 +1,11 @@ +package org.zhulei.test.hessian.first; + +import java.util.List; + +public interface IFirst { + + public String getString(String str); + + public List getData(String str1, String str2); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/ISecond.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/ISecond.java new file mode 100644 index 0000000000..0130d84658 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/ISecond.java @@ -0,0 +1,7 @@ +package org.zhulei.test.hessian.second; + +public interface ISecond { + + public String getString(String str); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/SecondImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/SecondImpl.java new file mode 100644 index 0000000000..9df4fb91d6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/SecondImpl.java @@ -0,0 +1,19 @@ +package org.zhulei.test.hessian.second; + +import org.osoa.sca.annotations.Reference; +import org.zhulei.test.hessian.first.IFirst; + +public class SecondImpl implements ISecond { + + private IFirst first; + + public String getString(String str) { + return first.getString(str) + "_second"; + } + + @Reference + public void setFirst(IFirst first) { + this.first = first; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/SecondTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/SecondTestCase.java new file mode 100644 index 0000000000..f390d5b104 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/java/org/zhulei/test/hessian/second/SecondTestCase.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.zhulei.test.hessian.second; + +import java.io.IOException; + +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.caucho.hessian.client.HessianProxyFactory; + +/** + * + */ +public class SecondTestCase { + private static SCANode node1; + private static SCANode node2; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + node1 = SCANodeFactory.newInstance().createSCANodeFromClassLoader("second_hessian.composite", null); + node1.start(); + + node2 = SCANodeFactory.newInstance().createSCANodeFromClassLoader("first_hessian.composite", null); + node2.start(); + } + + @Test + public void testServer() throws IOException { + try { + HessianProxyFactory proxyFactory = new HessianProxyFactory(); + ISecond service = (ISecond)proxyFactory.create(ISecond.class, "http://localhost:8085/hessian2"); + String str = service.getString("XYZ"); + System.out.println(str); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + node1.stop(); + node2.stop(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/resources/first_hessian.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/resources/first_hessian.composite new file mode 100644 index 0000000000..fd3eefaeaa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/resources/first_hessian.composite @@ -0,0 +1,21 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/resources/second_hessian.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/resources/second_hessian.composite new file mode 100644 index 0000000000..e502aac8be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-hessian/src/test/resources/second_hessian.composite @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/pom.xml new file mode 100644 index 0000000000..568d4eaaa6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/pom.xml @@ -0,0 +1,130 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-http-jsonrpc-runtime + Apache Tuscany SCA HTTP Binding JSON-RPC Runtime + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-http-jsonrpc + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-json + 1.6-SNAPSHOT + + + + javax.servlet + servlet-api + 2.5 + provided + + + + com.metaparadigm + json-rpc + 1.0 + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.http.wireformat.jsonrpc + ${pom.name} + org.apache.tuscany.sca.binding.http.wireformat.jsonrpc + org.apache.tuscany.sca.assembly.xml;version="1.4", * + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java new file mode 100644 index 0000000000..37c76d88d3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorInterceptor.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.provider; + +import java.io.CharArrayWriter; +import java.util.List; + +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.binding.http.HTTPBindingContext; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.json.JSONObject; + +import com.metaparadigm.jsonrpc.JSONRPCResult; + +/** + * JSON-RPC Operation Selector Interceptor + * + * @version $Rev$ $Date$ + */ +public class JSONRPCOperationSelectorInterceptor implements Interceptor { + private Invoker next; + + private RuntimeWire runtimeWire; + private HTTPBinding binding; + + private MessageFactory messageFactory; + + public JSONRPCOperationSelectorInterceptor(HTTPBinding binding, RuntimeWire runtimeWire, MessageFactory messageFactory) { + this.binding = binding; + this.runtimeWire = runtimeWire; + this.messageFactory = messageFactory; + } + + public Invoker getNext() { + return this.next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Message invoke(Message msg) { + + HTTPBindingContext bindingContext = msg.getBindingContext(); + if ("smd".equals(bindingContext.getHttpRequest().getQueryString())) { + return getNext().invoke(msg); + } + + JSONObject jsonReq = null; + String method = null; + try { + Object[] args = msg.getBody(); + CharArrayWriter data = (CharArrayWriter) args[0]; + jsonReq = new JSONObject(data.toString()); + method = jsonReq.getString("method"); + } catch (Exception e) { + Throwable exception = new RuntimeException("Unable to parse request", e); + } + + Operation jsonOperation = findOperation(method); + msg.setOperation(jsonOperation); + msg.setBody(jsonReq); + + return getNext().invoke(msg); + } + + /** + * Find the operation from the component service contract + * @param componentService + * @param method + * @return + */ + private Operation findOperation(String method) { + if (method.contains(".")) { + method = method.substring(method.lastIndexOf(".") + 1); + } + + List operations = runtimeWire.getTarget().getInterfaceContract().getInterface().getOperations(); + + Operation result = null; + for (Operation o : operations) { + if (o.getName().equalsIgnoreCase(method)) { + result = o; + break; + } + } + + return result; + } + + + + /** + * Create a Fault Message with a JSON representation of the current exception + * @param throwable + * @return + */ + private Message createJSONFaultMessage(Throwable throwable) { + Message jsonFaultMessage = messageFactory.createMessage(); + + JSONRPCResult jsonFault = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, null, throwable); + jsonFaultMessage.setBody(jsonFault); + + return jsonFaultMessage; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorProviderFactory.java new file mode 100644 index 0000000000..42ee2808c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorProviderFactory.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.sca.binding.http.operationselector.jsonrpc.provider; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelector; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * JSON-RPC Operation Selector Provider Factory + * + * @version $Rev$ $Date$ + */ +public class JSONRPCOperationSelectorProviderFactory implements OperationSelectorProviderFactory { + private ExtensionPointRegistry extensionPoints; + + public JSONRPCOperationSelectorProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + } + + public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return null; + } + + public OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new JSONRPCOperationSelectorServiceProvider(extensionPoints, component, service, binding); + } + + public Class getModelType() { + return JSONRPCOperationSelector.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.java new file mode 100644 index 0000000000..c24537f03f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/provider/JSONRPCOperationSelectorServiceProvider.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.sca.binding.http.operationselector.jsonrpc.provider; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.BindingRRB; +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelector; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * JSON-RPC Operation Selector Service Provider + * + * @version $Rev$ $Date$ + */ +public class JSONRPCOperationSelectorServiceProvider implements OperationSelectorProvider { + private MessageFactory messageFactory; + + private RuntimeComponent component; + private RuntimeComponentService service; + private Binding binding; + + public JSONRPCOperationSelectorServiceProvider(ExtensionPointRegistry extensionPoints, + RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + messageFactory = modelFactories.getFactory(MessageFactory.class); + + this.component = component; + this.service = service; + this.binding = binding; + } + + public Interceptor createInterceptor() { + if(binding instanceof BindingRRB) { + BindingRRB rrbBinding = (BindingRRB) binding; + OperationSelector operationSelector = rrbBinding.getOperationSelector(); + if(operationSelector != null && operationSelector instanceof JSONRPCOperationSelector) { + return new JSONRPCOperationSelectorInterceptor((HTTPBinding) binding, service.getRuntimeWire(binding), messageFactory); + } + } + + return null; + } + + public String getPhase() { + return Phase.SERVICE_BINDING_OPERATION_SELECTOR; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java new file mode 100644 index 0000000000..b314f69fcb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java @@ -0,0 +1,172 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.provider; + +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.binding.http.HTTPBindingContext; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.json.JSONArray; +import org.json.JSONObject; +import org.osoa.sca.ServiceRuntimeException; + +import com.metaparadigm.jsonrpc.JSONRPCResult; + +/** + * JSON-RPC Wire Format Interceptor + * + * @version $Rev$ $Date$ + */ +public class JSONRPCWireFormatInterceptor implements Interceptor { + private Invoker next; + + private RuntimeWire runtimeWire; + private HTTPBinding binding; + + private InterfaceContract serviceContract; + + private MessageFactory messageFactory; + + public JSONRPCWireFormatInterceptor(HTTPBinding binding, RuntimeWire runtimeWire, InterfaceContract serviceContract, MessageFactory messageFactory) { + this.binding = binding; + this.runtimeWire = runtimeWire; + + this.serviceContract = serviceContract; + + this.messageFactory = messageFactory; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + + } + + public Message invoke(Message msg) { + HTTPBindingContext bindingContext = msg.getBindingContext(); + Message returnMessage = null; + + if ("smd".equals(bindingContext.getHttpRequest().getQueryString())) { + returnMessage = handleSMDInvocation(msg); + } else { + returnMessage = handleJSONRPCInvocation(msg); + } + + return returnMessage; + + } + + /** + * Handle regular JSON-RPC Invocation + * @param msg + * @return + */ + private Message handleJSONRPCInvocation (Message msg) { + JSONObject jsonReq = (JSONObject) msg.getBody(); + String method = null; + Object[] args = null; + Object id = null; + try { + // Extract the method + method = jsonReq.getString("method"); + if ((method != null) && (method.indexOf('.') < 0)) { + jsonReq.putOpt("method", "Service" + "." + method); + } + + // Extract the arguments + JSONArray array = jsonReq.getJSONArray("params"); + args = new Object[array.length()]; + for (int i = 0; i < args.length; i++) { + args[i] = array.get(i); + } + id = jsonReq.get("id"); + + } catch (Exception e) { + throw new RuntimeException("Unable to find json method name", e); + } + + Message responseMessage = null; + try { + msg.setBody(args); + responseMessage = runtimeWire.getInvocationChain(msg.getOperation()).getHeadInvoker().invoke(msg); + } catch (RuntimeException re) { + Throwable exception = new RuntimeException("Error invoking service :" + re.getMessage(), re); + return createJSONFaultMessage(re); + } + + Object result = null; + if (!responseMessage.isFault()) { + //successful execution of the invocation + try { + result = responseMessage.getBody(); + JSONObject jsonResponse = new JSONObject(); + jsonResponse.put("result", result); + jsonResponse.putOpt("id", id); + //get response to send to client + responseMessage.setBody(jsonResponse); + return responseMessage; + } catch (Exception e) { + throw new ServiceRuntimeException("Unable to create JSON response", e); + } + } else { + //exception thrown while executing the invocation + Throwable exception = (Throwable)responseMessage.getBody(); + return createJSONFaultMessage(exception); + } + } + + /** + * handles requests for the SMD descriptor for a service + */ + private Message handleSMDInvocation(Message msg) { + HTTPBindingContext bindingContext = msg.getBindingContext(); + + String serviceUrl = bindingContext.getHttpRequest().getRequestURL().toString(); + JavaInterface interfaze = (JavaInterface) serviceContract.getInterface(); + String smd = JavaToSmd.interfaceToSmd(interfaze.getJavaClass(), serviceUrl); + + Message smdResponseMessage = messageFactory.createMessage(); + smdResponseMessage.setBody(smd); + + return smdResponseMessage; + } + + /** + * Create a Fault Message with a JSON representation of the current exception + * @param throwable + * @return + */ + private Message createJSONFaultMessage(Throwable throwable) { + Message jsonFaultMessage = messageFactory.createMessage(); + + JSONRPCResult jsonFault = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, null, throwable); + jsonFaultMessage.setBody(jsonFault); + + return jsonFaultMessage; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatProviderFactory.java new file mode 100644 index 0000000000..c5f91e2b15 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatProviderFactory.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.sca.binding.http.wireformat.jsonrpc.provider; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormat; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.provider.WireFormatProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * JSON-RPC Wire Format Provider Factory + * + * @version $Rev$ $Date$ + */ +public class JSONRPCWireFormatProviderFactory implements WireFormatProviderFactory { + private ExtensionPointRegistry extensionPoints; + + public JSONRPCWireFormatProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + } + + public WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new JSONRPCWireFormatReferenceProvider(extensionPoints, component, reference, binding); + } + + public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new JSONRPCWireFormatServiceProvider(extensionPoints, component, service, binding); + } + + public Class getModelType() { + return JSONRPCWireFormat.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatReferenceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatReferenceProvider.java new file mode 100644 index 0000000000..932072095a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatReferenceProvider.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.sca.binding.http.wireformat.jsonrpc.provider; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * JSON-RPC Wire Format Reference Provider + * + * @version $Rev$ $Date$ + */ +public class JSONRPCWireFormatReferenceProvider implements WireFormatProvider { + + public JSONRPCWireFormatReferenceProvider (ExtensionPointRegistry extensionPoints, + RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) { + return null; + } + + public Interceptor createInterceptor() { + return null; + } + + public String getPhase() { + return Phase.REFERENCE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java new file mode 100644 index 0000000000..1454fbdff2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.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.sca.binding.http.wireformat.jsonrpc.provider; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.BindingRRB; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormat; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; +import org.apache.tuscany.sca.databinding.json.JSONDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * JSON-RPC Wire Format Service Provider + * + * @version $Rev$ $Date$ + */ +public class JSONRPCWireFormatServiceProvider implements WireFormatProvider { + private MessageFactory messageFactory; + + private RuntimeComponent component; + private RuntimeComponentService service; + private InterfaceContract serviceContract; + private Binding binding; + + public JSONRPCWireFormatServiceProvider(ExtensionPointRegistry extensionPoints, + RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + messageFactory = modelFactories.getFactory(MessageFactory.class); + + this.component = component; + this.service = service; + this.serviceContract = service.getInterfaceContract(); + this.binding = binding; + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) { + this.serviceContract = interfaceContract; + + setDataBinding(serviceContract.getInterface()); + + // Set default databinding to json + serviceContract.getInterface().resetDataBinding(JSONDataBinding.NAME); + + return interfaceContract; + } + + public Interceptor createInterceptor() { + if(binding instanceof BindingRRB) { + BindingRRB rrbBinding = (BindingRRB) binding; + WireFormat wireFormat = rrbBinding.getRequestWireFormat(); + if(wireFormat != null && wireFormat instanceof JSONRPCWireFormat) { + return new JSONRPCWireFormatInterceptor((HTTPBinding) binding, service.getRuntimeWire(binding), serviceContract, messageFactory); + } + } + + return null; + } + + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + + + private void setDataBinding(Interface interfaze) { + List operations = interfaze.getOperations(); + for (Operation operation : operations) { + operation.setDataBinding(JSONDataBinding.NAME); + DataType> inputType = operation.getInputType(); + if (inputType != null) { + List logical = inputType.getLogical(); + for (DataType inArg : logical) { + if (!SimpleJavaDataBinding.NAME.equals(inArg.getDataBinding())) { + inArg.setDataBinding(JSONDataBinding.NAME); + } + } + } + DataType outputType = operation.getOutputType(); + if (outputType != null) { + if (!SimpleJavaDataBinding.NAME.equals(outputType.getDataBinding())) { + outputType.setDataBinding(JSONDataBinding.NAME); + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JavaToSmd.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JavaToSmd.java new file mode 100644 index 0000000000..c67060f7b6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JavaToSmd.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.sca.binding.http.wireformat.jsonrpc.provider; + +import java.lang.reflect.Method; + +/** + * Utility class to create a Simple Method Description (SMD) descriptor + * from a Java class. See http://dojo.jot.com/SMD. + * + * TODO: Change to work from the Tuscany Interface instead of a Java class + * + * @version $Rev$ $Date$ + */ +class JavaToSmd { + + static String interfaceToSmd(Class klazz, String serviceUrl) { + String name = klazz.getSimpleName(); + Method[] methods = klazz.getMethods(); + + StringBuffer smdSb = new StringBuffer(); + smdSb.append("{\"SMDVersion\":\".1\",\"objectName\":\"" + name + "\",\"serviceType\":\"JSON-RPC\",\"serviceURL\":\""+ serviceUrl + "\",\"methods\":["); + for (int i = 0; i < methods.length; i++) { + if (i != 0) smdSb.append(","); + Class[] params = methods[i].getParameterTypes(); + smdSb.append("{\"name\":\""+methods[i].getName() + "\",\"parameters\":["); + for (int j = 0; j < params.length; j++) { + if (j != 0) smdSb.append(","); + // right now Dojo doesn't look at the type value, so we'll default it to STRING + // also, since we can't introspect the method parameter names we'll just create an incrementing parameter name + smdSb.append("{\"name\":\"param" + j + "\",\"type\":\"STRING\"}"); + } + smdSb.append("]}"); + } + smdSb.append("]}"); + + return smdSb.toString(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory new file mode 100644 index 0000000000..61ee00271b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.provider.JSONRPCOperationSelectorProviderFactory;model=org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelector diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory new file mode 100644 index 0000000000..9b7d686ddd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the wire format provider factory +org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.provider.JSONRPCWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormat \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/pom.xml new file mode 100644 index 0000000000..08f2e084bf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-http-jsonrpc + Apache Tuscany SCA HTTP Binding JSON-RPC Model + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-http + 1.6-SNAPSHOT + + + + javax.servlet + servlet-api + 2.5 + provided + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.http.wireformat.jsonrpc + ${pom.name} + org.apache.tuscany.sca.binding.http.wireformat.jsonrpc + org.apache.tuscany.sca.assembly.xml;version="1.4", * + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/JSONRPCOperationSelector.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/JSONRPCOperationSelector.java new file mode 100644 index 0000000000..68024e8d5c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/JSONRPCOperationSelector.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.sca.binding.http.operationselector.jsonrpc; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * JSON-RPC Operation Selector model + * + * @version $Rev$ $Date$ + */ +public interface JSONRPCOperationSelector extends OperationSelector { + /** + * QName representing the HTTP JSON-RPC Operation Selector extension + */ + public static final QName OPERATION_SELECTOR_HTTP_JSONRPC_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jsonrpc"); + + QName getSchemaName(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/JSONRPCOperationSelectorFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/JSONRPCOperationSelectorFactory.java new file mode 100644 index 0000000000..37ceeed709 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/JSONRPCOperationSelectorFactory.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.sca.binding.http.operationselector.jsonrpc; + + +/** + * JSON-RPC Operation Selector model factory + * + * @version $Rev$ $Date$ + */ +public interface JSONRPCOperationSelectorFactory { + + /** + * Create a new JSON RPC Operation Selector + * @return + */ + JSONRPCOperationSelector createJSONRPCOperationSelector(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorFactoryImpl.java new file mode 100644 index 0000000000..107719dbc3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorFactoryImpl.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.sca.binding.http.operationselector.jsonrpc.impl; + +import org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelector; +import org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelectorFactory; + +/** + * JSON-RPC Operation Selector model factory implementation + * @version $Rev$ $Date$ + */ +public class JSONRPCOperationSelectorFactoryImpl implements JSONRPCOperationSelectorFactory { + + public JSONRPCOperationSelector createJSONRPCOperationSelector() { + return new JSONRPCOperationSelectorImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorImpl.java new file mode 100644 index 0000000000..5f36bf8d34 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorImpl.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.sca.binding.http.operationselector.jsonrpc.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelector; + +/** + * JSON-RPC Operation Selector model implementation + * @version $Rev$ $Date$ + */ +public class JSONRPCOperationSelectorImpl implements JSONRPCOperationSelector { + + public QName getSchemaName() { + return JSONRPCOperationSelector.OPERATION_SELECTOR_HTTP_JSONRPC_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/JSONRPCWireFormat.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/JSONRPCWireFormat.java new file mode 100644 index 0000000000..f9aaa57a51 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/JSONRPCWireFormat.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.sca.binding.http.wireformat.jsonrpc; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * JSON-RPC Wire Format model + * + * @version $Rev$ $Date$ + */ +public interface JSONRPCWireFormat extends WireFormat { + /** + * QName representing the HTTP JSON-RPC Wire Format extension + */ + public static final QName WIRE_FORMAT_HTTP_JSONRPC_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jsonrpc"); + + QName getSchemaName(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/JSONRPCWireFormatFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/JSONRPCWireFormatFactory.java new file mode 100644 index 0000000000..8d659faf41 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/JSONRPCWireFormatFactory.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.sca.binding.http.wireformat.jsonrpc; + +/** + * JSON-RPC Wire Format model factory + * @version $Rev$ $Date$ + */ +public interface JSONRPCWireFormatFactory { + + /** + * Create a new JSONRPC Wire Format + * @return + */ + JSONRPCWireFormat createJSONRPCWireFormat(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatFactoryImpl.java new file mode 100644 index 0000000000..392a32a8b7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatFactoryImpl.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.sca.binding.http.wireformat.jsonrpc.impl; + +import org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormat; +import org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormatFactory; + + +/** + * JSON-RPC Wire Format model factory implementation + * + * @version $Rev$ $Date$ + */ +public class JSONRPCWireFormatFactoryImpl implements JSONRPCWireFormatFactory { + + public JSONRPCWireFormat createJSONRPCWireFormat() { + return new JSONRPCWireFormatImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatImpl.java new file mode 100644 index 0000000000..d02d667ab4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatImpl.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.sca.binding.http.wireformat.jsonrpc.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormat; + +/** + * JSON-RPC Wire Format model implementation + * @version $Rev$ $Date$ + */ +public class JSONRPCWireFormatImpl implements JSONRPCWireFormat { + + public QName getSchemaName() { + return WIRE_FORMAT_HTTP_JSONRPC_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelectorFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelectorFactory new file mode 100644 index 0000000000..76203fbc11 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelectorFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for model factory +org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.impl.JSONRPCOperationSelectorFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormatFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormatFactory new file mode 100644 index 0000000000..3f72dd5a67 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormatFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for model factory +org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.impl.JSONRPCWireFormatFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..17a340c06c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#wireFormat.jsonrpc,model=org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormat,factory=org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormatFactory +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#operationSelector.jsonrpc,model=org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelector,factory=org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelectorFactory \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorProcessorTestCase.java new file mode 100644 index 0000000000..f6178fad0a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/http/operationselector/jsonrpc/impl/JSONRPCOperationSelectorProcessorTestCase.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.binding.http.operationselector.jsonrpc.JSONRPCOperationSelector; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** +* JSON RPC operation selector processor tests +* +* @version $Rev$ $Date$ +*/ +public class JSONRPCOperationSelectorProcessorTestCase { + + public static final String COMPOSITE_WITH_OPERATION_SELECTOR = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static XMLInputFactory inputFactory; + private static XMLOutputFactory outputFactory; + private static ExtensibleStAXArtifactProcessor staxProcessor; + private static Monitor monitor; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor); + + } + + /** + * Tests the APIs: + * public OperationSelector getOperationSelector(); + * + * @throws Exception + */ + @Test + public void testWireFormat() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_WITH_OPERATION_SELECTOR)); + + Composite composite = (Composite)staxProcessor.read(reader); + HTTPBinding binding = (HTTPBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + OperationSelector operationSelector = binding.getOperationSelector(); + assertEquals(JSONRPCOperationSelector.class, operationSelector.getClass().getInterfaces()[0]); + } + + @Test + public void testWriteWireFormat() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_WITH_OPERATION_SELECTOR)); + + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(COMPOSITE_WITH_OPERATION_SELECTOR); + // System.out.println(bos.toString()); + + assertEquals(COMPOSITE_WITH_OPERATION_SELECTOR, bos.toString()); + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatProcessorTestCase.java new file mode 100644 index 0000000000..5dd9db2a93 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/impl/JSONRPCWireFormatProcessorTestCase.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormat; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** +* JSON RPC wire format processor tests +* +* @version $Rev$ $Date$ +*/ +public class JSONRPCWireFormatProcessorTestCase { + + public static final String COMPOSITE_WITH_WIRE_FORMAT = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static XMLInputFactory inputFactory; + private static XMLOutputFactory outputFactory; + private static ExtensibleStAXArtifactProcessor staxProcessor; + private static Monitor monitor; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor); + + } + + /** + * Tests the APIs: + * public WireFormat getRequstWireFormat(); + * public WireFormat getResponseWireFormat(); + * + * @throws Exception + */ + @Test + public void testWireFormat() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_WITH_WIRE_FORMAT)); + + Composite composite = (Composite)staxProcessor.read(reader); + HTTPBinding binding = (HTTPBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + WireFormat requestWireFormat = binding.getRequestWireFormat(); + assertEquals(JSONRPCWireFormat.class, requestWireFormat.getClass().getInterfaces()[0]); + + WireFormat responseWireFormat = binding.getResponseWireFormat(); + assertEquals(JSONRPCWireFormat.class, responseWireFormat.getClass().getInterfaces()[0]); + } + + @Test + public void testWriteWireFormat() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_WITH_WIRE_FORMAT)); + + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(COMPOSITE_WITH_WIRE_FORMAT); + // System.out.println(bos.toString()); + + assertEquals(COMPOSITE_WITH_WIRE_FORMAT, bos.toString()); + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/pom.xml new file mode 100644 index 0000000000..3497e666ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/pom.xml @@ -0,0 +1,120 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-http-runtime + Apache Tuscany SCA HTTP Binding Runtime + + + + org.apache.tuscany.sca + tuscany-binding-http + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy-security-http + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + + javax.servlet + servlet-api + 2.5 + provided + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-resource-runtime + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.http.runtime + ${pom.name} + org.apache.tuscany.sca.binding.http* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java new file mode 100644 index 0000000000..12f1143e3a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java @@ -0,0 +1,516 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http.provider; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URLDecoder; +import java.text.ParseException; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.http.HTTPCacheContext; +import org.apache.tuscany.sca.binding.http.util.HTTPHeadersParser; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; + +/** + * Servlet responsible for dispatching HTTP requests to the + * target component implementation. + * + * @version $Rev$ $Date$ + */ +public class HTTPBindingListenerServlet extends HttpServlet { + private static final long serialVersionUID = 2865466417329430610L; + + private static final QName AUTEHTICATION_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0","authentication"); + + transient private Binding binding; + + transient private boolean requiresAuthentication = false; + transient private BasicAuthenticationPolicy basicAuthenticationPolicy = null; + + private MessageFactory messageFactory; + private Invoker getInvoker; + private Invoker conditionalGetInvoker; + private Invoker putInvoker; + private Invoker conditionalPutInvoker; + private Invoker postInvoker; + private Invoker conditionalPostInvoker; + private Invoker deleteInvoker; + private Invoker conditionalDeleteInvoker; + + /** + * Constructs a new HTTPServiceListenerServlet. + */ + public HTTPBindingListenerServlet(Binding binding, MessageFactory messageFactory) { + this.binding = binding; + this.messageFactory = messageFactory; + + + // find out which policies are active + if (binding instanceof PolicySetAttachPoint) { + List intents = ((PolicySetAttachPoint)binding).getRequiredIntents(); + for(Intent intent : intents) { + if(intent.getName().equals(AUTEHTICATION_INTENT)) { + requiresAuthentication = true; + } + } + + + List policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (BasicAuthenticationPolicy.class.isInstance(p)) { + basicAuthenticationPolicy = (BasicAuthenticationPolicy)p; + } else { + // etc. check for other types of policy being present + } + } + } + } + } + + + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + if(requiresAuthentication) { + if(! hasAuthorization(request, response)) { + response.setHeader("WWW-Authenticate", "BASIC realm=\"Tuscany\""); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } + } + + super.service(request, response); + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + if (path.length() ==0) { + // Redirect to a URL ending with / to make relative hrefs work + // relative to the served resource. + response.sendRedirect(request.getRequestURL().append('/').toString()); + return; + } + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + + //store http headers to message + requestMessage.getHeaders().addAll(HTTPHeadersParser.getHeaders(request)); + + String id = path.substring(1); + + Message responseMessage = null; + HTTPCacheContext cacheContext = null; + try { + cacheContext = HTTPCacheContext.getCacheContextFromRequest(request); + } catch (ParseException e) { + } + + // Route message based on availability of cache info and cache methods + if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalGetInvoker != null )) { + requestMessage.setBody(new Object[] {id, cacheContext}); + responseMessage = conditionalGetInvoker.invoke(requestMessage); + } else { + requestMessage.setBody(new Object[] {id}); + responseMessage = getInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + + int index = -1; + if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + return; + } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + return; + } + + throw new ServletException((Throwable)responseMessage.getBody()); + } + + // Write the response from the service implementation to the response + // output stream + InputStream is = (InputStream)responseMessage.getBody(); + OutputStream os = response.getOutputStream(); + byte[] buffer = new byte[2048]; + for (;;) { + int n = is.read(buffer); + if (n <= 0) + break; + os.write(buffer, 0, n); + } + os.flush(); + os.close(); + } + + @Override + protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + if (path.length() ==0) { + // Redirect to a URL ending with / to make relative hrefs work + // relative to the served resource. + response.sendRedirect(request.getRequestURL().append('/').toString()); + return; + } + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + String id = path.substring(1); + + Message responseMessage = null; + HTTPCacheContext cacheContext = null; + try { + cacheContext = HTTPCacheContext.getCacheContextFromRequest(request); + } catch (ParseException e) { + } + + // Route message based on availability of cache info and cache methods + if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalDeleteInvoker != null )) { + requestMessage.setBody(new Object[] {id, cacheContext}); + responseMessage = conditionalDeleteInvoker.invoke(requestMessage); + } else { + requestMessage.setBody(new Object[] {id}); + responseMessage = deleteInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + + int index = -1; + if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + return; + } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + return; + } + + throw new ServletException((Throwable)responseMessage.getBody()); + } + + // Write the response from the service implementation to the response + // output stream + InputStream is = (InputStream)responseMessage.getBody(); + OutputStream os = response.getOutputStream(); + byte[] buffer = new byte[2048]; + for (;;) { + int n = is.read(buffer); + if (n <= 0) + break; + os.write(buffer, 0, n); + } + os.flush(); + os.close(); + } + + @Override + protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + if (path.length() ==0) { + // Redirect to a URL ending with / to make relative hrefs work + // relative to the served resource. + response.sendRedirect(request.getRequestURL().append('/').toString()); + return; + } + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + String id = path.substring(1); + + Message responseMessage = null; + HTTPCacheContext cacheContext = null; + try { + cacheContext = HTTPCacheContext.getCacheContextFromRequest(request); + } catch (ParseException e) { + } + + // Route message based on availability of cache info and cache methods + if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalPutInvoker != null )) { + requestMessage.setBody(new Object[] {id, cacheContext}); + responseMessage = conditionalPutInvoker.invoke(requestMessage); + } else { + requestMessage.setBody(new Object[] {id}); + responseMessage = putInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + + int index = -1; + if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + return; + } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + return; + } + + throw new ServletException((Throwable)responseMessage.getBody()); + } + + // Write the response from the service implementation to the response + // output stream + InputStream is = (InputStream)responseMessage.getBody(); + OutputStream os = response.getOutputStream(); + byte[] buffer = new byte[2048]; + for (;;) { + int n = is.read(buffer); + if (n <= 0) + break; + os.write(buffer, 0, n); + } + os.flush(); + os.close(); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + if (path.length() ==0) { + // Redirect to a URL ending with / to make relative hrefs work + // relative to the served resource. + response.sendRedirect(request.getRequestURL().append('/').toString()); + return; + } + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + // String id = path.substring(1); + + Message responseMessage = null; + HTTPCacheContext cacheContext = null; + try { + cacheContext = HTTPCacheContext.getCacheContextFromRequest(request); + } catch (ParseException e) { + } + + // Route message based on availability of cache info and cache methods + if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalPostInvoker != null )) { + requestMessage.setBody(new Object[] {cacheContext}); + responseMessage = conditionalPostInvoker.invoke(requestMessage); + } else { + requestMessage.setBody(new Object[] {}); + responseMessage = postInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + + int index = -1; + if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + return; + } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + return; + } + + throw new ServletException((Throwable)responseMessage.getBody()); + } + + + // Test if the ETag and LastModified are returned as a cache context. + Object body = responseMessage.getBody(); + if ( body.getClass() == HTTPCacheContext.class ) { + // Transfer to header if so. + HTTPCacheContext cc = (HTTPCacheContext)responseMessage.getBody(); + if (( cc != null ) && ( cc.isEnabled() )) { + String eTag = cc.getETag(); + if ( eTag != null ) + response.setHeader( "ETag", cc.getETag() ); + String lastModified = cc.getLastModified(); + if ( lastModified != null) + response.setHeader( "LastModified", cc.getLastModified() ); + } + } + } + + /** + * @return the getInvoker + */ + public Invoker getGetInvoker() { + return getInvoker; + } + + /** + * @param getInvoker the getInvoker to set + */ + public void setGetInvoker(Invoker getInvoker) { + this.getInvoker = getInvoker; + } + + /** + * @return the conditionalGetInvoker + */ + public Invoker getConditionalGetInvoker() { + return conditionalGetInvoker; + } + + /** + * @param conditionalGetInvoker the conditionalGetInvoker to set + */ + public void setConditionalGetInvoker(Invoker conditionalGetInvoker) { + this.conditionalGetInvoker = conditionalGetInvoker; + } + + /** + * @return the putInvoker + */ + public Invoker getPutInvoker() { + return putInvoker; + } + + /** + * @param putInvoker the putInvoker to set + */ + public void setPutInvoker(Invoker putInvoker) { + this.putInvoker = putInvoker; + } + + /** + * @return the conditionalPutInvoker + */ + public Invoker getConditionalPutInvoker() { + return conditionalPutInvoker; + } + + /** + * @param conditionalPutInvoker the conditionalPutInvoker to set + */ + public void setConditionalPutInvoker(Invoker conditionalPutInvoker) { + this.conditionalPutInvoker = conditionalPutInvoker; + } + + /** + * @return the postInvoker + */ + public Invoker getPostInvoker() { + return postInvoker; + } + + /** + * @param postInvoker the postInvoker to set + */ + public void setPostInvoker(Invoker postInvoker) { + this.postInvoker = postInvoker; + } + + /** + * @return the conditionalPostInvoker + */ + public Invoker getConditionalPostInvoker() { + return conditionalPostInvoker; + } + + /** + * @param conditionalPostInvoker the conditionalPostInvoker to set + */ + public void setConditionalPostInvoker(Invoker conditionalPostInvoker) { + this.conditionalPostInvoker = conditionalPostInvoker; + } + + /** + * @return the deleteInvoker + */ + public Invoker getDeleteInvoker() { + return deleteInvoker; + } + + /** + * @param deleteInvoker the deleteInvoker to set + */ + public void setDeleteInvoker(Invoker deleteInvoker) { + this.deleteInvoker = deleteInvoker; + } + + /** + * @return the conditionalDeleteInvoker + */ + public Invoker getConditionalDeleteInvoker() { + return conditionalDeleteInvoker; + } + + /** + * @param conditionalDeleteInvoker the conditionalDeleteInvoker to set + */ + public void setConditionalDeleteInvoker(Invoker conditionalDeleteInvoker) { + this.conditionalDeleteInvoker = conditionalDeleteInvoker; + } + + + /** + * Utility Methods related to Policy + */ + + + private boolean hasAuthorization(HttpServletRequest request, ServletResponse response) { + boolean result = false; + if(request.getHeader("Authorization") != null) { + result = true; + } + + return result; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java new file mode 100644 index 0000000000..768636d478 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.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.sca.binding.http.provider; + +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + + +/** + * Factory for HTTP binding providers. + * + * @version $Rev$ $Date$ + */ +public class HTTPBindingProviderFactory implements BindingProviderFactory { + private ExtensionPointRegistry extensionPoints; + private MessageFactory messageFactory; + private ServletHost servletHost; + + public HTTPBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + messageFactory = modelFactories.getFactory(MessageFactory.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, HTTPBinding binding) { + return null; + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, HTTPBinding binding) { + return new HTTPServiceBindingProvider(component, service, binding, extensionPoints, messageFactory, servletHost); + } + + public Class getModelType() { + return HTTPBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPGetListenerServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPGetListenerServlet.java new file mode 100644 index 0000000000..e20d420d49 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPGetListenerServlet.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http.provider; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URLDecoder; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; + +/** + * Servlet responsible for dispatching HTTP GET requests to the + * target component implementation. + * + * @version $Rev$ $Date$ + */ +public class HTTPGetListenerServlet extends HttpServlet { + private static final long serialVersionUID = 2865466417329430610L; + + private MessageFactory messageFactory; + private Invoker getInvoker; + + /** + * Constructs a new HTTPServiceListenerServlet. + */ + public HTTPGetListenerServlet(Invoker getInvoker, MessageFactory messageFactory) { + this.getInvoker = getInvoker; + this.messageFactory = messageFactory; + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + if (path.length() ==0) { + + // Redirect to a URL ending with / to make relative hrefs work + // relative to the served resource. + response.sendRedirect(request.getRequestURL().append('/').toString()); + return; + } + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + String id = path.substring(1); + requestMessage.setBody(new Object[] {id}); + Message responseMessage = getInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + + // Write the response from the service implementation to the response + // output stream + InputStream is = (InputStream)responseMessage.getBody(); + OutputStream os = response.getOutputStream(); + byte[] buffer = new byte[2048]; + for (;;) { + int n = is.read(buffer); + if (n <= 0) + break; + os.write(buffer, 0, n); + } + os.flush(); + os.close(); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPRRBListenerServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPRRBListenerServlet.java new file mode 100644 index 0000000000..605e2c6211 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPRRBListenerServlet.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http.provider; + +import java.io.BufferedReader; +import java.io.CharArrayWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.http.HTTPBindingContext; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; + +public class HTTPRRBListenerServlet extends HttpServlet { + + private static final long serialVersionUID = 6688524143716091739L; + + transient private Binding binding; + transient private Invoker bindingInvoker; + transient private MessageFactory messageFactory; + + /** + * Constructs a new HTTPServiceListenerServlet. + */ + public HTTPRRBListenerServlet(Binding binding, Invoker bindingInvoker, MessageFactory messageFactory) { + this.binding = binding; + this.bindingInvoker = bindingInvoker; + this.messageFactory = messageFactory; + } + + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // Decode using the charset in the request if it exists otherwise + // use UTF-8 as this is what all browser implementations use. + // The JSON-RPC-Java JavaScript client is ASCII clean so it + // although here we can correctly handle data from other clients + // that do not escape non ASCII data + String charset = request.getCharacterEncoding(); + if (charset == null) { + charset = "UTF-8"; + } + BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), charset)); + + // Read the request + CharArrayWriter data = new CharArrayWriter(); + char[] buf = new char[4096]; + int ret; + while ((ret = in.read(buf, 0, 4096)) != -1) { + data.write(buf, 0, ret); + } + + HTTPBindingContext bindingContext = new HTTPBindingContext(); + bindingContext.setHttpRequest(request); + bindingContext.setHttpResponse(response); + + // Dispatch the service interaction to the service invoker + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBindingContext(bindingContext); + requestMessage.setBody(new Object[]{data}); + + Message responseMessage = bindingInvoker.invoke(requestMessage); + + // return response to client + if (responseMessage.isFault()) { + // Turn a fault into an exception + //throw new ServletException((Throwable)responseMessage.getBody()); + Throwable e = (Throwable)responseMessage.getBody(); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); + } else { + byte[] bout; + bout = responseMessage.getBody().toString().getBytes("UTF-8"); + response.getOutputStream().write(bout); + response.getOutputStream().flush(); + response.getOutputStream().close(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java new file mode 100644 index 0000000000..8e84d04b76 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java @@ -0,0 +1,265 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http.provider; + +import java.util.List; + +import javax.servlet.Servlet; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.http.SecurityContext; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.authentication.AuthenticationConfigurationPolicy; +import org.apache.tuscany.sca.policy.confidentiality.ConfidentialityPolicy; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; +import org.apache.tuscany.sca.provider.ServiceBindingProviderRRB; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.provider.WireFormatProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of an HTTP binding provider. + * + * @version $Rev$ $Date$ + */ +public class HTTPServiceBindingProvider implements ServiceBindingProviderRRB { + private static final QName AUTEHTICATION_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0","authentication"); + private static final QName CONFIDENTIALITY_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0","confidentiality"); + + private ExtensionPointRegistry extensionPoints; + + private RuntimeComponent component; + private RuntimeComponentService service; + private InterfaceContract serviceContract; + private HTTPBinding binding; + private MessageFactory messageFactory; + + private OperationSelectorProvider osProvider; + private WireFormatProvider wfProvider; + + private ServletHost servletHost; + private String servletMapping; + private HTTPBindingListenerServlet bindingListenerServlet; + + public HTTPServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + HTTPBinding binding, + ExtensionPointRegistry extensionPoints, + MessageFactory messageFactory, + ServletHost servletHost) { + this.component = component; + this.service = service; + + this.binding = binding; + this.extensionPoints = extensionPoints; + this.messageFactory = messageFactory; + this.servletHost = servletHost; + + // retrieve operation selector and wire format service providers + + ProviderFactoryExtensionPoint providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); + + + if (binding.getOperationSelector() != null) { + // Configure the interceptors for operation selection + OperationSelectorProviderFactory osProviderFactory = (OperationSelectorProviderFactory) providerFactories.getProviderFactory(binding.getOperationSelector().getClass()); + if (osProviderFactory != null) { + this.osProvider = osProviderFactory.createServiceOperationSelectorProvider(component, service, binding); + } + } + + if (binding.getRequestWireFormat() != null && binding.getResponseWireFormat() != null) { + // Configure the interceptors for wire format + WireFormatProviderFactory wfProviderFactory = (WireFormatProviderFactory) providerFactories.getProviderFactory(binding.getRequestWireFormat().getClass()); + if (wfProviderFactory != null) { + this.wfProvider = wfProviderFactory.createServiceWireFormatProvider(component, service, binding); + } + } + + + + //clone the service contract to avoid databinding issues + try { + this.serviceContract = (InterfaceContract) service.getInterfaceContract().clone(); + + // configure data binding + if (this.wfProvider != null) { + wfProvider.configureWireFormatInterfaceContract(service.getInterfaceContract()); + } + } catch(CloneNotSupportedException e) { + this.serviceContract = service.getInterfaceContract(); + } + + } + + public void start() { + // Get the invokers for the supported operations + RuntimeComponentService componentService = (RuntimeComponentService) service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + Servlet servlet = null; + bindingListenerServlet = new HTTPBindingListenerServlet(binding, messageFactory ); + for (InvocationChain invocationChain : wire.getInvocationChains()) { + Operation operation = invocationChain.getTargetOperation(); + String operationName = operation.getName(); + if (binding.getOperationSelector() != null || binding.getRequestWireFormat() != null) { + Invoker bindingInvoker = wire.getBindingInvocationChain().getHeadInvoker(); + servlet = new HTTPRRBListenerServlet(binding, bindingInvoker, messageFactory); + break; + } else if (operationName.equals("get")) { + Invoker getInvoker = invocationChain.getHeadInvoker(); + bindingListenerServlet.setGetInvoker(getInvoker); + servlet = bindingListenerServlet; + } else if (operationName.equals("conditionalGet")) { + Invoker conditionalGetInvoker = invocationChain.getHeadInvoker(); + bindingListenerServlet.setConditionalGetInvoker(conditionalGetInvoker); + servlet = bindingListenerServlet; + } else if (operationName.equals("delete")) { + Invoker deleteInvoker = invocationChain.getHeadInvoker(); + bindingListenerServlet.setDeleteInvoker(deleteInvoker); + servlet = bindingListenerServlet; + } else if (operationName.equals("conditionalDelete")) { + Invoker conditionalDeleteInvoker = invocationChain.getHeadInvoker(); + bindingListenerServlet.setConditionalDeleteInvoker(conditionalDeleteInvoker); + servlet = bindingListenerServlet; + } else if (operationName.equals("put")) { + Invoker putInvoker = invocationChain.getHeadInvoker(); + bindingListenerServlet.setPutInvoker(putInvoker); + servlet = bindingListenerServlet; + } else if (operationName.equals("conditionalPut")) { + Invoker conditionalPutInvoker = invocationChain.getHeadInvoker(); + bindingListenerServlet.setConditionalPutInvoker(conditionalPutInvoker); + servlet = bindingListenerServlet; + } else if (operationName.equals("post")) { + Invoker postInvoker = invocationChain.getHeadInvoker(); + bindingListenerServlet.setPostInvoker(postInvoker); + servlet = bindingListenerServlet; + } else if (operationName.equals("conditionalPost")) { + Invoker conditionalPostInvoker = invocationChain.getHeadInvoker(); + bindingListenerServlet.setConditionalPostInvoker(conditionalPostInvoker); + servlet = bindingListenerServlet; + } else if (operationName.equals("service")) { + Invoker serviceInvoker = invocationChain.getHeadInvoker(); + servlet = new HTTPServiceListenerServlet(binding, serviceInvoker, messageFactory); + break; + } + } + if (servlet == null) { + throw new IllegalStateException("No get or service method found on the service"); + } + + // Create our HTTP service listener Servlet and register it with the + // Servlet host + servletMapping = binding.getURI(); + if (!servletMapping.endsWith("/")) { + servletMapping += "/"; + } + if (!servletMapping.endsWith("*")) { + servletMapping += "*"; + } + + + SecurityContext securityContext = new SecurityContext(); + boolean isConfidentialityRequired = false; + boolean isAuthenticationRequired = false; + + + // find out which policies are active + if (binding instanceof PolicySetAttachPoint) { + List intents = ((PolicySetAttachPoint)binding).getRequiredIntents(); + for(Intent intent : intents) { + if (intent.getName().equals(AUTEHTICATION_INTENT)) { + isAuthenticationRequired = true; + } else if (intent.getName().equals(CONFIDENTIALITY_INTENT)) { + isConfidentialityRequired = true; + } + } + + List policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (ConfidentialityPolicy.class.isInstance(p) && isConfidentialityRequired) { + //Handle enabling and configuring SSL + ConfidentialityPolicy confidentialityPolicy = (ConfidentialityPolicy)p; + + securityContext.setSSLEnabled(true); + securityContext.setSSLProperties(confidentialityPolicy.toProperties()); + } else if(AuthenticationConfigurationPolicy.class.isInstance(p) && isAuthenticationRequired) { + // Handle authentication and user configuration + AuthenticationConfigurationPolicy authenticationConfiguration = (AuthenticationConfigurationPolicy)p; + + securityContext.setAuthenticationEnabled(true); + securityContext.getUsers().clear(); + securityContext.getUsers().addAll(authenticationConfiguration.getUsers()); + } + } + } + } + + + servletHost.addServletMapping(servletMapping, servlet, securityContext); + } + + public void stop() { + // Unregister the Servlet from the Servlet host + servletHost.removeServletMapping(servletMapping); + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + /** + * Add specific http interceptor to invocation chain + * @param runtimeWire + */ + public void configureBindingChain(RuntimeWire runtimeWire) { + + InvocationChain bindingChain = runtimeWire.getBindingInvocationChain(); + + if(osProvider != null) { + bindingChain.addInterceptor(Phase.SERVICE_BINDING_OPERATION_SELECTOR, osProvider.createInterceptor()); + } + + if (wfProvider != null) { + bindingChain.addInterceptor(Phase.SERVICE_BINDING_WIREFORMAT, wfProvider.createInterceptor()); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java new file mode 100644 index 0000000000..493255655d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http.provider; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; + +/** + * Servlet responsible for dispatching HTTP service requests to the + * target component implementation. + * + * @version $Rev$ $Date$ + */ +public class HTTPServiceListenerServlet implements Servlet { + private static final QName AUTEHTICATION_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0","authentication"); + + transient private Binding binding; + transient private ServletConfig config; + transient private MessageFactory messageFactory; + transient private Invoker serviceInvoker; + + transient private boolean requiresAuthentication = false; + transient private BasicAuthenticationPolicy basicAuthenticationPolicy = null; + + /** + * Constructs a new HTTPServiceListenerServlet. + */ + public HTTPServiceListenerServlet(Binding binding, Invoker serviceInvoker, MessageFactory messageFactory) { + this.binding = binding; + this.serviceInvoker = serviceInvoker; + this.messageFactory = messageFactory; + + // find out which policies are active + if (binding instanceof PolicySetAttachPoint) { + List intents = ((PolicySetAttachPoint)binding).getRequiredIntents(); + for(Intent intent : intents) { + if(intent.getName().equals(AUTEHTICATION_INTENT)) { + requiresAuthentication = true; + } + } + + + List policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (BasicAuthenticationPolicy.class.isInstance(p)) { + basicAuthenticationPolicy = (BasicAuthenticationPolicy)p; + } else { + // etc. check for other types of policy being present + } + } + } + } + } + + public ServletConfig getServletConfig() { + return config; + } + + public String getServletInfo() { + return ""; + } + + public void init(ServletConfig config) throws ServletException { + this.config = config; + } + + public void destroy() { + + } + + public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { + + if(requiresAuthentication) { + if(! hasAuthenticationHeader((HttpServletRequest)request, (HttpServletResponse)response)) { + ((HttpServletResponse)response).sendError(HttpServletResponse.SC_UNAUTHORIZED); + } + } + + // Dispatch the service interaction to the service invoker + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[]{request, response}); + Message responseMessage = serviceInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + // Turn a fault into an exception + //throw new ServletException((Throwable)responseMessage.getBody()); + Throwable e = (Throwable)responseMessage.getBody(); + ((HttpServletResponse)response).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); + } + } + + + private boolean hasAuthenticationHeader(HttpServletRequest request, ServletResponse response) { + boolean result = false; + if(request.getHeader("Authorization") != null) { + result = true; + } + + return result; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/util/HTTPHeadersParser.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/util/HTTPHeadersParser.java new file mode 100644 index 0000000000..1fe4600e31 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/util/HTTPHeadersParser.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.sca.binding.http.util; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.tuscany.sca.binding.http.HTTPHeader; + +public class HTTPHeadersParser { + + /** + * Parse http request headers to a map + * + * @param request + * @return + */ + public static List getHeaders(HttpServletRequest request) { + List headers = new ArrayList(); + + Enumeration headerNames = request.getHeaderNames(); + while (headerNames.hasMoreElements()) { + String headerName = (String) headerNames.nextElement(); + Object headerValue = request.getHeader(headerName); + HTTPHeader header = new HTTPHeader(headerName, headerValue); + headers.add(header); + } + return headers; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..0fa8d44c08 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.http.provider.HTTPBindingProviderFactory;model=org.apache.tuscany.sca.binding.http.HTTPBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java new file mode 100644 index 0000000000..bb5f6d5a8b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java @@ -0,0 +1,855 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.http; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.Socket; +import java.text.MessageFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * HTTP binding unit tests. + * + * @version $Rev$ $Date$ + */ +public class HTTPBindingCacheTestCase extends TestCase { + // RFC 822 date time + protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( + "EEE, dd MMM yyyy HH:mm:ss Z"); + + // Request with no predicates in header. + private static final String REQUEST1 = "{0} /httpbinding/{1} HTTP/1.0\n" + + "Host: localhost\n" + "Content-Type: text/xml\n" + + "Connection: close\n" + "Content-Length: {2}" + "\n\n{3}"; + + // Request with predicates in header + private static final String REQUEST2 = "{0} /httpbinding/{1} HTTP/1.0\n" + + "Host: localhost\n" + "Content-Type: text/xml\n" + "{2}: {3}\n" // predicate (If-Match, If-None-Match, If-Modified-Since, If-NotModified-Since): value (date or ETag) + + "Connection: close\n" + "Content-Length: {4}" + "\n\n{5}"; + + private static final int HTTP_PORT = 8085; + + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("testCache.composite"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + /** + * Test invoking a POJO get method implementation using the HTTP binding. + * @throws Exception + */ + public void testGet() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST1, "GET", index, content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + assertTrue(document.indexOf("

item=" + index) != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalGetIfModifiedNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "GET", index, + "If-Modified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("

item=" + index) != -1); + // Should return code 304 Not Modified. + // assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalGetIfModifiedPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "GET", index, + "If-Modified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("

item=" + index) != -1); + // Should return code 304 Not Modified. + assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalGetIfUnmodifiedNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "GET", index, + "If-Unmodified-Since", dateFormat.format(new Date()), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("

item=" + index) != -1); + // Should return code 304 Not Modified. + // assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalGetIfUnmodifiedPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "GET", index, + "If-Unmodified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("

item=" + index) != -1); + // Should return code 412 PreconditionFailed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalGetIfMatchNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "GET", index, + "If-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("

item=" + index) != -1); + // Should return code 412 precondition failed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalGetIfMatchPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "GET", index, + "If-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("

item=" + index) != -1); + // Should return code 412 PreconditionFailed. + // assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalGetIfNoneMatchNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "GET", index, + "If-None-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("

item=" + index) != -1); + // Should return code 412 precondition failed. + // assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalGetIfNoneMatchPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "GET", index, + "If-None-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("

item=" + index) != -1); + // Should return code 412 PreconditionFailed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a POJO get method implementation using the HTTP binding. + * @throws Exception + */ + public void testDelete() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST1, "DELETE", index, + content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + assertTrue(document.indexOf("deleted item=" + index) != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalDeleteIfModifiedNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "DELETE", index, + "If-Modified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("deleted item=" + index) != -1); + // Should return code 304 Not Modified. + // assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalDeleteIfModifiedPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "DELETE", index, + "If-Modified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("deleted item=" + index) != -1); + // Should return code 304 Not Modified. + assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalDeleteIfUnmodifiedNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "DELETE", index, + "If-Unmodified-Since", dateFormat.format(new Date()), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("deleted item=" + index) != -1); + // Should return code 304 Not Modified. + // assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalDeleteIfUnmodifiedPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "DELETE", index, + "If-Unmodified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("deleted item=" + index) != -1); + // Should return code 412 PreconditionFailed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalDeleteIfMatchNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "DELETE", index, + "If-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("deleted item=" + index) != -1); + // Should return code 412 precondition failed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalDeleteIfMatchPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "DELETE", index, + "If-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("deleted item=" + index) != -1); + // Should return code 412 PreconditionFailed. + // assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalDeleteIfNoneMatchNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "DELETE", index, + "If-None-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("deleted item=" + index) != -1); + // Should return code 412 precondition failed. + // assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalDeleteIfNoneMatchPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "DELETE", index, + "If-None-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("deleted item=" + index) != -1); + // Should return code 412 PreconditionFailed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a POJO get method implementation using the HTTP binding. + * @throws Exception + */ + public void testPost() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST1, "POST", index, content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPostIfModifiedNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "POST", index, + "If-Modified-Since", dateFormat.format(new Date()), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return code 200 OK + // assertTrue(document.indexOf("posted item=" + index) != -1); + assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1); + // Should return code 304 Not Modified. + // assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPostIfModifiedPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "POST", index, + "If-Modified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("posted item=" + index) != -1); + // Should return code 304 Not Modified. + assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPostIfUnmodifiedNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "POST", index, + "If-Unmodified-Since", dateFormat.format(new Date()), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return code 200 OK + assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1); + // Should return code 304 Not Modified. + // assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPostIfUnmodifiedPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "POST", index, + "If-Unmodified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("posted item=" + index) != -1); + // Should return code 412 PreconditionFailed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPostIfMatchNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "POST", index, + "If-Match", "eTagMatch", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return code 200 OK. + assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1); + // Should return code 412 precondition failed. + // assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPostIfMatchPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat + .format(REQUEST2, "POST", index, "If-Match", "eTagNoneMatch", + content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("posted item=" + index) != -1); + // Should return code 412 PreconditionFailed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPostIfNoneMatchNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "POST", index, + "If-None-Match", "eTagNoneMatch", content.getBytes().length, + content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return code 200 OK + assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1); + // Should return code 412 precondition failed. + // assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPostIfNoneMatchPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "POST", index, + "If-None-Match", "eTagMatch", content.getBytes().length, + content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("posted item=" + index) != -1); + // Should return code 412 PreconditionFailed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a POJO get method implementation using the HTTP binding. + * @throws Exception + */ + public void testPut() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST1, "PUT", index, content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + assertTrue(document.indexOf("updated item=" + index) != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPutIfModifiedNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "PUT", index, + "If-Modified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("updated item=" + index) != -1); + // Should return code 304 Not Modified. + // assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPutIfModifiedPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "PUT", index, + "If-Modified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("updated item=" + index) != -1); + // Should return code 304 Not Modified. + assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPutIfUnmodifiedNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "PUT", index, + "If-Unmodified-Since", dateFormat.format(new Date()), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("updated item=" + index) != -1); + // Should return code 304 Not Modified. + // assertTrue(document.indexOf("HTTP/1.1 304") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPutIfUnmodifiedPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "PUT", index, + "If-Unmodified-Since", dateFormat.format(new Date(0)), content + .getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("updated item=" + index) != -1); + // Should return code 412 PreconditionFailed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPutIfMatchNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "PUT", index, + "If-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("updated item=" + index) != -1); + // Should return code 412 precondition failed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPutIfMatchPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "PUT", index, + "If-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("updated item=" + index) != -1); + // Should return code 412 PreconditionFailed. + // assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPutIfNoneMatchNegative() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 1; + String content = ""; + String request = MessageFormat.format(REQUEST2, "PUT", index, + "If-None-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + assertTrue(document.indexOf("updated item=" + index) != -1); + // Should return code 412 precondition failed. + // assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Test invoking a conditional method implementation using the HTTP binding. + * @throws Exception + */ + public void testConditionalPutIfNoneMatchPositive() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String content = ""; + String request = MessageFormat.format(REQUEST2, "PUT", index, + "If-None-Match", "eTagXXX", content.getBytes().length, content); + os.write(request.getBytes()); + os.flush(); + + String document = read(client); + // Should return item + // assertTrue(document.indexOf("updated item=" + index) != -1); + // Should return code 412 PreconditionFailed. + assertTrue(document.indexOf("HTTP/1.1 412") != -1); + } + + /** + * Read response stream from the given socket. + * @param socket + * @return + * @throws IOException + */ + private static String read(Socket socket) throws IOException { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(socket + .getInputStream())); + StringBuffer sb = new StringBuffer(); + String str; + while ((str = reader.readLine()) != null) { + sb.append(str); + } + return sb.toString(); + } finally { + if (reader != null) { + reader.close(); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java new file mode 100644 index 0000000000..e5cad080a6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.http; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.Socket; +import java.text.MessageFormat; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * HTTP binding unit tests. + * + * @version $Rev$ $Date$ + */ +public class HTTPBindingTestCase extends TestCase { + + private static final String REQUEST1_HEADER = + "GET /httpservice/test HTTP/1.0\n" + "Host: localhost\n" + + "Content-Type: text/xml\n" + + "Connection: close\n" + + "Content-Length: "; + private static final String REQUEST1_CONTENT = ""; + private static final String REQUEST1 = + REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT; + + private static final String REQUEST2_HEADER = + "GET /webcontent/test.html HTTP/1.0\n" + "Host: localhost\n" + + "Content-Type: text/xml\n" + + "Connection: close\n" + + "Content-Length: "; + private static final String REQUEST2_CONTENT = ""; + private static final String REQUEST2 = + REQUEST2_HEADER + REQUEST2_CONTENT.getBytes().length + "\n\n" + REQUEST2_CONTENT; + + private static final String REQUEST3_HEADER = + "GET /httpget/{0} HTTP/1.0\n" + "Host: localhost\n" + + "Content-Type: text/xml\n" + + "Connection: close\n" + + "Content-Length: "; + private static final String REQUEST3_CONTENT = ""; + private static final String REQUEST3 = + REQUEST3_HEADER + REQUEST3_CONTENT.getBytes().length + "\n\n" + REQUEST3_CONTENT; + + private static final int HTTP_PORT = 8085; + + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("test.composite"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + /** + * Test invoking a POJO service implementation using the HTTP binding. + * @throws Exception + */ + public void testServiceImplementation() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + os.write(REQUEST1.getBytes()); + os.flush(); + + String document = read(client); + assertTrue(document.indexOf("

hey") != -1); + } + + /** + * Test invoking a POJO get method implementation using the HTTP binding. + * @throws Exception + */ + public void testGetImplementation() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + int index = 0; + String request = MessageFormat.format( REQUEST3, index ); + os.write( request.getBytes()); + os.flush(); + + String document = read(client); + assertTrue(document.indexOf("

item=" + index) != -1); + } + + /** + * Test getting a static resource provided using the HTTP binding. + * @throws Exception + */ + public void testStaticResourceImplementation() throws Exception { + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + os.write(REQUEST2.getBytes()); + os.flush(); + + String document = read(client); + assertTrue(document.indexOf("

hello") != -1); + } + + /** + * Read response stream from the given socket. + * @param socket + * @return + * @throws IOException + */ + private static String read(Socket socket) throws IOException { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); + StringBuffer sb = new StringBuffer(); + String str; + while ((str = reader.readLine()) != null) { + sb.append(str); + } + return sb.toString(); + } finally { + if (reader != null) { + reader.close(); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/NotModifiedException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/NotModifiedException.java new file mode 100644 index 0000000000..1d6efea2a1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/NotModifiedException.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.sca.binding.http; + +/** + * Indicates that a resource was not modified. + * + * @version $Rev$ $Date$ + */ +public class NotModifiedException extends Exception { + private static final long serialVersionUID = -5046027674128627383L; + + public NotModifiedException() { + } + + public NotModifiedException(String message) { + super(message); + } + + public NotModifiedException(Throwable cause) { + super(cause); + } + + public NotModifiedException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/PreconditionFailedException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/PreconditionFailedException.java new file mode 100644 index 0000000000..5728899ebe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/PreconditionFailedException.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.sca.binding.http; + +/** + * Indicates that a resource was not modified. + * + * @version $Rev$ $Date$ + */ +public class PreconditionFailedException extends Exception { + private static final long serialVersionUID = -5046027674128627383L; + + public PreconditionFailedException() { + } + + public PreconditionFailedException(String message) { + super(message); + } + + public PreconditionFailedException(Throwable cause) { + super(cause); + } + + public PreconditionFailedException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestBindingCacheImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestBindingCacheImpl.java new file mode 100644 index 0000000000..f2456f3175 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestBindingCacheImpl.java @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Date; + +/** + * Test service implementation that implements a various conditional HTTP + * methods. For testing, the id==0 items are very old (Date(0)), not modified, + * and always match ETags and the id==1 items are always brand new (Date()), + * modified, and never match ETags. Using these ids one can test the + * LastModified and ETag headers of the requests. + * + * @version $Rev$ $Date$ + */ +public class TestBindingCacheImpl { + + /** + * Implements the HTTP get method of the collection implementation. + * @param id + * @return + */ + public InputStream get(String id) { + return new ByteArrayInputStream( + ("

item=" + id + "").getBytes()); + } + + /** + * Implements the HTTP conditional get method of the collection implementation. + * @param id + * @return + */ + public InputStream conditionalGet(String id, HTTPCacheContext cacheContext) + throws NotModifiedException, PreconditionFailedException { + + if (cacheContext != null) { + if (cacheContext.ifModifiedSince) { + if ((id.equals("1")) + && (0 > cacheContext.lastModifiedDate + .compareTo(new Date()))) + throw new NotModifiedException("item 1 was modified on " + + new Date()); + } + if (cacheContext.ifUnmodifiedSince) { + if ((id.equals("0")) + && (0 > cacheContext.lastModifiedDate + .compareTo(new Date()))) + throw new PreconditionFailedException( + "item 0 was modified on " + new Date(0)); + } + if (cacheContext.ifMatch) { + if (id.equals("1")) + throw new PreconditionFailedException( + "item 1 eTag does not match " + + cacheContext.getETag()); + } + if (cacheContext.ifNoneMatch) { + if (id.equals("0")) + throw new PreconditionFailedException( + "item 0 eTag matches " + cacheContext.getETag()); + } + } + return new ByteArrayInputStream( + ("

item=" + id + "").getBytes()); + } + + /** + * Implements the HTTP delete method of the collection implementation. + * @param id + * @return + */ + public InputStream delete(String id) { + return new ByteArrayInputStream( + ("

deleted item=" + id + "") + .getBytes()); + } + + /** + * Implements the HTTP conditional delete method of the collection implementation. + * @param id + * @return + */ + public InputStream conditionalDelete(String id, HTTPCacheContext cacheContext) + throws NotModifiedException, PreconditionFailedException { + + if (cacheContext != null) { + if (cacheContext.ifModifiedSince) { + if ((id.equals("1")) + && (0 > cacheContext.lastModifiedDate + .compareTo(new Date()))) + throw new NotModifiedException("item 1 was modified on " + + new Date()); + } + if (cacheContext.ifUnmodifiedSince) { + if ((id.equals("0")) + && (0 > cacheContext.lastModifiedDate + .compareTo(new Date()))) + throw new PreconditionFailedException( + "item 0 was modified on " + new Date(0)); + } + if (cacheContext.ifMatch) { + if (id.equals("1")) + throw new PreconditionFailedException( + "item 1 eTag does not match " + + cacheContext.getETag()); + } + if (cacheContext.ifNoneMatch) { + if (id.equals("0")) + throw new PreconditionFailedException( + "item 0 eTag matches " + cacheContext.getETag()); + } + } + return new ByteArrayInputStream( + ("

deleted item=" + id + "") + .getBytes()); + } + + /** + * Implements the HTTP post method of the collection implementation. + * @param id + * @return + */ + public InputStream post() { + int id = (new java.util.Random()).nextInt(Integer.MAX_VALUE); + return new ByteArrayInputStream( + ("

posted item=" + id + "") + .getBytes()); + } + + /** + * Implements the HTTP conditional post method of the collection implementation. + * @param id + * @return + */ + public HTTPCacheContext conditionalPost(HTTPCacheContext cacheContext) + throws NotModifiedException, PreconditionFailedException { + String id = "" + (new java.util.Random()).nextInt(Integer.MAX_VALUE); + + if (cacheContext != null) { + if (cacheContext.ifModifiedSince) { + if (0 >= cacheContext.lastModifiedDate.compareTo(new Date(0))) + throw new NotModifiedException("item was modified on " + + new Date()); + } + if (cacheContext.ifUnmodifiedSince) { + if ((0 >= cacheContext.lastModifiedDate.compareTo(new Date(0)))) + throw new PreconditionFailedException( + "item was modified on " + new Date(0)); + } + if (cacheContext.ifMatch) { + if (cacheContext.getETag().equalsIgnoreCase("ETagNoneMatch")) + throw new PreconditionFailedException( + "item eTag does not match " + + cacheContext.getETag()); + } + if (cacheContext.ifNoneMatch) { + if (cacheContext.getETag().equalsIgnoreCase("ETagMatch")) + throw new PreconditionFailedException("item eTag matches " + + cacheContext.getETag()); + } + } + + // Return the ETag and LastModfied fields by serialize to a byte array + HTTPCacheContext returnContext = new HTTPCacheContext(); + returnContext.setETag( "ETag" + (new java.util.Random()).nextInt(Integer.MAX_VALUE) ); + returnContext.setLastModified( new Date() ); + return returnContext; + } + + /** + * Implements the HTTP update/put method of the collection implementation. + * @param id + * @return + */ + public InputStream put(String id) { + return new ByteArrayInputStream( + ("

updated item=" + id + "") + .getBytes()); + } + + /** + * Implements the HTTP conditional update/put method of the collection implementation. + * @param id + * @return + */ + public InputStream conditionalPut(String id, HTTPCacheContext cacheContext) + throws NotModifiedException, PreconditionFailedException { + + if (cacheContext != null) { + if (cacheContext.ifModifiedSince) { + if ((id.equals("1")) + && (0 > cacheContext.lastModifiedDate + .compareTo(new Date()))) + throw new NotModifiedException("item 1 was modified on " + + new Date()); + } + if (cacheContext.ifUnmodifiedSince) { + if ((id.equals("0")) + && (0 > cacheContext.lastModifiedDate + .compareTo(new Date()))) + throw new PreconditionFailedException( + "item 0 was modified on " + new Date(0)); + } + if (cacheContext.ifMatch) { + if (id.equals("1")) + throw new PreconditionFailedException( + "item 1 eTag does not match " + + cacheContext.getETag()); + } + if (cacheContext.ifNoneMatch) { + if (id.equals("0")) + throw new PreconditionFailedException( + "item 0 eTag matches " + cacheContext.getETag()); + } + } + + return new ByteArrayInputStream( + ("

updated item=" + id + "") + .getBytes()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java new file mode 100644 index 0000000000..333bacbab3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.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.sca.binding.http; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +/** + * Test service implementation that implements a get method. + * + * @version $Rev$ $Date$ + */ +public class TestGetImpl { + + public InputStream get(String id) { + return new ByteArrayInputStream(("

item=" + id + "").getBytes()); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceCacheImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceCacheImpl.java new file mode 100644 index 0000000000..ed846c1127 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceCacheImpl.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.sca.binding.http; + +import java.io.IOException; + +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.osoa.sca.annotations.Service; + +/** + * Test service implementation. + * + * @version $Rev$ $Date$ + */ + +@Service(Servlet.class) +public class TestServiceCacheImpl implements Servlet { + + public void init(ServletConfig config) throws ServletException { + } + + public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { + //HttpServletResponse httpResponse = (HttpServletResponse)response; + response.getOutputStream().print("

hey"); + } + + public void destroy() { + } + + public ServletConfig getServletConfig() { + return null; + } + + public String getServletInfo() { + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java new file mode 100644 index 0000000000..11945c8cd1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.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.sca.binding.http; + +import java.io.IOException; + +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.osoa.sca.annotations.Service; + +/** + * Test service implementation. + * + * @version $Rev$ $Date$ + */ + +@Service(Servlet.class) +public class TestServiceImpl implements Servlet { + + public void init(ServletConfig config) throws ServletException { + } + + public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { + //HttpServletResponse httpResponse = (HttpServletResponse)response; + response.getOutputStream().print("

hey"); + } + + public void destroy() { + } + + public ServletConfig getServletConfig() { + return null; + } + + public String getServletInfo() { + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/content/test.html b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/content/test.html new file mode 100644 index 0000000000..f4b79d7f01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/content/test.html @@ -0,0 +1,21 @@ + + +

hello + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/test.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/test.composite new file mode 100644 index 0000000000..62c4af4e22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/test.composite @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/testCache.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/testCache.composite new file mode 100644 index 0000000000..d805402c4f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http-runtime/src/test/resources/testCache.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/pom.xml new file mode 100644 index 0000000000..3d907ceca5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/pom.xml @@ -0,0 +1,87 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-http + Apache Tuscany SCA HTTP Binding Model + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 1.6-SNAPSHOT + + + + javax.servlet + servlet-api + 2.5 + provided + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.http + ${pom.name} + org.apache.tuscany.sca.binding.http* + org.apache.tuscany.sca.assembly.xml;version="1.4", * + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBinding.java new file mode 100644 index 0000000000..3a749c5f29 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBinding.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.sca.binding.http; + +import org.apache.tuscany.sca.assembly.BindingRRB; + + +/** + * HTTP binding model. + * + * @version $Rev$ $Date$ +*/ +public interface HTTPBinding extends BindingRRB { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBindingContext.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBindingContext.java new file mode 100644 index 0000000000..f7e5bac606 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBindingContext.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.sca.binding.http; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * HTTP Binding Context + * + * @version $Rev$ $Date$ + */ +public class HTTPBindingContext { + private HttpServletRequest request; + private HttpServletResponse response; + + public HttpServletRequest getHttpRequest() { + return request; + } + public void setHttpRequest(HttpServletRequest request) { + this.request = request; + } + public HttpServletResponse getHttpResponse() { + return response; + } + public void setHttpResponse(HttpServletResponse response) { + this.response = response; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBindingFactory.java new file mode 100644 index 0000000000..e66896c68e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPBindingFactory.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.sca.binding.http; + +/** + * Factory for the HTTP binding model. + * + * @version $Rev$ $Date$ + */ +public interface HTTPBindingFactory { + + /** + * Creates a new HTTP binding. + * @return a new HTTP binding + */ + HTTPBinding createHTTPBinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPCacheContext.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPCacheContext.java new file mode 100644 index 0000000000..fb9242c26c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPCacheContext.java @@ -0,0 +1,257 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.http; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; + +/** + * A class to store cache settings for Atom and HTTP requests and responses. + * + * Predicates are statements that work in conjunction with + * ETags and LastModified dates to determine if a precondition + * or postcondition is satisfied. + * See HTTP specification for how predicates wrk: + * http://tools.ietf.org/html/rfc2616 + * Example predicates in HTTP include If-Match, If-None-Match, + * If-Modified-Since, If-Unmodified-Since, If-Range. + + */ +public class HTTPCacheContext { + public static final SimpleDateFormat RFC822DateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time + + public boolean enabled; + public String eTag; + public String lastModified; + public Date lastModifiedDate; + public boolean ifModifiedSince; + public boolean ifUnmodifiedSince; + public boolean ifMatch; + public boolean ifNoneMatch; + public boolean ifRange; + + /** + * An ETag is a unique ID for an item. It changes when + * a field in the item or the update date changes. + * See HTTP specification for how ETags work: + * http://tools.ietf.org/html/rfc2616 + * @return the eTag + */ + public String getETag() { + return eTag; + } + /** + * @param tag the eTag to set + */ + public void setETag(String tag) { + eTag = tag; + enabled = true; + } + /** + * The LastModified date is the time the item was last + * changed. See HTTP specification for how ETags work: + * http://tools.ietf.org/html/rfc2616 + * @return the lastModified + */ + public String getLastModified() { + return lastModified; + } + /** + * The LastModified date is the time the item was last + * changed. See HTTP specification for how ETags work: + * http://tools.ietf.org/html/rfc2616 + * @return the lastModified + */ + public Date getLastModifiedAsDate() { + return lastModifiedDate; + } + /** + * @param lastModified the lastModified to set + */ + public void setLastModified(String lastModified) throws java.text.ParseException { + this.lastModified = lastModified; + // Catch date formatting on input to help debugging. + lastModifiedDate = RFC822DateFormat.parse( lastModified ); + enabled = true; + } + + /** + * @param lastModified the lastModified to set + */ + public void setLastModified(Date updated) { + this.lastModified = RFC822DateFormat.format( updated ); + lastModifiedDate = updated; + enabled = true; + } + + /** + * @return the ifModifedSince + */ + public boolean isIfModifiedSince() { + return ifModifiedSince; + } + /** + * @param ifModifedSince the ifModifedSince to set + */ + public void setIfModifiedSince(boolean ifModifiedSince) { + this.ifModifiedSince = ifModifiedSince; + if ( ifModifiedSince ) + enabled = true; + } + /** + * @return the ifUnModifiedSince + */ + public boolean isIfUnmodifiedSince() { + return ifUnmodifiedSince; + } + /** + * @param ifUnModifiedSince the ifUnModifiedSince to set + */ + public void setIfUnmodifiedSince(boolean ifUnmodifiedSince) { + this.ifUnmodifiedSince = ifUnmodifiedSince; + if ( ifUnmodifiedSince ) + enabled = true; + } + /** + * @return the ifMatch + */ + public boolean isIfMatch() { + return ifMatch; + } + /** + * @param ifMatch the ifMatch to set + */ + public void setIfMatch(boolean ifMatch) { + this.ifMatch = ifMatch; + if ( ifMatch ) + enabled = true; + } + /** + * @return the ifNoneMatch + */ + public boolean isIfNoneMatch() { + return ifNoneMatch; + } + /** + * @param ifNoneMatch the ifNoneMatch to set + */ + public void setIfNoneMatch(boolean ifNoneMatch) { + this.ifNoneMatch = ifNoneMatch; + if ( ifNoneMatch ) + enabled = true; + } + /** + * @return the ifRange + */ + public boolean isIfRange() { + return ifRange; + } + /** + * @param ifRange the ifRange to set + */ + public void setIfRange(boolean ifRange) { + this.ifRange = ifRange; + if ( ifRange ) + enabled = true; + } + + public String toString() { + final String PREDPREFIX = ", predicates="; + StringBuffer sb = new StringBuffer(PREDPREFIX); + if ( ifMatch || ifNoneMatch || ifModifiedSince || ifUnmodifiedSince || ifRange ) { + if ( ifMatch ) { + if ( sb.length() > PREDPREFIX.length() ) sb.append( ", "); + sb.append("If-Match"); + } + if ( ifNoneMatch ) { + if ( sb.length() > PREDPREFIX.length() ) sb.append( ", "); + sb.append("If-None-Match"); + } + if ( ifModifiedSince ) { + if ( sb.length() > PREDPREFIX.length() ) sb.append( ", "); + sb.append("If-Modified-Since"); + } + if ( ifUnmodifiedSince ) { + if ( sb.length() > PREDPREFIX.length() ) sb.append( ", "); + sb.append("If-UnModified-Since"); + } + if ( ifRange ) { + if ( sb.length() > PREDPREFIX.length() ) sb.append( ", "); + sb.append("If-Range"); + } + } else { + sb.append("null"); + } + + return "eTag=" + eTag + ", lastModified=" + lastModified + + sb.toString(); + } + + /** + * Gets the cache context information (ETag, LastModified, predicates) from the Http request. + * @param request + * @return + */ + public static HTTPCacheContext getCacheContextFromRequest( HttpServletRequest request ) throws java.text.ParseException { + HTTPCacheContext context = new HTTPCacheContext(); + + String eTag = request.getHeader( "If-Match" ); + if ( eTag != null ) { + context.setETag( eTag ); + context.setIfMatch( true ); + } + eTag = request.getHeader( "If-None-Match" ); + if ( eTag != null ) { + context.setETag( eTag ); + context.setIfNoneMatch( true ); + } + String lastModifiedString = request.getHeader( "If-Modified-Since" ); + if ( lastModifiedString != null ) { + context.setLastModified( lastModifiedString ); + context.setIfModifiedSince( true ); + } + lastModifiedString = request.getHeader( "If-Unmodified-Since" ); + if ( lastModifiedString != null ) { + context.setLastModified( lastModifiedString ); + context.setIfUnmodifiedSince( true ); + } + lastModifiedString = request.getHeader( "If-Range" ); + if ( lastModifiedString != null ) { + context.setLastModified( lastModifiedString ); + context.setIfRange( true ); + } + return context; + } + /** + * Enabled is true whenever ETag, LastModified, or predicate is set. + * @return the enabled + */ + public boolean isEnabled() { + return enabled; + } + /** + * @param enabled the enabled to set + */ + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPHeader.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPHeader.java new file mode 100644 index 0000000000..69e44cf35c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPHeader.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.sca.binding.http; + +public class HTTPHeader { + private String name; + private Object value; + + public HTTPHeader() { + + } + + public HTTPHeader(String name, Object value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPBindingFactoryImpl.java new file mode 100644 index 0000000000..678cd1a426 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPBindingFactoryImpl.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.sca.binding.http.impl; + +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.binding.http.HTTPBindingFactory; + +/** + * Factory for the HTTP binding model. + * + * @version $Rev$ $Date$ + */ +public class HTTPBindingFactoryImpl implements HTTPBindingFactory { + + public HTTPBinding createHTTPBinding() { + return new HTTPBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPBindingImpl.java new file mode 100644 index 0000000000..c902797a79 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPBindingImpl.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.sca.binding.http.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + + +/** + * Implementation of the HTTP binding model. + * + * @version $Rev$ $Date$ + */ +class HTTPBindingImpl implements HTTPBinding, PolicySetAttachPoint { + + private String name; + private String uri; + + private WireFormat wireFormat; + private OperationSelector operationSelector; + + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + // The sample binding is always resolved + } + +// Wireformat and Operation selection + + public WireFormat getRequestWireFormat() { + return wireFormat; + } + + public void setRequestWireFormat(WireFormat wireFormat) { + this.wireFormat = wireFormat; + } + + public WireFormat getResponseWireFormat() { + return wireFormat; + } + + public void setResponseWireFormat(WireFormat wireFormat) { + this.wireFormat = wireFormat; + } + + public OperationSelector getOperationSelector() { + return operationSelector; + } + + public void setOperationSelector(OperationSelector operationSelector) { + this.operationSelector = operationSelector; + } + + //Policy related getters/setters + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java new file mode 100644 index 0000000000..cdd5c0d992 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.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.sca.binding.http.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.binding.http.HTTPBindingFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.policy.PolicyFactory; + +public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + private static final String BINDING_HTTP = "binding.http"; + private static final QName BINDING_HTTP_QNAME = new QName(Constants.SCA10_TUSCANY_NS, BINDING_HTTP); + + private static final String NAME = "name"; + private static final String URI = "uri"; + + private HTTPBindingFactory httpBindingFactory; + private StAXArtifactProcessor extensionProcessor; + private StAXAttributeProcessor extensionAttributeProcessor; + private PolicyFactory policyFactory; + private PolicyAttachPointProcessor policyProcessor; + private Monitor monitor; + + public HTTPBindingProcessor(ExtensionPointRegistry extensionPoints, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.httpBindingFactory = modelFactories.getFactory(HTTPBindingFactory.class); + this.extensionProcessor = (StAXArtifactProcessor)extensionProcessor; + this.extensionAttributeProcessor = extensionAttributeProcessor; + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.monitor = monitor; + } + + public QName getArtifactType() { + return BINDING_HTTP_QNAME; + } + + public Class getModelType() { + return HTTPBinding.class; + } + + public HTTPBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + HTTPBinding httpBinding = httpBindingFactory.createHTTPBinding(); + + // Read policies + policyProcessor.readPolicies(httpBinding, reader); + + while(reader.hasNext()) { + QName elementName = null; + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + elementName = reader.getName(); + + if (BINDING_HTTP_QNAME.equals(elementName)) { + String name = getString(reader, NAME); + if(name != null) { + httpBinding.setName(name); + } + + String uri = getString(reader, URI); + if (uri != null) { + httpBinding.setURI(uri); + } + } else { + // Read an extension element + Object extension = extensionProcessor.read(reader); + if (extension != null) { + if (extension instanceof WireFormat) { + httpBinding.setRequestWireFormat((WireFormat)extension); + } else if(extension instanceof OperationSelector) { + httpBinding.setOperationSelector((OperationSelector)extension); + } + } + } + + } + + if (event == END_ELEMENT && BINDING_HTTP_QNAME.equals(reader.getName())) { + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return httpBinding; + } + + public void write(HTTPBinding httpBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + writeStart(writer, BINDING_HTTP_QNAME.getNamespaceURI(), BINDING_HTTP_QNAME.getLocalPart()); + + //write policies + policyProcessor.writePolicyAttributes(httpBinding, writer); + + // Write binding name + if (httpBinding.getName() != null) { + writer.writeAttribute(NAME, httpBinding.getName()); + } + + // Write binding URI + if (httpBinding.getURI() != null) { + writer.writeAttribute(URI, httpBinding.getURI()); + } + + if ( httpBinding.getRequestWireFormat() != null ) { + extensionProcessor.write(httpBinding.getRequestWireFormat(), writer); + } + + if ( httpBinding.getOperationSelector() != null ) { + extensionProcessor.write(httpBinding.getOperationSelector(), writer); + } + writeEnd(writer); + } + + + public void resolve(HTTPBinding model, ModelResolver resolver) throws ContributionResolveException { + policyProcessor.resolvePolicies(model, resolver); + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "binding-http-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.HTTPBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.HTTPBindingFactory new file mode 100644 index 0000000000..44da6b166c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.HTTPBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for model factory +org.apache.tuscany.sca.binding.http.impl.HTTPBindingFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..ac004e826a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.http.xml.HTTPBindingProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.http,model=org.apache.tuscany.sca.binding.http.HTTPBinding,factory=org.apache.tuscany.sca.binding.http.HTTPBindingFactory diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/pom.xml new file mode 100644 index 0000000000..03e09982d5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-jms-policy + Apache Tuscany SCA Policy Model for JMS Binding + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.geronimo.specs + geronimo-jms_1.1_spec + 1.1 + provided + + + org.apache.geronimo.specs + geronimo-jms_1.1_spec + + + + + + org.apache.tuscany.sca + tuscany-binding-jms-runtime + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy-reliability + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy-security + 1.6-SNAPSHOT + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.jms.policy + ${pom.name} + org.apache.tuscany.sca.binding.jms.policy* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/JMSBindingDefinitionsProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/JMSBindingDefinitionsProvider.java new file mode 100644 index 0000000000..de54545f7e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/JMSBindingDefinitionsProvider.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.sca.binding.jms.policy; + +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; + +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.provider.SCADefinitionsProvider; +import org.apache.tuscany.sca.provider.SCADefinitionsProviderException; + +/** + * Provider for Policy Intents and PolicySet definitions for the JMS binding + * + * @version $Rev$ $Date$ + */ +public class JMSBindingDefinitionsProvider implements SCADefinitionsProvider { + private String definitionsFile = "org/apache/tuscany/sca/binding/jms/policy/definitions.xml"; + URLArtifactProcessor urlArtifactProcessor = null; + + public JMSBindingDefinitionsProvider(ExtensionPointRegistry registry) { + URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + urlArtifactProcessor = (URLArtifactProcessor)documentProcessors.getProcessor(SCADefinitions.class); + } + + public SCADefinitions getSCADefinition() throws SCADefinitionsProviderException { + final URL definitionsFileUrl = getClass().getClassLoader().getResource(definitionsFile); + SCADefinitions scaDefn = null; + try { + final URI uri = new URI(definitionsFile); + // Allow bindings to read properties. Requires PropertyPermission read in security policy. + scaDefn = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public SCADefinitions run() throws ContributionReadException { + return (SCADefinitions)urlArtifactProcessor.read(null, uri, definitionsFileUrl); + } + }); + } catch (Exception e) { + throw new SCADefinitionsProviderException(e); + } + return scaDefn; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java new file mode 100644 index 0000000000..16ed2a53a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.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.sca.binding.jms.policy.authentication.token; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.policy.Policy; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationPolicy implements Policy { + public static final QName JMS_TOKEN_AUTHENTICATION_POLICY_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "jmsTokenAuthentication"); + public static final String JMS_TOKEN_AUTHENTICATION_TOKEN_NAME = "tokenName"; + + private QName tokenName; + + public QName getTokenName() { + return tokenName; + } + + public void setTokenName(QName tokenName) { + this.tokenName = tokenName; + } + + public QName getSchemaName() { + return JMS_TOKEN_AUTHENTICATION_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java new file mode 100644 index 0000000000..11747914da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.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.sca.binding.jms.policy.authentication.token; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_POLICY_QNAME; + } + + public JMSTokenAuthenticationPolicyProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public JMSTokenAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + JMSTokenAuthenticationPolicy policy = new JMSTokenAuthenticationPolicy(); + int event = reader.getEventType(); + QName name = null; + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(getArtifactType()) ) { + policy.setTokenName(getQName(reader, JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_TOKEN_NAME)); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( getArtifactType().equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(JMSTokenAuthenticationPolicy policy, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + if ( policy.getTokenName() != null ) { + writer.writeAttribute(prefix, + getArtifactType().getNamespaceURI(), + JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_TOKEN_NAME, + policy.getTokenName().toString()); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return JMSTokenAuthenticationPolicy.class; + } + + public void resolve(JMSTokenAuthenticationPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProviderFactory.java new file mode 100644 index 0000000000..fd77e57418 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProviderFactory.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.sca.binding.jms.policy.authentication.token; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationPolicyProviderFactory implements PolicyProviderFactory { + private ExtensionPointRegistry registry; + + public JMSTokenAuthenticationPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) { + return null;//new TokenAuthenticationImplementationPolicyProvider(component, implementation); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new JMSTokenAuthenticationReferencePolicyProvider(component, reference, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new JMSTokenAuthenticationServicePolicyProvider(component, service, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationReferencePolicyInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationReferencePolicyInterceptor.java new file mode 100644 index 0000000000..56fffeb817 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationReferencePolicyInterceptor.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.policy.authentication.token; + + +import javax.jms.JMSException; +import javax.security.auth.Subject; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.SecurityUtil; +import org.apache.tuscany.sca.policy.authentication.token.TokenPrincipal; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationReferencePolicyInterceptor implements Interceptor { + + private Invoker next; + private PolicySet policySet = null; + private String context; + private JMSTokenAuthenticationPolicy policy; + + public JMSTokenAuthenticationReferencePolicyInterceptor(String context, PolicySet policySet) { + super(); + this.policySet = policySet; + this.context = context; + init(); + } + + private void init() { + if (policySet != null) { + for (Object policyObject : policySet.getPolicies()){ + if (policyObject instanceof JMSTokenAuthenticationPolicy){ + policy = (JMSTokenAuthenticationPolicy)policyObject; + break; + } + } + } + } + + public Message invoke(Message msg) { + try { + javax.jms.Message jmsMsg = msg.getBody(); + + if ( policy.getTokenName() != null){ + + Subject subject = SecurityUtil.getSubject(msg); + TokenPrincipal principal = SecurityUtil.getPrincipal(subject, TokenPrincipal.class); + + if (principal == null){ + // should call out here to some 3rd party system to get credentials + // and correct token. Here we are just putting in the token name + principal = new TokenPrincipal("DummyTokenID"); + subject.getPrincipals().add(principal); + } + + jmsMsg.setStringProperty(policy.getTokenName().toString(), principal.getName()); + } + + return getNext().invoke(msg); + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationReferencePolicyProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationReferencePolicyProvider.java new file mode 100644 index 0000000000..b4fa617f74 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationReferencePolicyProvider.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.policy.authentication.token; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationReferencePolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private RuntimeComponentReference reference; + private Binding binding; + + public JMSTokenAuthenticationReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.component = component; + this.reference = reference; + this.binding = binding; + } + + private PolicySet findPolicySet() { + if (binding instanceof PolicySetAttachPoint) { + List policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (JMSTokenAuthenticationPolicy.class.isInstance(p)) { + return ps; + } + } + } + } + return null; + } + + private String getContext() { + return "component.reference: " + component.getURI() + + "#" + + reference.getName() + + "(" + + binding.getClass().getName() + + ")"; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor(Operation operation) { + PolicySet ps = findPolicySet(); + return ps == null ? null : new JMSTokenAuthenticationReferencePolicyInterceptor(getContext(), ps); + + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.REFERENCE_BINDING_POLICY; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java new file mode 100644 index 0000000000..c8d28ad5db --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.policy.authentication.token; + + + +import javax.jms.JMSException; +import javax.security.auth.Subject; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.SecurityUtil; +import org.apache.tuscany.sca.policy.authentication.token.TokenPrincipal; + +/** + * Policy handler to handle token based authentication + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationServicePolicyInterceptor implements Interceptor { + private Invoker next; + private PolicySet policySet = null; + private String context; + private JMSTokenAuthenticationPolicy policy; + + public JMSTokenAuthenticationServicePolicyInterceptor(String context, PolicySet policySet) { + super(); + this.policySet = policySet; + this.context = context; + init(); + } + + private void init() { + if (policySet != null) { + for (Object policyObject : policySet.getPolicies()){ + if (policyObject instanceof JMSTokenAuthenticationPolicy){ + policy = (JMSTokenAuthenticationPolicy)policyObject; + break; + } + } + } + } + + public Message invoke(Message msg) { + try{ + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + + String token = jmsMsg.getStringProperty(policy.getTokenName().toString()); + + Subject subject = SecurityUtil.getSubject(msg); + TokenPrincipal principal = SecurityUtil.getPrincipal(subject, TokenPrincipal.class); + + if (principal == null){ + principal = new TokenPrincipal(token); + subject.getPrincipals().add(principal); + } + + System.out.println("JMS service received token: " + principal.getName()); + + // call out here to some 3rd party system to do whatever you + // need to authenticate the principal + + return getNext().invoke(msg); + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyProvider.java new file mode 100644 index 0000000000..4b0944a420 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyProvider.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.policy.authentication.token; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationServicePolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private RuntimeComponentService service; + private Binding binding; + + public JMSTokenAuthenticationServicePolicyProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) { + super(); + this.component = component; + this.service = service; + this.binding = binding; + } + + private PolicySet findPolicySet() { + if (binding instanceof PolicySetAttachPoint) { + List policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (JMSTokenAuthenticationPolicy.class.isInstance(p)) { + return ps; + } + } + } + } + return null; + } + + private String getContext() { + return "component.service: " + component.getURI() + + "#" + + service.getName() + + "(" + + binding.getClass().getName() + + ")"; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor(Operation operation) { + PolicySet ps = findPolicySet(); + return ps == null ? null : new JMSTokenAuthenticationServicePolicyInterceptor(getContext(), ps); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.SERVICE_BINDING_POLICY; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java new file mode 100644 index 0000000000..1c16e3fa1b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.policy.header; + +import java.util.Hashtable; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.policy.Policy; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class JMSHeaderPolicy implements Policy { + public static final QName JMS_HEADER_POLICY_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "jmsHeader"); + public static final String JMS_HEADER_JMS_TYPE = "JMSType"; + public static final String JMS_HEADER_JMS_CORRELATION_ID = "JMSCorrelationID"; + public static final String JMS_HEADER_JMS_DELIVERY_MODE = "JMSDeliveryMode"; + public static final String JMS_HEADER_JMS_TIME_TO_LIVE = "JMSTimeToLive"; + public static final String JMS_HEADER_JMS_PRIORITY = "JMSPriority"; + public static final String JMS_HEADER_JMS_PROPERTY = "property"; + public static final String JMS_HEADER_JMS_PROPERTY_NAME = "name"; + + private String jmsType = null; + private String jmsCorrelationId = null; + private Boolean deliveryModePersistent = null; + private Long timeToLive = null; + private Integer jmsPriority = null; + private Map properties = new Hashtable(); + + public String getJmsType() { + return jmsType; + } + + public void setJmsType(String jmsType) { + this.jmsType = jmsType; + } + + public String getJmsCorrelationId() { + return jmsCorrelationId; + } + + public void setJmsCorrelationId(String jmsCorrelationId) { + this.jmsCorrelationId = jmsCorrelationId; + } + + public Boolean getDeliveryModePersistent() { + return deliveryModePersistent; + } + + public void setDeliveryModePersistent(Boolean deliveryModePersistent) { + this.deliveryModePersistent = deliveryModePersistent; + } + + public Long getTimeToLive() { + return timeToLive; + } + + public void setTimeToLive(Long timeToLive) { + this.timeToLive = timeToLive; + } + + public Integer getJmsPriority() { + return jmsPriority; + } + + public void setJmsPriority(Integer jmsPriority) { + this.jmsPriority = jmsPriority; + } + + public Map getProperties() { + return properties; + } + + public QName getSchemaName() { + return JMS_HEADER_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + @Override + public String toString() { + String result = "jmsHeader"; + + result += " JMSType "; + result += getJmsType(); + result += " JMSDeliveryMode "; + result += getJmsCorrelationId(); + result += " JMSDeliveryMode "; + result += getDeliveryModePersistent(); + result += " JMSTimeToLive "; + result += getTimeToLive(); + result += " JMSPriority "; + result += getJmsPriority(); + + for (String propertyName : properties.keySet()){ + result += " property "; + result += propertyName; + result += " "; + result += properties.get(propertyName); + } + + return result; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java new file mode 100644 index 0000000000..de2b69201b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.policy.header; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.Hashtable; +import java.util.Map; +import java.util.logging.Level; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * + * @version $Rev$ $Date$ + */ +public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + private Monitor monitor; + + public QName getArtifactType() { + return JMSHeaderPolicy.JMS_HEADER_POLICY_QNAME; + } + + public JMSHeaderPolicyProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + this.monitor = monitor; + } + + /** + * Marshals warnings into the monitor + * + * @param message + * @param model + * @param messageParameters + */ + protected void warning(String message, Object model, String... messageParameters) { + if (monitor != null){ + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-xml-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Marshals errors into the monitor + * + * @param problems + * @param message + * @param model + */ + protected void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + + public JMSHeaderPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + JMSHeaderPolicy policy = new JMSHeaderPolicy(); + int event = reader.getEventType(); + QName name = null; + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(getArtifactType()) ) { + + policy.setJmsType(getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_TYPE)); + policy.setJmsCorrelationId(getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_CORRELATION_ID)); + + String deliveryMode = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_DELIVERY_MODE); + if (deliveryMode != null){ + if (deliveryMode.equals("PERSISTENT")) { + policy.setDeliveryModePersistent(true); + } else if (deliveryMode.equals("NON_PERSISTENT")){ + policy.setDeliveryModePersistent(false); + } else { + error("InvalidDeliveryMode", policy, deliveryMode); + } + } + + String timeToLive = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_TIME_TO_LIVE); + + if ( timeToLive != null){ + try { + policy.setTimeToLive(Long.valueOf(timeToLive)); + } catch (NumberFormatException ex){ + error("InvalidTimeToLive", policy, timeToLive); + } + } + + String priority = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_PRIORITY); + + if ( priority != null){ + try { + policy.setJmsPriority(Integer.valueOf(priority)); + } catch (NumberFormatException ex){ + error("InvalidPriority", policy, priority); + } + } + } else if (name.getLocalPart().equals(JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY)) { + String propertyName = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY_NAME); + String propertyValue = reader.getElementText(); + policy.getProperties().put(propertyName, propertyValue); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( getArtifactType().equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(JMSHeaderPolicy policy, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + if (policy.getJmsType() != null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_TYPE, policy.getJmsType()); + } + + if (policy.getJmsCorrelationId() != null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_CORRELATION_ID, policy.getJmsCorrelationId()); + } + + if (policy.getDeliveryModePersistent() == true){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_DELIVERY_MODE, "PERSISTENT"); + } else { + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_DELIVERY_MODE, "NON_PERSISTENT"); + } + + if (policy.getTimeToLive()!= null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_TIME_TO_LIVE, policy.getTimeToLive().toString()); + } + + if (policy.getJmsPriority()!= null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_PRIORITY, policy.getJmsPriority().toString()); + } + + for (String propertyName : policy.getProperties().keySet()){ + writer.writeStartElement(prefix, + JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY, + getArtifactType().getNamespaceURI()); + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY_NAME, propertyName); + writer.writeCharacters(policy.getProperties().get(propertyName)); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return JMSHeaderPolicy.class; + } + + public void resolve(JMSHeaderPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProviderFactory.java new file mode 100644 index 0000000000..ded3da05b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProviderFactory.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.sca.binding.jms.policy.header; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class JMSHeaderPolicyProviderFactory implements PolicyProviderFactory { + private ExtensionPointRegistry registry; + + public JMSHeaderPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) { + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new JMSHeaderReferencePolicyProvider(component, reference, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderReferencePolicyInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderReferencePolicyInterceptor.java new file mode 100644 index 0000000000..3c7b4467ba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderReferencePolicyInterceptor.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.sca.binding.jms.policy.header; + + +import java.util.Map; + +import javax.jms.DeliveryMode; +import javax.jms.JMSException; +import javax.security.auth.Subject; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.policy.JMSBindingDefinitionsProvider; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.SecurityUtil; +import org.apache.tuscany.sca.policy.authentication.token.TokenPrincipal; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class JMSHeaderReferencePolicyInterceptor implements Interceptor { + + private Invoker next; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private JMSBinding jmsBinding; + private PolicySet policySet = null; + private String context; + private JMSHeaderPolicy jmsHeaderPolicy; + + public JMSHeaderReferencePolicyInterceptor(String context, RuntimeComponent component, RuntimeComponentReference reference, Binding binding, PolicySet policySet) { + super(); + this.component = component; + this.reference = reference; + this.jmsBinding = (JMSBinding)binding; + this.policySet = policySet; + this.context = context; + + init(); + } + + private void init() { + if (policySet != null) { + for (Object policyObject : policySet.getPolicies()){ + if (policyObject instanceof JMSHeaderPolicy){ + jmsHeaderPolicy = (JMSHeaderPolicy)policyObject; + break; + } + } + } + } + + public Message invoke(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + + javax.jms.Message jmsMsg = msg.getBody(); + + // JMS header attrs set on MessageProducer via interceptors. + + return getNext().invoke(msg); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderReferencePolicyProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderReferencePolicyProvider.java new file mode 100644 index 0000000000..3983541de3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderReferencePolicyProvider.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.policy.header; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class JMSHeaderReferencePolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private RuntimeComponentReference reference; + private Binding binding; + + public JMSHeaderReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.component = component; + this.reference = reference; + this.binding = binding; + } + + private PolicySet findPolicySet() { + if (binding instanceof PolicySetAttachPoint) { + List policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (JMSHeaderPolicy.class.isInstance(p)) { + return ps; + } + } + } + } + return null; + } + + private String getContext() { + return "component.reference: " + component.getURI() + + "#" + + reference.getName() + + "(" + + binding.getClass().getName() + + ")"; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor(Operation operation) { + PolicySet ps = findPolicySet(); + return ps == null ? null : new JMSHeaderReferencePolicyInterceptor(getContext(), component, reference, binding, ps); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.REFERENCE_BINDING_POLICY; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..e6f22e327c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#jmsTokenAuthentication,model=org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy +org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#jmsHeader,model=org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory new file mode 100644 index 0000000000..b04c71d8e3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the policy extension +org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicyProviderFactory;model=org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider new file mode 100644 index 0000000000..0598cdc368 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for SCA Definitions Providers +org.apache.tuscany.sca.binding.jms.policy.JMSBindingDefinitionsProvider \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/binding-jms-policy-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/binding-jms-policy-validation-messages.properties new file mode 100644 index 0000000000..fd43b2c4e9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/binding-jms-policy-validation-messages.properties @@ -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. +# +# +InvalidDeliveryMode = JMSDeliveryMode must be either PERSISTENT or NON_PERSISTENT but found {0} +InvalidTimeToLive = JMSTimeToLive must be a long integer but found {0} +InvalidPriority = JMSPriority must be a integer but found {0} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml new file mode 100644 index 0000000000..c87079dd54 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + Communication through this binding requires JMS + + + + + + + This intent is used to indicate the deliver mode + of the sent message + + + + + + Message are sent persistently + + + + + + Message are sent persistently + + + + + + + This intent is used to indicate the priority of the + sent message + + + + + + Messages are high priority + + + + + + Messages are medium priority + + + + + + Messages are low priority + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java new file mode 100644 index 0000000000..a9da07ca7d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.policy; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy; +import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicyProcessor; +import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy; +import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicyProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.policy.Policy; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class PolicyProcessorTestCase { + private final static List SEQ = + Arrays.asList("property value", + ""); + + @Test + public void testRead() throws Exception { + List results = new ArrayList(); + Map processors = new HashMap(); + processors.put(JMSHeaderPolicy.JMS_HEADER_POLICY_QNAME, new JMSHeaderPolicyProcessor(null, null)); + processors.put(JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_POLICY_QNAME, new JMSTokenAuthenticationPolicyProcessor(null, null)); + + InputStream is = getClass().getResourceAsStream("mock_policy_definitions.xml"); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + + XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + + while (true) { + int event = reader.getEventType(); + if (event == XMLStreamConstants.START_ELEMENT) { + if ("policySet".equals(reader.getName().getLocalPart())) { + reader.nextTag(); + StAXArtifactProcessor processor = processors.get(reader.getName()); + Policy policy = (Policy)processor.read(reader); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(outputStream); + processor.write(policy, writer); + writer.flush(); + results.add(outputStream.toString()); + } + } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } + Assert.assertEquals(SEQ, results); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/test/resources/org/apache/tuscany/sca/binding/jms/policy/mock_policy_definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/test/resources/org/apache/tuscany/sca/binding/jms/policy/mock_policy_definitions.xml new file mode 100644 index 0000000000..3631c682aa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-policy/src/test/resources/org/apache/tuscany/sca/binding/jms/policy/mock_policy_definitions.xml @@ -0,0 +1,39 @@ + + + + + + + + property value + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/pom.xml new file mode 100644 index 0000000000..6e1598872b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/pom.xml @@ -0,0 +1,142 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-jms-runtime + Apache Tuscany SCA JMS Binding Runtime + + + + + org.apache.tuscany.sca + tuscany-binding-jms + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-jms + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-axiom + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws-wsdlgen + 1.6-SNAPSHOT + + + + org.apache.geronimo.specs + geronimo-jms_1.1_spec + 1.1 + provided + + + org.apache.geronimo.specs + geronimo-jms_1.1_spec + + + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.jms.runtime + ${pom.name} + org.apache.tuscany.sca.binding.jms.provider* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.java new file mode 100644 index 0000000000..677f8eb6f8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/context/JMSBindingContext.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.context; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Session; +import javax.naming.NamingException; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; + + +/** + * Context that the JMS binding puts on the Tuscany wire + * + * @version $Rev$ $Date$ + */ +public class JMSBindingContext { + + private Message jmsMsg; + private Session jmsSession; + private Session jmsResponseSession; + private Destination requestDestination; + private Destination replyToDestination; + private JMSResourceFactory jmsResourceFactory; + private long timeToLive; + private boolean useBytesForWFJMSDefaultResponse; + + public Message getJmsMsg() { + return jmsMsg; + } + + public void setJmsMsg(Message jmsMsg) { + this.jmsMsg = jmsMsg; + } + + public synchronized Session getJmsSession() { + if (jmsSession == null) { + try { + jmsSession = getJmsResourceFactory().createSession(); + } catch (Exception e) { + throw new JMSBindingException(e); + } + } + return jmsSession; + } + + public synchronized void closeJmsSession() { + if (jmsSession != null) { + try { + getJmsResourceFactory().closeSession(jmsSession); + } catch (Exception e) { + throw new JMSBindingException(e); + } finally { + jmsSession = null; + } + } + } + + public synchronized Session getJmsResponseSession() { + if (jmsResponseSession == null) { + try { + jmsResponseSession = getJmsResourceFactory().createResponseSession(); + } catch (Exception e) { + throw new JMSBindingException(e); + } + } + return jmsResponseSession; + } + + public synchronized void closeJmsResponseSession() { + if (jmsResponseSession != null) { + try { + getJmsResourceFactory().closeResponseSession(jmsResponseSession); + } catch (Exception e) { + throw new JMSBindingException(e); + } finally { + jmsResponseSession = null; + } + } + } + + public Destination getRequestDestination() { + return requestDestination; + } + + public void setRequestDestination(Destination requestDestination) { + this.requestDestination = requestDestination; + } + + public Destination getReplyToDestination() { + return replyToDestination; + } + + public void setReplyToDestination(Destination replyToDestination) { + this.replyToDestination = replyToDestination; + } + + // TODO - difficult to get the resource factory into all the JMS providers + // so it's here for the moment + public JMSResourceFactory getJmsResourceFactory() { + return jmsResourceFactory; + } + + public void setJmsResourceFactory(JMSResourceFactory jmsResourceFactory) { + this.jmsResourceFactory = jmsResourceFactory; + } + + public long getTimeToLive() { + return timeToLive; + } + + public void setTimeToLive(long timeToLive) { + this.timeToLive = timeToLive; + } + + public boolean isUseBytesForWFJMSDefaultResponse() { + return useBytesForWFJMSDefaultResponse; + } + + public void setUseBytesForWFJMSDefaultResponse( + boolean useBytesForWFJMSDefaultResponse) { + this.useBytesForWFJMSDefaultResponse = useBytesForWFJMSDefaultResponse; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java new file mode 100644 index 0000000000..5b7c8f992d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.headers; + + + + +import java.util.Map; + +import javax.jms.DeliveryMode; +import javax.jms.JMSException; +import javax.jms.Session; + +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSBindingServiceBindingProvider; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * + * @version $Rev$ $Date$ + */ +public class HeaderReferenceInterceptor implements Interceptor { + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + private String correlationScheme; + private WireFormat requestWireFormat; + private WireFormat responseWireFormat; + + public HeaderReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + this.correlationScheme = jmsBinding.getCorrelationScheme(); + + } + + public Message invoke(Message msg) { + + return next.invoke(invokeRequest(msg)); + + } + + public Message invokeRequest(Message tuscanyMsg) { + try { + // get the jms context + JMSBindingContext context = tuscanyMsg.getBindingContext(); + javax.jms.Message jmsMsg = tuscanyMsg.getBody(); + + Operation operation = tuscanyMsg.getOperation(); + String operationName = operation.getName(); + RuntimeComponentReference reference = (RuntimeComponentReference)runtimeWire.getSource().getContract(); + + // I think the OASIS spec suggests we do not need to do anything with + // @nativeOperation here on the reference side. + requestMessageProcessor.setOperationName(operationName, jmsMsg); + + if (jmsBinding.getOperationJMSDeliveryMode(operationName) != null) { + if (jmsBinding.getOperationJMSDeliveryMode(operationName)) { + jmsMsg.setJMSDeliveryMode(DeliveryMode.PERSISTENT); + } else { + jmsMsg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); + } + } + + if (jmsBinding.getOperationJMSCorrelationId(operationName) != null) { + jmsMsg.setJMSCorrelationID(jmsBinding.getOperationJMSCorrelationId(operationName)); + } + + if (jmsBinding.getOperationJMSPriority(operationName) != null) { + jmsMsg.setJMSPriority(jmsBinding.getOperationJMSPriority(operationName)); + } + + if (jmsBinding.getOperationJMSType(operationName) != null) { + jmsMsg.setJMSType(jmsBinding.getOperationJMSType(operationName)); + } + + ReferenceParameters parameters = tuscanyMsg.getFrom().getReferenceParameters(); + + Object conversationID = parameters.getConversationID(); + if (conversationID != null) { + jmsMsg.setStringProperty(JMSBindingConstants.CONVERSATION_ID_PROPERTY, conversationID.toString()); + } + + if (tuscanyMsg.getFrom().getCallbackEndpoint() != null) { + + if (parameters.getCallbackID() != null) { + jmsMsg.setStringProperty(JMSBindingConstants.CALLBACK_ID_PROPERTY, parameters.getCallbackID().toString()); + } + + String callbackDestName = getCallbackDestinationName(reference); + if (callbackDestName != null) { + jmsMsg.setStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY, callbackDestName); + } + } + + for (String propName : jmsBinding.getPropertyNames()) { + Object value = jmsBinding.getProperty(propName); + jmsMsg.setObjectProperty(propName, value); + } + + Map operationProperties = jmsBinding.getOperationProperties(operationName); + if (operationProperties != null) { + for (String propName : operationProperties.keySet()) { + Object value = operationProperties.get(propName); + jmsMsg.setObjectProperty(propName, value); + } + } + + if (jmsBinding.getOperationJMSTimeToLive(operationName) != null) { + context.setTimeToLive(jmsBinding.getOperationJMSTimeToLive(operationName) * 2); + } else { + context.setTimeToLive(JMSBindingConstants.DEFAULT_TIME_TO_LIVE); + } + + return tuscanyMsg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + + protected String getCallbackDestinationName(RuntimeComponentReference reference) { + RuntimeComponentService s = (RuntimeComponentService)reference.getCallbackService(); + JMSBinding b = s.getBinding(JMSBinding.class); + if (b != null) { + JMSBindingServiceBindingProvider bp = (JMSBindingServiceBindingProvider)s.getBindingProvider(b); + return bp.getDestinationName(); + } + return null; + } + + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultProviderFactory.java new file mode 100644 index 0000000000..64d01b2863 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultProviderFactory.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.sca.binding.jms.operationselector.jmsdefault.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefault; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSDefaultProviderFactory implements OperationSelectorProviderFactory { + private ExtensionPointRegistry registry; + + public OperationSelectorJMSDefaultProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + */ + public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return null; + } + + /** + */ + public OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new OperationSelectorJMSDefaultServiceProvider(component, service, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java new file mode 100644 index 0000000000..66f875621c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java @@ -0,0 +1,196 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.runtime; + +import java.io.ByteArrayInputStream; +import java.io.StringReader; +import java.util.List; + +import javax.jms.BytesMessage; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.TextMessage; +import javax.jms.Topic; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML; +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSDefaultServiceInterceptor implements Interceptor { + + private static final String ON_MESSAGE_METHOD_NAME = "onMessage"; + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + private RuntimeComponentService service; + private List serviceOperations; + + + public OperationSelectorJMSDefaultServiceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, + RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + this.service = (RuntimeComponentService)runtimeWire.getTarget().getContract(); + this.serviceOperations = service.getInterfaceContract().getInterface().getOperations(); + } + + public Message invoke(Message msg) { + return next.invoke(invokeRequest(msg)); + } + + public Message invokeRequest(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + + String operationName = requestMessageProcessor.getOperationName(jmsMsg); + Operation operation = getTargetOperation(operationName, jmsMsg); + msg.setOperation(operation); + + return msg; + } + + protected Operation getTargetOperation(String operationName, javax.jms.Message jmsMsg) { + Operation operation = null; + + if (serviceOperations.size() == 1) { + + // SCA JMS Binding Specification - Rule 1.5.1 line 203 + operation = serviceOperations.get(0); + + } else if (operationName != null) { + + // SCA JMS Binding Specification - Rule 1.5.1 line 205 + for (Operation op : serviceOperations) { + if (op.getName().equals(operationName)) { + operation = op; + break; + } + } + } else if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault + || jmsBinding.getRequestWireFormat() instanceof WireFormatJMSTextXML) { + + OMElement rootElement; + String operationFromPayload; + + try { + if (jmsMsg instanceof TextMessage) { + String xmlPayload = ((TextMessage) jmsMsg).getText(); + + if (xmlPayload != null) { + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlPayload)); + StAXOMBuilder builder = new StAXOMBuilder(reader); + rootElement = builder.getDocumentElement(); + operationFromPayload = rootElement.getLocalName(); + for (Operation op : serviceOperations) { + if (op.getName().equals(operationFromPayload)) { + operation = op; + break; + } + } + } + } else if (jmsMsg instanceof BytesMessage) { + long noOfBytes = ((BytesMessage) jmsMsg).getBodyLength(); + byte[] bytes = new byte[(int) noOfBytes]; + ((BytesMessage) jmsMsg).readBytes(bytes); + ((BytesMessage) jmsMsg).reset(); + + if (bytes != null) { + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(bytes)); + StAXOMBuilder builder = new StAXOMBuilder(reader); + rootElement = builder.getDocumentElement(); + operationFromPayload = rootElement.getLocalName(); + for (Operation op : serviceOperations) { + if (op.getName().equals(operationFromPayload)) { + operation = op; + break; + } + } + } + } + + } catch (XMLStreamException e) { + //let's ignore this in case the client doesn't want to use a wrapped xml message + } catch (JMSException e) { + throw new JMSBindingException(e); + } + + // If operation is still null we attempt the last rule + if (operation == null) { + + // SCA JMS Binding Specification - Rule 1.5.1 line 207 + for (Operation op : serviceOperations) { + if (op.getName().equals(ON_MESSAGE_METHOD_NAME)) { + operation = op; + break; + } + } + } + } + + if (operation == null) { + throw new JMSBindingException("Can't find operation " + (operationName != null ? operationName : ON_MESSAGE_METHOD_NAME)); + } + + return operation; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceProvider.java new file mode 100644 index 0000000000..1cceb4e382 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceProvider.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.sca.binding.jms.operationselector.jmsdefault.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSDefaultServiceProvider implements OperationSelectorProvider { + private RuntimeComponent component; + private RuntimeComponentService service; + private Binding binding; + + public OperationSelectorJMSDefaultServiceProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) { + super(); + this.component = component; + this.service = service; + this.binding = binding; + } + + /** + */ + public Interceptor createInterceptor() { + return new OperationSelectorJMSDefaultServiceInterceptor((JMSBinding)binding, + null, + service.getRuntimeWire(binding)); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_OPERATION_SELECTOR; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropProviderFactory.java new file mode 100644 index 0000000000..49ad6add50 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropProviderFactory.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.sca.binding.jms.operationselector.jmsuserprop.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.operationselector.jmsuserprop.OperationSelectorJMSUserProp; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +public class OperationSelectorJMSUserPropProviderFactory implements OperationSelectorProviderFactory { + private ExtensionPointRegistry registry; + + public OperationSelectorJMSUserPropProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + */ + public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return null; + } + + /** + */ + public OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new OperationSelectorJMSUserPropServiceProvider(component, service, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java new file mode 100644 index 0000000000..272a0a3c21 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.operationselector.jmsuserprop.runtime; + +import java.util.List; + +import javax.jms.JMSException; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.operationselector.jmsuserprop.OperationSelectorJMSUserProp; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Interceptor for user property based operation selection + * + * + * + */ +public class OperationSelectorJMSUserPropServiceInterceptor implements Interceptor { + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSBinding jmsBinding; + private OperationSelectorJMSUserProp operationSelector; + private RuntimeComponentService service; + private List serviceOperations; + + public OperationSelectorJMSUserPropServiceInterceptor(JMSBinding jmsBinding, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.operationSelector = (OperationSelectorJMSUserProp)jmsBinding.getOperationSelector(); + this.runtimeWire = runtimeWire; + this.service = (RuntimeComponentService) runtimeWire.getTarget().getContract(); + this.serviceOperations = service.getInterfaceContract().getInterface().getOperations(); + } + + public Message invoke(Message msg) { + return next.invoke(invokeRequest(msg)); + } + + public Message invokeRequest(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + + Operation operation = getTargetOperation(jmsMsg); + msg.setOperation(operation); + + return msg; + } + + protected Operation getTargetOperation(javax.jms.Message jmsMsg) { + String operationName = null; + String opSelectorPropertyName = operationSelector.getPropertyName(); + + try { + operationName = jmsMsg.getStringProperty(opSelectorPropertyName); + } catch(JMSException e) { + throw new JMSBindingException(e); + } + + if (operationName == null){ + throw new JMSBindingException("Property " + opSelectorPropertyName + " not found in message header"); + } + + for (Operation op : serviceOperations) { + if (op.getName().equals(operationName)) { + return op; + } + } + + throw new JMSBindingException("Can't find operation " + operationName); + } + + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceProvider.java new file mode 100644 index 0000000000..ece54f5974 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceProvider.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.sca.binding.jms.operationselector.jmsuserprop.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +public class OperationSelectorJMSUserPropServiceProvider implements OperationSelectorProvider { + private RuntimeComponent component; + private RuntimeComponentService service; + private Binding binding; + + public OperationSelectorJMSUserPropServiceProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) { + super(); + this.component = component; + this.service = service; + this.binding = binding; + } + + /** + */ + public Interceptor createInterceptor() { + return new OperationSelectorJMSUserPropServiceInterceptor((JMSBinding)binding, service.getRuntimeWire(binding)); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_OPERATION_SELECTOR; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java new file mode 100644 index 0000000000..e2fc49834e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.provider; + +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Logger; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.ObjectMessage; +import javax.jms.Session; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Base MessageProcessor for the JMSBinding. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractMessageProcessor implements JMSMessageProcessor { + private static final Logger logger = Logger.getLogger(AbstractMessageProcessor.class.getName()); + + protected String operationPropertyName; + protected boolean xmlFormat = true; + + public AbstractMessageProcessor(JMSBinding jmsBinding) { + this.operationPropertyName = jmsBinding.getOperationSelectorPropertyName(); + } + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#getOperationName(javax.jms.Message) + */ + public String getOperationName(Message message) { + try { + + return message.getStringProperty(operationPropertyName); + + } catch (JMSException e) { + throw new JMSBindingException("Exception retreiving operation name from message", e); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#setOperationName(javax.jms.Message, java.lang.String) + */ + public void setOperationName(String operationName, Message message) { + try { + + message.setStringProperty(operationPropertyName, operationName); + + } catch (JMSException e) { + throw new JMSBindingException("Exception setting the operation name on message", e); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#extractPayload(javax.jms.Session, java.lang.Object) + */ + public Message insertPayloadIntoJMSMessage(Session session, Object o) { + return createJMSMessage(session, o); + } + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#extractPayload(javax.jms.Message) + */ + public Object extractPayloadFromJMSMessage(Message msg) { + try { + if (msg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) { + Object exc = ((ObjectMessage)msg).getObject(); + if (exc instanceof RuntimeException) { + throw new ServiceRuntimeException("remote service exception, see nested exception", (Throwable)exc); + } else { + return new InvocationTargetException((Throwable) exc); + } + } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + return extractPayload(msg); + } + + public Message createFaultMessage(Session session, Throwable o) { + if (session == null) { + logger.fine("no response session to create fault message: " + String.valueOf(o)); + return null; + } + try { + + ObjectMessage message = session.createObjectMessage(); + String causeMsg; + if (o instanceof RuntimeException) { + message.setObject(new RuntimeException(o.getMessage())); + } else { + // for a checked exception return the checked exception + message.setObject(o); + } + message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true); + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + protected abstract Object extractPayload(Message msg); + + protected abstract Message createJMSMessage(Session session, Object o); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java new file mode 100644 index 0000000000..5d1990eb90 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.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.sca.binding.jms.provider; + +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Logger; + +import javax.jms.BytesMessage; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.ObjectMessage; +import javax.jms.Session; +import javax.jms.TextMessage; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.osoa.sca.ServiceRuntimeException; + +/** + * MessageProcessor for sending/receiving javax.jms.BytesMessage with the JMSBinding. + * + * @version $Rev$ $Date$ + */ +public class BytesMessageProcessor extends AbstractMessageProcessor { + private static final Logger logger = Logger.getLogger(AbstractMessageProcessor.class.getName()); + + public BytesMessageProcessor(JMSBinding jmsBinding) { + super(jmsBinding); + } + +/* TUSCANY-2967 - disable this change while we decide what to do and + * return faults as JMSObject messages to be consistent + * again with other wire formats + @Override + public Object extractPayloadFromJMSMessage(Message msg) { + byte [] bytes = (byte [])extractPayload(msg); + + try { + if (msg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) { + return new InvocationTargetException(new ServiceRuntimeException(new String(bytes))); + } else { + return bytes; + } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } +*/ + + @Override + protected Object extractPayload(Message msg) { + try { + + if (!(msg instanceof BytesMessage)) { + throw new IllegalStateException("expecting JMS BytesMessage: " + msg); + } + + long noOfBytes = ((BytesMessage)msg).getBodyLength(); + byte [] bytes = new byte[(int)noOfBytes]; + ((BytesMessage)msg).readBytes(bytes); + ((BytesMessage)msg).reset(); + return bytes; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + +/* TUSCANY-2967 - disable this change while we decide what to do and + * return faults as JMSObject messages to be consistent + * again with other wire formats + @Override + public Message createFaultMessage(Session session, Throwable o) { + try { + Message message = createJMSMessage(session, o.toString().getBytes()); + message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true); + return message; + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } +*/ + + @Override + protected Message createJMSMessage(Session session, Object o) { + if (session == null) { + logger.fine("no response session to create message: " + String.valueOf(o)); + return null; + } + try { + + // TODO - an experiment. How to enforce a single + // byte array parameter + BytesMessage message = session.createBytesMessage(); + + if (o != null){ + message.writeBytes((byte[])o); + } + + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java new file mode 100644 index 0000000000..1de85ea773 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.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.sca.binding.jms.provider; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; + +public class DefaultJMSResourceFactoryExtensionPoint implements JMSResourceFactoryExtensionPoint { + + public JMSResourceFactory createJMSResourceFactory(JMSBinding binding) { + return new JMSResourceFactoryImpl(binding.getConnectionFactoryName(), binding.getResponseConnectionFactoryName(), binding.getInitialContextFactoryName(), binding.getJndiURL()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java new file mode 100644 index 0000000000..05f264db78 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultMessageProcessor.java @@ -0,0 +1,287 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.provider; + +import java.io.ByteArrayInputStream; +import java.io.StringReader; +import java.util.logging.Logger; + +import javax.jms.BytesMessage; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMNode; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.interfacedef.util.FaultException; + +/** + * MessageProcessor for sending/receiving XML over javax.jms.TextMessage or javax.jms.BytesMessage + * with the JMSBinding. + * This is very specific to the default wire format and is not tied into the usual hierarchy + * of message processors + * + * @version $Rev$ $Date$ + */ +public class DefaultMessageProcessor extends AbstractMessageProcessor { + private static final Logger logger = Logger.getLogger(DefaultMessageProcessor.class.getName()); + + public DefaultMessageProcessor(JMSBinding jmsBinding) { + super(jmsBinding); + } + + // inherited methods that don't do anything useful + @Override + protected Message createJMSMessage(Session session, Object o) { + // should not be used + return null; + } + + @Override + protected Object extractPayload(Message msg) { + // if it's not a text/bytes message or a fault then we don;t know what to do with it + return null; + } + + // TODO - This makes the assumption that whatever the text/bytes configuration of the + // jms binding, unchecked faults will be sent as bytes. + @Override + public Message createFaultMessage(Session session, Throwable o) { + return createFaultJMSBytesMessage(session, o); + } + + // handle text messages + + public Object extractPayloadFromJMSTextMessage(Message msg, OMElement wrapper) { + if (msg instanceof TextMessage) { + try { + String xml = ((TextMessage) msg).getText(); + Object os; + if (xml != null) { + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml)); + StAXOMBuilder builder = new StAXOMBuilder(reader); + os = builder.getDocumentElement(); + } else { + os = null; + } + + if (wrapper != null){ + //don't modify the original wrapper since it will be reused + //clone the wrapper + OMElement newWrapper = wrapper.cloneOMElement(); + if (os != null){ + newWrapper.addChild((OMNode)os); + } + return newWrapper; + } + + return os; + + } catch (XMLStreamException e) { + throw new JMSBindingException(e); + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } else { + // handle the non-text fault case + return super.extractPayloadFromJMSMessage(msg); + } + } + + public Message insertPayloadIntoJMSTextMessage(Session session, Object o, boolean unwrap) { + + try { + + TextMessage message = session.createTextMessage(); + + if (o instanceof OMElement) { + + if (unwrap){ + OMElement firstElement = ((OMElement)o).getFirstElement(); + if (firstElement == null ) { + message.setText(null); + } else { + message.setText(firstElement.toString()); + } + }else { + message.setText(o.toString()); + } + } else if ((o instanceof Object[]) && ((Object[]) o)[0] instanceof OMElement) { + if (unwrap){ + OMElement firstElement = ((OMElement)((Object[]) o)[0]).getFirstElement(); + if (firstElement == null ) { + message.setText(null); + } else { + message.setText(firstElement.toString()); + } + }else { + message.setText(((Object[]) o)[0].toString()); + } + } else if (o != null) { + throw new IllegalStateException("expecting OMElement payload: " + o); + } + + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Message createFaultJMSTextMessage(Session session, Throwable o) { + + if (session == null) { + logger.fine("no response session to create fault message: " + String.valueOf(o)); + return null; + } + if (o instanceof FaultException) { + try { + + TextMessage message = session.createTextMessage(); + message.setText(String.valueOf(((FaultException) o).getFaultInfo())); + message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true); + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } else { + // handle the non XML fault case + return super.createFaultMessage(session, o); + } + } + + // handle bytes messages + + public Object extractPayloadFromJMSBytesMessage(Message msg, OMElement wrapper) { + + if (msg instanceof BytesMessage) { + try { + Object os; + + long noOfBytes = ((BytesMessage) msg).getBodyLength(); + byte[] bytes = new byte[(int) noOfBytes]; + ((BytesMessage) msg).readBytes(bytes); + ((BytesMessage)msg).reset(); + + if ((bytes != null) && (bytes.length > 0)) { + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(bytes)); + StAXOMBuilder builder = new StAXOMBuilder(reader); + os = builder.getDocumentElement(); + } else { + os = null; + } + + if (wrapper != null){ + //don't modify the original wrapper since it will be reused + //clone the wrapper + OMElement newWrapper = wrapper.cloneOMElement(); + if (os != null){ + newWrapper.addChild((OMNode)os); + } + return newWrapper; + } + + return os; + + } catch (XMLStreamException e) { + throw new JMSBindingException(e); + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } else { + // trap the non-bytes fault case + return super.extractPayloadFromJMSMessage(msg); + } + } + + public Message insertPayloadIntoJMSBytesMessage(Session session, Object o, boolean unwrap) { + + try { + + BytesMessage message = session.createBytesMessage(); + + + if (o instanceof OMElement) { + if (unwrap) { + OMElement firstElement = ((OMElement)o).getFirstElement(); + if (firstElement == null ) { + //do nothing, the message will just be set with a byte[0] + } else { + message.writeBytes(firstElement.toString().getBytes()); + } + + } else { + message.writeBytes(o.toString().getBytes()); + } + + } else if ((o instanceof Object[]) && ((Object[]) o)[0] instanceof OMElement) { + if (unwrap){ + OMElement firstElement = ((OMElement)((Object[]) o)[0]).getFirstElement(); + if (firstElement == null ) { + //do nothing, the message will just be set with a byte[0] + } else { + message.writeBytes(firstElement.toString().getBytes()); + } + + }else { + message.writeBytes(((Object[]) o)[0].toString().getBytes()); + } + } else if (o != null) { + throw new IllegalStateException("expecting OMElement payload: " + o); + } + + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Message createFaultJMSBytesMessage(Session session, Throwable o) { + + if (session == null) { + logger.fine("no response session to create fault message: " + String.valueOf(o)); + return null; + } + + if (o instanceof FaultException) { + try { + + BytesMessage message = session.createBytesMessage(); + message.writeBytes(String.valueOf(((FaultException) o).getFaultInfo()).getBytes()); + message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true); + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } else { + return super.createFaultMessage(session, o); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java new file mode 100644 index 0000000000..c9a11dc41e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.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.sca.binding.jms.provider; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.jms.JMSHostExtensionPoint; +import org.apache.tuscany.sca.host.jms.JMSServiceListenerFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * A factory from creating the JMS binding provider. + * + * @version $Rev$ $Date$ + */ +public class JMSBindingProviderFactory implements BindingProviderFactory { + + private ExtensionPointRegistry extensionPoints; + private JMSResourceFactoryExtensionPoint jmsRFEP; + private JMSServiceListenerFactory serviceListenerFactory; + + public JMSBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + + jmsRFEP = (JMSResourceFactoryExtensionPoint)extensionPoints.getExtensionPoint(JMSResourceFactoryExtensionPoint.class); + if (jmsRFEP == null) { + jmsRFEP = new DefaultJMSResourceFactoryExtensionPoint(); + extensionPoints.addExtensionPoint(jmsRFEP); + } + + JMSHostExtensionPoint jmsHostExtensionPoint = (JMSHostExtensionPoint)extensionPoints.getExtensionPoint(JMSHostExtensionPoint.class); + serviceListenerFactory = jmsHostExtensionPoint.getJMSServiceListenerFactory(); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, JMSBinding binding) { + JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory(binding); + return new JMSBindingReferenceBindingProvider(component, reference, binding, extensionPoints, jmsRF); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, JMSBinding binding) { + JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory(binding); + return new JMSBindingServiceBindingProvider(component, service, binding, binding, serviceListenerFactory, extensionPoints, jmsRF); + } + + public Class getModelType() { + return JMSBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java new file mode 100644 index 0000000000..0e44b84ea0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.provider; + +import java.util.ArrayList; +import java.util.List; + +import javax.jms.JMSException; + +import org.apache.tuscany.sca.binding.jms.headers.HeaderReferenceInterceptor; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.transport.TransportReferenceInterceptor; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; +import org.apache.tuscany.sca.provider.ReferenceBindingProviderRRB; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.provider.WireFormatProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the JMS reference binding provider. + * + * @version $Rev$ $Date$ + */ +public class JMSBindingReferenceBindingProvider implements ReferenceBindingProviderRRB { + + private RuntimeComponentReference reference; + private JMSBinding jmsBinding; + private JMSResourceFactory jmsResourceFactory; + private RuntimeComponent component; + private InterfaceContract interfaceContract; + private ExtensionPointRegistry extensions; + + private ProviderFactoryExtensionPoint providerFactories; + + private WireFormatProviderFactory requestWireFormatProviderFactory; + private WireFormatProvider requestWireFormatProvider; + + private WireFormatProviderFactory responseWireFormatProviderFactory; + private WireFormatProvider responseWireFormatProvider; + + public JMSBindingReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, JMSBinding binding, ExtensionPointRegistry extensions, JMSResourceFactory jmsResourceFactory) { + this.reference = reference; + this.jmsBinding = binding; + this.extensions = extensions; + this.component = component; + this.jmsResourceFactory = jmsResourceFactory; + + // Get the factories/providers for operation selection + this.providerFactories = extensions.getExtensionPoint(ProviderFactoryExtensionPoint.class); + + // Get the factories/providers for wire format + this.requestWireFormatProviderFactory = + (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getRequestWireFormat().getClass()); + if (this.requestWireFormatProviderFactory != null){ + this.requestWireFormatProvider = requestWireFormatProviderFactory.createReferenceWireFormatProvider(component, reference, jmsBinding); + } + + this.responseWireFormatProviderFactory = + (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getResponseWireFormat().getClass()); + if (this.responseWireFormatProviderFactory != null){ + this.responseWireFormatProvider = responseWireFormatProviderFactory.createReferenceWireFormatProvider(component, reference, jmsBinding); + } + + // create an interface contract that reflects both request and response + // wire formats + try { + interfaceContract = (InterfaceContract)reference.getInterfaceContract().clone(); + + requestWireFormatProvider.configureWireFormatInterfaceContract(interfaceContract); + responseWireFormatProvider.configureWireFormatInterfaceContract(interfaceContract); + } catch (CloneNotSupportedException ex){ + interfaceContract = reference.getInterfaceContract(); + } + } + + public Invoker createInvoker(Operation operation) { + + if (jmsBinding.getDestinationName() == null) { + if (!reference.isCallback()) { + throw new JMSBindingException("No destination specified for reference " + reference.getName()); + } + } + + Invoker invoker = null; + invoker = new RRBJMSBindingInvoker(jmsBinding, operation, jmsResourceFactory, reference); + + return invoker; + } + + public boolean supportsOneWayInvocation() { + return true; + } + + public InterfaceContract getBindingInterfaceContract() { + return interfaceContract; + } + + public void start() { + + } + + public void stop() { + try { + jmsResourceFactory.closeConnection(); + jmsResourceFactory.closeResponseConnection(); + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + /* + * set up the reference binding wire with the right set of jms reference + * interceptors + */ + public void configureBindingChain(RuntimeWire runtimeWire) { + + InvocationChain bindingChain = runtimeWire.getBindingInvocationChain(); + + // add transport interceptor + bindingChain.addInterceptor(Phase.REFERENCE_BINDING_TRANSPORT, + new TransportReferenceInterceptor(jmsBinding, + jmsResourceFactory, + runtimeWire) ); + + // add request wire format + bindingChain.addInterceptor(requestWireFormatProvider.getPhase(), + requestWireFormatProvider.createInterceptor()); + + // add response wire format, but only add it if it's different from the request + if (!jmsBinding.getRequestWireFormat().equals(jmsBinding.getResponseWireFormat())){ + bindingChain.addInterceptor(responseWireFormatProvider.getPhase(), + responseWireFormatProvider.createInterceptor()); + } + + // add the header processor that comes after the wire formatter but before the + // policy interceptors + bindingChain.addInterceptor(Phase.REFERENCE_BINDING_WIREFORMAT, + new HeaderReferenceInterceptor(jmsBinding, + jmsResourceFactory, + runtimeWire) ); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java new file mode 100644 index 0000000000..de16edb044 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java @@ -0,0 +1,228 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.provider; + +import java.util.logging.Logger; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.transport.TransportServiceInterceptor; +import org.apache.tuscany.sca.binding.jms.wire.CallbackDestinationInterceptor; +import org.apache.tuscany.sca.binding.jms.wire.OperationPropertiesInterceptor; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.jms.JMSServiceListener; +import org.apache.tuscany.sca.host.jms.JMSServiceListenerDetails; +import org.apache.tuscany.sca.host.jms.JMSServiceListenerFactory; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; +import org.apache.tuscany.sca.provider.ServiceBindingProviderRRB; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.provider.WireFormatProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the JMS service binding provider. + * + * @version $Rev$ $Date$ + */ +public class JMSBindingServiceBindingProvider implements ServiceBindingProviderRRB, JMSServiceListenerDetails { + private static final Logger logger = Logger.getLogger(JMSBindingServiceBindingProvider.class.getName()); + + private RuntimeComponentService service; + private Binding targetBinding; + private JMSBinding jmsBinding; + private JMSResourceFactory jmsResourceFactory; + private JMSServiceListenerFactory serviceListenerFactory; + private JMSServiceListener serviceListener; + + private RuntimeComponent component; + private InterfaceContract interfaceContract; + + private ProviderFactoryExtensionPoint providerFactories; + private ModelFactoryExtensionPoint modelFactories; + + private MessageFactory messageFactory; + + private OperationSelectorProviderFactory operationSelectorProviderFactory; + private OperationSelectorProvider operationSelectorProvider; + + private WireFormatProviderFactory requestWireFormatProviderFactory; + private WireFormatProvider requestWireFormatProvider; + + private WireFormatProviderFactory responseWireFormatProviderFactory; + private WireFormatProvider responseWireFormatProvider; + + public JMSBindingServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, Binding targetBinding, JMSBinding binding, JMSServiceListenerFactory serviceListenerFactory, ExtensionPointRegistry extensionPoints, JMSResourceFactory jmsResourceFactory) { + this.component = component; + this.service = service; + this.jmsBinding = binding; + this.serviceListenerFactory = serviceListenerFactory; + this.targetBinding = targetBinding; + this.jmsResourceFactory = jmsResourceFactory; + + // Set the default destination when using a connection factory. + // If an activation spec is being used, do not set the destination + // because the activation spec provides the destination. + if (jmsBinding.getDestinationName() == null && + (jmsBinding.getActivationSpecName() == null || jmsBinding.getActivationSpecName().equals(""))) { + if (!service.isCallback()) { + // use the SCA service name as the default destination name + jmsBinding.setDestinationName(service.getName()); + } + } + + // Get Message factory + modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + messageFactory = modelFactories.getFactory(MessageFactory.class); + + // Get the factories/providers for operation selection + this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); + this.operationSelectorProviderFactory = + (OperationSelectorProviderFactory)providerFactories.getProviderFactory(jmsBinding.getOperationSelector().getClass()); + if (this.operationSelectorProviderFactory != null){ + this.operationSelectorProvider = operationSelectorProviderFactory.createServiceOperationSelectorProvider(component, service, jmsBinding); + } + + // Get the factories/providers for wire format + this.requestWireFormatProviderFactory = + (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getRequestWireFormat().getClass()); + if (this.requestWireFormatProviderFactory != null){ + this.requestWireFormatProvider = requestWireFormatProviderFactory.createServiceWireFormatProvider(component, service, jmsBinding); + } + + this.responseWireFormatProviderFactory = + (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getResponseWireFormat().getClass()); + if (this.responseWireFormatProviderFactory != null){ + this.responseWireFormatProvider = responseWireFormatProviderFactory.createServiceWireFormatProvider(component, service, jmsBinding); + } + + // create an interface contract that reflects both request and response + // wire formats + try { + interfaceContract = (InterfaceContract)service.getInterfaceContract().clone(); + + requestWireFormatProvider.configureWireFormatInterfaceContract(interfaceContract); + responseWireFormatProvider.configureWireFormatInterfaceContract(interfaceContract); + } catch (CloneNotSupportedException ex){ + interfaceContract = service.getInterfaceContract(); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return interfaceContract; + } + + public boolean supportsOneWayInvocation() { + return true; + } + + public void start() { + try { + + this.serviceListener = serviceListenerFactory.createJMSServiceListener(this); + serviceListener.start(); + + } catch (Exception e) { + throw new JMSBindingException("Error starting JMSServiceBinding", e); + } + } + + public void stop() { + try { + serviceListener.stop(); + } catch (Exception e) { + throw new JMSBindingException("Error stopping JMSServiceBinding", e); + } + } + + public String getDestinationName() { + return serviceListener.getDestinationName(); + } + + /* + * Adds JMS specific interceptors to the binding chain + */ + public void configureBindingChain(RuntimeWire runtimeWire) { + + InvocationChain bindingChain = runtimeWire.getBindingInvocationChain(); + + // add transport interceptor + bindingChain.addInterceptor(Phase.SERVICE_BINDING_TRANSPORT, + new TransportServiceInterceptor(jmsBinding, + jmsResourceFactory, + runtimeWire) ); + + // add operation selector interceptor + bindingChain.addInterceptor(operationSelectorProvider.getPhase(), + operationSelectorProvider.createInterceptor()); + + // add operationProperties interceptor after operation selector + bindingChain.addInterceptor(Phase.SERVICE_BINDING_OPERATION_SELECTOR, + new OperationPropertiesInterceptor(jmsBinding, runtimeWire)); + + // add callback destination interceptor after operation selector + bindingChain.addInterceptor(Phase.SERVICE_BINDING_WIREFORMAT, + new CallbackDestinationInterceptor(runtimeWire)); + + // add request wire format + bindingChain.addInterceptor(requestWireFormatProvider.getPhase(), + requestWireFormatProvider.createInterceptor()); + + // add response wire format, but only add it if it's different from the request + if (!jmsBinding.getRequestWireFormat().equals(jmsBinding.getResponseWireFormat())){ + bindingChain.addInterceptor(responseWireFormatProvider.getPhase(), + responseWireFormatProvider.createInterceptor()); + } + } + + public RuntimeComponent getComponent() { + return component; + } + + public RuntimeComponentService getService() { + return service; + } + + public Binding getTargetBinding() { + return targetBinding; + } + + public JMSBinding getJmsBinding() { + return jmsBinding; + } + + public MessageFactory getMessageFactory() { + return messageFactory; + } + + public JMSResourceFactory getResourceFactory() { + return jmsResourceFactory; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java new file mode 100644 index 0000000000..821b9d7873 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.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.sca.binding.jms.provider; + +import javax.jms.Message; +import javax.jms.Session; + +/** + * Interface for a component that does operation selection and message payload processing + * + * @version $Rev$ $Date$ + */ +public interface JMSMessageProcessor { + + /** + * Get the operation name from a JMS Message + */ + String getOperationName(Message message); + + /** + * Set the operation name on a JMS Message + */ + void setOperationName(String operationName, Message message); + + /** + * Extracts the payload from a JMS Message + */ + Object extractPayloadFromJMSMessage(Message msg); + + /** + * Create a JMS Message containing the payload + */ + Message insertPayloadIntoJMSMessage(Session session, Object payload); + + /** + * Create a JMS Message for reporting an exception + */ + Message createFaultMessage(Session session, Throwable responsePayload); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java new file mode 100644 index 0000000000..699b1cb176 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.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.sca.binding.jms.provider; + +import java.lang.reflect.Constructor; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; + +/** + * Utility methods to load JMS message processors. + * + * @version $Rev: $ $Date: $ + */ +public class JMSMessageProcessorUtil { + + /** + * Used to create instances of the JMSResourceFactory and RequestMessageProcessor and ResponseMessageProcessor from + * string based class name provided in the configuration + * + * @param cl ClassLoader + * @param className the string based class name to load and instantiate + * @return the new object + */ + private static Object instantiate(ClassLoader cl, String className, JMSBinding binding) { + Object instance; + if (cl == null) { + cl = binding.getClass().getClassLoader(); + } + + try { + Class clazz; + + try { + clazz = cl.loadClass(className); + } catch (ClassNotFoundException e) { + clazz = binding.getClass().getClassLoader().loadClass(className); + } + + Constructor constructor = clazz.getDeclaredConstructor(new Class[] {JMSBinding.class}); + instance = constructor.newInstance(binding); + + } catch (Throwable e) { + throw new JMSBindingException("Exception instantiating OperationAndDataBinding class", e); + } + + return instance; + } + + public static JMSMessageProcessor getRequestMessageProcessor(JMSBinding binding) { + return (JMSMessageProcessor)instantiate(null, binding.getRequestMessageProcessorName(), binding); + } + + public static JMSMessageProcessor getResponseMessageProcessor(JMSBinding binding) { + return (JMSMessageProcessor)instantiate(null, binding.getResponseMessageProcessorName(), binding); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java new file mode 100644 index 0000000000..348764fe43 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.provider; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Session; +import javax.naming.NamingException; + +public interface JMSResourceFactory { + + /* + * 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. E.g. 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 abstract Connection getConnection() throws NamingException, JMSException; + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.binding.jms.JMSResourceFactory#createSession() + */ + public abstract Session createSession() throws JMSException, NamingException; + + public abstract void closeSession(Session session) throws JMSException; + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.binding.jms.JMSResourceFactory#startConnection() + */ + public abstract void startConnection() throws JMSException, NamingException; + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.binding.jms.JMSResourceFactory#closeConnection() + */ + public abstract void closeConnection() throws JMSException; + + public abstract Destination lookupDestination(String destName) throws NamingException; + + /** + * You can create a destination in ActiveMQ (and have it appear in JNDI) by putting "dynamicQueues/" in front of the queue name being looked up + */ + public abstract Destination createDestination(String jndiName) throws NamingException; + + /* + * 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. E.g. 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 abstract Connection getResponseConnection() throws NamingException, JMSException; + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.binding.jms.JMSResourceFactory#createSession() + */ + public abstract Session createResponseSession() throws JMSException, NamingException; + + public abstract void closeResponseSession(Session session) throws JMSException; + + public abstract void closeResponseConnection() throws JMSException; + + /* + * Indicates whether connections obtained using getConnection() or getResponseConnection() + * must be closed after each use. This is necessary in environments where connections are + * shared with other users, or where connections cannot be held across transaction boundaries. + */ + public abstract boolean isConnectionClosedAfterUse(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryExtensionPoint.java new file mode 100644 index 0000000000..57fbfb3215 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryExtensionPoint.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.sca.binding.jms.provider; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; + +public interface JMSResourceFactoryExtensionPoint { + + JMSResourceFactory createJMSResourceFactory(JMSBinding binding); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java new file mode 100644 index 0000000000..1debc61dff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java @@ -0,0 +1,282 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.provider; + +import java.util.Properties; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Session; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; + +/** + * Abstracts away any JMS provide specific feature from the JMS binding + * + * @version $Rev$ $Date$ + */ +public class JMSResourceFactoryImpl implements JMSResourceFactory { + + protected String initialContextFactoryName; + protected String connectionFactoryName = "ConnectionFactory"; + protected String jndiURL; + + protected Connection connection; + protected Context context; + protected boolean isConnectionStarted; + private Connection responseConnection; + private String responseConnectionFactoryName; + + public JMSResourceFactoryImpl(String connectionFactoryName, String responseConnectionFactoryName, String initialContextFactoryName, String jndiURL) { + if (connectionFactoryName != null && connectionFactoryName.trim().length() > 0) { + this.connectionFactoryName = connectionFactoryName.trim(); + } + if (responseConnectionFactoryName != null && responseConnectionFactoryName.trim().length() > 0) { + this.responseConnectionFactoryName = responseConnectionFactoryName.trim(); + } + if (initialContextFactoryName != null && initialContextFactoryName.trim().length() > 0) { + this.initialContextFactoryName = initialContextFactoryName.trim(); + } + if (jndiURL != null) { + this.jndiURL = jndiURL.trim(); + } + } + + /* + * 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. E.g. if Tuscany is running inside + * an AppServer Then we could leverage the JMS resources it provides + * + * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#getConnection() + */ + public Connection getConnection() throws NamingException, JMSException { + if (connection == null) { + createConnection(); + } + return connection; + } + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#createSession() + */ + public Session createSession() throws JMSException, NamingException { + return getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); + } + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#closeSession(javax.jms.Session) + */ + public void closeSession(Session session) throws JMSException { + session.close(); + } + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#startConnection() + */ + public void startConnection() throws JMSException, NamingException { + if (!isConnectionStarted) { + getConnection().start(); + isConnectionStarted = true; + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#closeConnection() + */ + public void closeConnection() throws JMSException { + if (connection != null) { + try { + connection.close(); + } catch (JMSException e) { + // if using an embedded broker then when shutting down Tuscany the broker may get closed + // before this stop method is called. I can't see how to detect that so for now just + // ignore the exception if the message is that the transport is already disposed + if (!e.getMessage().contains("disposed")) { + throw e; + } + } + } + } + + protected void createConnection() throws NamingException, JMSException { + ConnectionFactory connectionFactory = (ConnectionFactory)jndiLookUp(connectionFactoryName); + if (connectionFactory == null) { + throw new JMSBindingException("connection factory not found: " + connectionFactoryName); + } + connection = connectionFactory.createConnection(); + } + + protected synchronized Context getInitialContext() throws NamingException { + if (context == null) { + Properties props = new Properties(); + + if (initialContextFactoryName != null) { + props.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName); + } + if (jndiURL != null) { + props.setProperty(Context.PROVIDER_URL, jndiURL); + } + + initJREEnvironment(props); + + context = new InitialContext(props); + } + return context; + } + + /** + * If using the WAS JMS Client with a non-IBM JRE then an additional + * environment property needs to be set to initialize the ORB correctly. + * See: http://www-1.ibm.com/support/docview.wss?uid=swg24012804 + */ + protected void initJREEnvironment(Properties props) { + if ("com.ibm.websphere.naming.WsnInitialContextFactory".equals(props.get(Context.INITIAL_CONTEXT_FACTORY))) { + String vendor = System.getProperty("java.vendor"); + if (vendor == null || !vendor.contains("IBM")) { + props.setProperty("com.ibm.CORBA.ORBInit", "com.ibm.ws.sib.client.ORB"); + } + } + } + + /* (non-Javadoc) + * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#lookupDestination(java.lang.String) + */ + public Destination lookupDestination(String destName) throws NamingException { + if (destName == null) { + return null; + } + + Destination dest = (Destination)jndiLookUp(destName); + if (dest == null) { + dest = lookupPhysical(destName); + } + return dest; + } + + protected Destination lookupPhysical(String jndiName) { + + // TODO: the SCA JMS spec says a destination name may be a non-jndi plain destination name + +// Session session = null; +// try { +// +// Destination dest; +// session = createSession(); +// dest = session.createQueue(jndiName); +// return dest; +// +// } catch (JMSException e) { +// throw new JMSBindingException(e); +// } catch (NamingException e) { +// throw new JMSBindingException(e); +// } finally { +// if (session != null) { +// try { +// session.close(); +// } catch (JMSException e) { +// throw new JMSBindingException(e); +// } +// } +// } + return null; + } + + /* (non-Javadoc) + * @see org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory#createDestination(java.lang.String) + */ + public Destination createDestination(String jndiName) throws NamingException { + return lookupDestination("dynamicQueues/" + jndiName); + } + + protected Object jndiLookUp(String name) { + Object o = null; + try { + o = getInitialContext().lookup("java:comp/env/" + name); + } catch (Exception ex) { + // ignore + } + if (o == null) { + try { + o = getInitialContext().lookup(name); + } catch (NamingException ex) { + // ignore + } + } + return o; + } + + public Session createResponseSession() throws JMSException, NamingException { + return getResponseConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); + } + + public void closeResponseSession(Session session) throws JMSException { + session.close(); + } + + public Connection getResponseConnection() throws NamingException, JMSException { + if (responseConnection == null) { + if (responseConnectionFactoryName != null) { + ConnectionFactory connectionFactory = (ConnectionFactory)jndiLookUp(responseConnectionFactoryName); + if (connectionFactory == null) { + throw new JMSBindingException("connection factory not found: " + responseConnectionFactoryName); + } + responseConnection = connectionFactory.createConnection(); + } else { + // if no response connection is defined in the SCDL use the request connection + responseConnection = getConnection(); + } + } + return responseConnection; + } + + public void closeResponseConnection() throws JMSException { + if (responseConnection != null && !responseConnection.equals(connection)) { + try { + responseConnection.close(); + } catch (JMSException e) { + // if using an embedded broker then when shutting down Tuscany the broker may get closed + // before this stop method is called. I can't see how to detect that so for now just + // ignore the exception if the message is that the transport is already disposed + if (!e.getMessage().contains("disposed")) { + throw e; + } + } + } + } + + public boolean isConnectionClosedAfterUse() { + // It is assumed this resource factory is used in an environment + // where the connection can be held for the life of the binding. + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java new file mode 100644 index 0000000000..331c63f20f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java @@ -0,0 +1,230 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.provider; + +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Logger; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.ObjectMessage; +import javax.jms.Session; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.osoa.sca.ServiceRuntimeException; + +/** + * MessageProcessor for sending/receiving Serializable objects with the JMSBinding. + * + */ +public class ObjectMessageProcessor extends AbstractMessageProcessor { + private static final Logger logger = Logger.getLogger(ObjectMessageProcessor.class.getName()); + + public ObjectMessageProcessor(JMSBinding jmsBinding) { + super(jmsBinding); + } + + @Override + protected Message createJMSMessage(Session session, Object o) { + if (session == null) { + logger.fine("no response session to create message: " + String.valueOf(o)); + return null; + } + try { + + ObjectMessage message = session.createObjectMessage(); + + if (o != null){ + if (!(o instanceof Serializable)) { + throw new IllegalStateException("JMS ObjectMessage payload not Serializable: " + o); + } + + message.setObject((Serializable)o); + } + + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + @Override + public Object extractPayloadFromJMSMessage(Message msg) { + try { + Object o = ((ObjectMessage)msg).getObject(); + if (o instanceof Throwable ) { + if (o instanceof RuntimeException) { + throw new ServiceRuntimeException("remote service exception, see nested exception", (RuntimeException)o); + } else { + return new InvocationTargetException((Throwable) o); + } + } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + return extractPayload(msg); + } + + @Override + protected Object extractPayload(Message msg) { + try { + + return ((ObjectMessage)msg).getObject(); + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + // special methods for handling operations with single parameters + + public Message createJMSMessageForSingleParamOperation(Session session, Object o, boolean wrapSingleInput) { + if (session == null) { + logger.fine("no response session to create message: " + String.valueOf(o)); + return null; + } + try { + + ObjectMessage message = session.createObjectMessage(); + + if (o != null) { + if (!(o instanceof Serializable)) { + throw new IllegalStateException("JMS ObjectMessage payload not Serializable: " + o); + } + + // If the user has specifically requests that single parameters + // be wrapped then leave is as is as it will have already been + // wrapped by Tuscany. Otherwise unwrap it. + if (wrapSingleInput) { + message.setObject((Serializable) o); + } else { // unwrap from array + message.setObject((Serializable) ((Object[]) o)[0]); + } + + } + + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Object extractPayloadFromJMSMessageForSingleParamOperation(Message msg, Class argType, boolean wrapSingle) { + // We always have a one arg operation if this method is called so we need to + // decide if the data on the wire is wrapped or not. This is the algorithm. + // + // If the payload is null then create an empty array and pass it on + // If the payload is not an array then it must represent an unwrapped + // single arg. Wrap it up and pass it on + // If the payload is an array then determine if it's a wrapped single arg or not + // If the service interface arg type matches the type of the array and not it's contents + // then it's an unwrapped argument so wrap it and pass it on + // If the service interface arg type matches the type of the contents and not the type + // of the array then the parameter is already wrapped so pass it on as is + // If the service interface arg type matches both the type of the + // array and the type of its contents then assume that the whole array is the + // parameter and decide whether to unwrap it or pass it on as is based on the + // setting of the wrapSingle attribute + // + + try { + Object payload = ((ObjectMessage) msg).getObject(); + + if (payload instanceof Throwable) { + if (payload instanceof RuntimeException) { + throw new ServiceRuntimeException("remote service exception, see nested exception", (RuntimeException) payload); + } else { + return new InvocationTargetException((Throwable) payload); + } + } + + if (payload == null) { + // methodA(null) was not wrapped on wire so wrap it here in order + // that it passes through the rest of the Tuscany wire successfully + return new Object[] { payload }; + } + + boolean payloadIsArray = payload.getClass().isArray(); + + // Non-array payload is single arg + if (!payloadIsArray) { + // methodB(arg) wasn't wrapped on wire so wrap it here in order + // that it passes through the rest of the Tuscany wire successfully + return new Object[] { payload }; + } else { + int size = ((Object[]) payload).length; + + // An initial quick check to determine whether the payload is not + // wrapped. If the array has anything other than a single entry + // then it's not the result of reference side wrapping so wrap it + // here and pass it on + if (size != 1) { + return new Object[] { payload }; + } + + // we know the array has only one entry now so get it + Object arrayContents = ((Object[]) payload)[0]; + + // Is the operation argument the same type as the array itself? + if (argType.isAssignableFrom(payload.getClass())) { + + // So we believe that the whole array is the argument but need + // to check what is in the array to be sure + if (arrayContents == null) { + // There is nothing in the array so it could be an accident that + // the array type matches the argument type, e.g. op(Object) + // so rely on the wrapSingle setting to choose + if (wrapSingle) { + return payload; + } else { + return new Object[] { payload }; + } + } else if (argType.isAssignableFrom(arrayContents.getClass())) { + // We can't tell as the argument type matches both the array type and + // the array contents type so use the wrapSingle setting to choose + if (wrapSingle) { + return payload; + } else { + return new Object[] { payload }; + } + } else { + // So by now we know the whole array is intended to be the + // parameter to wrap it and send it on + return new Object[] { payload }; + } + + } else { + // The array type doesn't match the argument type so assume that the + // array contents will match the argument type and that hence the + // parameter is already wrapped so just send it as is. If the contents + // type doesn't match the argument type a exception will be thrown further + // along the wire + return payload; + } + } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java new file mode 100644 index 0000000000..ee9501bf89 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.provider; + +import java.lang.reflect.InvocationTargetException; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Session; +import javax.naming.NamingException; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Invoker for the JMS binding. + * + * @version $Rev$ $Date$ + */ +public class RRBJMSBindingInvoker implements Invoker, DataExchangeSemantics { + + protected Operation operation; + protected String operationName; + + protected JMSBinding jmsBinding; + protected JMSResourceFactory jmsResourceFactory; + protected Destination bindingRequestDest; + protected Destination bindingReplyDest; + protected RuntimeComponentReference reference; + protected RuntimeWire runtimeWire; + + public RRBJMSBindingInvoker(JMSBinding jmsBinding, Operation operation, JMSResourceFactory jmsResourceFactory, RuntimeComponentReference reference) { + + this.operation = operation; + operationName = operation.getName(); + + this.jmsBinding = jmsBinding; + this.jmsResourceFactory = jmsResourceFactory; + this.reference = reference; + this.runtimeWire = reference.getRuntimeWire(jmsBinding); + + try { + // If this is a callback reference, the destination is determined dynamically based on + // properties of the inbound service request. We should not look for or require a + // statically-configured destination unless a message is received that does not have + // the necessary properties. + if (!reference.isCallback()) { + bindingRequestDest = lookupDestination(); + } + bindingReplyDest = lookupResponseDestination(); + } catch (NamingException e) { + throw new JMSBindingException(e); + } + } + + /** + * Looks up the Destination Queue for the JMS Binding + * + * @return The Destination Queue + * @throws NamingException Failed to lookup Destination Queue + * @throws JMSBindingException Failed to lookup Destination Queue + * @see #lookupDestinationQueue(boolean) + */ + protected Destination lookupDestination() throws NamingException, JMSBindingException { + return lookupDestinationQueue(false); + } + + /** + * Looks up the Destination Response Queue for the JMS Binding + * + * @return The Destination Response Queue + * @throws NamingException Failed to lookup Destination Response Queue + * @throws JMSBindingException Failed to lookup Destination Response Queue + * @see #lookupDestinationQueue(boolean) + */ + protected Destination lookupResponseDestination() throws NamingException, JMSBindingException { + return lookupDestinationQueue(true); + } + + /** + * Looks up the Destination Queue for the JMS Binding. + *

+ * What happens in the look up will depend on the create mode specified for the JMS Binding: + *

    + *
  • always - the JMS queue is always created. It is an error if the queue already exists + *
  • ifnotexist - the JMS queue is created if it does not exist. It is not an error if the queue already exists + *
  • never - the JMS queue is never created. It is an error if the queue does not exist + *
+ * See the SCA JMS Binding specification for more information. + *

+ * + * @param isReponseQueue true if we are creating a response queue. + * false if we are creating a request queue + * @return The Destination queue. + * @throws NamingException Failed to lookup JMS queue + * @throws JMSBindingException Failed to lookup JMS Queue. Probable cause is that + * the JMS queue's current existence/non-existence is not compatible with + * the create mode specified on the binding + */ + protected Destination lookupDestinationQueue(boolean isReponseQueue) throws NamingException, JMSBindingException { + String queueName; + String queueType; + String qCreateMode; + + if (isReponseQueue) { + queueName = jmsBinding.getResponseDestinationName(); + queueType = "JMS Response Destination "; + qCreateMode = jmsBinding.getResponseDestinationCreate(); + if (queueName == null) { + return null; + } + } else { + queueName = jmsBinding.getDestinationName(); + queueType = "JMS Destination "; + qCreateMode = jmsBinding.getDestinationCreate(); + } + + Destination dest = jmsResourceFactory.lookupDestination(queueName); + + if (qCreateMode.equals(JMSBindingConstants.CREATE_ALWAYS)) { + // In this mode, the queue must not already exist as we are creating it + if (dest != null) { + throw new JMSBindingException(queueType + queueName + + " already exists but has create mode of \"" + + qCreateMode + + "\" while registering binding " + + jmsBinding.getName() + + " invoker"); + } + // Create the queue + dest = jmsResourceFactory.createDestination(queueName); + + } else if (qCreateMode.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) { + // In this mode, the queue may nor may not exist. It will be created if it does not exist + if (dest == null) { + dest = jmsResourceFactory.createDestination(queueName); + } + + } else if (qCreateMode.equals(JMSBindingConstants.CREATE_NEVER)) { + // In this mode, the queue must have already been created. + if (dest == null) { + throw new JMSBindingException(queueType + queueName + + " not found but create mode of \"" + + qCreateMode + + "\" while registering binding " + + jmsBinding.getName() + + " invoker"); + } + } + + // Make sure we ended up with a queue + if (dest == null) { + throw new JMSBindingException(queueType + queueName + + " not found with create mode of \"" + + qCreateMode + + "\" while registering binding " + + jmsBinding.getName() + + " invoker"); + } + + return dest; + } + + public org.apache.tuscany.sca.invocation.Message invoke(org.apache.tuscany.sca.invocation.Message tuscanyMsg) { + try { + // populate the message context with JMS binding information + JMSBindingContext context = new JMSBindingContext(); + context.setJmsResourceFactory(jmsResourceFactory); + tuscanyMsg.setBindingContext(context); + + // get a jms session to cover the creation and sending of the message + Session session = context.getJmsSession(); + + context.setRequestDestination(getRequestDestination(tuscanyMsg, session)); + context.setReplyToDestination(getReplyToDestination(session)); + + try { + tuscanyMsg = runtimeWire.getBindingInvocationChain().getHeadInvoker().invoke(tuscanyMsg); + } catch (ServiceRuntimeException e) { + if (e.getCause() instanceof InvocationTargetException) { + if ((e.getCause().getCause() instanceof RuntimeException)) { + tuscanyMsg.setFaultBody(e.getCause()); + } else { + tuscanyMsg.setFaultBody(((InvocationTargetException)e.getCause()).getTargetException()); + } + } else if (e.getCause() instanceof FaultException) { + tuscanyMsg.setFaultBody(e.getCause()); + } else { + tuscanyMsg.setFaultBody(e); + } + } catch (IllegalStateException e) { + tuscanyMsg.setFaultBody(e); + } catch (Throwable e) { + tuscanyMsg.setFaultBody(e); + } finally { + context.closeJmsSession(); + if (jmsResourceFactory.isConnectionClosedAfterUse()) { + jmsResourceFactory.closeConnection(); + } + } + + return tuscanyMsg; + } catch (Exception e) { + throw new JMSBindingException(e); + } + } + + protected Destination getRequestDestination(org.apache.tuscany.sca.invocation.Message tuscanyMsg, Session session) throws JMSBindingException, NamingException, JMSException { + Destination requestDestination; + if (reference.isCallback()) { + String toURI = tuscanyMsg.getTo().getURI(); + if (toURI != null && toURI.startsWith("jms:")) { + // the msg to uri contains the callback destination name + // this is an jms physical name not a jndi name so need to use session.createQueue + requestDestination = session.createQueue(toURI.substring(4)); + } else { + requestDestination = lookupDestination(); + } + } else { + requestDestination = bindingRequestDest; + } + + return requestDestination; + } + + protected Destination getReplyToDestination(Session session) throws JMSException, JMSBindingException, NamingException { + Destination replyToDest; + if (operation.isNonBlocking()) { + replyToDest = null; + } else { + if (bindingReplyDest != null) { + replyToDest = bindingReplyDest; + } else { + replyToDest = session.createTemporaryQueue(); + } + } + return replyToDest; + } + + public boolean allowsPassByReference() { + // JMS always pass by value + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java new file mode 100644 index 0000000000..c1b5e6562d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.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.sca.binding.jms.provider; + +import java.util.logging.Logger; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Session; +import javax.jms.TextMessage; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; + +/** + * MessageProcessor for sending/receiving javax.jms.TextMessage with the JMSBinding. + * + * @version $Rev$ $Date$ + */ +public class TextMessageProcessor extends AbstractMessageProcessor { + private static final Logger logger = Logger.getLogger(TextMessageProcessor.class.getName()); + + public TextMessageProcessor(JMSBinding jmsBinding) { + super(jmsBinding); + } + + @Override + protected Object extractPayload(Message msg) { + try { + + if (!(msg instanceof TextMessage)) { + throw new IllegalStateException("expecting JMS TextMessage: " + msg); + } + + return ((TextMessage)msg).getText(); + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + @Override + protected Message createJMSMessage(Session session, Object o) { + if (session == null) { + logger.fine("no response session to create message: " + String.valueOf(o)); + return null; + } + try { + + TextMessage message = session.createTextMessage(); + + if (o != null){ + message.setText(String.valueOf(o)); + } + + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java new file mode 100644 index 0000000000..5a9e82b7da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLBytesMessageProcessor.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.provider; + +import java.io.ByteArrayInputStream; +import java.util.logging.Logger; + +import javax.jms.BytesMessage; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Session; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.interfacedef.util.FaultException; + +/** + * MessageProcessor for sending/receiving XML javax.jms.BytesMessage with the JMSBinding. + */ +public class XMLBytesMessageProcessor extends AbstractMessageProcessor { + private static final Logger logger = Logger.getLogger(XMLBytesMessageProcessor.class.getName()); + + public XMLBytesMessageProcessor(JMSBinding jmsBinding) { + super(jmsBinding); + } + + @Override + protected Object extractPayload(Message msg) { + try { + + if (!(msg instanceof BytesMessage)) { + throw new IllegalStateException("expecting JMS BytesMessage: " + msg); + } + + long noOfBytes = ((BytesMessage)msg).getBodyLength(); + byte [] bytes = new byte[(int)noOfBytes]; + ((BytesMessage)msg).readBytes(bytes); + ((BytesMessage)msg).reset(); + + Object os; + if (noOfBytes > 0) { + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(bytes)); + StAXOMBuilder builder = new StAXOMBuilder(reader); + os = builder.getDocumentElement(); + } else { + os = null; + } + return os; + } catch (XMLStreamException e) { + throw new JMSBindingException(e); + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + @Override + public Object extractPayloadFromJMSMessage(Message msg) { + if (msg instanceof BytesMessage) { + return extractPayload(msg); + } else { + return super.extractPayloadFromJMSMessage(msg); + } + } + + @Override + protected Message createJMSMessage(Session session, Object o) { + if (session == null) { + logger.fine("no response session to create message: " + String.valueOf(o)); + return null; + } + try { + BytesMessage message = session.createBytesMessage(); + + if (o instanceof OMElement) { + message.writeBytes(o.toString().getBytes()); + } else if ((o instanceof Object[]) && ((Object[])o)[0] instanceof OMElement) { + message.writeBytes(((Object[])o)[0].toString().getBytes()); + } else if (o != null) { + throw new IllegalStateException("expecting OMElement payload: " + o); + } + + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + @Override + public Message createFaultMessage(Session session, Throwable o) { + + if (session == null) { + logger.fine("no response session to create fault message: " + String.valueOf(o)); + return null; + } + if (o instanceof FaultException) { + try { + + BytesMessage message = session.createBytesMessage(); + message.writeBytes(String.valueOf(((FaultException) o).getFaultInfo()).getBytes()); + message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true); + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } else { + return super.createFaultMessage(session, o); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java new file mode 100644 index 0000000000..8794f80126 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.provider; + +import java.io.StringReader; +import java.util.logging.Logger; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.interfacedef.util.FaultException; + +/** + * MessageProcessor for sending/receiving XML javax.jms.TextMessage with the JMSBinding. + * + * @version $Rev$ $Date$ + */ +public class XMLTextMessageProcessor extends AbstractMessageProcessor { + private static final Logger logger = Logger.getLogger(XMLTextMessageProcessor.class.getName()); + + public XMLTextMessageProcessor(JMSBinding jmsBinding) { + super(jmsBinding); + } + + @Override + protected Object extractPayload(Message msg) { + try { + + String xml = ((TextMessage)msg).getText(); + Object os; + if (xml != null) { + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml)); + StAXOMBuilder builder = new StAXOMBuilder(reader); + os = builder.getDocumentElement(); + } else { + os = null; + } + return os; + + } catch (XMLStreamException e) { + throw new JMSBindingException(e); + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + @Override + public Object extractPayloadFromJMSMessage(Message msg) { + if (msg instanceof TextMessage) { + return extractPayload(msg); + } else { + return super.extractPayloadFromJMSMessage(msg); + } + } + + @Override + protected Message createJMSMessage(Session session, Object o) { + if (session == null) { + logger.fine("no response session to create message: " + String.valueOf(o)); + return null; + } + try { + + TextMessage message = session.createTextMessage(); + + if (o instanceof OMElement) { + message.setText(o.toString()); + } else if ((o instanceof Object[]) && ((Object[])o)[0] instanceof OMElement) { + message.setText(((Object[])o)[0].toString()); + } else if (o != null) { + throw new IllegalStateException("expecting OMElement payload: " + o); + } + + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + @Override + public Message createFaultMessage(Session session, Throwable o) { + if (session == null) { + logger.fine("no response session to create fault message: " + String.valueOf(o)); + return null; + } + if (o instanceof FaultException) { + try { + + TextMessage message = session.createTextMessage(); + message.setText(String.valueOf(((FaultException)o).getFaultInfo())); + message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true); + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } else { + return super.createFaultMessage(session, o); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java new file mode 100644 index 0000000000..0628cfbb32 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.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.sca.binding.jms.transport; + +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.naming.NamingException; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class TransportReferenceInterceptor implements Interceptor { + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private RuntimeComponentReference reference; + + public TransportReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.reference = (RuntimeComponentReference)runtimeWire.getSource().getContract(); + } + + public Message invoke(Message msg) { + Message responseMsg = invokeRequest(msg); + + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + + if (context.getReplyToDestination() == null) { + responseMsg.setBody(null); + } else { + responseMsg = invokeResponse(msg); + } + + return responseMsg; + } + + public Message invokeRequest(Message msg) { + try { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsSession(); + + MessageProducer producer = session.createProducer(context.getRequestDestination()); + + // Set JMS header attributes in producer, not message. + String opName = msg.getOperation().getName(); + if (jmsBinding.getOperationJMSTimeToLive(msg.getOperation().getName()) != null) { + producer.setTimeToLive(jmsBinding.getOperationJMSTimeToLive(msg.getOperation().getName())); + } + Integer priority = jmsBinding.getOperationJMSPriority( opName ); + if (priority != null) { + producer.setPriority(priority.intValue()); + } + Boolean deliveryModePersistent = jmsBinding.getOperationJMSDeliveryMode(opName); + if (deliveryModePersistent != null) { + if (deliveryModePersistent.booleanValue()) + producer.setDeliveryMode(javax.jms.DeliveryMode.PERSISTENT); + else + producer.setDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT); + } + + try { + producer.send((javax.jms.Message)msg.getBody()); + } finally { + producer.close(); + } + return msg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Message invokeResponse(Message msg) { + JMSBindingContext context = msg.getBindingContext(); + try { + Session session = context.getJmsResponseSession(); + + javax.jms.Message requestMessage = (javax.jms.Message)msg.getBody(); + + String msgSelector = "JMSCorrelationID = '" + + requestMessage.getJMSMessageID() + + "'"; + MessageConsumer consumer = session.createConsumer(context.getReplyToDestination(), msgSelector); + + javax.jms.Message replyMsg; + try { + context.getJmsResourceFactory().startConnection(); + //jmsResourceFactory.startConnection(); + replyMsg = consumer.receive(context.getTimeToLive()); + } finally { + consumer.close(); + } + if (replyMsg == null) { + throw new JMSBindingException("No reply message received on " + + context.getReplyToDestination() + + " for message id " + + requestMessage.getJMSMessageID()); + } + + msg.setBody(replyMsg); + return msg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } catch (NamingException e) { + throw new JMSBindingException(e); + } finally { + try { + context.closeJmsResponseSession(); + if (jmsResourceFactory.isConnectionClosedAfterUse()) + jmsResourceFactory.closeResponseConnection(); + } catch (JMSException e) { + } + } + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java new file mode 100644 index 0000000000..626e44f34f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.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.sca.binding.jms.transport; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.naming.NamingException; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * + * @version $Rev$ $Date$ + */ +public class TransportServiceInterceptor implements Interceptor { + private static final Logger logger = Logger.getLogger(TransportServiceInterceptor.class.getName()); + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + private RuntimeComponentService service; + private String correlationScheme; + + + public TransportServiceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + this.service = (RuntimeComponentService)runtimeWire.getTarget().getContract(); + this.correlationScheme = jmsBinding.getCorrelationScheme(); + } + + public Message invoke(Message msg) { + try { + return invokeResponse(next.invoke(invokeRequest(msg))); + } catch (Throwable e) { + logger.log(Level.SEVERE, "Exception invoking service '" + service.getName(), e); + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message replyJMSMsg = responseMessageProcessor.createFaultMessage(context.getJmsResponseSession(), + (Throwable)e); + msg.setBody(replyJMSMsg); + invokeResponse(msg); + return msg; + } finally { + try { + ((JMSBindingContext)msg.getBindingContext()).closeJmsResponseSession(); + if (jmsResourceFactory.isConnectionClosedAfterUse()) + jmsResourceFactory.closeResponseConnection(); + } catch (JMSException e) { + } + } + } + + public Message invokeRequest(Message msg) { + try { + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message requestJMSMsg = context.getJmsMsg(); + + EndpointReference from = new EndpointReferenceImpl(null); + msg.setFrom(from); + from.setCallbackEndpoint(new EndpointReferenceImpl("/")); // TODO: whats this for? + ReferenceParameters parameters = from.getReferenceParameters(); + + String conversationID = requestJMSMsg.getStringProperty(JMSBindingConstants.CONVERSATION_ID_PROPERTY); + if (conversationID != null) { + parameters.setConversationID(conversationID); + } + + return msg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Message invokeResponse(Message msg) { + try { + + //if operation is oneway, return back. + Operation operation = msg.getOperation(); + if (operation != null && operation.isNonBlocking()) { + return msg; + } + + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsResponseSession(); + javax.jms.Message requestJMSMsg = context.getJmsMsg(); + javax.jms.Message responseJMSMsg = msg.getBody(); + + Destination replyDest = requestJMSMsg.getJMSReplyTo(); + if (replyDest == null) { + if (jmsBinding.getResponseDestinationName() != null) { + try { + replyDest = jmsResourceFactory.lookupDestination(jmsBinding.getResponseDestinationName()); + } catch (NamingException e) { + throw new JMSBindingException("Exception lookingup response destination", e); + } + } + } + + if (replyDest == null) { + // assume no reply is expected + if (msg.getBody() != null) { + logger.log(Level.FINE, "JMS service '" + service.getName() + "' dropped response as request has no replyTo"); + } + return msg; + } + + responseJMSMsg.setJMSDeliveryMode(requestJMSMsg.getJMSDeliveryMode()); + responseJMSMsg.setJMSPriority(requestJMSMsg.getJMSPriority()); + + if (correlationScheme == null || + JMSBindingConstants.CORRELATE_MSG_ID.equalsIgnoreCase(correlationScheme)) { + responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSMessageID()); + } else if (JMSBindingConstants.CORRELATE_CORRELATION_ID.equalsIgnoreCase(correlationScheme)) { + responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSCorrelationID()); + } + + MessageProducer producer = session.createProducer(replyDest); + + // Set jms header attributes in producer, not message. + int deliveryMode = requestJMSMsg.getJMSDeliveryMode(); + producer.setDeliveryMode(deliveryMode); + int deliveryPriority = requestJMSMsg.getJMSPriority(); + producer.setPriority(deliveryPriority); + + producer.send((javax.jms.Message)msg.getBody()); + + producer.close(); + context.closeJmsResponseSession(); + + return msg; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java new file mode 100644 index 0000000000..64badf9002 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.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.sca.binding.jms.wire; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Topic; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class CallbackDestinationInterceptor implements Interceptor { + private Invoker next; + private RuntimeComponentService service; + + public CallbackDestinationInterceptor(RuntimeWire runtimeWire) { + super(); + this.service = (RuntimeComponentService) runtimeWire.getTarget().getContract(); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Message invoke(Message msg) { + return next.invoke(invokeRequest(msg)); + } + + public Message invokeRequest(Message msg) { + try { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + + ReferenceParameters parameters = msg.getFrom().getReferenceParameters(); + + if (service.getInterfaceContract().getCallbackInterface() != null) { + + String callbackdestName = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY); + if (callbackdestName == null && msg.getOperation().isNonBlocking()) { + // if the request has a replyTo but this service operation is oneway but the service uses callbacks + // then use the replyTo as the callback destination + Destination replyTo = jmsMsg.getJMSReplyTo(); + if (replyTo != null) { + callbackdestName = (replyTo instanceof Queue) ? ((Queue) replyTo).getQueueName() : ((Topic) replyTo).getTopicName(); + } + } + + if (callbackdestName != null) { + // append "jms:" to make it an absolute uri so the invoker can determine it came in on the request + // as otherwise the invoker should use the uri from the service callback binding + parameters.setCallbackReference(new EndpointReferenceImpl("jms:" + callbackdestName)); + } + + String callbackID = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_ID_PROPERTY); + if (callbackID != null) { + parameters.setCallbackID(callbackID); + } + } + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + + return msg; + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java new file mode 100644 index 0000000000..2ba2429dfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.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.sca.binding.jms.wire; + +import java.util.List; + +import javax.jms.Destination; +import javax.jms.Queue; +import javax.jms.Topic; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class OperationPropertiesInterceptor implements Interceptor { + private Invoker next; + private JMSBinding jmsBinding; + private RuntimeComponentService service; + private List serviceOperations; + + public OperationPropertiesInterceptor(JMSBinding jmsBinding, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.service = (RuntimeComponentService) runtimeWire.getTarget().getContract(); + this.serviceOperations = service.getInterfaceContract().getInterface().getOperations(); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Message invoke(Message msg) { + return next.invoke(invokeRequest(msg)); + } + + public Message invokeRequest(Message msg) { + // TODO - could probably optimize this better + String operationName = msg.getOperation().getName(); + String operationNameOverride = jmsBinding.getNativeOperationName(operationName); + for (Operation op : serviceOperations) { + if (op.getName().equals(operationNameOverride)) { + msg.setOperation(op); + break; + } + } + return msg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.java new file mode 100644 index 0000000000..aa5df2b8bb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesProviderFactory.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.sca.binding.jms.wireformat.jmsbytes.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.provider.WireFormatProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSBytesProviderFactory implements WireFormatProviderFactory { + private ExtensionPointRegistry registry; + + public WireFormatJMSBytesProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + */ + public WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new WireFormatJMSBytesReferenceProvider(registry, component, reference, binding); + } + + /** + */ + public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new WireFormatJMSBytesServiceProvider(registry, component, service, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java new file mode 100644 index 0000000000..d08707a1ba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.runtime; + + +import java.lang.reflect.InvocationTargetException; +import javax.jms.JMSException; +import javax.jms.Session; + +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSBytesReferenceInterceptor implements Interceptor { + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + + public WireFormatJMSBytesReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + } + + public Message invoke(Message msg) { + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytes){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSBytes){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + try { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsSession(); + + Object[] requestParams = msg.getBody(); + javax.jms.Message requestMsg = null; + if (requestParams != null && requestParams.length > 0 ){ + requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, requestParams[0]); + } else { + requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, null); + } + msg.setBody(requestMsg); + + requestMsg.setJMSReplyTo(context.getReplyToDestination()); + + return msg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Message invokeResponse(Message msg) { + if (msg.getBody() != null){ + Object response = responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody()); + if (response instanceof InvocationTargetException) { + msg.setFaultBody(((InvocationTargetException) response).getCause()); + } else { + if (response != null){ + msg.setBody(response); + } else { + msg.setBody(null); + } + } + } + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceProvider.java new file mode 100644 index 0000000000..610c9901ec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceProvider.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSBytesReferenceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private JMSBinding binding; + private InterfaceContract interfaceContract; + + public WireFormatJMSBytesReferenceProvider(ExtensionPointRegistry registry, + RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.registry = registry; + this.component = component; + this.reference = reference; + this.binding = (JMSBinding)binding; + + // configure the reference based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing however overried + // any message processors specied in the SCDL in this case + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytes){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytes){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME); + } + + // just point to the reference interface contract so no + // databinding transformation takes place + interfaceContract = reference.getReference().getInterfaceContract(); + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null ) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytes){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytes){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + public Interceptor createInterceptor() { + return new WireFormatJMSBytesReferenceInterceptor(binding, + null, + reference.getRuntimeWire(binding)); + } + + public String getPhase() { + return Phase.REFERENCE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java new file mode 100644 index 0000000000..5128309233 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.runtime; + +import javax.jms.Session; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSBytesServiceInterceptor implements Interceptor { + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + + public WireFormatJMSBytesServiceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + } + + public Message invoke(Message msg) { + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytes){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + //if it's oneway return back + Operation operation = msg.getOperation(); + if (operation != null && operation.isNonBlocking()) { + return msg; + } + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSBytes){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + + Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg); + msg.setBody(new Object[]{requestPayload}); + + return msg; + } + + public Message invokeResponse(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsResponseSession(); + + javax.jms.Message responseJMSMsg; + if (msg.isFault()) { + responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody()); + } else { + Object response = msg.getBody(); + responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, response); + } + + msg.setBody(responseJMSMsg); + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.java new file mode 100644 index 0000000000..426bca28c6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceProvider.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.sca.binding.jms.wireformat.jmsbytes.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSBytesServiceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentService service; + private JMSBinding binding; + private InterfaceContract interfaceContract; + + public WireFormatJMSBytesServiceProvider(ExtensionPointRegistry registry, + RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + super(); + this.registry = registry; + this.component = component; + this.service = service; + this.binding = (JMSBinding)binding; + + // configure the service based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing however override + // any message processors specified in the SCDL in this case + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytes){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytes){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME); + } + + // just point to the reference interface contract so no + // databinding transformation takes place + interfaceContract = service.getService().getInterfaceContract(); + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null ) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytes){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytes){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + /** + */ + public Interceptor createInterceptor() { + return new WireFormatJMSBytesServiceInterceptor((JMSBinding)binding, + null, + service.getRuntimeWire(binding)); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.java new file mode 100644 index 0000000000..782f226fe6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLProviderFactory.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.sca.binding.jms.wireformat.jmsbytesxml.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.provider.WireFormatProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + + +public class WireFormatJMSBytesXMLProviderFactory implements WireFormatProviderFactory { + private ExtensionPointRegistry registry; + private JMSResourceFactoryExtensionPoint jmsRFEP; + + public WireFormatJMSBytesXMLProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + jmsRFEP = (JMSResourceFactoryExtensionPoint)registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class); + } + + /** + */ + public WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new WireFormatJMSBytesXMLReferenceProvider(registry, component, reference, binding); + } + + /** + */ + public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory((JMSBinding)binding); + return new WireFormatJMSBytesXMLServiceProvider(registry, component, service, binding, jmsRF); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java new file mode 100644 index 0000000000..cbcd848c85 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.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.sca.binding.jms.wireformat.jmsbytesxml.runtime; + +import javax.jms.JMSException; +import javax.jms.Session; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.WireFormatJMSBytesXML; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + + +public class WireFormatJMSBytesXMLReferenceInterceptor implements Interceptor { + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + + public WireFormatJMSBytesXMLReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + } + + public Message invoke(Message msg) { + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + try { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsSession(); + + javax.jms.Message requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody()); + + msg.setBody(requestMsg); + + requestMsg.setJMSReplyTo(context.getReplyToDestination()); + + return msg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Message invokeResponse(Message msg) { + if (msg.getBody() != null){ + javax.jms.Message jmsMsg = (javax.jms.Message)msg.getBody(); + Object response = responseMessageProcessor.extractPayloadFromJMSMessage(jmsMsg); + if (response != null ){ + msg.setBody(response); + try { + if (jmsMsg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) { + FaultException e = new FaultException("remote exception", response); + OMElement om = (OMElement) response; + e.setFaultName(new QName(om.getNamespace().getNamespaceURI(), om.getLocalName())); + msg.setFaultBody(e); + } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } else { + msg.setBody(null); + } + } + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.java new file mode 100644 index 0000000000..bd04d4b24f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceProvider.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.sca.binding.jms.wireformat.jmsbytesxml.runtime; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.WireFormatJMSBytesXML; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +public class WireFormatJMSBytesXMLReferenceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private JMSBinding binding; + private InterfaceContract interfaceContract; + + public WireFormatJMSBytesXMLReferenceProvider(ExtensionPointRegistry registry, + RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.registry = registry; + this.component = component; + this.reference = reference; + this.binding = (JMSBinding)binding; + + // configure the reference based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing however overried + // any message processors specied in the SCDL in this case + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.XML_BYTES_MP_CLASSNAME); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.XML_BYTES_MP_CLASSNAME); + } + + // create a local interface contract that is configured specifically to + // deal with the data format that this wire format is expecting to sent to + // and receive from the databinding interceptor. The request/response parts of + // this interface contract will be copied into the binding interface contract + // as required + WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class); + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + BindingWSDLGenerator.generateWSDL(component, reference, wsBinding, registry, null); + interfaceContract = wsBinding.getBindingInterfaceContract(); + interfaceContract.getInterface().resetDataBinding(OMElement.class.getName()); + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null ) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + public Interceptor createInterceptor() { + return new WireFormatJMSBytesXMLReferenceInterceptor(binding, + null, + reference.getRuntimeWire(binding)); + } + + public String getPhase() { + return Phase.REFERENCE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java new file mode 100644 index 0000000000..e3d22fa814 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.runtime; + +import javax.jms.Session; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.WireFormatJMSBytesXML; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class WireFormatJMSBytesXMLServiceInterceptor implements Interceptor { + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + + public WireFormatJMSBytesXMLServiceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + } + + public Message invoke(Message msg) { + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + //if it's oneway return back + Operation operation = msg.getOperation(); + if (operation != null && operation.isNonBlocking()) { + return msg; + } + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + + Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg); + msg.setBody(new Object[]{requestPayload}); + + return msg; + } + + public Message invokeResponse(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsResponseSession(); + + javax.jms.Message responseJMSMsg; + if (msg.isFault()) { + responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody()); + } else { + Object response = msg.getBody(); + responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, response); + } + + msg.setBody(responseJMSMsg); + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java new file mode 100644 index 0000000000..c2d81600e1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceProvider.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.runtime; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.WireFormatJMSBytesXML; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +public class WireFormatJMSBytesXMLServiceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentService service; + private JMSBinding binding; + private JMSResourceFactory jmsResourceFactory; + private InterfaceContract interfaceContract; + + public WireFormatJMSBytesXMLServiceProvider(ExtensionPointRegistry registry, + RuntimeComponent component, + RuntimeComponentService service, + Binding binding, + JMSResourceFactory jmsResourceFactory) { + super(); + this.registry = registry; + this.component = component; + this.service = service; + this.binding = (JMSBinding)binding; + this.jmsResourceFactory = jmsResourceFactory; + + // configure the service based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing however override + // any message processors specified in the SCDL in this case + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.XML_BYTES_MP_CLASSNAME); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.XML_BYTES_MP_CLASSNAME); + } + + // create a local interface contract that is configured specifically to + // deal with the data format that this wire format is expecting to sent to + // and receive from the databinding interceptor. The request/response parts of + // this interface contract will be copied into the binding interface contract + // as required + WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class); + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + BindingWSDLGenerator.generateWSDL(component, service, wsBinding, registry, null); + interfaceContract = wsBinding.getBindingInterfaceContract(); + interfaceContract.getInterface().resetDataBinding(OMElement.class.getName()); + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null ) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSBytesXML){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSBytesXML){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + /** + */ + public Interceptor createInterceptor() { + return new WireFormatJMSBytesXMLServiceInterceptor((JMSBinding)binding, + jmsResourceFactory, + service.getRuntimeWire(binding)); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultProviderFactory.java new file mode 100644 index 0000000000..cde7dfd6aa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultProviderFactory.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.sca.binding.jms.wireformat.jmsdefault.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.provider.WireFormatProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultProviderFactory implements WireFormatProviderFactory { + private ExtensionPointRegistry registry; + private JMSResourceFactoryExtensionPoint jmsRFEP; + + public WireFormatJMSDefaultProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + jmsRFEP = (JMSResourceFactoryExtensionPoint) registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class); + } + + /** + */ + public WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, RuntimeComponentReference reference, + Binding binding) { + return new WireFormatJMSDefaultReferenceProvider(registry, component, reference, binding); + } + + /** + */ + public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) { + JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory((JMSBinding) binding); + return new WireFormatJMSDefaultServiceProvider(registry, component, service, binding, jmsRF); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java new file mode 100644 index 0000000000..f132940b22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.runtime; + +import java.util.HashMap; +import java.util.List; +import javax.jms.BytesMessage; +import javax.jms.JMSException; +import javax.jms.Session; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.DefaultMessageProcessor; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultReferenceInterceptor implements Interceptor { + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private DefaultMessageProcessor requestMessageProcessor; + private DefaultMessageProcessor responseMessageProcessor; + private HashMap inputWrapperMap; + private HashMap outputWrapperMap; + + public WireFormatJMSDefaultReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire, HashMap inputWrapperMap, + HashMap outputWrapperMap) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + // Note the default processor doesn't follow the normal processor pattern + // as it has to handle both text and bytes messages + this.requestMessageProcessor = new DefaultMessageProcessor(jmsBinding); + this.responseMessageProcessor = new DefaultMessageProcessor(jmsBinding); + this.inputWrapperMap = inputWrapperMap; + this.outputWrapperMap = outputWrapperMap; + } + + public Message invoke(Message msg) { + + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault) { + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSDefault) { + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + try { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsSession(); + + javax.jms.Message requestMsg; + + if (((WireFormatJMSDefault) jmsBinding.getRequestWireFormat()).isUseBytesMessage()) { + requestMsg = requestMessageProcessor.insertPayloadIntoJMSBytesMessage(session, msg.getBody(), this.inputWrapperMap.get(msg.getOperation().getName())); + } else { + requestMsg = requestMessageProcessor.insertPayloadIntoJMSTextMessage(session, msg.getBody(), this.inputWrapperMap.get(msg.getOperation().getName())); + } + + msg.setBody(requestMsg); + + requestMsg.setJMSReplyTo(context.getReplyToDestination()); + + return msg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Message invokeResponse(Message msg) { + if (msg.getBody() != null) { + javax.jms.Message jmsMsg = (javax.jms.Message) msg.getBody(); + + Operation op = msg.getOperation(); + DataType outputDataType = op.getOutputType(); + + Class outputType = null; + if (outputDataType != null) { + outputType = outputDataType.getPhysical(); + } + + if (outputType != null && javax.jms.Message.class.isAssignableFrom(outputType)) { + msg.setBody(jmsMsg); + } else { + + OMElement wrapper = null; + // if we have a fault no need to wrap the response + try { + if (!jmsMsg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) { + // If there is only one arg we must add a wrapper if the operation is wrapper style + wrapper = this.outputWrapperMap.get(msg.getOperation().getName()); + } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + + Object response; + if (jmsMsg instanceof BytesMessage) { + response = responseMessageProcessor.extractPayloadFromJMSBytesMessage(jmsMsg, wrapper); + } else { + response = responseMessageProcessor.extractPayloadFromJMSTextMessage(jmsMsg, wrapper); + } + + if (response != null) { + msg.setBody(response); + try { + if (jmsMsg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) { + FaultException e = new FaultException("remote exception", response); + OMElement om = (OMElement) response; + e.setFaultName(new QName(om.getNamespace().getNamespaceURI(), om.getLocalName())); + msg.setFaultBody(e); + } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } else { + msg.setBody(null); + } + } + } + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java new file mode 100644 index 0000000000..f15d7317f8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceProvider.java @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.runtime; + +import java.util.HashMap; +import java.util.List; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultReferenceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private JMSBinding binding; + private InterfaceContract interfaceContract; + private HashMap inputWrapperMap; + private HashMap outputWrapperMap; + + public WireFormatJMSDefaultReferenceProvider(ExtensionPointRegistry registry, RuntimeComponent component, RuntimeComponentReference reference, Binding binding) { + super(); + this.registry = registry; + this.component = component; + this.reference = reference; + this.binding = (JMSBinding) binding; + + this.inputWrapperMap = new HashMap(); + this.outputWrapperMap = new HashMap(); + + // configure the reference based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing so set the message + // type here if not set explicitly in SCDL + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSDefault){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.DEFAULT_MP_CLASSNAME); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSDefault){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.DEFAULT_MP_CLASSNAME); + } + + // TODO - can be null if it's a $self$ reference. Need to decide if + // that's valid + if (reference.getReference() == null){ + interfaceContract = reference.getInterfaceContract(); + return; + } + + List opList = reference.getReference().getInterfaceContract().getInterface().getOperations(); + + // Go through each operation and add wrapper info + OMFactory factory = OMAbstractFactory.getOMFactory(); + + // set the binding interface contract to represent the WSDL for the + // xml messages that will be sent + // I think we have to check for asIs because the Java2WSDL will blow up when using javax.jms.Message + if (reference.getInterfaceContract() != null && !isAsIs()) { + WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class); + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + BindingWSDLGenerator.generateWSDL(component, reference, wsBinding, registry, null); + interfaceContract = wsBinding.getBindingInterfaceContract(); + interfaceContract.getInterface().resetDataBinding(OMElement.class.getName()); + + List wsdlOpList = interfaceContract.getInterface().getOperations(); + + for (Operation op : opList) { + + String name = op.getName(); + Operation matchingWsdlOp = null; + + // find the matching wsdlop + for (Operation wsdlOp : wsdlOpList) { + if (name.equals(wsdlOp.getName())) { + matchingWsdlOp = wsdlOp; + + break; + } + } + + // only add operations that need to be wrapped/unwrapped + // we need to look at the wsdl interface to determine if the op is wrapped or not + + // TODO - not sure we really support viewing the input/output as separately wrapped + // like the separate code paths imply. Not sure how many @OneWay tests we have, this might + // not be an issue. + + if (matchingWsdlOp.isInputWrapperStyle()) { + if (op.getInputType().getLogical().size() == 1) { + this.inputWrapperMap.put(name, true); + } else { + this.inputWrapperMap.put(name, false); + } + } else { + this.inputWrapperMap.put(name, false); + } + + if (matchingWsdlOp.isOutputWrapperStyle()) { + // we only need to know what the wrapper is on the deserialization + // might need to change this when there input/output wrapper style is different + ElementInfo ei = op.getOutputWrapper().getWrapperElement(); + String namespace = ei.getQName().getNamespaceURI(); + String opName = ei.getQName().getLocalPart(); + OMNamespace ns = factory.createOMNamespace(namespace, "ns2"); + OMElement wrapper = factory.createOMElement(opName, ns); + + this.outputWrapperMap.put(name, wrapper); + } + } + } else { + interfaceContract = reference.getReference().getInterfaceContract(); + } + + } + + protected boolean isAsIs() { + InterfaceContract ic = reference.getInterfaceContract(); + if (ic.getInterface().getOperations().size() != 1) { + return false; + } + + List inputDataTypes = ic.getInterface().getOperations().get(0).getInputType().getLogical(); + + if (inputDataTypes.size() != 1) { + return false; + } + + Class inputType = inputDataTypes.get(0).getPhysical(); + + if (javax.jms.Message.class.isAssignableFrom(inputType)) { + return true; + } + return false; + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null && + !isAsIs()) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSDefault){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSDefault){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + public Interceptor createInterceptor() { + return new WireFormatJMSDefaultReferenceInterceptor((JMSBinding) binding, null, reference.getRuntimeWire(binding), inputWrapperMap, outputWrapperMap); + } + + public String getPhase() { + return Phase.REFERENCE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java new file mode 100644 index 0000000000..0753b8e7ef --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.runtime; + +import java.util.HashMap; +import java.util.List; + +import javax.jms.BytesMessage; +import javax.jms.Session; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.DefaultMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Policy handler to handle PolicySet related to Logging with the QName {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultServiceInterceptor implements Interceptor { + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private DefaultMessageProcessor requestMessageProcessor; + private DefaultMessageProcessor responseMessageProcessor; + private HashMap inputWrapperMap; + private HashMap outputWrapperMap; + + public WireFormatJMSDefaultServiceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire, HashMap inputWrapperMap, + HashMap outputWrapperMap) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + // Note the default processor doesn't follow the normal processor pattern + // as it has to handle both text and bytes messages + this.requestMessageProcessor = new DefaultMessageProcessor(jmsBinding); + this.responseMessageProcessor = new DefaultMessageProcessor(jmsBinding); + this.inputWrapperMap = inputWrapperMap; + this.outputWrapperMap = outputWrapperMap; + + } + + public Message invoke(Message msg) { + + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault) { + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + // if it's oneway return back + Operation operation = msg.getOperation(); + if (operation != null && operation.isNonBlocking()) { + return msg; + } + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSDefault) { + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + + Operation op = msg.getOperation(); + List inputDataTypes = op.getInputType().getLogical(); + + Class inputType = null; + if (inputDataTypes.size() == 1) { + inputType = inputDataTypes.get(0).getPhysical(); + } + if (inputType != null && javax.jms.Message.class.isAssignableFrom(inputType)) { + msg.setBody(new Object[] { jmsMsg }); + + if (jmsMsg instanceof BytesMessage) { + context.setUseBytesForWFJMSDefaultResponse(true); + } else { + context.setUseBytesForWFJMSDefaultResponse(false); + } + } else { + + // If there is only one arg we must add a wrapper if the operation is wrapper style + OMElement wrapper = this.inputWrapperMap.get(msg.getOperation().getName()); + + Object requestPayload; + if (jmsMsg instanceof BytesMessage) { + requestPayload = responseMessageProcessor.extractPayloadFromJMSBytesMessage(jmsMsg, wrapper); + context.setUseBytesForWFJMSDefaultResponse(true); + } else { + requestPayload = responseMessageProcessor.extractPayloadFromJMSTextMessage(jmsMsg, wrapper ); + context.setUseBytesForWFJMSDefaultResponse(false); + } + + msg.setBody(new Object[] { requestPayload }); + } + + return msg; + + } + + public Message invokeResponse(Message msg) { + + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsResponseSession(); + + javax.jms.Message responseJMSMsg; + + boolean respondBytesMessage = context.isUseBytesForWFJMSDefaultResponse(); + + if (msg.isFault()) { + if (respondBytesMessage == true) { + responseJMSMsg = requestMessageProcessor.createFaultJMSBytesMessage(session, (Throwable) msg.getBody()); + } else { + responseJMSMsg = responseMessageProcessor.createFaultJMSTextMessage(session, (Throwable) msg.getBody()); + } + } else { + boolean unwrap = false; + + if (this.outputWrapperMap.get(msg.getOperation().getName()) != null){ + unwrap = this.outputWrapperMap.get(msg.getOperation().getName()); + } + + if (respondBytesMessage == true) { + responseJMSMsg = requestMessageProcessor.insertPayloadIntoJMSBytesMessage(session, msg.getBody(), unwrap); + } else { + responseJMSMsg = requestMessageProcessor.insertPayloadIntoJMSTextMessage(session, msg.getBody(), unwrap); + } + } + + msg.setBody(responseJMSMsg); + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java new file mode 100644 index 0000000000..4f63867350 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceProvider.java @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.runtime; + +import java.util.HashMap; +import java.util.List; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultServiceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentService service; + private JMSBinding binding; + private JMSResourceFactory jmsResourceFactory; + private InterfaceContract interfaceContract; + private HashMap inputWrapperMap; + private HashMap outputWrapperMap; + + public WireFormatJMSDefaultServiceProvider(ExtensionPointRegistry registry, RuntimeComponent component, RuntimeComponentService service, Binding binding, JMSResourceFactory jmsResourceFactory) { + super(); + this.component = component; + this.service = service; + this.binding = (JMSBinding) binding; + this.jmsResourceFactory = jmsResourceFactory; + + this.inputWrapperMap = new HashMap(); + this.outputWrapperMap = new HashMap(); + + // configure the service based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing so set the message + // type here if not set explicitly in SCDL + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSDefault){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.DEFAULT_MP_CLASSNAME); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSDefault){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.DEFAULT_MP_CLASSNAME); + } + + List opList = service.getService().getInterfaceContract().getInterface().getOperations(); + + // Go through each operation and add wrapper info + OMFactory factory = OMAbstractFactory.getOMFactory(); + + // set the binding interface contract to represent the WSDL for the + // xml messages that will be sent + + // I think we have to check for asIs because the Java2WSDL will blow up when using javax.jms.Message + if (service.getInterfaceContract() != null && !isAsIs()) { + WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class); + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + BindingWSDLGenerator.generateWSDL(component, service, wsBinding, registry, null); + interfaceContract = wsBinding.getBindingInterfaceContract(); + interfaceContract.getInterface().resetDataBinding(OMElement.class.getName()); + + List wsdlOpList = interfaceContract.getInterface().getOperations(); + + for (Operation op : opList) { + String name = op.getName(); + + Operation matchingWsdlOp = null; + + // find the matching wsdlop + for (Operation wsdlOp : wsdlOpList) { + if (name.equals(wsdlOp.getName())) { + matchingWsdlOp = wsdlOp; + break; + } + } + + // only add operations that need to be wrapped/unwrapped + + // TODO - not sure we really support viewing the input/output as separately wrapped + // like the separate code paths imply. Not sure how many @OneWay tests we have, this might + // not be an issue. + if (matchingWsdlOp.isInputWrapperStyle()) { + if (op.getInputType().getLogical().size() == 1) { + // we only need to know what the wrapper is on the deserialization + // might need to change this when the input/output wrapper style is different + ElementInfo ei = op.getInputWrapper().getWrapperElement(); + String namespace = ei.getQName().getNamespaceURI(); + String opName = ei.getQName().getLocalPart(); + OMNamespace ns = factory.createOMNamespace(namespace, "ns1"); + OMElement wrapper = factory.createOMElement(opName, ns); + this.inputWrapperMap.put(name, wrapper); + } + } + + if (matchingWsdlOp.isOutputWrapperStyle()) { + this.outputWrapperMap.put(name, true); + } else { + this.outputWrapperMap.put(name, false); + } + + } + + } else { + interfaceContract = service.getService().getInterfaceContract(); + } + } + + protected boolean isAsIs() { + InterfaceContract ic = service.getInterfaceContract(); + if (ic.getInterface().getOperations().size() != 1) { + return false; + } + + List inputDataTypes = ic.getInterface().getOperations().get(0).getInputType().getLogical(); + + if (inputDataTypes.size() != 1) { + return false; + } + + Class inputType = inputDataTypes.get(0).getPhysical(); + + if (javax.jms.Message.class.isAssignableFrom(inputType)) { + return true; + } + return false; + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null && + !isAsIs()) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSDefault){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSDefault){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + + public Interceptor createInterceptor() { + return new WireFormatJMSDefaultServiceInterceptor(binding, jmsResourceFactory, service.getRuntimeWire(binding), this.inputWrapperMap, this.outputWrapperMap); + } + + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.java new file mode 100644 index 0000000000..9e92bf40bf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectProviderFactory.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.sca.binding.jms.wireformat.jmsobject.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.provider.WireFormatProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSObjectProviderFactory implements WireFormatProviderFactory { + private ExtensionPointRegistry registry; + + public WireFormatJMSObjectProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + */ + public WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new WireFormatJMSObjectReferenceProvider(registry, component, reference, binding); + } + + /** + */ + public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new WireFormatJMSObjectServiceProvider(registry, component, service, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java new file mode 100644 index 0000000000..22c66b0b78 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.runtime; + + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; + +import javax.jms.JMSException; +import javax.jms.Session; + +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSObjectReferenceInterceptor implements Interceptor { + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + + private HashMap singleArgMap; + + public WireFormatJMSObjectReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire, HashMap hashMap) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + this.singleArgMap = hashMap; + } + + public Message invoke(Message msg) { + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSObject){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSObject){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + try { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsSession(); + + javax.jms.Message requestMsg; + + // Tuscany automatically wraps operation arguments in an array before we + // get to this point so here we need to decide how they are going to appear + // on the wire. + // + // If the operation has a single parameter and the user has set @wrapSingle=false + // then + // send the single parameter out onto the wire unwrapped + // else + // send out the message as is + // + if (singleArgMap.get(msg.getOperation().getName()) == null) { + requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody()); + } else { + // we know that wrapSinle is set to false here as the provider only + // populates singleArgMap if it is set false + requestMsg = ((ObjectMessageProcessor) requestMessageProcessor).createJMSMessageForSingleParamOperation(session, msg.getBody(), false); + } + + msg.setBody(requestMsg); + + requestMsg.setJMSReplyTo(context.getReplyToDestination()); + + return msg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Message invokeResponse(Message msg) { + if (msg.getBody() != null){ + Object response = responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody()); + + if (response instanceof InvocationTargetException) { + msg.setFaultBody(((InvocationTargetException) response).getCause()); + } else { + if (response != null){ + msg.setBody(response); + } else { + msg.setBody(null); + } + } + } + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java new file mode 100644 index 0000000000..e09c146f48 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceProvider.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.runtime; + +import java.util.HashMap; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSObjectReferenceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private JMSBinding binding; + private InterfaceContract interfaceContract; + + private HashMap singleArgMap; //map of one arg operations, leave empty if wrapSingleInput is true + + public WireFormatJMSObjectReferenceProvider(ExtensionPointRegistry registry, + RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.registry = registry; + this.component = component; + this.reference = reference; + this.binding = (JMSBinding)binding; + + this.singleArgMap = new HashMap(); + + // configure the reference based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing however override + // any message processors specified in the SCDL in this case + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSObject){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME); + + //we don't need to create this map if wrapSingleInput is true + if (!((WireFormatJMSObject) this.binding.getRequestWireFormat()).isWrappedSingleInput()){ + List opList = reference.getReference().getInterfaceContract().getInterface().getOperations(); + + for (Operation op: opList) { + if (op.getInputType().getLogical().size() == 1){ + this.singleArgMap.put(op.getName(), ""); + } + } + } + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSObject){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME); + } + + // just point to the reference interface contract so no + // databinding transformation takes place + interfaceContract = reference.getReference().getInterfaceContract(); + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null ) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSObject){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSObject){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + public Interceptor createInterceptor() { + return new WireFormatJMSObjectReferenceInterceptor(binding, + null, + reference.getRuntimeWire(binding), this.singleArgMap); + } + + public String getPhase() { + return Phase.REFERENCE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java new file mode 100644 index 0000000000..5979bc9214 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.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.sca.binding.jms.wireformat.jmsobject.runtime; + +import java.util.HashMap; + +import javax.jms.Session; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSObjectServiceInterceptor implements Interceptor { + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + private HashMap> singleArgMap; + private boolean wrapSingle; + + public WireFormatJMSObjectServiceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, + RuntimeWire runtimeWire, HashMap> singleArgMap, boolean wrapSingle) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + this.singleArgMap = singleArgMap; + this.wrapSingle = wrapSingle; + } + + public Message invoke(Message msg) { + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSObject){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + //if it's oneway return back + Operation operation = msg.getOperation(); + if (operation != null && operation.isNonBlocking()) { + return msg; + } + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSObject){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + Object requestPayload; + + // If the service interface has a single argument then we need + // to check if the object from the wire is expected + // to be unwrapped or not + // + Class argType = this.singleArgMap.get(msg.getOperation().getName()); + if (argType == null) { + requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg); + }else { + requestPayload = ((ObjectMessageProcessor)requestMessageProcessor).extractPayloadFromJMSMessageForSingleParamOperation(jmsMsg, argType, wrapSingle); + } + + if (requestPayload != null && requestPayload.getClass().isArray()) { + msg.setBody(requestPayload); + } else if (requestPayload == null) { + msg.setBody(new Object[0]); + } else { + msg.setBody(new Object[] {requestPayload}); + } + + return msg; + } + + public Message invokeResponse(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsResponseSession(); + + javax.jms.Message responseJMSMsg = null; + if (msg.isFault()) { + responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody()); + } else { + responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody()); + } + + msg.setBody(responseJMSMsg); + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.java new file mode 100644 index 0000000000..f112c0cff9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceProvider.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.sca.binding.jms.wireformat.jmsobject.runtime; + + +import java.util.HashMap; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSObjectServiceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentService service; + private JMSBinding binding; + private InterfaceContract interfaceContract; + private HashMap> singleArgMap; + private boolean wrapSingle = true; + + public WireFormatJMSObjectServiceProvider(ExtensionPointRegistry registry, + RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + super(); + this.registry = registry; + this.component = component; + this.service = service; + this.binding = (JMSBinding)binding; + this.singleArgMap = new HashMap>(); + + // configure the service based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing however override + // any message processors specified in the SCDL in this case + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSObject){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME); + + List opList = service.getService().getInterfaceContract().getInterface().getOperations(); + + for (Operation op: opList) { + if (op.getInputType().getLogical().size() == 1){ + this.singleArgMap.put(op.getName(), op.getInputType().getLogical().get(0).getPhysical()); + } + } + + wrapSingle = ((WireFormatJMSObject) this.binding.getRequestWireFormat()).isWrappedSingleInput(); + + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSObject){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME); + } + + // just point to the reference interface contract so no + // databinding transformation takes place + interfaceContract = service.getService().getInterfaceContract(); + + + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null ) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSObject){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSObject){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + /** + */ + public Interceptor createInterceptor() { + + return new WireFormatJMSObjectServiceInterceptor((JMSBinding)binding, null,service.getRuntimeWire(binding), + this.singleArgMap, wrapSingle ); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.java new file mode 100644 index 0000000000..555dfb47b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextProviderFactory.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.sca.binding.jms.wireformat.jmstext.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSText; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.provider.WireFormatProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextProviderFactory implements WireFormatProviderFactory { + private ExtensionPointRegistry registry; + + public WireFormatJMSTextProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + */ + public WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new WireFormatJMSTextReferenceProvider(registry, component, reference, binding); + } + + /** + */ + public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new WireFormatJMSTextServiceProvider(registry, component, service, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java new file mode 100644 index 0000000000..49e745ffaa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat.jmstext.runtime; + + +import java.lang.reflect.InvocationTargetException; +import javax.jms.JMSException; +import javax.jms.Session; + +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSText; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextReferenceInterceptor implements Interceptor { + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + + public WireFormatJMSTextReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + } + + public Message invoke(Message msg) { + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSText){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSText){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + try { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsSession(); + + Object[] requestParams = msg.getBody(); + javax.jms.Message requestMsg = null; + if (requestParams != null && requestParams.length > 0 ){ + requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, requestParams[0]); + } else { + requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, null); + } + msg.setBody(requestMsg); + + requestMsg.setJMSReplyTo(context.getReplyToDestination()); + + return msg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Message invokeResponse(Message msg) { + if (msg.getBody() != null){ + Object response = responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody()); + + if (response instanceof InvocationTargetException) { + msg.setFaultBody(((InvocationTargetException) response).getCause()); + } else { + if (response != null){ + msg.setBody(response); + } else { + msg.setBody(null); + } + } + } + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceProvider.java new file mode 100644 index 0000000000..8d96fc7634 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceProvider.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.sca.binding.jms.wireformat.jmstext.runtime; + + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSText; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextReferenceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private JMSBinding binding; + private InterfaceContract interfaceContract; + + public WireFormatJMSTextReferenceProvider(ExtensionPointRegistry registry, + RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.registry = registry; + this.component = component; + this.reference = reference; + this.binding = (JMSBinding)binding; + + // configure the reference based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing however override + // any message processors specified in the SCDL in this case + + // this wire format doubles up as the execution logic for user defined + // message processors so check the processor name is still set to default + // before overwriting + + if ((this.binding.getRequestWireFormat() instanceof WireFormatJMSText) && + (this.binding.getRequestMessageProcessorName().equals(JMSBindingConstants.DEFAULT_MP_CLASSNAME))){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.TEXT_MP_CLASSNAME); + } + if ((this.binding.getResponseWireFormat() instanceof WireFormatJMSText) && + (this.binding.getResponseMessageProcessorName().equals(JMSBindingConstants.DEFAULT_MP_CLASSNAME))){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.TEXT_MP_CLASSNAME); + } + + + // just point to the reference interface contract so no + // databinding transformation takes place + interfaceContract = reference.getReference().getInterfaceContract(); + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null ) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSText){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSText){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + public Interceptor createInterceptor() { + return new WireFormatJMSTextReferenceInterceptor(binding, + null, + reference.getRuntimeWire(binding)); + } + + public String getPhase() { + return Phase.REFERENCE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java new file mode 100644 index 0000000000..cf9e49afef --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat.jmstext.runtime; + +import javax.jms.Session; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSText; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextServiceInterceptor implements Interceptor { + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + + public WireFormatJMSTextServiceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + } + + public Message invoke(Message msg) { + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSText){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + //if it's oneway return back + Operation operation = msg.getOperation(); + if (operation != null && operation.isNonBlocking()) { + return msg; + } + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSText){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + + Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg); + msg.setBody(new Object[]{requestPayload}); + + return msg; + } + + public Message invokeResponse(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsResponseSession(); + + javax.jms.Message responseJMSMsg; + if (msg.isFault()) { + responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody()); + } else { + Object response = msg.getBody(); + responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, response); + } + + msg.setBody(responseJMSMsg); + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java new file mode 100644 index 0000000000..983b01b121 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceProvider.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.wireformat.jmstext.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSText; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextServiceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentService service; + private JMSBinding binding; + private InterfaceContract interfaceContract; + + public WireFormatJMSTextServiceProvider(ExtensionPointRegistry registry, + RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + super(); + this.registry = registry; + this.component = component; + this.service = service; + this.binding = (JMSBinding)binding; + + // configure the service based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing however override + // any message processors specified in the SCDL in this case + + // this wire format doubles up as the execution logic for user defined + // message processors so check the processor name is still set to default + // before overwriting + + if ((this.binding.getRequestWireFormat() instanceof WireFormatJMSText) && + (this.binding.getRequestMessageProcessorName().equals(JMSBindingConstants.DEFAULT_MP_CLASSNAME))){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.TEXT_MP_CLASSNAME); + } + if ((this.binding.getResponseWireFormat() instanceof WireFormatJMSText) && + (this.binding.getResponseMessageProcessorName().equals(JMSBindingConstants.DEFAULT_MP_CLASSNAME))){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.TEXT_MP_CLASSNAME); + } + + // just point to the reference interface contract so no + // databinding transformation takes place + interfaceContract = service.getService().getInterfaceContract(); + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null ) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSText){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSText){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + /** + */ + public Interceptor createInterceptor() { + return new WireFormatJMSTextServiceInterceptor((JMSBinding)binding, + null, + service.getRuntimeWire(binding)); + } + + /** + */ + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLProviderFactory.java new file mode 100644 index 0000000000..44f490ee37 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLProviderFactory.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.sca.binding.jms.wireformat.jmstextxml.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.provider.WireFormatProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextXMLProviderFactory implements WireFormatProviderFactory { + private ExtensionPointRegistry registry; + private JMSResourceFactoryExtensionPoint jmsRFEP; + + public WireFormatJMSTextXMLProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + jmsRFEP = (JMSResourceFactoryExtensionPoint)registry.getExtensionPoint(JMSResourceFactoryExtensionPoint.class); + } + + /** + */ + public WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new WireFormatJMSTextXMLReferenceProvider(registry, component, reference, binding); + } + + /** + */ + public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory((JMSBinding)binding); + return new WireFormatJMSTextXMLServiceProvider(registry, component, service, binding, jmsRF); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java new file mode 100644 index 0000000000..adf3fda98c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.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.sca.binding.jms.wireformat.jmstextxml.runtime; + + + + +import javax.jms.JMSException; +import javax.jms.Session; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextXMLReferenceInterceptor implements Interceptor { + + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + + + public WireFormatJMSTextXMLReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + } + + public Message invoke(Message msg) { + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSTextXML){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSTextXML){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + try { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsSession(); + + javax.jms.Message requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody()); + msg.setBody(requestMsg); + + requestMsg.setJMSReplyTo(context.getReplyToDestination()); + + return msg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + public Message invokeResponse(Message msg) { + if (msg.getBody() != null){ + javax.jms.Message jmsMsg = (javax.jms.Message)msg.getBody(); + Object response = responseMessageProcessor.extractPayloadFromJMSMessage(jmsMsg); + if (response != null ){ + msg.setBody(response); + try { + if (jmsMsg.getBooleanProperty(JMSBindingConstants.FAULT_PROPERTY)) { + FaultException e = new FaultException("remote exception", response); + OMElement om = (OMElement) response; + e.setFaultName(new QName(om.getNamespace().getNamespaceURI(), om.getLocalName())); + msg.setFaultBody(e); + } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } else { + msg.setBody(null); + } + } + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java new file mode 100644 index 0000000000..a52ee3df18 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceProvider.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.runtime; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextXMLReferenceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private JMSBinding binding; + private InterfaceContract interfaceContract; + + public WireFormatJMSTextXMLReferenceProvider(ExtensionPointRegistry registry, + RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.registry = registry; + this.component = component; + this.reference = reference; + this.binding = (JMSBinding)binding; + + // configure the reference based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing so set the message + // type here if not set explicitly in SCDL + + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSTextXML){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.XML_MP_CLASSNAME); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSTextXML){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.XML_MP_CLASSNAME); + } + + // create a local interface contract that is configured specifically to + // deal with the data format that this wire format is expecting to sent to + // and receive from the databinding interceptor. The request/response parts of + // this interface contract will be copied into the binding interface contract + // as required + WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class); + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + BindingWSDLGenerator.generateWSDL(component, reference, wsBinding, registry, null); + interfaceContract = wsBinding.getBindingInterfaceContract(); + interfaceContract.getInterface().resetDataBinding(OMElement.class.getName()); + } + + protected boolean isOnMessage() { + InterfaceContract ic = reference.getInterfaceContract(); + if (ic.getInterface().getOperations().size() != 1) { + return false; + } + return "onMessage".equals(ic.getInterface().getOperations().get(0).getName()); + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null && + !isOnMessage()) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSTextXML){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSTextXML){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + public Interceptor createInterceptor() { + return new WireFormatJMSTextXMLReferenceInterceptor((JMSBinding)binding, + null, + reference.getRuntimeWire(binding)); + } + + public String getPhase() { + return Phase.REFERENCE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java new file mode 100644 index 0000000000..e0a5c86202 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.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.sca.binding.jms.wireformat.jmstextxml.runtime; + +import javax.jms.Session; + +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; +import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextXMLServiceInterceptor implements Interceptor { + private Invoker next; + private RuntimeWire runtimeWire; + private JMSResourceFactory jmsResourceFactory; + private JMSBinding jmsBinding; + private JMSMessageProcessor requestMessageProcessor; + private JMSMessageProcessor responseMessageProcessor; + + public WireFormatJMSTextXMLServiceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { + super(); + this.jmsBinding = jmsBinding; + this.runtimeWire = runtimeWire; + this.jmsResourceFactory = jmsResourceFactory; + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); + this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + } + + public Message invoke(Message msg) { + + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSTextXML){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + //if it's oneway return back + Operation operation = msg.getOperation(); + if (operation != null && operation.isNonBlocking()) { + return msg; + } + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSTextXML){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + + Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg); + msg.setBody(new Object[] { requestPayload }); + + return msg; + } + + public Message invokeResponse(Message msg) { + + // get the jms context + JMSBindingContext context = msg.getBindingContext(); + Session session = context.getJmsResponseSession(); + + javax.jms.Message responseJMSMsg; + if (msg.isFault()) { + responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody()); + } else { + responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody()); + } + + msg.setBody(responseJMSMsg); + + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java new file mode 100644 index 0000000000..7e48dc76a0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceProvider.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.runtime; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.WireFormatProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextXMLServiceProvider implements WireFormatProvider { + private ExtensionPointRegistry registry; + private RuntimeComponent component; + private RuntimeComponentService service; + private JMSBinding binding; + private JMSResourceFactory jmsResourceFactory; + private InterfaceContract interfaceContract; + + public WireFormatJMSTextXMLServiceProvider(ExtensionPointRegistry registry, + RuntimeComponent component, + RuntimeComponentService service, + Binding binding, + JMSResourceFactory jmsResourceFactory) { + super(); + this.component = component; + this.service = service; + this.binding = (JMSBinding)binding; + this.jmsResourceFactory = jmsResourceFactory; + + // configure the service based on this wire format + + // currently maintaining the message processor structure which + // contains the details of jms message processing so set the message + // type here if not set explicitly in SCDL + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSTextXML){ + this.binding.setRequestMessageProcessorName(JMSBindingConstants.XML_MP_CLASSNAME); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSTextXML){ + this.binding.setResponseMessageProcessorName(JMSBindingConstants.XML_MP_CLASSNAME); + } + + // create a local interface contract that is configured specifically to + // deal with the data format that this wire format is expecting to sent to + // and receive from the databinding interceptor. The request/response parts of + // this interface contract will be copied into the binding interface contract + // as required + WebServiceBindingFactory wsFactory = registry.getExtensionPoint(WebServiceBindingFactory.class); + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + BindingWSDLGenerator.generateWSDL(component, service, wsBinding, registry, null); + interfaceContract = wsBinding.getBindingInterfaceContract(); + interfaceContract.getInterface().resetDataBinding(OMElement.class.getName()); + } + + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract){ + + if (this.interfaceContract != null) { + if (this.binding.getRequestWireFormat() instanceof WireFormatJMSTextXML){ + // set the request data transformation + interfaceContract.getInterface().resetInterfaceInputTypes(this.interfaceContract.getInterface()); + } + if (this.binding.getResponseWireFormat() instanceof WireFormatJMSTextXML){ + // set the response data transformation + interfaceContract.getInterface().resetInterfaceOutputTypes(this.interfaceContract.getInterface()); + } + } + + return interfaceContract; + } + + public Interceptor createInterceptor() { + return new WireFormatJMSTextXMLServiceInterceptor((JMSBinding)binding, + jmsResourceFactory, + service.getRuntimeWire(binding)); + } + + public String getPhase() { + return Phase.SERVICE_BINDING_WIREFORMAT; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..dec0991984 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.jms.provider.JMSBindingProviderFactory;model=org.apache.tuscany.sca.binding.jms.impl.JMSBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory new file mode 100644 index 0000000000..e98e85c0f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.runtime.OperationSelectorJMSDefaultProviderFactory;model=org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefault +org.apache.tuscany.sca.binding.jms.operationselector.jmsuserprop.runtime.OperationSelectorJMSUserPropProviderFactory;model=org.apache.tuscany.sca.binding.jms.operationselector.jmsuserprop.OperationSelectorJMSUserProp diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory new file mode 100644 index 0000000000..845c32a7d1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.runtime.WireFormatJMSDefaultProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault +org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.runtime.WireFormatJMSTextXMLProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML +org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.runtime.WireFormatJMSBytesProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes +org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.runtime.WireFormatJMSBytesXMLProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.WireFormatJMSBytesXML +org.apache.tuscany.sca.binding.jms.wireformat.jmstext.runtime.WireFormatJMSTextProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSText +org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.runtime.WireFormatJMSObjectProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldClientImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldClientImpl.java new file mode 100644 index 0000000000..fb80362457 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldClientImpl.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.sca.binding.jms; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service. + * + * @version $Rev$ $Date$ + */ +@Service(HelloWorldService.class) +public class HelloWorldClientImpl implements HelloWorldService { + + private HelloWorldService serviceA; + + @Reference + public void setServiceA(HelloWorldService service) { + this.serviceA = service; + } + + public String sayHello(String name) { + return serviceA.sayHello(name); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldService.java new file mode 100644 index 0000000000..515da3144a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldService.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.sca.binding.jms; + +import org.osoa.sca.annotations.Remotable; + +/** + * Interface for the HelloWorld Service. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface HelloWorldService { + String sayHello(String name); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldServiceImpl.java new file mode 100644 index 0000000000..a8808c1bd1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/HelloWorldServiceImpl.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.sca.binding.jms; + +/** + * Implementation of the HelloWorldService. + * + * @version $Rev$ $Date$ + */ +public class HelloWorldServiceImpl implements HelloWorldService { + + public String sayHello(String name) { + return "jmsHello " + name; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/OperationSelectionTestCaseFIXME.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/OperationSelectionTestCaseFIXME.java new file mode 100644 index 0000000000..efd64361dd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/java/org/apache/tuscany/sca/binding/jms/OperationSelectionTestCaseFIXME.java @@ -0,0 +1,237 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms; + +import java.util.ArrayList; +import java.util.List; + +import javax.jms.TextMessage; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.easymock.EasyMock; +import org.junit.Test; + +/** + * This unit test is used to ensure that a JMS Message delivered to a Component will select the correct operation based + * on the details in section 1.5 of the JMS Binding specification. + * + * @version $Rev$ $Date$ + */ +public class OperationSelectionTestCaseFIXME { + /** + * This test attempts to invoke a Service with a Single method where scaOperationName is not specified in the JMS + * Message + *

+ * Expected behaviour is that the single method will be invoked as scaOperationName is ignored + * + * @throws Exception Failed + */ + @Test + public void testServiceWithOnlyOneOperationScaOperationNameNotSpecified() throws Exception { + // Create the operation we should match + final Operation expectedOperation = newOperation("myOperation"); + + // Create the list of operations for the Service + final List operations = new ArrayList(); + operations.add(expectedOperation); + + // The name of the Operation in the JMS Message - not specified + final String scaOperationName = null; + + // Do the test + doTestJMSBinding(expectedOperation, operations, scaOperationName); + } + + /** + * This test attempts to invoke a Service with a Single method where scaOperationName in the JMS Message matches the + * method name on the Service + *

+ * Expected behaviour is that the single method will be invoked as scaOperationName is ignored + * + * @throws Exception Failed + */ + @Test + public void testServiceWithOnlyOneOperationScaOperationNameMatches() throws Exception { + // Create the operation we should match + final Operation expectedOperation = newOperation("myOperation"); + + // Create the list of operations for the Service + final List operations = new ArrayList(); + operations.add(expectedOperation); + + // The name of the Operation in the JMS Message - matches operation name + final String scaOperationName = expectedOperation.getName(); + + // Do the test + doTestJMSBinding(expectedOperation, operations, scaOperationName); + } + + /** + * This test attempts to invoke a Service with a Single method where scaOperationName in the JMS Message is + * different the method name on the Service + *

+ * Expected behaviour is that the single method will be invoked as scaOperationName is ignored + * + * @throws Exception Failed + */ + @Test + public void testServiceWithOnlyOneOperationScaOperationNameDifferent() throws Exception { + // Create the operation we should match + final Operation expectedOperation = newOperation("myOperation"); + + // Create the list of operations for the Service + final List operations = new ArrayList(); + operations.add(expectedOperation); + + // The name of the Operation in the JMS Message - different to operation name + final String scaOperationName = "Does Not Match Opeation Name"; + + // Do the test + doTestJMSBinding(expectedOperation, operations, scaOperationName); + } + + /** + * This test attempts to invoke a Service with a multiple operations where scaOperationName specified in the JMS + * Message matches an operation name + *

+ * Expected behaviour is that the named method will be invoked. + * + * @throws Exception Failed + */ + @Test + public void testServiceWithMultipleOperationsScaOperationNameSpecified() throws Exception { + // Create the list of operations for the Service + final List operations = new ArrayList(); + for (int i = 0; i < 5; i++) { + operations.add(newOperation("operation" + i)); + } + + // Now try and invoke each operation + for (Operation expectedOperation : operations) { + // The name of the Operation in the JMS Message + final String scaOperationName = expectedOperation.getName(); + + // Do the test + doTestJMSBinding(expectedOperation, operations, scaOperationName); + } + } + + /** + * This test attempts to invoke a Service with a multiple operations where scaOperationName specified in the JMS + * Message is not set so we invoke the onMessage() method + *

+ * Expected behaviour is that the onMessage() method should be used instead + * + * @throws Exception Failed + */ + @Test + public void testServiceWithMultipleOperationsScaOperationNotSpecified() throws Exception { + // Create the list of operations for the Service + final List operations = new ArrayList(); + for (int i = 0; i < 5; i++) { + operations.add(newOperation("operation" + i)); + } + + // Add the onMessage operation to the Service Contract + final Operation onMessageOperation = newOperation("onMessage"); + operations.add(onMessageOperation); + + // The name of the Operation in the JMS Message is not set so it will attempt + // to invoke the onMessage() method + final String scaOperationName = null; + + // Do the test + doTestJMSBinding(onMessageOperation, operations, scaOperationName); + } + + /** + * This is the test method that will attempt to unit test invoking a Service with the specified operations using a + * JMS Message with the specified scaOperationName to ensure that it invokes the expectedOperation + * + * @param expectedOperation The Operation we are expecting to be invoked over JMS + * @param operations The list of Operations supported by the Service + * @param scaOperationName The value to set scaOperationName in the JMS Message + * @throws Exception Failed + */ + private void doTestJMSBinding(Operation expectedOperation, List operations, String scaOperationName) + throws Exception { + // Create the test JMS Binding + final JMSBinding jmsBinding = new JMSBinding(); + JMSResourceFactory jmsResourceFactory = null; + + // Extra information for the method we are invoking + final String operationParams = "Hello"; + final Object operationReturnValue = "Operation Success"; + + // Mock up the Service. Basically, it is going to call: + // List opList = service.getInterfaceContract().getInterface().getOperations(); + final InterfaceContract ifaceContract = EasyMock.createStrictMock(InterfaceContract.class); + final RuntimeComponentService service = EasyMock.createStrictMock(RuntimeComponentService.class); + final Interface iface = EasyMock.createStrictMock(Interface.class); + EasyMock.expect(iface.getOperations()).andReturn(operations); + EasyMock.expect(ifaceContract.getInterface()).andReturn(iface); + EasyMock.expect(service.getInterfaceContract()).andReturn(ifaceContract); + + // Mock up getting and invoking the RuntimeWire. It is going to call: + // service.getRuntimeWire(jmsBinding).invoke(operation, (Object[])requestPayload); + final RuntimeWire runtimeWire = EasyMock.createStrictMock(RuntimeWire.class); + EasyMock.expect(service.getRuntimeWire(jmsBinding)).andReturn(runtimeWire); + EasyMock.expect(runtimeWire.invoke(expectedOperation, new Object[] {operationParams})) + .andReturn(operationReturnValue); + + // Create the JMS Binding Listener + // final DefaultJMSBindingListener bindingListener = new DefaultJMSBindingListener(jmsBinding, jmsResourceFactory, service, null); + + // Simulate a message + final TextMessage requestJMSMsg = EasyMock.createStrictMock(TextMessage.class); + EasyMock.expect(requestJMSMsg.getStringProperty("scaOperationName")).andReturn(scaOperationName); + EasyMock.expect(requestJMSMsg.getText()).andReturn(operationParams); + EasyMock.expect(requestJMSMsg.getJMSReplyTo()).andReturn(null); + + // Lets put all the mocks into replay mode + // EasyMock.replay(iface); + EasyMock.replay(ifaceContract); + EasyMock.replay(service); + EasyMock.replay(requestJMSMsg); + EasyMock.replay(runtimeWire); + + // Do the test + // bindingListener.onMessage(requestJMSMsg); + + // Verify our Mock objects + // EasyMock.verify(iface); + // EasyMock.verify(ifaceContract); + // EasyMock.verify(service); + // EasyMock.verify(requestJMSMsg); + // EasyMock.verify(runtimeWire); + } + + private static Operation newOperation(String name) { + Operation operation = new OperationImpl(); + operation.setName(name); + return operation; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/resources/simple/client.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/resources/simple/client.composite new file mode 100644 index 0000000000..dcea428493 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/resources/simple/client.composite @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/resources/simple/service.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/resources/simple/service.composite new file mode 100644 index 0000000000..44b7b29610 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms-runtime/src/test/resources/simple/service.composite @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/pom.xml new file mode 100644 index 0000000000..682f3e1bcb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/pom.xml @@ -0,0 +1,66 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-jms + Apache Tuscany SCA JMS Binding Model + + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + junit + junit + 4.5 + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.jms + ${pom.name} + org.apache.tuscany.sca.binding.jms* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/BindingProperty.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/BindingProperty.java new file mode 100644 index 0000000000..277cba43ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/BindingProperty.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.sca.binding.jms.impl; + +public class BindingProperty { + + private String name; + private String type; + private Object value; + + public BindingProperty(String name, String type, Object value) { + this.name = name; + this.type = type; + this.value = value; + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public Object getValue() { + return value; + } + + @Override + public boolean equals( Object object ) { + return ( object instanceof BindingProperty ) && equals( (BindingProperty) object ); + } + + /** + * Test whether this and another Binding Property are equal. + * @param property + * @return true if all fields of property match. + */ + public boolean equals( BindingProperty property ) { + if ( name == null && property.getName() != null ) + return false; + else if ( !name.equals( property.getName() )) + return false; + else if ( type == null && property.getType() != null ) + return false; + else if ( !type.equals( property.getType() )) + return false; + else if ( value == null && property.getValue() != null ) + return false; + else if ( !value.equals( property.getValue() )) + return false; + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java new file mode 100644 index 0000000000..4c9e2fff7e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java @@ -0,0 +1,970 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.BindingRRB; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.DefinitionElement; +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Models a binding to a JMS resource. + * + * @version $Rev$ $Date$ + */ + +public class JMSBinding implements BindingRRB, PolicySetAttachPoint, OperationsConfigurator, DefinitionElement { + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + // properties required to implement the Tuscany binding extension SPI + private String uri = null; + private String name = null; + private boolean unresolved = false; + private List extensions = new ArrayList(); + + // properties required by PolicySetAttachPoint + private List policySets = new ArrayList(); + private List applicablePolicySets = new ArrayList(); + + // properties required by IntentAttachPoint + private List requiredIntents = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + + // properties required to describe configured operations + private List configuredOperations = new ArrayList(); + + // properties required by DefinitionElement @575803A + private String targetNamespace; + + // Properties required to describe the JMS binding model + + private String correlationScheme = JMSBindingConstants.CORRELATE_MSG_ID; + private String initialContextFactoryName; + private String jndiURL; + + private String destinationName = null; + private String destinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; + private String destinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map destinationProperties = new HashMap(); + + private String connectionFactoryName = null; + private String connectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map connectionFactoryProperties = new HashMap(); + + private String activationSpecName = null; + private String activationSpecCreate = null; + private Map activationSpecProperties = new HashMap(); + + private String resourceAdapterName;; + private Map resourceAdapterProperties = new HashMap(); + + private String responseActivationSpecName = null; + private String responseActivationSpecCreate = null; + private Map responseActivationSpecProperties = new HashMap(); + + private String responseDestinationName = null; + private String responseDestinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; + private String responseDestinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map responseDestinationProperties = new HashMap(); + + private String responseConnectionFactoryName = null; + private String responseConnectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map responseConnectionFactoryProperties = new HashMap(); + + // Provides the name of the factory that interfaces to the JMS API for us. + private String jmsResourceFactoryName = JMSBindingConstants.DEFAULT_RF_CLASSNAME; + + // Message processors used to deal with the request and response messages + public String requestMessageProcessorName = JMSBindingConstants.DEFAULT_MP_CLASSNAME; + public String responseMessageProcessorName = JMSBindingConstants.DEFAULT_MP_CLASSNAME; + + // The JMS message property used to hold the name of the operation being called + private String operationSelectorPropertyName = JMSBindingConstants.DEFAULT_OPERATION_PROP_NAME; + + // If the operation selector is derived automatically from the service interface it's stored here + private String operationSelectorName = null; + + private boolean containsHeaders = false; + private String replyTo; + private String jmsType; + private String jmsCorrelationId; + private Boolean deliveryModePersistent; + private Long timeToLive; + private Integer jmsPriority; + + private Map properties = new HashMap(); + private Map> operationProperties = new HashMap>(); + private Map nativeOperationNames = new HashMap(); + private Map operationJMSTypes = new HashMap(); + private Map operationJMSCorrelationIds = new HashMap(); + private Map operationJMSDeliveryModes = new HashMap(); + private Map operationJMSTimeToLives = new HashMap(); + private Map operationJMSPriorities = new HashMap(); + private Map> operationPropertiesProperties = new HashMap>(); + + private String jmsSelector; + private QName requestConnectionName; + private QName responseConnectionName; + private QName operationPropertiesName; + private JMSBinding requestConnectionBinding; + private JMSBinding responseConnectionBinding; + private JMSBinding operationPropertiesBinding; + + private WireFormat requestWireFormat; + private WireFormat responseWireFormat; + private OperationSelector operationSelector; + + public JMSBinding() { + super(); + } + + // operations required by Binding + public String getURI() { + return this.uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isUnresolved() { + return this.unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public List getExtensions() { + return extensions; + } + + public WireFormat getRequestWireFormat() { + return requestWireFormat; + } + + public void setRequestWireFormat(WireFormat wireFormat) { + this.requestWireFormat = wireFormat; + } + + public WireFormat getResponseWireFormat() { + return responseWireFormat; + } + + public void setResponseWireFormat(WireFormat wireFormat) { + this.responseWireFormat = wireFormat; + } + + public OperationSelector getOperationSelector() { + return operationSelector; + } + + public void setOperationSelector(OperationSelector operationSelector) { + this.operationSelector = operationSelector; + } + + // Methods for getting/setting JMS binding model information + // as derived from the XML of the binding.jms element + + public void setCorrelationScheme(String correlationScheme) { + this.correlationScheme = correlationScheme; + } + + public String getCorrelationScheme() { + return correlationScheme; + } + + public String getInitialContextFactoryName() { + return initialContextFactoryName; + } + + public void setInitialContextFactoryName(String initialContextFactoryName) { + this.initialContextFactoryName = initialContextFactoryName; + } + + public String getJndiURL() { + return this.jndiURL; + } + + public void setJndiURL(String jndiURL) { + this.jndiURL = jndiURL; + } + + public String getDestinationName() { + if (requestConnectionBinding != null && requestConnectionBinding.getDestinationName() != null) { + return requestConnectionBinding.getDestinationName(); + } else { + return destinationName; + } + } + + public void setDestinationName(String destinationName) { + this.destinationName = destinationName; + } + + public String getDestinationType() { + if (requestConnectionBinding != null && requestConnectionBinding.getDestinationType() != null) { + return requestConnectionBinding.getDestinationType(); + } else { + return destinationType; + } + } + + public void setDestinationType(String destinationType) { + this.destinationType = destinationType; + } + + public String getDestinationCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getDestinationCreate() != null) { + return requestConnectionBinding.getDestinationCreate(); + } else { + return this.destinationCreate; + } + } + + public void setDestinationCreate(String create) { + this.destinationCreate = create; + } + + public String getConnectionFactoryName() { + if (requestConnectionBinding != null && requestConnectionBinding.getConnectionFactoryName() != null) { + return requestConnectionBinding.getConnectionFactoryName(); + } else { + return connectionFactoryName; + } + } + + public void setConnectionFactoryName(String connectionFactoryName) { + this.connectionFactoryName = connectionFactoryName; + } + + public String getConnectionFactoryCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getConnectionFactoryCreate() != null) { + return requestConnectionBinding.getConnectionFactoryCreate(); + } else { + return this.connectionFactoryCreate; + } + } + + public void setConnectionFactoryCreate(String create) { + this.connectionFactoryCreate = create; + } + + public String getResourceAdapterName() { + return resourceAdapterName; + } + + public void setResourceAdapterName(String name) { + resourceAdapterName = name; + } + + public String getActivationSpecName() { + if (requestConnectionBinding != null && requestConnectionBinding.getActivationSpecName() != null) { + return requestConnectionBinding.getActivationSpecName(); + } else { + return activationSpecName; + } + } + + public void setActivationSpecName(String activationSpecName) { + this.activationSpecName = activationSpecName; + } + + public String getActivationSpecCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getActivationSpecCreate() != null) { + return requestConnectionBinding.getActivationSpecCreate(); + } else { + return this.activationSpecCreate; + } + } + + public void setActivationSpecCreate(String create) { + this.activationSpecCreate = create; + } + + public String getResponseDestinationName() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseDestinationName() != null) { + return requestConnectionBinding.getResponseDestinationName(); + } else { + return this.responseDestinationName; + } + } + + public void setResponseDestinationName(String name) { + this.responseDestinationName = name; + } + + public String getResponseDestinationType() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseDestinationType() != null) { + return requestConnectionBinding.getResponseDestinationType(); + } else { + return this.responseDestinationType; + } + } + + public void setResponseDestinationType(String type) { + this.responseDestinationType = type; + } + + public String getResponseDestinationCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseDestinationCreate() != null) { + return requestConnectionBinding.getResponseDestinationCreate(); + } else { + return this.responseDestinationCreate; + } + } + + public void setResponseDestinationCreate(String create) { + this.responseDestinationCreate = create; + } + + public String getResponseConnectionFactoryName() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseConnectionFactoryName() != null) { + return requestConnectionBinding.getResponseConnectionFactoryName(); + } else { + return responseConnectionFactoryName; + } + } + + public void setResponseConnectionFactoryName(String connectionFactoryName) { + this.responseConnectionFactoryName = connectionFactoryName; + } + + public String getResponseConnectionFactoryCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseConnectionFactoryCreate() != null) { + return requestConnectionBinding.getResponseConnectionFactoryCreate(); + } else { + return this.responseConnectionFactoryCreate; + } + } + + public void setResponseConnectionFactoryCreate(String create) { + this.responseConnectionFactoryCreate = create; + } + + public String getResponseActivationSpecName() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseActivationSpecName() != null) { + return requestConnectionBinding.getResponseActivationSpecName(); + } else { + return responseActivationSpecName; + } + } + + public void setResponseActivationSpecName(String activationSpecName) { + this.responseActivationSpecName = activationSpecName; + } + + public String getResponseActivationSpecCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseActivationSpecCreate() != null) { + return requestConnectionBinding.getResponseActivationSpecCreate(); + } else { + return this.responseActivationSpecCreate; + } + } + + public void setResponseActivationSpecCreate(String create) { + this.responseActivationSpecCreate = create; + } + + public String getJmsResourceFactoryName() { + return jmsResourceFactoryName; + } + + public void setJmsResourceFactoryName(String jmsResourceFactoryName) { + this.jmsResourceFactoryName = jmsResourceFactoryName; + } + + public void setRequestMessageProcessorName(String name) { + this.requestMessageProcessorName = name; + } + + public String getRequestMessageProcessorName() { + return requestMessageProcessorName; + } + + public void setResponseMessageProcessorName(String name) { + this.responseMessageProcessorName = name; + } + + public String getResponseMessageProcessorName() { + return responseMessageProcessorName; + } + + public String getOperationSelectorPropertyName() { + return operationSelectorPropertyName; + } + + public void setOperationSelectorPropertyName(String operationSelectorPropertyName) { + this.operationSelectorPropertyName = operationSelectorPropertyName; + } + + public String getOperationSelectorName() { + return operationSelectorName; + } + + public void setOperationSelectorName(String operationSelectorName) { + this.operationSelectorName = operationSelectorName; + } + + public void setHeaders( boolean containsHeaders ) { + this.containsHeaders = containsHeaders; + } + + public boolean containsHeaders() { + return this.containsHeaders; + } + + public String getReplyTo() { + return replyTo; + } + + public void setReplyTo(String replyTo) { + this.replyTo = replyTo; + } + + public String getJMSType() { + return jmsType; + } + public void setJMSType(String jmsType) { + setHeaders( true ); + this.jmsType = jmsType; + } + + public String getJMSCorrelationId() { + return jmsCorrelationId; + } + + public void setJMSCorrelationId(String jmsCorrelationId) { + setHeaders( true ); + this.jmsCorrelationId = jmsCorrelationId; + } + + public Boolean isdeliveryModePersistent() { + return deliveryModePersistent; + } + public void setJMSDeliveryMode(boolean persistent) { + setHeaders( true ); + this.deliveryModePersistent = Boolean.valueOf(persistent); + } + + public Integer getJMSPriority() { + return jmsPriority; + } + + public void setJMSPriority(int jmsPriority) { + setHeaders( true ); + this.jmsPriority = Integer.valueOf(jmsPriority); + } + + public Long getJMSTimeToLive() { + return timeToLive; + } + + public void setJMSTimeToLive(long timeToLive) { + setHeaders( true ); + this.timeToLive = Long.valueOf(timeToLive); + } + + public Set getPropertyNames() { + return properties.keySet(); + } + + public Object getProperty(String name) { + return properties.get(name); + } + + public void setProperty(String name, Object value) { + properties.put(name, value); + } + + protected Map getProperties() { + return properties; + } + + /** + * Adds an operationName to this binding. + * @param opName + */ + public void addOperationName(String opName) { + Map props = operationProperties.get(opName); + if (props == null) { + props = new HashMap(); + operationProperties.put(opName, props); + } + } + + /** + * Provides set of operation names in this binding. + * @return a Set of operation names + */ + public Set getOperationNames() { + if (operationPropertiesBinding != null) { + return operationPropertiesBinding.getOperationNames(); + } else { + // Make a defensive copy since key changes affect map, map changes affect keys. + Set opNames = operationProperties.keySet(); + Set opNamesCopy = new TreeSet( opNames ); + return opNamesCopy; + } + } + + public Map getOperationProperties(String opName) { + if (operationPropertiesBinding != null) { + return operationPropertiesBinding.getOperationProperties(opName); + } else { + return operationProperties.get(opName); + } + } + + public void setOperationProperty(String opName, String propName, Object value) { + Map props = operationProperties.get(opName); + if (props == null) { + props = new HashMap(); + operationProperties.put(opName, props); + } + props.put(propName, value); + } + + /** + * Provides the value of a property for a given operation + * @param opName is the name of the operation in this binding. + * @param propName is the key name for the property + * @return Object representing the property value for this property name. Returns + * null for non existant operation name or property name. + */ + public Object getOperationProperty(String opName, String propName ) { + if (operationPropertiesBinding != null) { + return operationPropertiesBinding.getOperationProperty(opName, propName); + } else { + Map props = operationProperties.get(opName); + if (props == null) { + return null; + } + return props.get(propName); + } + } + + public boolean hasNativeOperationName(String opName) { + if (operationPropertiesBinding != null) { + return operationPropertiesBinding.hasNativeOperationName(opName); + } else { + return nativeOperationNames.containsKey(opName); + } + } + + public String getNativeOperationName(String opName) { + if (operationPropertiesBinding != null && operationPropertiesBinding.getNativeOperationName(opName) != null) { + return operationPropertiesBinding.getNativeOperationName(opName); + } else { + if (nativeOperationNames.containsKey(opName)) { + return nativeOperationNames.get(opName); + } else { + return opName; + } + } + } + + public void setNativeOperationName(String opName, String nativeOpName) { + this.nativeOperationNames .put(opName, nativeOpName); + } + + public String getOperationJMSType(String opName) { + if (operationPropertiesBinding != null && operationPropertiesBinding.getOperationJMSType(opName) != null) { + return operationPropertiesBinding.getOperationJMSType(opName); + } else { + if (operationJMSTypes.containsKey(opName)) { + return operationJMSTypes.get(opName); + } else { + return jmsType; + } + } + } + public void setOperationJMSType(String opName, String jmsType) { + this.operationJMSTypes.put(opName, jmsType); + } + + public String getOperationJMSCorrelationId(String opName) { + if (operationPropertiesBinding != null) { + if (operationPropertiesBinding.getOperationJMSCorrelationId(opName) != null) { + return operationPropertiesBinding.getOperationJMSCorrelationId(opName); + } else { + return jmsCorrelationId; + } + } else { + if (operationJMSCorrelationIds.containsKey(opName)) { + return operationJMSCorrelationIds.get(opName); + } else { + return jmsCorrelationId; + } + } + } + public void setOperationJMSCorrelationId(String opName, String jmsCorrelationId) { + operationJMSCorrelationIds.put(opName, jmsCorrelationId); + } + + public Boolean getOperationJMSDeliveryMode(String opName) { + if (operationPropertiesBinding != null) { + if (operationPropertiesBinding.getOperationJMSDeliveryMode(opName) != null) { + return operationPropertiesBinding.getOperationJMSDeliveryMode(opName); + } else { + return deliveryModePersistent; + } + } else { + if (operationJMSDeliveryModes.containsKey(opName)) { + return operationJMSDeliveryModes.get(opName); + } else { + return deliveryModePersistent; + } + } + } + public void setOperationJMSDeliveryMode(String opName, boolean b) { + operationJMSDeliveryModes.put(opName, b); + } + + public Long getOperationJMSTimeToLive(String opName) { + if (operationPropertiesBinding != null) { + if (operationPropertiesBinding.getOperationJMSTimeToLive(opName) != null) { + return operationPropertiesBinding.getOperationJMSTimeToLive(opName); + } else { + return timeToLive; + } + } else { + if (operationJMSTimeToLives.containsKey(opName)) { + return operationJMSTimeToLives.get(opName); + } else { + return timeToLive; + } + } + } + public void setOperationJMSTimeToLive(String opName, Long ttl) { + operationJMSTimeToLives.put(opName, ttl); + } + + public Integer getOperationJMSPriority(String opName) { + if (operationPropertiesBinding != null) { + if (operationPropertiesBinding.getOperationJMSPriority(opName) != null) { + return operationPropertiesBinding.getOperationJMSPriority(opName); + } else { + return jmsPriority; + } + } else { + if (operationJMSPriorities.containsKey(opName)) { + return operationJMSPriorities.get(opName); + } else { + return jmsPriority; + } + } + } + public void setOperationJMSPriority(String opName, int p) { + operationJMSPriorities.put(opName, p); + } + + public String getJMSSelector() { + return jmsSelector; + } + public void setJMSSelector(String jmsSelector) { + this.jmsSelector = jmsSelector; + } + + public QName getRequestConnectionName() { + return requestConnectionName; + } + + public void setRequestConnectionName(QName requestConnectionName) { + this.requestConnectionName = requestConnectionName; + } + + public void setResponseConnectionName(QName responseConnectionName) { + this.responseConnectionName = responseConnectionName; + } + + public QName getResponseConnectionName() { + return responseConnectionName; + } + + public void setRequestConnectionBinding(JMSBinding binding) { + this.requestConnectionBinding = binding; + } + public JMSBinding getRequestConnectionBinding() { + return requestConnectionBinding; + } + + public void setResponseConnectionBinding(JMSBinding binding) { + this.responseConnectionBinding = binding; + } + public JMSBinding getResponseConnectionBinding() { + return responseConnectionBinding; + } + + public void setOperationPropertiesName(QName nameValue) { + this.operationPropertiesName = nameValue; + } + public QName getOperationPropertiesName() { + return operationPropertiesName; + } + + public void setOperationPropertiesBinding(JMSBinding binding) { + this.operationPropertiesBinding = binding; + } + public JMSBinding getOperationPropertiesBinding() { + return operationPropertiesBinding; + } + + // operations required by PolicySetAttachPoint + public List getPolicySets() { + return policySets; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + // operations required by IntentAttachPoint + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + public Map getDestinationProperties() { + return destinationProperties; + } + + public Map getConnectionFactoryProperties() { + return connectionFactoryProperties; + } + + public Map getResourceAdapterProperties() { + return resourceAdapterProperties; + } + + public Map getActivationSpecProperties() { + return activationSpecProperties; + } + + public Map getResponseActivationSpecProperties() { + return responseActivationSpecProperties; + } + + public Map getResponseDestinationProperties() { + return responseDestinationProperties; + } + + public Map getResponseConnectionFactoryProperties() { + return responseConnectionFactoryProperties; + } + + public Map getOperationPropertiesProperties(String opName) { + if (operationPropertiesProperties.get(opName)==null) { + operationPropertiesProperties.put(opName, new HashMap()); + } + return operationPropertiesProperties.get(opName); + } + + public List getConfiguredOperations() { + return configuredOperations; + } + + public void setConfiguredOperations(List configuredOperations) { + this.configuredOperations = configuredOperations; + } + + public String getTargetNamespace() { + return targetNamespace; + } + + public void setTargetNamespace(String ns) { + targetNamespace = ns; + } + + // hashCode() is here because binding elements in definitions documents are added + // to the model resolver hashmap. The namespace and name are keys. + @Override + public int hashCode() { + return (String.valueOf(getTargetNamespace()) + String.valueOf(getName())).hashCode(); + } + + @Override + public boolean equals( Object object ) { + return ( object instanceof JMSBinding ) && equals( (JMSBinding) object ); + } + + /** + * Compares two JMS bindings for equality. + * Because of the many fields, this comparison is rather large O(n). + * @param binding test binding for equality comparison + * @return boolean stating whether objects are equal + */ + public boolean equals( JMSBinding binding ) { + // If the target namespace is set, this binding came from a definitions document. + // The target namespace and name are used as keys for doing model resolver hashmap lookups. + // Only the target namespace and name can be compared. + if (this.targetNamespace != null) { + if ( !optStringEquals( this.targetNamespace, binding.getTargetNamespace() )) return false; + if ( !optStringEquals( this.name, binding.getName() )) return false; + return true; + } + + // Test all fields for equality. + // First test simple fields to quickly weed out mismatches. + if ( !optStringEquals( this.uri, binding.getURI() )) return false; + if ( !optStringEquals( this.name, binding.getName() )) return false; + if ( !optStringEquals( this.targetNamespace, binding.getTargetNamespace() )) return false; + if ( !optStringEquals( this.destinationName, binding.getDestinationName() )) return false; + if ( !optStringEquals( this.correlationScheme, binding.getCorrelationScheme() )) return false; + if ( !optStringEquals( this.initialContextFactoryName, binding.getInitialContextFactoryName() )) return false; + if ( !optStringEquals( this.jndiURL, binding.getJndiURL() )) return false; + if ( !optStringEquals( this.requestConnectionName, binding.getRequestConnectionName() )) return false; + if ( !optStringEquals( this.responseConnectionName, binding.getResponseConnectionName() )) return false; + if ( !optStringEquals( this.jmsSelector, binding.getJMSSelector() )) return false; + if ( !equals( properties, binding.getProperties()) ) + return false; + + // Test operation properties + Set operationNamesA = this.getOperationNames(); + Set operationNamesB = binding.getOperationNames(); + if ( operationNamesA != null && operationNamesB != null ) { + if ( operationNamesA == null && operationNamesB != null ) return false; + if ( operationNamesA != null && operationNamesB == null ) return false; + if ( operationNamesA.size() != operationNamesB.size() ) return false; + for(Iterator it=operationNamesA.iterator(); it.hasNext(); ) { + String opName = it.next(); + if ( !operationNamesB.contains( opName )) { + return false; + } + } + } + + // Destination properties + if ( !optStringEquals( this.getDestinationName(), binding.getDestinationName() )) return false; + if ( !optStringEquals( this.getDestinationType(), binding.getDestinationType() )) return false; + + // Connection factory properties + if ( !optStringEquals( this.getConnectionFactoryName(), binding.getConnectionFactoryName() )) return false; + + // Activation spec properties + if ( !optStringEquals( this.getActivationSpecName(), binding.getActivationSpecName() )) return false; + + // Response properties + if ( !optStringEquals( this.getResponseDestinationName(), binding.getResponseDestinationName() )) return false; + if ( !optStringEquals( this.getResponseActivationSpecName(), binding.getResponseActivationSpecName() )) return false; + if ( !optStringEquals( this.getResponseConnectionFactoryName(), binding.getResponseConnectionFactoryName() )) return false; + + // Resource adapter + if ( !optStringEquals( this.getResourceAdapterName(), binding.getResourceAdapterName() )) return false; + + // Configured operations + if ( this.configuredOperations.size() != binding.getConfiguredOperations().size() ) return false; + + // wire format + if ( this.getRequestWireFormat().getClass() != binding.getRequestWireFormat().getClass()) return false; + if ( this.getResponseWireFormat().getClass() != binding.getResponseWireFormat().getClass()) return false; + + // operation selector + if ( this.getOperationSelector().getClass() != binding.getOperationSelector().getClass()) return false; + + + // Other fields could also be checked for equality. See class fields for details. + return true; + } + + /** + * Tests if Strings are equal. + * Either one may be null. This will match true if both + * are null or both are non-null and equal. + * @param p1 property list 1 + * @param p2 property list 2 + * @return whether or not properties are equal + */ + public static boolean optStringEquals( Object s1, Object s2 ) { + if ( s1 == null && s2 == null ) return true; + if ( s1 != null && s2 == null ) return false; + if ( s1 == null && s2 != null ) return false; + return s1.equals( s2 ); + } + + /** + * Tests if two property lists are equal. + * Either one may be null. This will match true if both + * are null or both are non-null and equal. + * @param p1 property list 1 + * @param p2 property list 2 + * @return whether or not properties are equal + */ + public static boolean equals( Map p1, Map p2 ) { + if ( p1 == null && p2 == null) + return true; + if ( p1 == null || p2 == null) + return false; + if ( p1.size() != p2.size()) + return false; + + // For both the keys and values of a map + for (Iterator it=p1.entrySet().iterator(); it.hasNext(); ) { + Map.Entry entry = (Map.Entry)it.next(); + Object k1 = entry.getKey(); + Object v1 = entry.getValue(); + Object v2 = p2.get( k1 ); + + if ( v1 == null && v2 != null ) + return false; + if ( v1 != null && v2 == null ) + return false; + if ( !v1.equals( v2 )) + return false; + } + + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java new file mode 100644 index 0000000000..83c213997f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.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.sca.binding.jms.impl; + +import java.util.Arrays; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Constants for the JMS binding. + * + * @version $Rev$ $Date$ + */ +public interface JMSBindingConstants { + + // Constants used when describing the JMS binding + // model and for setting up defaults + String BINDING_JMS = "binding.jms"; + QName BINDING_JMS_QNAME = new QName(Constants.SCA10_NS, BINDING_JMS); + String CORRELATE_MSG_ID = "requestmsgidtocorrelid"; + String CORRELATE_CORRELATION_ID = "requestcorrelidtocorrelid"; + String CORRELATE_NONE = "none"; + List VALID_CORRELATION_SCHEMES = + Arrays.asList(new String[] {CORRELATE_MSG_ID, CORRELATE_CORRELATION_ID, CORRELATE_NONE}); + String DESTINATION_TYPE_QUEUE = "queue"; // 0 + String DESTINATION_TYPE_TOPIC = "topic"; // 1 + List VALID_DESTINATION_TYPES = + Arrays.asList(new String[] {DESTINATION_TYPE_QUEUE, DESTINATION_TYPE_TOPIC}); + String CREATE_ALWAYS = "always"; + String CREATE_NEVER = "never"; + String CREATE_IF_NOT_EXIST = "ifnotexist"; + String DEFAULT_CONTEXT_FACTORY_NAME = "org.apache.activemq.jndi.ActiveMQInitialContextFactory"; + String DEFAULT_JNDI_URL = "tcp://localhost:61616"; + int DEFAULT_TIME_TO_LIVE = 20000; // in milliseconds + int DEFAULT_PRIORITY = 1; + int NON_PERSISTENT = 1; // Maps to javax.jms.DeliveryMode + String DEFAULT_RF_CLASSNAME = "org.apache.tuscany.sca.host.jms.activemq.JMSResourceFactoryImpl"; + String XML_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.XMLTextMessageProcessor"; + String TEXT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.TextMessageProcessor"; + String OBJECT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor"; + String BYTES_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.BytesMessageProcessor"; + String XML_BYTES_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.XMLBytesMessageProcessor"; + String DEFAULT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.DefaultMessageProcessor"; + String DEFAULT_OPERATION_PROP_NAME = "scaOperationName"; + + String FAULT_PROPERTY = "org_apache_tuscany_sca_fault"; + + String CALLBACK_ID_PROPERTY = "CallbackID"; + String CALLBACK_Q_PROPERTY = "scaCallbackQueue"; + String CONVERSATION_ID_PROPERTY = "scaConversationId"; + + // XML element and attribute names + String HEADERS = "headers"; + + int MSG_CTXT_POSITION = 0; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingException.java new file mode 100644 index 0000000000..0928e02082 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingException.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.sca.binding.jms.impl; + +/** + * Base exception for the JMSBinding. + * + * @version $Rev$ $Date$ + */ +public class JMSBindingException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public JMSBindingException() { + super(); + } + + public JMSBindingException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + + public JMSBindingException(String arg0) { + super(arg0); + } + + public JMSBindingException(Throwable arg0) { + super(arg0); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java new file mode 100644 index 0000000000..49875d84d0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java @@ -0,0 +1,1560 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.impl; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.xml.ConfiguredOperationProcessor; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; +import org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefault; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSText; +import org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * A processor to read the XML that describes the JMS binding... + * + * + * + * + * * + * ? + * + * + * * + * ? + * + * + * * + * ? + * + * + * * + * ? + * + * + * + * * + * ? + * + * + * * + * ? + * + * + * * + * ? + * + * ? + * ? + * + * + * + * + * + * ? + * * + * ? + * + * + * * + * + * * + * ? + * * + * + * ? + * + * + * Parsing error messages are recorded locally and reported as validation exceptions. Parsing + * warnings do not cause validation exceptions. + * + * @version $Rev$ $Date$ + */ + +public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + private PolicyFactory policyFactory; + private PolicyAttachPointProcessor policyProcessor; + private ConfiguredOperationProcessor configuredOperationProcessor; + protected StAXArtifactProcessor extensionProcessor; + private Monitor monitor; + + private ModelFactoryExtensionPoint modelFactories; // DOB + public JMSBindingProcessor(ModelFactoryExtensionPoint modelFactories, StAXArtifactProcessor extensionProcessor, Monitor monitor) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.configuredOperationProcessor = + new ConfiguredOperationProcessor(modelFactories, this.monitor); + this.extensionProcessor = extensionProcessor; + this.monitor = monitor; + this.modelFactories = modelFactories; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void warning(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "binding-jms-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report an error. + * One side effect is that error messages are saved for future validation calls. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "binding-jms-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return JMSBindingConstants.BINDING_JMS_QNAME; + } + + public Class getModelType() { + return JMSBinding.class; + } + + public JMSBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + JMSBinding jmsBinding = new JMSBinding(); + // Reset validation message to keep track of validation issues. + + // Read policies + policyProcessor.readPolicies(jmsBinding, reader); + + // Read binding name + String name = reader.getAttributeValue(null, "name"); + if (name != null) { + jmsBinding.setName(name); + } + + // Read binding URI + String uri = reader.getAttributeValue(null, "uri"); + if (uri != null && uri.length() > 0) { + parseURI(uri, jmsBinding); + } + + // Read correlation scheme + String correlationScheme = reader.getAttributeValue(null, "correlationScheme"); + if (correlationScheme != null && correlationScheme.length() > 0) { + if (JMSBindingConstants.VALID_CORRELATION_SCHEMES.contains(correlationScheme.toLowerCase())) { + jmsBinding.setCorrelationScheme(correlationScheme); + } else { + error("InvalidCorrelationScheme", reader, correlationScheme); + } + } + + // Read initial context factory + String initialContextFactory = reader.getAttributeValue(null, "initialContextFactory"); + if (initialContextFactory != null && initialContextFactory.length() > 0) { + jmsBinding.setInitialContextFactoryName(initialContextFactory); + } + + // Read JNDI URL + String jndiURL = reader.getAttributeValue(null, "jndiURL"); + if (jndiURL != null && jndiURL.length() > 0) { + jmsBinding.setJndiURL(jndiURL); + } + + // Read message processor class name + // TODO - maintain this for the time being but move over to + // configuring wire formats instead of message processors + String messageProcessorName = reader.getAttributeValue(null, "messageProcessor"); + if (messageProcessorName != null && messageProcessorName.length() > 0) { + if ("XMLTextMessage".equalsIgnoreCase(messageProcessorName)) { + // may be overwritten be real wire format later + jmsBinding.setRequestWireFormat(new WireFormatJMSTextXML()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); + } else if ("TextMessage".equalsIgnoreCase(messageProcessorName)) { + // may be overwritten be real wire format later + jmsBinding.setRequestWireFormat(new WireFormatJMSText()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); + } else if ("ObjectMessage".equalsIgnoreCase(messageProcessorName)) { + // may be overwritten be real wire format later + jmsBinding.setRequestWireFormat(new WireFormatJMSObject()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); + } else { + jmsBinding.setRequestMessageProcessorName(messageProcessorName); + jmsBinding.setResponseMessageProcessorName(messageProcessorName); + // exploit the text wire format code to drive the user selected + // message processor + jmsBinding.setRequestWireFormat(new WireFormatJMSText()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); + } + } + + String requestConnectionName = reader.getAttributeValue(null, "requestConnection"); + if (requestConnectionName != null && requestConnectionName.length() > 0) { + jmsBinding.setRequestConnectionName(getQNameValue(reader, requestConnectionName)); + } + String responseConnectionName = reader.getAttributeValue(null, "responseConnection"); + if (responseConnectionName != null && responseConnectionName.length() > 0) { + jmsBinding.setResponseConnectionName(getQNameValue(reader, responseConnectionName)); + } + + String operationPropertiesName = reader.getAttributeValue(null, "operationProperties"); + if (operationPropertiesName != null && operationPropertiesName.length() > 0) { + jmsBinding.setOperationPropertiesName(getQNameValue(reader, operationPropertiesName)); + } + + // Read sub-elements of binding.jms + boolean endFound = false; + while (!endFound) { + int fg = reader.next(); + switch (fg) { + case START_ELEMENT: + String elementName = reader.getName().getLocalPart(); + if ("destination".equals(elementName)) { + parseDestination(reader, jmsBinding); + } else if ("connectionFactory".equals(elementName)) { + parseConnectionFactory(reader, jmsBinding); + } else if ("activationSpec".equals(elementName)) { + parseActivationSpec(reader, jmsBinding); + } else if ("response".equals(elementName)) { + parseResponse(reader, jmsBinding); + } else if ("resourceAdapter".equals(elementName)) { + parseResourceAdapter(reader, jmsBinding); + } else if ("headers".equals(elementName)) { + parseHeaders(reader, jmsBinding); + } else if ("operationProperties".equals(elementName)) { + parseOperationProperties(reader, jmsBinding); + } else if ("SubscriptionHeaders".equals(elementName)) { + parseSubscriptionHeaders(reader, jmsBinding); + } else if (Constants.OPERATION_QNAME.equals(reader.getName())) { + ConfiguredOperation confOp = configuredOperationProcessor.read(reader); + if (confOp != null) { + ((OperationsConfigurator)jmsBinding).getConfiguredOperations().add(confOp); + } + } else { + Object extension = extensionProcessor.read(reader); + if (extension != null) { + if (extension instanceof WireFormat) { + if (jmsBinding.getRequestWireFormat() == null) { + jmsBinding.setRequestWireFormat((WireFormat) extension); + } else { + throw new ContributionReadException("The request wireformat has already been defined. " + "Only one request wire format can be specified."); + } + } else if (extension instanceof OperationSelector) { + if (jmsBinding.getOperationSelector() == null) { + jmsBinding.setOperationSelector((OperationSelector) extension); + } else { + throw new ContributionReadException("More than one operation selector has been specified. " + "Only one operation selector can be specified."); + } + + } else { + error("UnexpectedElement", reader, extension.toString()); + } + } + } + //reader.next(); + break; + case END_ELEMENT: + QName x = reader.getName(); + if (Constants.OPERATION.equals(x.getLocalPart())) break; + // This assumption is not captured in schema, which isn't good, but will probably be fine for now. + // A better solution might be to require each processor to advance to its own END_ELEMENT. + if (x.getLocalPart().startsWith("wireFormat.") || x.getLocalPart().startsWith("operationSelector.")) { + break; + } + if (x.equals(JMSBindingConstants.BINDING_JMS_QNAME)) { + endFound = true; + } else { + error("UnexpectedElement: expected " + JMSBindingConstants.BINDING_JMS_QNAME + ", found " + x.toString(), + reader, x.toString()); + } + } + } + + // if no operation selector is specified then assume the default + if (jmsBinding.getOperationSelector() == null){ + jmsBinding.setOperationSelector(new OperationSelectorJMSDefault()); + } + + // if no request wire format specified then assume the default + if (jmsBinding.getRequestWireFormat() == null){ + jmsBinding.setRequestWireFormat(new WireFormatJMSDefault()); + } + + // if no response wire format specific then assume the same as the request + if (jmsBinding.getResponseWireFormat() == null){ + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); + } + + validate( jmsBinding ); + + return jmsBinding; + } + + protected void parseURI(String uri, JMSBinding jmsBinding) { + if (!uri.startsWith("jms:")) { + error("MustStartWithSchema", jmsBinding, uri); + return; + } + int i = uri.indexOf('?'); + if (i >= 0) { + StringTokenizer st = new StringTokenizer(uri.substring(i+1),"&"); + while (st.hasMoreTokens()) { + String s = st.nextToken(); + if (s.startsWith("connectionFactoryName=")) { + jmsBinding.setConnectionFactoryName(s.substring(22)); + } else { + error("UnknownTokenInURI", jmsBinding, s, uri); + return; + } + } + jmsBinding.setDestinationName(uri.substring(4, i)); + } else { + jmsBinding.setDestinationName(uri.substring(4)); + } + } + + public void resolve(JMSBinding model, ModelResolver resolver) throws ContributionResolveException { + if (model.getRequestConnectionName() != null) { + model.setRequestConnectionBinding(getConnectionBinding(model, "requestConnection", model.getRequestConnectionName(), resolver)); + } + if (model.getResponseConnectionName() != null) { + model.setResponseConnectionBinding(getConnectionBinding(model, "responseConnection", model.getResponseConnectionName(), resolver)); + } + if (model.getOperationPropertiesName() != null) { + model.setOperationPropertiesBinding(getConnectionBinding(model, "operationProperties", model.getOperationPropertiesName(), resolver)); + } + } + + @SuppressWarnings("unchecked") + private JMSBinding getConnectionBinding(JMSBinding model, String attrName, QName bindingName, ModelResolver resolver) { + JMSBinding binding = new JMSBinding(); + binding.setTargetNamespace(bindingName.getNamespaceURI()); + binding.setName(bindingName.getLocalPart()); + binding.setUnresolved(true); + binding = resolver.resolveModel(JMSBinding.class, binding); + if (binding.isUnresolved()) + error("BindingNotFound", model, attrName, bindingName); + return binding; + } + + private void parseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setDestinationName(name); + } + + String type = reader.getAttributeValue(null, "type"); + if (type != null && type.length() > 0) { + warning("DoesntProcessDestinationType", jmsBinding); + if (JMSBindingConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(type)) { + jmsBinding.setDestinationType(JMSBindingConstants.DESTINATION_TYPE_QUEUE); + } else if (JMSBindingConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(type)) { + jmsBinding.setDestinationType(JMSBindingConstants.DESTINATION_TYPE_TOPIC); + } else { + error("InvalidDestinationType", reader, type); + } + } + + String create = reader.getAttributeValue(null, "create"); + if (create != null && create.length() > 0) { + jmsBinding.setDestinationCreate(create); + } + + jmsBinding.getDestinationProperties().putAll(parseBindingProperties(reader)); + } + + private void parseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setConnectionFactoryName(name); + } else { + error("MissingConnectionFactoryName", reader); + } + jmsBinding.getConnectionFactoryProperties().putAll(parseBindingProperties(reader)); + } + + private void parseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setActivationSpecName(name); + } else { + warning("MissingActivationSpecName", reader); + } + jmsBinding.getActivationSpecProperties().putAll(parseBindingProperties(reader)); + } + + private void parseResponseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setResponseDestinationName(name); + } + + String type = reader.getAttributeValue(null, "type"); + if (type != null && type.length() > 0) { + warning("DoesntProcessResponseDestinationType", jmsBinding); + if (JMSBindingConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(type)) { + jmsBinding.setResponseDestinationType(JMSBindingConstants.DESTINATION_TYPE_QUEUE); + } else if (JMSBindingConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(type)) { + jmsBinding.setResponseDestinationType(JMSBindingConstants.DESTINATION_TYPE_TOPIC); + } else { + error("InvalidResponseDestinationType", reader, type); + } + } + + String create = reader.getAttributeValue(null, "create"); + if (create != null && create.length() > 0) { + jmsBinding.setResponseDestinationCreate(create); + } + + jmsBinding.getResponseDestinationProperties().putAll(parseBindingProperties(reader)); + } + + private void parseResponseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setResponseConnectionFactoryName(name); + } else { + warning("MissingResponseConnectionFactory", reader); + } + jmsBinding.getResponseConnectionFactoryProperties().putAll(parseBindingProperties(reader)); + } + + private void parseResponseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setResponseActivationSpecName(name); + } else { + warning("MissingResponseActivationSpec", reader); + } + jmsBinding.getResponseActivationSpecProperties().putAll(parseBindingProperties(reader)); + } + + private void parseResponse(XMLStreamReader reader, JMSBinding jmsBinding) throws ContributionReadException, XMLStreamException { + // Read sub-elements of response + while (true) { + switch (reader.next()) { + case START_ELEMENT: + String elementName = reader.getName().getLocalPart(); + if ("destination".equals(elementName)) { + parseResponseDestination(reader, jmsBinding); + } else if ("connectionFactory".equals(elementName)) { + parseResponseConnectionFactory(reader, jmsBinding); + } else if ("activationSpec".equals(elementName)) { + parseResponseActivationSpec(reader, jmsBinding); + } else { + Object extension = extensionProcessor.read(reader); + if (extension != null) { + if (extension instanceof WireFormat) { + if (jmsBinding.getResponseWireFormat() == null) { + jmsBinding.setResponseWireFormat((WireFormat)extension); + } else { + throw new ContributionReadException("The response wireformat has already been defined. " + "Only one response wire format can be specified."); + } + } else { + error("UnexpectedElement", reader, extension.toString()); + } + } + reader.next(); + } + //reader.next(); + break; + case END_ELEMENT: + QName x = reader.getName(); + if (x.getLocalPart().equals("response")) { + return; + } else { + error("UnexpectedResponseElement", reader, x.toString()); + } + } + } + } + + private void parseResourceAdapter(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setResourceAdapterName(name); + } else { + error("MissingResourceAdapterName", reader); + } + jmsBinding.getResourceAdapterProperties().putAll(parseBindingProperties(reader)); + } + + /** + * + * * + * ? + */ + private void parseHeaders(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String jmsType = reader.getAttributeValue(null, "JMSType"); + if (jmsType != null && jmsType.length() > 0) { + jmsBinding.setJMSType(jmsType); + } + + String jmsCorrelationId = reader.getAttributeValue(null, "JMSCorrelationID"); + if (jmsCorrelationId != null && jmsCorrelationId.length() > 0) { + jmsBinding.setJMSCorrelationId(jmsCorrelationId); + } + + String jmsDeliveryMode = reader.getAttributeValue(null, "JMSDeliveryMode"); + if (jmsDeliveryMode != null && jmsDeliveryMode.length() > 0) { + if ("PERSISTENT".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setJMSDeliveryMode(true); + } else if ("NON_PERSISTENT".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setJMSDeliveryMode(false); + } else { + error("InvalidJMSDeliveryMode", jmsBinding, jmsDeliveryMode); + } + } + + String jmsTimeToLive = reader.getAttributeValue(null, "JMSTimeToLive"); + if (jmsTimeToLive != null && jmsTimeToLive.length() > 0) { + jmsBinding.setJMSTimeToLive(Long.parseLong(jmsTimeToLive)); + } + + String jmsPriority = reader.getAttributeValue(null, "JMSPriority"); + if (jmsPriority != null && jmsPriority.length() > 0) { + try { + int p = Integer.parseInt(jmsPriority); + if (p >= 0 && p <= 9) { + jmsBinding.setJMSPriority(p); + } else { + warning("InvalidJMSPriority", jmsBinding, jmsPriority); + } + } catch (NumberFormatException ex) { + error("InvalidJMSPriority", jmsBinding, jmsPriority); + } + } + + while (true) { + switch (reader.next()) { + case START_ELEMENT: + if (reader.getName().getLocalPart().equals("property")) { + parseProperty(reader, jmsBinding); + } + break; + case END_ELEMENT: + QName x = reader.getName(); + if (x.getLocalPart().equals("headers")) { + return; + } else { + error("UnexpectedResponseElement", reader, x.toString()); + } + } + } + } + + private void parseProperty(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + jmsBinding.setHeaders( true ); + String name = reader.getAttributeValue(null, "name"); + String type = reader.getAttributeValue(null, "type"); + if (name != null && name.length() > 0) { + Object value = reader.getElementText(); + if ("boolean".equalsIgnoreCase(type)) { + value = Boolean.parseBoolean((String)value); + } else if ("byte".equalsIgnoreCase(type)) { + value = Byte.parseByte(((String)value)); + } else if ("short".equalsIgnoreCase(type)) { + value = Short.parseShort((String)value); + } else if ("int".equalsIgnoreCase(type)) { + value = Integer.parseInt((String)value); + } else if ("long".equalsIgnoreCase(type)) { + value = Long.parseLong((String)value); + } else if ("float".equalsIgnoreCase(type)) { + value = Float.parseFloat((String)value); + } else if ("double".equalsIgnoreCase(type)) { + value = Double.parseDouble((String)value); + } else if ("String".equalsIgnoreCase(type)) { + // its already a string + } + jmsBinding.setProperty(name, value); + } + } + + /** + * + * * + * + * * + * ? + * * + */ + private void parseOperationProperties(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + + if (jmsBinding.getOperationPropertiesName() != null) { + error("DuplicateOperationProperties", jmsBinding); + } + + String opName = reader.getAttributeValue(null, "name"); + if (opName == null || opName.length() < 1) { + warning("MissingJMSOperationPropertyName", jmsBinding); + return; + } + // Since nativeOpName, headers, and property elements are optional, must add opName. + jmsBinding.addOperationName(opName); + String nativeOpName = reader.getAttributeValue(null, "nativeOperation"); // optional + if (nativeOpName != null && nativeOpName.length() > 0) { + jmsBinding.setNativeOperationName(opName, nativeOpName); + } + + Map props = new HashMap(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + if (reader.getName().getLocalPart().equals("headers")) { // optional + parseOperationHeaders(reader, jmsBinding, opName); + } else if (reader.getName().getLocalPart().equals("property")) { // optional + processProperty(reader, props); + } + break; + case END_ELEMENT: + if (reader.isEndElement()) { + QName x = reader.getName(); + if (x.getLocalPart().equals("headers")) { + break; + } + if (x.getLocalPart().equals("property")) { + break; + } + if (x.getLocalPart().equals("operationProperties")) { + jmsBinding.getOperationPropertiesProperties(opName).putAll(props); + return; + } else { + error("UnexpectedResponseElement", reader, x.toString()); + } + } + } + } + } + + private void parseOperationHeaders(XMLStreamReader reader, JMSBinding jmsBinding, String opName) throws XMLStreamException { + String jmsType = reader.getAttributeValue(null, "JMSType"); + if (jmsType != null && jmsType.length() > 0) { + jmsBinding.setOperationJMSType(opName, jmsType); + } + + String jmsCorrelationId = reader.getAttributeValue(null, "JMSCorrelationID"); + if (jmsCorrelationId != null && jmsCorrelationId.length() > 0) { + jmsBinding.setOperationJMSCorrelationId(opName, jmsCorrelationId); + } + + String jmsDeliveryMode = reader.getAttributeValue(null, "JMSDeliveryMode"); + if (jmsDeliveryMode != null && jmsDeliveryMode.length() > 0) { + if ("PERSISTENT".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setOperationJMSDeliveryMode(opName, true); + } else if ("NON_PERSISTENT".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setOperationJMSDeliveryMode(opName, false); + } else { + error("InvalidOPJMSDeliveryMode", jmsBinding, jmsDeliveryMode); + } + } + + String jmsTimeToLive = reader.getAttributeValue(null, "JMSTimeToLive"); + if (jmsTimeToLive != null && jmsTimeToLive.length() > 0) { + jmsBinding.setOperationJMSTimeToLive(opName, Long.parseLong(jmsTimeToLive)); + } + + String jmsPriority = reader.getAttributeValue(null, "JMSPriority"); + if (jmsPriority != null && jmsPriority.length() > 0) { + try { + int p = Integer.parseInt(jmsPriority); + if (p >= 0 && p <= 9) { + jmsBinding.setOperationJMSPriority(opName, p); + } else { + warning("InvalidOPJMSPriority", jmsBinding, jmsPriority); + } + } catch (NumberFormatException ex) { + error("InvalidOPJMSPriority", jmsBinding, jmsPriority); + } + } + + while (true) { + switch (reader.next()) { + case START_ELEMENT: + if (reader.getName().getLocalPart().equals("property")) { + parseOperationPropertyProperties(reader, jmsBinding, opName); + } + break; + case END_ELEMENT: + QName x = reader.getName(); + if (x.getLocalPart().equals("headers")) { + return; + } else { + error("UnexpectedResponseElement", reader, x.toString()); + } + } + } + } + + private void parseOperationPropertyProperties(XMLStreamReader reader, JMSBinding jmsBinding, String opName) throws XMLStreamException { + String propName = reader.getAttributeValue(null, "name"); + String type = reader.getAttributeValue(null, "type"); + if (propName != null && propName.length() > 0) { + Object value = reader.getElementText(); + if ("boolean".equalsIgnoreCase(type)) { + value = Boolean.parseBoolean((String)value); + } else if ("byte".equalsIgnoreCase(type)) { + value = Byte.parseByte(((String)value)); + } else if ("short".equalsIgnoreCase(type)) { + value = Short.parseShort((String)value); + } else if ("int".equalsIgnoreCase(type)) { + value = Integer.parseInt((String)value); + } else if ("long".equalsIgnoreCase(type)) { + value = Long.parseLong((String)value); + } else if ("float".equalsIgnoreCase(type)) { + value = Float.parseFloat((String)value); + } else if ("double".equalsIgnoreCase(type)) { + value = Double.parseDouble((String)value); + } else if ("String".equalsIgnoreCase(type)) { + // its already a string + } + jmsBinding.setOperationProperty(opName, propName, value); + } + } + + private void parseSubscriptionHeaders(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String jmsSelector = reader.getAttributeValue(null, "JMSSelector"); + if (jmsSelector != null && jmsSelector.length() > 0) { + jmsBinding.setJMSSelector(jmsSelector); + } + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && "SubscriptionHeaders".equals(reader.getName().getLocalPart())) { + break; + } + } // end while + } + + private Map parseBindingProperties(XMLStreamReader reader) throws XMLStreamException { + Map props = new HashMap(); + String parentName = reader.getName().getLocalPart(); + // Parse for all the properties within this element, until the end of + // the element is reached. + boolean completed = false; + while (!completed) { + switch (reader.next()) { + case START_ELEMENT: + String elementName = reader.getName().getLocalPart(); + if ("property".equals(elementName)) { + processProperty(reader, props); + } + break; + case END_ELEMENT: + String endName = reader.getName().getLocalPart(); + if (parentName.equals(endName)) { + completed = true; + break; + } + } + } + return props; + } + + private void processProperty(XMLStreamReader reader, Map props) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name == null || name.length() < 1) { + error("InvalidPropertyElement", reader); + } + String type = reader.getAttributeValue(null, "type"); + String value = reader.getElementText(); + props.put(name, new BindingProperty(name, type, value)); + } + + /** + * Preserve an existing public method. The method validate() is a legacy method + * that was called from reading am XML stream via the read(XMLStreamReader) method above. + * However read(XMLStreamReader) now calls validate(JMSBinding jmsBinding) and + * passes in the jmsBinding model. + * The older validate() now calls validate(JMSBinding jmsBinding) with a null model. + */ + public void validate() { + validate( null ); + } + + /** + * Validates JMS parsing and JMSBinding model. + * Validation rules are taken from the binding schema and the OSOA and OASIS specs: + * http://www.oasis-open.org/committees/documents.php?wg_abbrev=sca-bindings + * (sca-binding-jms-1.1-spec-cd01-rev4.pdf) + * http://www.osoa.org/display/Main/Service+Component+Architecture+Specifications + * (SCA JMS Binding V1.00 ) + * @param jmsBinding an optional JMS binding model to check for validity. + * @since 1.4 + */ + protected void validate( JMSBinding jmsBinding ) { + // If no JMSBinding model is provided, that is all the validation we can do. + if ( jmsBinding == null ) { + return; + } + + // Connection factory should not contradict destination type. + String connectionFactoryName = jmsBinding.getConnectionFactoryName(); + if (( connectionFactoryName != null ) && ( connectionFactoryName.length() > 0 )) { + if (JMSBindingConstants.DESTINATION_TYPE_QUEUE == jmsBinding.getDestinationType()) { + if ( connectionFactoryName.contains( "topic" )) { + error("DestinationQueueContradiction", jmsBinding, connectionFactoryName ); + } + } + if (JMSBindingConstants.DESTINATION_TYPE_TOPIC == jmsBinding.getDestinationType()) { + if ( connectionFactoryName.contains( "queue" )) { + error("DestinationTopicContradiction", jmsBinding, connectionFactoryName ); + } + } + } + + // Connection factory and activation Specification are mutually exclusive. + if (( connectionFactoryName != null ) && ( connectionFactoryName.length() > 0 )) { + String activationSpecName = jmsBinding.getActivationSpecName(); + if ((activationSpecName != null) && (activationSpecName.length() > 0 )) { + error("ConnectionFactoryActivationSpecContradiction", jmsBinding, connectionFactoryName, activationSpecName ); + } + } + + // Given a response connection name attribute, there must not be a response element. + // 156 • /binding.jms/@responseConnection – identifies a binding.jms element that is present in a + // 157 definition document, whose response child element is used to define the values for this binding. In + // 158 this case this binding.jms element MUST NOT contain a response element. + QName responseConnectionName = jmsBinding.getResponseConnectionName(); + if (( responseConnectionName != null ) && ( responseConnectionName.getLocalPart().length() > 0 )) { + String responseDestinationName = jmsBinding.getResponseDestinationName(); + if (( responseDestinationName != null ) && (responseDestinationName.length() > 0)) { + error("ResponseAttrElement", jmsBinding, responseConnectionName, responseDestinationName ); + } + } + + // Other jmsBinding model validation may be added here. + + } + + /** + * Given a valid JMSBinding, write it as XML using the given XML writer. + * + * This high-level method handles binding.jms element and its attributes. + * Sub elements have their own writer methods and are called from here. + * + * + * @param jmsBinding JMSBinding model + * @param writer an XMLStreamWriter that writes XML attributes and elements + */ + public void write(JMSBinding jmsBinding, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + // Write a + writeStart(writer, Constants.SCA10_NS, JMSBindingConstants.BINDING_JMS, + new XAttr("requestConnection", jmsBinding.getRequestConnectionName()), + new XAttr("responseConnection", jmsBinding.getResponseConnectionName()), + new XAttr("operationProperties", jmsBinding.getOperationPropertiesName())); + + if (jmsBinding.getName() != null) { + writer.writeAttribute("name", jmsBinding.getName()); + } + + if (jmsBinding.getURI() != null) { + writer.writeAttribute("uri", jmsBinding.getURI()); + } + + //String dest = jmsBinding.getDestinationName(); + //if (dest != null) { + // if ( dest != null ) { + // writer.writeAttribute("uri", "jms:" + jmsBinding.getDestinationName()); + // } + //} + + String correlationScheme = jmsBinding.getCorrelationScheme(); + if ( correlationScheme != null ) { + if ( !correlationScheme.equals(JMSBindingConstants.CORRELATE_MSG_ID) ) { + writer.writeAttribute("correlationScheme", jmsBinding.getCorrelationScheme()); + } + } + + if ( jmsBinding.getInitialContextFactoryName() != null ) { + writer.writeAttribute("initialContextFactory", jmsBinding.getInitialContextFactoryName()); + } + + if ( jmsBinding.getJndiURL() != null ) { + writer.writeAttribute("jndiURL", jmsBinding.getJndiURL()); + } + + if ( jmsBinding.containsHeaders() ) { + writeHeaders( jmsBinding, writer); + } + + writeOperationProperties( jmsBinding, writer ); + + writeSubscriptionHeaders( jmsBinding, writer ); + + writeDestinationProperties( jmsBinding, writer ); + + writeConnectionFactoryProperties( jmsBinding, writer ); + + writeActivationSpecProperties( jmsBinding, writer ); + + // Write response info, if names are not defaults. + String responseDestName = jmsBinding.getResponseDestinationName(); + String responseCFName = jmsBinding.getResponseConnectionFactoryName(); + String responseASName = jmsBinding.getResponseActivationSpecName(); + if ( responseDestName != null || + responseCFName != null || + responseASName != null ) { + + writer.writeStartElement(Constants.SCA10_NS, "response"); + writeResponseDestinationProperties( jmsBinding, writer ); + writeResponseConnectionFactoryProperties( jmsBinding, writer ); + writeResponseActivationSpecProperties( jmsBinding, writer ); + + if ((jmsBinding.getResponseWireFormat() != null) && + !(jmsBinding.getResponseWireFormat() instanceof WireFormatJMSDefault)){ + writeWireFormat(jmsBinding.getResponseWireFormat(), writer); + } + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters( " " ); + } + + writeResourceAdapterProperties( jmsBinding, writer ); + + writeConfiguredOperations( jmsBinding, writer ); + + if ((jmsBinding.getRequestWireFormat() != null) && + !(jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault)){ + writeWireFormat(jmsBinding.getRequestWireFormat(), writer); + } + + if ((jmsBinding.getOperationSelector() != null) && + !(jmsBinding.getOperationSelector() instanceof OperationSelectorJMSDefault)){ + writeOperationSelector(jmsBinding.getOperationSelector(), writer); + } + + writeEnd(writer); + } + + /** + * Writes headers element and its attributes. + * + * * + * ? + */ + private void writeHeaders( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + + writer.writeStartElement(Constants.SCA10_NS, JMSBindingConstants.HEADERS); + + String jmsType = jmsBinding.getJMSType(); + if (jmsType != null && jmsType.length() > 0) { + writer.writeAttribute("JMSType", jmsType); + } + + String jmsCorrelationId = jmsBinding.getJMSCorrelationId(); + if (jmsCorrelationId != null && jmsCorrelationId.length() > 0) { + writer.writeAttribute("JMSCorrelationID", jmsCorrelationId); + } + + Boolean jmsDeliveryMode = jmsBinding.isdeliveryModePersistent(); + if (jmsDeliveryMode != null) { + if ( jmsDeliveryMode.booleanValue() ) + writer.writeAttribute("JMSDeliveryMode", "PERSISTENT"); + else + writer.writeAttribute("JMSDeliveryMode", "NON_PERSISTENT"); + } + + Long jmsTimeToLive = jmsBinding.getJMSTimeToLive(); + if (jmsTimeToLive != null) { + writer.writeAttribute("JMSTimeToLive", jmsTimeToLive.toString()); + } + + Integer jmsPriority = jmsBinding.getJMSPriority(); + if (jmsPriority != null) { + writer.writeAttribute("JMSPriority", jmsPriority.toString()); + } + + Map properties = jmsBinding.getProperties(); + writeProperties( properties, writer ); + //writer.writeCharacters( " " ); + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters( " " ); + } + + /** + * Writes a complete set of properties to the given XML stream writer. + * If the value is of type string, the property will be output: + * StringValue + * If the value is of type box (e.g.Integer, Long) or BindingProperty, the output will be + * 42 + */ + private void writeProperties(Map properties, XMLStreamWriter writer) throws XMLStreamException { + if (( properties == null ) || ( properties.size() == 0 )) { + return; + } + + // For both the keys and values of a map + for (Iterator it=properties.entrySet().iterator(); it.hasNext(); ) { + Map.Entry entry = (Map.Entry)it.next(); + Object key = entry.getKey(); + Object value = entry.getValue(); + + writer.writeStartElement(Constants.SCA10_NS, "property" ); + writer.writeAttribute("name", key.toString()); + + if ( value instanceof String) { + writer.writeCharacters( value.toString() ); + } else if ( value instanceof BindingProperty ) { + BindingProperty property = (BindingProperty) value; + String type = property.getType(); + if ( type != null ) { + writer.writeAttribute("type", type); + } + writer.writeCharacters( property.getValue().toString() ); + } else if ( value instanceof Boolean ) { + writer.writeAttribute("type", "boolean"); + writer.writeCharacters( value.toString() ); + } else if ( value instanceof Byte ) { + writer.writeAttribute("type", "byte"); + writer.writeCharacters( value.toString() ); + } else if ( value instanceof Short ) { + writer.writeAttribute("type", "short"); + writer.writeCharacters( value.toString() ); + } else if ( value instanceof Integer ) { + writer.writeAttribute("type", "int"); + writer.writeCharacters( value.toString() ); + } else if ( value instanceof Long ) { + writer.writeAttribute("type", "long"); + writer.writeCharacters( value.toString() ); + } else if ( value instanceof Float ) { + writer.writeAttribute("type", "float"); + writer.writeCharacters( value.toString() ); + } else if ( value instanceof Double ) { + writer.writeAttribute("type", "double"); + writer.writeCharacters( value.toString() ); + } else { + writer.writeCharacters( value.toString() ); + } + writer.writeEndElement(); + } + } + + /** + * Writes operation properties if there are any. + * + * + * * + * + * * + * ? + * * + * + */ + private void writeOperationProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + if (jmsBinding.getOperationPropertiesBinding() != null) { + return; + } + Set operationNames = jmsBinding.getOperationNames(); + if (operationNames == null || (operationNames.size() < 1)) { + return; + } + + for(Iterator it=operationNames.iterator(); it.hasNext(); ) { + String opName = it.next(); + + writer.writeStartElement(Constants.SCA10_NS, "operationProperties"); + writer.writeAttribute("name", opName); + + String nativeOperation = jmsBinding.getNativeOperationName(opName); + if (nativeOperation != null && nativeOperation.length() > 0) { + if ( !nativeOperation.equals( opName )) { + writer.writeAttribute("nativeOperation", nativeOperation); + } + } + + Map operationPropertiesProperties = + jmsBinding.getOperationPropertiesProperties(opName); + writeBindingProperties( operationPropertiesProperties, writer ); + + String jmsType = jmsBinding.getOperationJMSType(opName); + String jmsCorrelationId = jmsBinding.getOperationJMSCorrelationId(opName); + Boolean jmsDeliveryMode = jmsBinding.getOperationJMSDeliveryMode(opName); + Long jmsTimeToLive = jmsBinding.getOperationJMSTimeToLive(opName); + Integer jmsPriority = jmsBinding.getOperationJMSPriority(opName); + Map operationProperties = jmsBinding.getOperationProperties(opName); + + if (operationProperties != null){ + if ((jmsType != null && jmsType.length() > 0) || + (jmsCorrelationId != null && jmsCorrelationId.length() > 0) || + jmsDeliveryMode != null || jmsTimeToLive != null || + jmsPriority != null) { + + writer.writeStartElement(Constants.SCA10_NS, JMSBindingConstants.HEADERS); + + if (jmsType != null && jmsType.length() > 0) { + writer.writeAttribute("JMSType", jmsType); + } + + if (jmsCorrelationId != null && jmsCorrelationId.length() > 0) { + writer.writeAttribute("JMSCorrelationID", jmsCorrelationId); + } + + if (jmsDeliveryMode != null) { + if (jmsDeliveryMode.booleanValue()) + writer.writeAttribute("JMSDeliveryMode", "PERSISTENT"); + else + writer.writeAttribute("JMSDeliveryMode", "NON_PERSISTENT"); + } + + if (jmsTimeToLive != null) { + writer.writeAttribute("JMSTimeToLive", jmsTimeToLive.toString()); + } + + if (jmsPriority != null) { + writer.writeAttribute("JMSPriority", jmsPriority.toString()); + } + + writeProperties( operationProperties, writer ); + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + // writer.writeCharacters( " " ); + } + } + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + } + + /** + * Writes a complete set of properties to the given XML stream writer. + * If the value is of type string, the property will be output: + * StringValue + * If the value is of type box (e.g.Integer, Long) or BindingProperty, the output will be + * 42 + */ + private void writeBindingProperties(Map properties, XMLStreamWriter writer) throws XMLStreamException { + if (( properties == null ) || ( properties.size() == 0 )) { + return; + } + + // For both the keys and values of a map + for (Iterator it=properties.entrySet().iterator(); it.hasNext(); ) { + Map.Entry entry = (Map.Entry)it.next(); + Object key = entry.getKey(); + Object value = entry.getValue(); + + writer.writeStartElement(Constants.SCA10_NS, "property" ); + if (key != null){ + writer.writeAttribute("name", key.toString()); + } + + if ( value instanceof String) { + writer.writeCharacters( value.toString() ); + } else if ( value instanceof BindingProperty ) { + BindingProperty property = (BindingProperty) value; + String type = property.getType(); + if ( type != null ) { + writer.writeAttribute("type", type); + } + writer.writeCharacters( property.getValue().toString() ); + } else { + writer.writeCharacters( value.toString() ); + } + writer.writeEndElement(); + } + } + + /** + * Writes subscription headers if there are any. + * + * + * + * + */ + private void writeSubscriptionHeaders( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String jmsSubscriptionHeaders = jmsBinding.getJMSSelector(); + if (jmsSubscriptionHeaders != null && jmsSubscriptionHeaders.length() > 0) { + writer.writeStartElement(Constants.SCA10_NS, "SubscriptionHeaders"); + writer.writeAttribute("JMSSelector", jmsSubscriptionHeaders); + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + // writer.writeCharacters( " " ); + } + } + + /** + * Writes destination properties if there are any. + * + * * + * ? + */ + private void writeDestinationProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String destinationName = jmsBinding.getDestinationName(); + if (destinationName == null || (destinationName.length() < 1)) { + return; + } + if (destinationName == null) { + return; + } + + writer.writeStartElement(Constants.SCA10_NS, "destination"); + + if ( destinationName != null && destinationName.length() > 0) { + writer.writeAttribute("name", destinationName); + } + + // Type not handled yet + // String destinationType = jmsBinding.getDestinationType(); + // if ( destinationType != null && destinationType.length() > 0) { + // writer.writeAttribute("type", destinationType); + // } + + String destinationCreate = jmsBinding.getDestinationCreate(); + if ( destinationCreate != null && destinationCreate.length() > 0 && + !destinationCreate.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) { + writer.writeAttribute("create", destinationCreate); + } + + Map destinationProperties = + jmsBinding.getDestinationProperties(); + writeBindingProperties( destinationProperties, writer ); + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + + /** + * Writes connection factory properties if there are any. + * + * * + * ? + */ + private void writeConnectionFactoryProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String cfName = jmsBinding.getConnectionFactoryName(); + if (cfName == null || (cfName.length() < 1)) { + return; + } + + writer.writeStartElement(Constants.SCA10_NS, "connectionFactory"); + + if ( cfName != null && cfName.length() > 0) { + writer.writeAttribute("name", cfName); + } + + String destinationCreate = jmsBinding.getConnectionFactoryCreate(); + if ( destinationCreate != null && destinationCreate.length() > 0 && + !destinationCreate.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) { + writer.writeAttribute("create", destinationCreate); + } + + Map cfProperties = + jmsBinding.getConnectionFactoryProperties(); + writeBindingProperties( cfProperties, writer ); + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + + /** + * Writes activation Spec properties if there are any. + * + * * + * ? + * + */ + private void writeActivationSpecProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String asName = jmsBinding.getActivationSpecName(); + if (asName == null || (asName.length() < 1)) { + return; + } + + writer.writeStartElement(Constants.SCA10_NS, "activationSpec"); + + if ( asName != null && asName.length() > 0) { + writer.writeAttribute("name", asName); + } + + String destinationCreate = jmsBinding.getActivationSpecCreate(); + if ( destinationCreate != null && destinationCreate.length() > 0) { + writer.writeAttribute("create", destinationCreate); + } + + Map cfProperties = + jmsBinding.getActivationSpecProperties(); + writeBindingProperties( cfProperties, writer ); + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + + /** + * Writes response destination properties if there are any. + * + * * + * ? + */ + private void writeResponseDestinationProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String destinationName = jmsBinding.getResponseDestinationName(); + if (destinationName == null || (destinationName.length() < 1)) { + return; + } + if (destinationName == null) { + return; + } + + writer.writeStartElement(Constants.SCA10_NS, "destination"); + + if ( destinationName != null && destinationName.length() > 0) { + writer.writeAttribute("name", destinationName); + } + + // Type not handled yet + // String destinationType = jmsBinding.getDestinationType(); + // if ( destinationType != null && destinationType.length() > 0) { + // writer.writeAttribute("type", destinationType); + // } + + String destinationCreate = jmsBinding.getResponseDestinationCreate(); + if ( destinationCreate != null && destinationCreate.length() > 0) { + writer.writeAttribute("create", destinationCreate); + } + + Map destinationProperties = + jmsBinding.getResponseDestinationProperties(); + writeBindingProperties( destinationProperties, writer ); + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + + /** + * Writes response connection factory properties if there are any. + * + * * + * ? + * + */ + private void writeResponseConnectionFactoryProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String cfName = jmsBinding.getResponseConnectionFactoryName(); + if (cfName == null || (cfName.length() < 1)) { + return; + } + + writer.writeStartElement(Constants.SCA10_NS, "connectionFactory"); + + if ( cfName != null && cfName.length() > 0) { + writer.writeAttribute("name", cfName); + } + + String destinationCreate = jmsBinding.getResponseConnectionFactoryCreate(); + if ( destinationCreate != null && destinationCreate.length() > 0) { + writer.writeAttribute("create", destinationCreate); + } + + Map cfProperties = + jmsBinding.getResponseConnectionFactoryProperties(); + writeBindingProperties( cfProperties, writer ); + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + + /** + * Writes response activation Spec properties if there are any. + * + * * + * ? + * + */ + private void writeResponseActivationSpecProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String asName = jmsBinding.getResponseActivationSpecName(); + if (asName == null || (asName.length() < 1)) { + return; + } + + writer.writeStartElement(Constants.SCA10_NS, "activationSpec"); + + if ( asName != null && asName.length() > 0) { + writer.writeAttribute("name", asName); + } + + String destinationCreate = jmsBinding.getResponseActivationSpecCreate(); + if ( destinationCreate != null && destinationCreate.length() > 0) { + writer.writeAttribute("create", destinationCreate); + } + + Map cfProperties = + jmsBinding.getResponseActivationSpecProperties(); + writeBindingProperties( cfProperties, writer ); + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + + /** + * Writes resource adapter properties if there are any. + * ? + * * + * ? + */ + private void writeResourceAdapterProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String asName = jmsBinding.getResourceAdapterName(); + if (asName == null || (asName.length() < 1)) { + return; + } + + writer.writeStartElement(Constants.SCA10_NS, "resourceAdapter"); + + if ( asName != null && asName.length() > 0) { + writer.writeAttribute("name", asName); + } + + Map cfProperties = + jmsBinding.getResourceAdapterProperties(); + writeBindingProperties( cfProperties, writer ); + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + + /** + * Writes configured operations if there are any. + * " + * " + * " + * " + * " + */ + private void writeConfiguredOperations( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException, ContributionWriteException { + List configOps = jmsBinding.getConfiguredOperations(); + if (configOps == null || (configOps.size() < 1)) { + return; + } + + for( Iterator it = configOps.iterator(); it.hasNext();) { + configuredOperationProcessor.write(it.next(), writer); + } + + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + + /** + * Wire out a request or response wire format element. Uses extension processors + * to do this as wire format is an extension point + * + * @param wireFormat + * @param writer + */ + private void writeWireFormat(WireFormat wireFormat, XMLStreamWriter writer ) throws XMLStreamException, ContributionWriteException { + extensionProcessor.write(wireFormat, writer); + } + + /** + * Wire out an operation selector element. Uses extension processors + * to do this as operation selector is an extension point + * + * @param operationSeletor + * @param writer + */ + private void writeOperationSelector(OperationSelector operationSeletor, XMLStreamWriter writer ) throws XMLStreamException, ContributionWriteException{ + extensionProcessor.write(operationSeletor, writer); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefault.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefault.java new file mode 100644 index 0000000000..ce7c2a71b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefault.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.sca.binding.jms.operationselector.jmsdefault; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.OperationSelector; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSDefault implements OperationSelector { + public static final QName OPERATION_SELECTOR_JMS_DEFAULT_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "operationSelector.jmsdefault"); + + public QName getSchemaName() { + return OPERATION_SELECTOR_JMS_DEFAULT_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProcessor.java new file mode 100644 index 0000000000..4a8e4a1bd2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/OperationSelectorJMSDefaultProcessor.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.sca.binding.jms.operationselector.jmsdefault; + + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSDefaultProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return OperationSelectorJMSDefault.OPERATION_SELECTOR_JMS_DEFAULT_QNAME; + } + + public OperationSelectorJMSDefaultProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public OperationSelectorJMSDefault read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + OperationSelectorJMSDefault wireFormat = new OperationSelectorJMSDefault(); + + return wireFormat; + } + + public void write(OperationSelectorJMSDefault wireFormat, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + writer.writeEndElement(); + } + + public Class getModelType() { + return OperationSelectorJMSDefault.class; + } + + public void resolve(OperationSelectorJMSDefault arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/OperationSelectorJMSUserProp.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/OperationSelectorJMSUserProp.java new file mode 100644 index 0000000000..5e76405754 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/OperationSelectorJMSUserProp.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.sca.binding.jms.operationselector.jmsuserprop; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.OperationSelector; + +/** + * Model of user property based operation selection + * + * + * + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSUserProp implements OperationSelector { + public static final QName OPERATION_SELECTOR_JMS_USERPROP_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "operationSelector.jmsUserProp"); + public static final String OPERATION_SELECTOR_JMS_USERPROP_ATTR = "propertyName"; + + private String propertyName; + + public QName getSchemaName() { + return OPERATION_SELECTOR_JMS_USERPROP_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + public String getPropertyName() { + return propertyName; + } + + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/OperationSelectorJMSUserPropProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/OperationSelectorJMSUserPropProcessor.java new file mode 100644 index 0000000000..f1fd97cb4e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/OperationSelectorJMSUserPropProcessor.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.sca.binding.jms.operationselector.jmsuserprop; + + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSUserPropProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_QNAME; + } + + public OperationSelectorJMSUserPropProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public OperationSelectorJMSUserProp read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + OperationSelectorJMSUserProp opSelector = new OperationSelectorJMSUserProp(); + String propertyName = reader.getAttributeValue(null, OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_ATTR); + if (propertyName != null && propertyName.length() > 0) { + opSelector.setPropertyName(propertyName); + } else { + throw new ContributionReadException(OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_QNAME.toString() + ": " + + OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_ATTR + " is a required attribute."); + } + + return opSelector; + } + + public void write(OperationSelectorJMSUserProp opSelector, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + if (opSelector.getPropertyName() != null) { + writer.writeAttribute(OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_ATTR, opSelector.getPropertyName()); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return OperationSelectorJMSUserProp.class; + } + + public void resolve(OperationSelectorJMSUserProp arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytes.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytes.java new file mode 100644 index 0000000000..84d1a2740f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytes.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.sca.binding.jms.wireformat.jmsbytes; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.WireFormat; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSBytes implements WireFormat { + public static final QName WIRE_FORMAT_JMS_BYTES_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jmsBytes"); + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesProcessor.java new file mode 100644 index 0000000000..2d807d49cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesProcessor.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.sca.binding.jms.wireformat.jmsbytes; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSBytesProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSBytes.WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public WireFormatJMSBytesProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public WireFormatJMSBytes read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + WireFormatJMSBytes wireFormat = new WireFormatJMSBytes(); + + return wireFormat; + } + + public void write(WireFormatJMSBytes wireFormat, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSBytes.class; + } + + public void resolve(WireFormatJMSBytes arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/WireFormatJMSBytesXML.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/WireFormatJMSBytesXML.java new file mode 100644 index 0000000000..668171fc9f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/WireFormatJMSBytesXML.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.sca.binding.jms.wireformat.jmsbytesxml; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.WireFormat; + + +public class WireFormatJMSBytesXML implements WireFormat { + public static final QName WIRE_FORMAT_JMS_BYTES_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jmsBytesXML"); + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/WireFormatJMSBytesXMLProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/WireFormatJMSBytesXMLProcessor.java new file mode 100644 index 0000000000..105aed270a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/WireFormatJMSBytesXMLProcessor.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.sca.binding.jms.wireformat.jmsbytesxml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + + +public class WireFormatJMSBytesXMLProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSBytesXML.WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public WireFormatJMSBytesXMLProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public WireFormatJMSBytesXML read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + WireFormatJMSBytesXML wireFormat = new WireFormatJMSBytesXML(); + + return wireFormat; + } + + public void write(WireFormatJMSBytesXML wireFormat, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSBytesXML.class; + } + + public void resolve(WireFormatJMSBytesXML arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java new file mode 100644 index 0000000000..8cca30a8ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.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.sca.binding.jms.wireformat.jmsdefault; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.WireFormat; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefault implements WireFormat { + public static final QName WIRE_FORMAT_JMS_DEFAULT_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jmsdefault"); + + public static final String WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR = "sendFormat"; + + public static final String WIRE_FORMAT_JMS_DEFAULT_TEXT_FORMAT_VAL = "text"; + public static final String WIRE_FORMAT_JMS_DEFAULT_BYTES_FORMAT_VAL = "bytes"; + + //default is to use a javax.jms.BytesMessage + private boolean useBytesMessage = true; + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_DEFAULT_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + @Override + public boolean equals(Object obj) { + return this.getClass() == obj.getClass(); + } + + public void setUseBytesMessage(boolean useBytesMessage) { + this.useBytesMessage = useBytesMessage; + } + + public boolean isUseBytesMessage() { + return useBytesMessage; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProcessor.java new file mode 100644 index 0000000000..1c3f666577 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProcessor.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_QNAME; + } + + public WireFormatJMSDefaultProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + public WireFormatJMSDefault read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + WireFormatJMSDefault wireFormat = new WireFormatJMSDefault(); + + String sendFormat = reader.getAttributeValue(null, WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR); + if (sendFormat != null && sendFormat.length() > 0) { + if (WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_TEXT_FORMAT_VAL.equalsIgnoreCase(sendFormat)) { + wireFormat.setUseBytesMessage(false); + }else if (WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_BYTES_FORMAT_VAL.equalsIgnoreCase(sendFormat)) { + wireFormat.setUseBytesMessage(true); + }else{ + throw new ContributionReadException(WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_QNAME.toString() +" " +sendFormat + " is not a valid attribute value for " + + WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR); + } + } + + return wireFormat; + } + + public void write(WireFormatJMSDefault wireFormat, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, getArtifactType().getLocalPart(), getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + if (wireFormat.isUseBytesMessage()) { + writer.writeAttribute(WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR, WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_BYTES_FORMAT_VAL); + } else { + writer.writeAttribute(WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR, WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_TEXT_FORMAT_VAL); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSDefault.class; + } + + public void resolve(WireFormatJMSDefault arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObject.java new file mode 100644 index 0000000000..a485d2b5ec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObject.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.sca.binding.jms.wireformat.jmsobject; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.WireFormat; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSObject implements WireFormat { + public static final QName WIRE_FORMAT_JMS_BYTES_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jmsObject"); + + public static final String WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR = "wrapSingle"; + + private boolean wrappedSingleInput = false; + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + public void setWrappedSingleInput(boolean wrappedSingleInput) { + this.wrappedSingleInput = wrappedSingleInput; + } + + public boolean isWrappedSingleInput() { + return wrappedSingleInput; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObjectProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObjectProcessor.java new file mode 100644 index 0000000000..62b2a91d62 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/WireFormatJMSObjectProcessor.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat.jmsobject; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSObjectProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSObject.WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public WireFormatJMSObjectProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public WireFormatJMSObject read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + WireFormatJMSObject wireFormat = new WireFormatJMSObject(); + + String wrappedSingleInput = reader.getAttributeValue(null, WireFormatJMSObject.WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR); + if (wrappedSingleInput != null && wrappedSingleInput.length() > 0) { + if ("true".equalsIgnoreCase(wrappedSingleInput)) { + wireFormat.setWrappedSingleInput(true); + } else if ("false".equalsIgnoreCase(wrappedSingleInput)) { + wireFormat.setWrappedSingleInput(false); + } else { + throw new ContributionReadException(WireFormatJMSObject.WIRE_FORMAT_JMS_BYTES_QNAME.toString() + ": " + wrappedSingleInput + + " is not a valid attribute value for " + WireFormatJMSObject.WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR); + } + } + return wireFormat; + } + + public void write(WireFormatJMSObject wireFormat, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + writer.writeAttribute(WireFormatJMSObject.WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR, String.valueOf(wireFormat.isWrappedSingleInput())); + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSObject.class; + } + + public void resolve(WireFormatJMSObject arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/WireFormatJMSText.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/WireFormatJMSText.java new file mode 100644 index 0000000000..fff33df1f4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/WireFormatJMSText.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.sca.binding.jms.wireformat.jmstext; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.WireFormat; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSText implements WireFormat { + public static final QName WIRE_FORMAT_JMS_BYTES_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jmsText"); + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/WireFormatJMSTextProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/WireFormatJMSTextProcessor.java new file mode 100644 index 0000000000..9b675df290 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/WireFormatJMSTextProcessor.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.sca.binding.jms.wireformat.jmstext; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSText.WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public WireFormatJMSTextProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public WireFormatJMSText read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + WireFormatJMSText wireFormat = new WireFormatJMSText(); + + return wireFormat; + } + + public void write(WireFormatJMSText wireFormat, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSText.class; + } + + public void resolve(WireFormatJMSText arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/WireFormatJMSTextXML.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/WireFormatJMSTextXML.java new file mode 100644 index 0000000000..23a53b9d96 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/WireFormatJMSTextXML.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.sca.binding.jms.wireformat.jmstextxml; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.WireFormat; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextXML implements WireFormat { + public static final QName WIRE_FORMAT_JMS_DEFAULT_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jmsTextXML"); + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_DEFAULT_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + @Override + public boolean equals(Object obj) { + return this.getClass() == obj.getClass(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/WireFormatJMSTextXMLProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/WireFormatJMSTextXMLProcessor.java new file mode 100644 index 0000000000..8248fc771a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/WireFormatJMSTextXMLProcessor.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.sca.binding.jms.wireformat.jmstextxml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextXMLProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSTextXML.WIRE_FORMAT_JMS_DEFAULT_QNAME; + } + + public WireFormatJMSTextXMLProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public WireFormatJMSTextXML read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + WireFormatJMSTextXML wireFormat = new WireFormatJMSTextXML(); + + return wireFormat; + } + + public void write(WireFormatJMSTextXML wireFormat, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSTextXML.class; + } + + public void resolve(WireFormatJMSTextXML arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..05f9f377ba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -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. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.jms.impl.JMSBindingProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#binding.jms,model=org.apache.tuscany.sca.binding.jms.impl.JMSBinding +org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefaultProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#wireFormat.jmsdefault,model=org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault +org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXMLProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#wireFormat.jmsTextXML,model=org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML +org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytesProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#wireFormat.jmsBytes,model=org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes +org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.WireFormatJMSBytesXMLProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#wireFormat.jmsBytesXML,model=org.apache.tuscany.sca.binding.jms.wireformat.jmsbytesxml.WireFormatJMSBytesXML +org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSTextProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#wireFormat.jmsText,model=org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSText +org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObjectProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#wireFormat.jmsObject,model=org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject +org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefaultProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#operationSelector.jmsdefault,model=org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefault +org.apache.tuscany.sca.binding.jms.operationselector.jmsuserprop.OperationSelectorJMSUserPropProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#operationSelector.jmsUserProp,model=org.apache.tuscany.sca.binding.jms.operationselector.jmsuserprop.OperationSelectorJMSUserProp \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties new file mode 100644 index 0000000000..9361bb0e3c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties @@ -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. +# +# +DoesntProcessOperationProperties = JMS Binding doesn't process operationProperties yet +DoesntProcessHeaders = JMS Binding doesn't process headers yet +DoesntProcessResourceAdapter = JMS Binding doesn't process resourceAdapter yet +DoesntProcessResponseConnectionFactory = JMS Binding doesn't process response connectionFactory yet +DoesntProcessResponseActivationSpec = JMS Binding doesn't process response activationSpec yet +DoesntProcessResponseDestinationType = JMS Binding doesn't process response destination type yet +DoesntProcessActivationSpec = JMS Binding doesn't process activationSpec yet +DoesntProcessDestinationType = JMS Binding doesn't process destination type yet +MissingConnectionFactoryName = Missing ConnectionFactory Name +MissingResponseConnectionFactory = Missing response connectionFactory name +InvalidResponseDestinationType = Invalid response destination type: {0} +InvalidDestinationType = Invalid destination type: {0} +MissingActivationSpecName = Missing ActivationSpec Name +MissingResponseActivationSpec = Missing response ActivationSpec name +UnknownTokenInURI = Unknown token {0} in uri: {1} +MustStartWithSchema = URI must start with the scheme 'jms:' for uri: {0} +InvalidCorrelationScheme = Invalid correlationScheme: {0} +UnexpectedElement = Incomplete binding.jms definition found unexpected element: {0} +UnexpectedResponseElement = Incomplete binding.jms/response definition found unexpected element: {0} +InvalidJMSDeliveryMode = Invalid JMSDeliveryMode: {0} +InvalidJMSPriority = Invalid JMSPriority: {0} +MissingJMSOperationPropertyName = Missing JMSOperationProperty Name +InvalidOPJMSDeliveryMode = Invalid OPJMSDeliveryMode: {0} +InvalidOPJMSPriority = Invalid OPJMSPriority: {0} +DestinationQueueContradiction = Destination type queue contradicts connection factory name: {0} +DestinationTopicContradiction = Destination type topic contradicts connection factory name: {0} +ConnectionFactoryActivationSpecContradiction = Connection factory \"{0}\" and activation specification \"{0}\" are mutually exclusive +ResponseAttrElement = Response connection \"{0}\" and response element \"{1}\" are mutually exclusive +BindingNotFound = {0} refers to a binding definition {1} which is not found +DuplicateOperationProperties = Must not use both operationProperties attribute and operationProperties element diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java new file mode 100644 index 0000000000..e05f31da1b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java @@ -0,0 +1,783 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.impl; + +import java.io.StringReader; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; + +/** + * Tests for JMS binding xml + */ +public class JMSBindingProcessorTestCase extends TestCase { + // Note: If you are adding new JMS binding read test cases, + // consider adding a similar test case to JMSBindingProcessorWriteTestCase. + public static final String COMPOSITE = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String HEADERS1 = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String HEADERS_INVALID_PRIORITY = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String PROPERTIES1 = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " bla" + + " 42" + + " " + + " " + + " " + + " " + + ""; + + public static final String OP_PROPERTIES1 = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " bla" + + " 42" + + " " + + " " + + " " + + " " + + " op2bla" + + " 77" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String OP_NAMES_NO_PROPERTIES1 = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String SELECTOR = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String COMPOSITE_INVALID_URI = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + // Invalid: contains both a response attribute and a response element. + public static final String COMPOSITE_INVALID_RESPONSE_ATTR_ELEMENT = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String DEST_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String CF_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String AS_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String RESP_DEST_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String RESP_CF_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String RESP_AS_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String OP_PROPS_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String RES_ADPT_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String CONFIGURED_OPERATIONS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String WIRE_FORMAT = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String OP_PROP_NAME = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + @Override + protected void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); + + } + + /** + * Test parsing valid composite definition. Valid composite populated with correct values expected. + * @throws Exception + */ + public void testLoadValidComposite() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals("testQueue", binding.getDestinationName()); + } + + public void testHeaders1() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(HEADERS1)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals("myType", binding.getJMSType()); + assertEquals("myCorrelId", binding.getJMSCorrelationId()); + assertTrue(binding.isdeliveryModePersistent()); + assertEquals(54321, binding.getJMSTimeToLive().longValue()); + assertEquals(5, binding.getJMSPriority().intValue()); + } + + public void testProperties1() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(PROPERTIES1)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals("bla", binding.getProperty("p1")); + assertEquals(42, ((Integer)binding.getProperty("intProp")).intValue()); + } + + public void testOpProperties1() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROPERTIES1)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + + Map op1Props = binding.getOperationProperties("op1"); + assertEquals("op1Type", binding.getOperationJMSType("op1")); + assertEquals("bla", op1Props.get("p1")); + assertEquals(42, ((Integer)op1Props.get("intProp")).intValue()); + + assertEquals("op2Type", binding.getOperationJMSType("op2")); + Map op2Props = binding.getOperationProperties("op2"); + assertEquals("op2bla", op2Props.get("p2")); + assertEquals(77, ((Integer)op2Props.get("intProp")).intValue()); + } + + public void testSubscriptionHeaders () throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(SELECTOR)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + + assertEquals("prop1 = 2", binding.getJMSSelector()); + } + + /** Test various parsing validation requirements. */ + public void testParsingValidationErrors1() throws Exception { + // Composite with malformed URI. + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_INVALID_URI)); + + try { + Composite composite = (Composite)staxProcessor.read(reader); + } catch(Exception e) { + // JMSBindingExceptions are expected with invalid composite. + if ( !e.getClass().isAssignableFrom( JMSBindingException.class ) ) + throw e; + // Do assertion to make sure test registers results. + assertTrue( e.getClass().isAssignableFrom( JMSBindingException.class ) ); + } + } + + public void testParsingValidationErrors2() throws Exception { + // Composite with invalid priority + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(HEADERS_INVALID_PRIORITY)); + + try { + Composite composite = (Composite)staxProcessor.read(reader); + } catch(Exception e) { + // JMSBindingExceptions are expected with invalid composite. + if ( !e.getClass().isAssignableFrom( JMSBindingException.class ) ) + throw e; + // Do assertion to make sure test registers results. + assertTrue( e.getClass().isAssignableFrom( JMSBindingException.class ) ); + return; + } + } + + /** Test various model validation requirements. */ + public void testValidationErrors1() throws Exception { + // Composite with response connection attr and element. + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_INVALID_RESPONSE_ATTR_ELEMENT)); + + try { + Composite composite = (Composite)staxProcessor.read(reader); + } catch(Exception e) { + // JMSBindingExceptions are expected with invalid composite. + if ( !e.getClass().isAssignableFrom( JMSBindingException.class ) ) + throw e; + // Do assertion to make sure test registers results. + assertTrue( e.getClass().isAssignableFrom( JMSBindingException.class ) ); + } + } + + public void testDestinationProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(DEST_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getDestinationProperties()); + assertEquals(2, binding.getDestinationProperties().size()); + BindingProperty bp = binding.getDestinationProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getDestinationProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testConnectionFactoryProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(CF_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getConnectionFactoryProperties()); + assertEquals(2, binding.getConnectionFactoryProperties().size()); + BindingProperty bp = binding.getConnectionFactoryProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getConnectionFactoryProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testActivationSpecProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(AS_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getActivationSpecProperties()); + assertEquals(2, binding.getActivationSpecProperties().size()); + BindingProperty bp = binding.getActivationSpecProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getActivationSpecProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testResponseDestinationProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_DEST_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getResponseDestinationProperties()); + assertEquals(2, binding.getResponseDestinationProperties().size()); + BindingProperty bp = binding.getResponseDestinationProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getResponseDestinationProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testResponseConnectionFactoryProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_CF_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getResponseConnectionFactoryProperties()); + assertEquals(2, binding.getResponseConnectionFactoryProperties().size()); + BindingProperty bp = binding.getResponseConnectionFactoryProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getResponseConnectionFactoryProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testResponseActivationSpecProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_AS_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getResponseActivationSpecProperties()); + assertEquals(2, binding.getResponseActivationSpecProperties().size()); + BindingProperty bp = binding.getResponseActivationSpecProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getResponseActivationSpecProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testOperationPropertiesProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROPS_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getOperationPropertiesProperties("op1")); + assertEquals(2, binding.getOperationPropertiesProperties("op1").size()); + BindingProperty bp = binding.getOperationPropertiesProperties("op1").get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getOperationPropertiesProperties("op1").get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testResouceAdapterProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RES_ADPT_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals("r1", binding.getResourceAdapterName()); + assertNotNull(binding.getResourceAdapterProperties()); + assertEquals(2, binding.getResourceAdapterProperties().size()); + BindingProperty bp = binding.getResourceAdapterProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getResourceAdapterProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + + /** + * Tests the APIs: + * public Set getOperationNames(); + * public Object getOperationProperty(String opName, String propName ); + * @throws Exception + */ + public void testOpProperties2() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROPERTIES1)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + + Set opNames = binding.getOperationNames(); + assertEquals( 2, opNames.size() ); + // Recall that order is not guaranteed iterating over a set. + for (Iterator it=opNames.iterator(); it.hasNext(); ) { + String opName = it.next(); + assertTrue( opName.equals( "op1") || opName.equals( "op2")); + } + + Object value = binding.getOperationProperty( "op1", "p1" ); + assertEquals("bla", value); + value = binding.getOperationProperty( "op1", "intProp" ); + assertEquals(42, ((Integer)value).intValue()); + + value = binding.getOperationProperty( "op2", "p2" ); + assertEquals("op2bla", value); + value = binding.getOperationProperty( "op2", "intProp" ); + assertEquals(77, ((Integer)value).intValue()); + } + + /** + * Tests the APIs: + * public Set getOperationNames(); + * Provides no optional properties or sub elements + * @throws Exception + */ + public void testOpProperties3() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_NAMES_NO_PROPERTIES1)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + + Set opNames = binding.getOperationNames(); + assertEquals( 2, opNames.size() ); + // Recall that order is not guaranteed iterating over a set. + for (Iterator it=opNames.iterator(); it.hasNext(); ) { + String opName = it.next(); + assertTrue( opName.equals( "op1") || opName.equals( "op2")); + } + } + + /** + * Tests the APIs: + * public Set getOperationNames(); + * Provides no optional properties or sub elements + * @throws Exception + */ + public void testConfiguredOperations1() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(CONFIGURED_OPERATIONS)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + OperationsConfigurator opConfig = ((OperationsConfigurator)binding); + assertEquals(opConfig.getConfiguredOperations().get(0).getRequiredIntents().size(), 2); + } + + /** + * Tests the APIs: + * public WireFormat getRequstWireFormat(); + * public WireFormat getResponseWireFormat(); + * + * @throws Exception + */ + public void testWireFormat() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(WIRE_FORMAT)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + WireFormat requestWireFormat = binding.getRequestWireFormat(); + assertEquals(WireFormatJMSObject.class, requestWireFormat.getClass()); + + WireFormat responseWireFormat = binding.getResponseWireFormat(); + assertEquals(WireFormatJMSBytes.class, responseWireFormat.getClass()); + } + + public void testOpPropertiesName() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROP_NAME)); + + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals( "foo", binding.getOperationPropertiesName().getLocalPart() ); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorWriteTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorWriteTestCase.java new file mode 100644 index 0000000000..d3efdfb606 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorWriteTestCase.java @@ -0,0 +1,456 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.impl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.StringReader; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; + +/** + * Tests for JMS binding XML writes. + * In general, for each JMS binding XML read test case, there + * is a write test case. + */ +public class JMSBindingProcessorWriteTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + public static final String DEFAULT = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + @Override + protected void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); + } + + /** + * Test parsing valid composite definition. Valid composite populated with correct values expected. + * @throws Exception + */ + public void testLoadValidComposite() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.COMPOSITE)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals( binding, binding2); + } + + public void testHeaders1() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.HEADERS1)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals( binding, binding2 ); + } + + public void testProperties1() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.PROPERTIES1)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals( binding, binding2 ); + } + + public void testOpProperties1() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.OP_PROPERTIES1)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testSubscriptionHeaders() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.SELECTOR)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testDestinationProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.DEST_PROPS)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testConnectionFactoryProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.CF_PROPS)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testActivationSpecProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.AS_PROPS)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testResponseDestinationProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RESP_DEST_PROPS)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testResponseConnectionFactoryProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RESP_CF_PROPS)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testResponseActivationSpecProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RESP_AS_PROPS)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testOperationPropertiesProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.OP_PROPS_PROPS)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testResouceAdapterProperties() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RES_ADPT_PROPS)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testConfiguredOperations() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.CONFIGURED_OPERATIONS)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + public void testWireFormat() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.WIRE_FORMAT)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + // TUSCANY-3120 + // Checking we don't write out values unless the use has specified them on input + public void testDefault() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(DEFAULT)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + System.out.println(bos.toString()); + assertEquals(bos.toString(), + "" + + "" + + "" + + "" + + " " + + "" + + "" + + " " + + " "+ + " " + + "" + + "" + + "" + + ""); + } + + public void testOperationPropertiesName() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.OP_PROP_NAME)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals("foo", binding2.getOperationPropertiesName().getLocalPart()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/pom.xml new file mode 100644 index 0000000000..ecb94283ac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-jsonrpc-js-dojo + Apache Tuscany SCA JSON-RPC Binding JavaScript using Dojo + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-web-javascript + 1.6-SNAPSHOT + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.jsonrpc-js + ${pom.name} + org.apache.tuscany.sca.binding.jsonrpc.js* + org.apache.tuscany.sca.assembly.xml;version="1.4", * + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java new file mode 100644 index 0000000000..4fe32cff6d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.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.sca.binding.jsonrpc.js.dojo; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; +import org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory; + +public class JSONRPCBindingJavascriptProxyFactoryImpl implements JavascriptProxyFactory { + private static final QName NAME = new QName("http://tuscany.apache.org/xmlns/sca/1.0", "binding.jsonrpc"); + + public Class getModelType() { + return JSONRPCBinding.class; + } + + public QName getQName() { + return NAME; + } + + public String getJavascriptProxyFile() { + return null; + } + + public InputStream getJavascriptProxyFileAsStream() throws IOException { + return null; + } + + public String createJavascriptReference(ComponentReference componentReference) throws IOException { + Binding binding = componentReference.getBindings().get(0); + URI targetURI = URI.create(binding.getURI()); + String targetPath = targetURI.getPath(); + + return "dojo.rpc.JsonService(\"" + targetPath + "?smd\")"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory new file mode 100644 index 0000000000..90a9e0a9d8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js-dojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the Javascript Proxy Factory +org.apache.tuscany.sca.binding.jsonrpc.js.dojo.JSONRPCBindingJavascriptProxyFactoryImpl;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.jsonrpc,model=org.apache.tuscany.sca.binding.atom.AtomBinding,model=org.apache.tuscany.sca.binding.atom.JSONRPCBinding \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/pom.xml new file mode 100644 index 0000000000..2f9c543aad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-jsonrpc-js + Apache Tuscany SCA JSON-RPC Binding JavaScript + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-web-javascript + 1.6-SNAPSHOT + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.jsonrpc-js + ${pom.name} + org.apache.tuscany.sca.binding.jsonrpc.js* + org.apache.tuscany.sca.assembly.xml;version="1.4", * + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/JSONRPCBindingJavascriptProxyFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/JSONRPCBindingJavascriptProxyFactoryImpl.java new file mode 100644 index 0000000000..b0fd4d9556 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/JSONRPCBindingJavascriptProxyFactoryImpl.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.sca.binding.jsonrpc.js; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; +import org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory; + +public class JSONRPCBindingJavascriptProxyFactoryImpl implements JavascriptProxyFactory { + private static final QName NAME = new QName("http://tuscany.apache.org/xmlns/sca/1.0", "binding.jsonrpc"); + private static final String JAVASCRIPT_FILE_NAME = "binding-jsonrpc.js"; + + public Class getModelType() { + return JSONRPCBinding.class; + } + + public QName getQName() { + return NAME; + } + + public String getJavascriptProxyFile() { + return JAVASCRIPT_FILE_NAME; + } + + public InputStream getJavascriptProxyFileAsStream() throws IOException { + InputStream is = this.getClass().getClassLoader().getResourceAsStream(JAVASCRIPT_FILE_NAME); + if (is == null) { + throw new IOException("Could not find Javascript '" + JAVASCRIPT_FILE_NAME + "'" ); + } + + return is; + } + + public String createJavascriptReference(ComponentReference componentReference) throws IOException { + Binding binding = componentReference.getBindings().get(0); + URI targetURI = URI.create(binding.getURI()); + String targetPath = targetURI.getPath(); + + return "JSONRpcClient(\"" + targetPath + "\").Service"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory new file mode 100644 index 0000000000..812afe568a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/resources/META-INF/services/org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the Javascript Proxy Factory +org.apache.tuscany.sca.binding.jsonrpc.js.JSONRPCBindingJavascriptProxyFactoryImpl;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.jsonrpc,model=org.apache.tuscany.sca.binding.atom.AtomBinding,model=org.apache.tuscany.sca.binding.atom.JSONRPCBinding \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/resources/binding-jsonrpc.js b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/resources/binding-jsonrpc.js new file mode 100644 index 0000000000..ca3c2a8605 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-js/src/main/resources/binding-jsonrpc.js @@ -0,0 +1,492 @@ +/* + * JSON-RPC JavaScript client + * + * $Id: jsonrpc.js,v 1.36.2.3 2006/03/08 15:09:37 mclark Exp $ + * + * Copyright (c) 2003-2004 Jan-Klaas Kollhof + * Copyright (c) 2005 Michael Clark, Metaparadigm Pte Ltd + * + * This code is based on Jan-Klaas' JavaScript o lait library (jsolait). + * + * 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. + * + */ + +/* + * Modifications for Apache Tuscany: + * - JSONRpcClient_createMethod changed so callback is last arg + */ + +/* escape a character */ + +escapeJSONChar = +function escapeJSONChar(c) +{ + if(c == "\"" || c == "\\") return "\\" + c; + else if (c == "\b") return "\\b"; + else if (c == "\f") return "\\f"; + else if (c == "\n") return "\\n"; + else if (c == "\r") return "\\r"; + else if (c == "\t") return "\\t"; + var hex = c.charCodeAt(0).toString(16); + if(hex.length == 1) return "\\u000" + hex; + else if(hex.length == 2) return "\\u00" + hex; + else if(hex.length == 3) return "\\u0" + hex; + else return "\\u" + hex; +}; + + +/* encode a string into JSON format */ + +escapeJSONString = +function escapeJSONString(s) +{ + /* The following should suffice but Safari's regex is b0rken + (doesn't support callback substitutions) + return "\"" + s.replace(/([^\u0020-\u007f]|[\\\"])/g, + escapeJSONChar) + "\""; + */ + + /* Rather inefficient way to do it */ + var parts = s.split(""); + for(var i=0; i < parts.length; i++) { + var c =parts[i]; + if(c == '"' || + c == '\\' || + c.charCodeAt(0) < 32 || + c.charCodeAt(0) >= 128) + parts[i] = escapeJSONChar(parts[i]); + } + return "\"" + parts.join("") + "\""; +}; + + +/* Marshall objects to JSON format */ + +toJSON = function toJSON(o) +{ + if(o == null) { + return "null"; + } else if(o.constructor == String) { + return escapeJSONString(o); + } else if(o.constructor == Number) { + return o.toString(); + } else if(o.constructor == Boolean) { + return o.toString(); + } else if(o.constructor == Date) { + return '{javaClass: "java.util.Date", time: ' + o.valueOf() +'}'; + } else if(o.constructor == Array) { + var v = []; + for(var i = 0; i < o.length; i++) v.push(toJSON(o[i])); + return "[" + v.join(", ") + "]"; + } else { + var v = []; + for(attr in o) { + if(o[attr] == null) v.push("\"" + attr + "\": null"); + else if(typeof o[attr] == "function"); /* skip */ + else v.push(escapeJSONString(attr) + ": " + toJSON(o[attr])); + } + return "{" + v.join(", ") + "}"; + } +}; + + +/* JSONRpcClient constructor */ + +JSONRpcClient = +function JSONRpcClient_ctor(serverURL, user, pass, objectID) +{ + this.serverURL = serverURL; + this.user = user; + this.pass = pass; + this.objectID = objectID; + + /* Add standard methods */ + if(this.objectID) { + this._addMethods(["listMethods"]); + var req = this._makeRequest("listMethods", []); + } else { + this._addMethods(["system.listMethods"]); + var req = this._makeRequest("system.listMethods", []); + } + var m = this._sendRequest(req); + this._addMethods(m); +}; + + +/* JSONRpcCLient.Exception */ + +JSONRpcClient.Exception = +function JSONRpcClient_Exception_ctor(code, message, javaStack) +{ + this.code = code; + var name; + if(javaStack) { + this.javaStack = javaStack; + var m = javaStack.match(/^([^:]*)/); + if(m) name = m[0]; + } + if(name) this.name = name; + else this.name = "JSONRpcClientException"; + this.message = message; +}; + +JSONRpcClient.Exception.CODE_REMOTE_EXCEPTION = 490; +JSONRpcClient.Exception.CODE_ERR_CLIENT = 550; +JSONRpcClient.Exception.CODE_ERR_PARSE = 590; +JSONRpcClient.Exception.CODE_ERR_NOMETHOD = 591; +JSONRpcClient.Exception.CODE_ERR_UNMARSHALL = 592; +JSONRpcClient.Exception.CODE_ERR_MARSHALL = 593; + +JSONRpcClient.Exception.prototype = new Error(); + +JSONRpcClient.Exception.prototype.toString = +function JSONRpcClient_Exception_toString(code, msg) +{ + return this.name + ": " + this.message; +}; + + +/* Default top level exception handler */ + +JSONRpcClient.default_ex_handler = +function JSONRpcClient_default_ex_handler(e) { alert(e); }; + + +/* Client settable variables */ + +JSONRpcClient.toplevel_ex_handler = JSONRpcClient.default_ex_handler; +JSONRpcClient.profile_async = false; +JSONRpcClient.max_req_active = 1; +JSONRpcClient.requestId = 1; + + +/* JSONRpcClient implementation */ + +JSONRpcClient.prototype._createMethod = +function JSONRpcClient_createMethod(methodName) +{ + var fn=function() + { + var args = []; + var callback = null; + for(var i=0;i 0) { + var res = JSONRpcClient.async_responses.shift(); + if(res.canceled) continue; + if(res.profile) res.profile.dispatch = new Date(); + try { + res.cb(res.result, res.ex, res.profile); + } catch(e) { + JSONRpcClient.toplevel_ex_handler(e); + } + } + + while(JSONRpcClient.async_requests.length > 0 && + JSONRpcClient.num_req_active < JSONRpcClient.max_req_active) { + var req = JSONRpcClient.async_requests.shift(); + if(req.canceled) continue; + req.client._sendRequest.call(req.client, req); + } +}; + +JSONRpcClient.kick_async = +function JSONRpcClient_kick_async() +{ + if(JSONRpcClient.async_timeout == null) + JSONRpcClient.async_timeout = + setTimeout(JSONRpcClient._async_handler, 0); +}; + +JSONRpcClient.cancelRequest = +function JSONRpcClient_cancelRequest(requestId) +{ + /* If it is in flight then mark it as canceled in the inflight map + and the XMLHttpRequest callback will discard the reply. */ + if(JSONRpcClient.async_inflight[requestId]) { + JSONRpcClient.async_inflight[requestId].canceled = true; + return true; + } + + /* If its not in flight yet then we can just mark it as canceled in + the the request queue and it will get discarded before being sent. */ + for(var i in JSONRpcClient.async_requests) { + if(JSONRpcClient.async_requests[i].requestId == requestId) { + JSONRpcClient.async_requests[i].canceled = true; + return true; + } + } + + /* It may have returned from the network and be waiting for its callback + to be dispatched, so mark it as canceled in the response queue + and the response will get discarded before calling the callback. */ + for(var i in JSONRpcClient.async_responses) { + if(JSONRpcClient.async_responses[i].requestId == requestId) { + JSONRpcClient.async_responses[i].canceled = true; + return true; + } + } + + return false; +}; + +JSONRpcClient.prototype._makeRequest = +function JSONRpcClient_makeRequest(methodName, args, cb) +{ + var req = {}; + req.client = this; + req.requestId = JSONRpcClient.requestId++; + + var obj = {}; + obj.id = req.requestId; + if (this.objectID) + obj.method = ".obj#" + this.objectID + "." + methodName; + else + obj.method = methodName; + obj.params = args; + + if (cb) req.cb = cb; + if (JSONRpcClient.profile_async) + req.profile = { "submit": new Date() }; + req.data = toJSON(obj); + + return req; +}; + +JSONRpcClient.prototype._sendRequest = +function JSONRpcClient_sendRequest(req) +{ + if(req.profile) req.profile.start = new Date(); + + /* Get free http object from the pool */ + var http = JSONRpcClient.poolGetHTTPRequest(); + JSONRpcClient.num_req_active++; + + /* Send the request */ + if (typeof(this.user) == "undefined") { + http.open("POST", this.serverURL, (req.cb != null)); + } else { + http.open("POST", this.serverURL, (req.cb != null), this.user, this.pass); + } + + /* setRequestHeader is missing in Opera 8 Beta */ + try { http.setRequestHeader("Content-type", "text/plain"); } catch(e) {} + + /* Construct call back if we have one */ + if(req.cb) { + var self = this; + http.onreadystatechange = function() { + if(http.readyState == 4) { + http.onreadystatechange = function () {}; + var res = { "cb": req.cb, "result": null, "ex": null}; + if (req.profile) { + res.profile = req.profile; + res.profile.end = new Date(); + } + try { res.result = self._handleResponse(http); } + catch(e) { res.ex = e; } + if(!JSONRpcClient.async_inflight[req.requestId].canceled) + JSONRpcClient.async_responses.push(res); + delete JSONRpcClient.async_inflight[req.requestId]; + JSONRpcClient.kick_async(); + } + }; + } else { + http.onreadystatechange = function() {}; + } + + JSONRpcClient.async_inflight[req.requestId] = req; + + try { + http.send(req.data); + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + if(!req.cb) return this._handleResponse(http); +}; + +JSONRpcClient.prototype._handleResponse = +function JSONRpcClient_handleResponse(http) +{ + /* Get the charset */ + if(!this.charset) { + this.charset = JSONRpcClient._getCharsetFromHeaders(http); + } + + /* Get request results */ + var status, statusText, data; + try { + status = http.status; + statusText = http.statusText; + data = http.responseText; + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + JSONRpcClient.kick_async(); + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + /* Return http object to the pool; */ + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + + /* Unmarshall the response */ + if(status != 200) { + throw new JSONRpcClient.Exception(status, statusText); + } + var obj; + try { + eval("obj = " + data); + } catch(e) { + throw new JSONRpcClient.Exception(550, "error parsing result"); + } + if(obj.error) + throw new JSONRpcClient.Exception(obj.error.code, obj.error.msg, + obj.error.trace); + var res = obj.result; + + /* Handle CallableProxy */ + if(res && res.objectID && res.JSONRPCType == "CallableReference") + return new JSONRpcClient(this.serverURL, this.user, + this.pass, res.objectID); + + return res; +}; + + +/* XMLHttpRequest wrapper code */ + +/* XMLHttpRequest pool globals */ +JSONRpcClient.http_spare = []; +JSONRpcClient.http_max_spare = 8; + +JSONRpcClient.poolGetHTTPRequest = +function JSONRpcClient_pool_getHTTPRequest() +{ + if(JSONRpcClient.http_spare.length > 0) { + return JSONRpcClient.http_spare.pop(); + } + return JSONRpcClient.getHTTPRequest(); +}; + +JSONRpcClient.poolReturnHTTPRequest = +function JSONRpcClient_poolReturnHTTPRequest(http) +{ + if(JSONRpcClient.http_spare.length >= JSONRpcClient.http_max_spare) + delete http; + else + JSONRpcClient.http_spare.push(http); +}; + +JSONRpcClient.msxmlNames = [ "MSXML2.XMLHTTP.5.0", + "MSXML2.XMLHTTP.4.0", + "MSXML2.XMLHTTP.3.0", + "MSXML2.XMLHTTP", + "Microsoft.XMLHTTP" ]; + +JSONRpcClient.getHTTPRequest = +function JSONRpcClient_getHTTPRequest() +{ + /* Mozilla XMLHttpRequest */ + try { + JSONRpcClient.httpObjectName = "XMLHttpRequest"; + return new XMLHttpRequest(); + } catch(e) {} + + /* Microsoft MSXML ActiveX */ + for (var i=0;i < JSONRpcClient.msxmlNames.length; i++) { + try { + JSONRpcClient.httpObjectName = JSONRpcClient.msxmlNames[i]; + return new ActiveXObject(JSONRpcClient.msxmlNames[i]); + } catch (e) {} + } + + /* None found */ + JSONRpcClient.httpObjectName = null; + throw new JSONRpcClient.Exception(0, "Can't create XMLHttpRequest object"); +}; diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/pom.xml new file mode 100644 index 0000000000..2284282fc3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/pom.xml @@ -0,0 +1,164 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-jsonrpc-runtime + Apache Tuscany SCA JSON-RPC Binding Runtime + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-json + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + + com.metaparadigm + json-rpc + 1.0 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + commons-logging + commons-logging + 1.1.1 + + + commons-logging + commons-logging + + + javax.servlet + servlet-api + + + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + httpunit + httpunit + 1.6.1 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.jsonrpc.runtime + ${pom.name} + + !org.apache.tuscany.sca.binding.jsonrpc, + org.apache.tuscany.sca.binding.jsonrpc* + + + org.apache.tuscany.sca.assembly.xml, + org.apache.tuscany.sca.binding.jsonrpc, + * + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java new file mode 100644 index 0000000000..a9fff462fa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.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.sca.binding.jsonrpc.provider; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Invoker for the JSONRPC Binding + * + * @version $Rev$ $Date$ + */ +public class JSONRPCBindingInvoker implements Invoker { + Operation operation; + String uri; + + public JSONRPCBindingInvoker(Operation operation, String uri) { + this.operation = operation; + this.uri = uri; + } + + public Message invoke(Message msg) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java new file mode 100644 index 0000000000..245eade7ad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.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.sca.binding.jsonrpc.provider; + +import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * JSON-RPC Provider Factory + * + * @version $Rev$ $Date$ + */ +public class JSONRPCBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private ServletHost servletHost; + + public JSONRPCBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + messageFactory = modelFactories.getFactory(MessageFactory.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + JSONRPCBinding binding) { + + return new JSONRPCReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + JSONRPCBinding binding) { + return new JSONRPCServiceBindingProvider(component, service, binding, messageFactory, servletHost); + } + + public Class getModelType() { + return JSONRPCBinding.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java new file mode 100644 index 0000000000..e2528f59e5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.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.sca.binding.jsonrpc.provider; + +import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the JSONRPC Binding Provider for References + * + * @version $Rev$ $Date$ + */ +public class JSONRPCReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private JSONRPCBinding binding; + + public JSONRPCReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + JSONRPCBinding binding) { + this.reference = reference; + this.binding = binding; + + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public Invoker createInvoker(Operation operation) { + return new JSONRPCBindingInvoker(operation, binding.getURI()); + } + + public void start() { + // TODO Auto-generated method stub + + } + + public void stop() { + // TODO Auto-generated method stub + + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java new file mode 100644 index 0000000000..909bd7bc19 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.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.sca.binding.jsonrpc.provider; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; +import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; +import org.apache.tuscany.sca.databinding.json.JSONDataBinding; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the JSONRPC Binding Provider for Services + * + * @version $Rev$ $Date$ + */ +public class JSONRPCServiceBindingProvider implements ServiceBindingProvider { + + // Path to the scaDomain.js script + // Note: this is the same as the Ajax binding to keep the client code + // the same for clients using either the ajax or jsonrpc binding + private static final String SCA_DOMAIN_SCRIPT = "/SCADomain/scaDomain.js"; + + private MessageFactory messageFactory; + + private RuntimeComponent component; + private RuntimeComponentService service; + private InterfaceContract serviceContract; + private JSONRPCBinding binding; + private ServletHost servletHost; + private List servletMappings = new ArrayList(); + private String domainScriptMapping; + + public JSONRPCServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + JSONRPCBinding binding, + MessageFactory messageFactory, + ServletHost servletHost) { + this.component = component; + this.service = service; + this.binding = binding; + this.messageFactory = messageFactory; + this.servletHost = servletHost; + + //clone the service contract to avoid databinding issues + try { + this.serviceContract = (InterfaceContract)service.getInterfaceContract().clone(); + } catch(CloneNotSupportedException e) { + this.serviceContract = service.getInterfaceContract(); + } + + setDataBinding(serviceContract.getInterface()); + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + // Set default databinding to json + serviceContract.getInterface().resetDataBinding(JSONDataBinding.NAME); + + // Determine the service business interface + Class serviceInterface = getTargetJavaClass(serviceContract.getInterface()); + + // Create a Java proxy to the target service + Object proxy = component.getComponentContext().createSelfReference(serviceInterface, service).getService(); + + // Create and register a Servlet for this service + JSONRPCServiceServlet serviceServlet = + new JSONRPCServiceServlet(messageFactory, binding, service, serviceContract, serviceInterface, proxy); + String mapping = binding.getURI(); + if (!mapping.endsWith("/")) { + mapping += "/"; + } + if (!mapping.endsWith("*")) { + mapping += "*"; + } + + servletHost.addServletMapping(mapping, serviceServlet); + servletMappings.add(mapping); + servletHost.addServletMapping(binding.getURI(), serviceServlet); + servletMappings.add(binding.getURI()); + + // Register service to scaDomain.js + int port; + URI uri = URI.create(servletHost.getURLMapping(binding.getURI()).toString()); + port = uri.getPort(); + if (port == -1) { + port = servletHost.getDefaultPort(); + } + + // get the ScaDomainScriptServlet, if it doesn't yet exist create one + // this uses removeServletMapping / addServletMapping as there is no getServletMapping facility + domainScriptMapping = URI.create("http://localhost:" + port + SCA_DOMAIN_SCRIPT).toString(); + ScaDomainScriptServlet scaDomainServlet = + (ScaDomainScriptServlet)servletHost.getServletMapping(domainScriptMapping); + if (scaDomainServlet == null) { + scaDomainServlet = new ScaDomainScriptServlet(); + servletHost.addServletMapping(domainScriptMapping, scaDomainServlet); + } + + // Add this service to the SCA Domain Script Servlet + scaDomainServlet.addService(binding.getName()); + } + + public void stop() { + + // Remove the Servlet mappings we've added + for (String mapping: servletMappings) { + servletHost.removeServletMapping(mapping); + } + + // Unregister the service from the SCA Domain Script Servlet + ScaDomainScriptServlet scaDomainServlet = (ScaDomainScriptServlet) servletHost.getServletMapping(domainScriptMapping); + if (scaDomainServlet != null) { + scaDomainServlet.removeService(binding.getName()); + + // Remove the Servlet if there's no more registered services + if (scaDomainServlet.getServiceNames().isEmpty()) { + servletHost.removeServletMapping(domainScriptMapping); + } + } + + } + + private Class getTargetJavaClass(Interface targetInterface) { + // TODO: right now assume that the target is always a Java + // Implementation. Need to figure out how to generate Java + // Interface in cases where the target is not a Java Implementation + return ((JavaInterface)targetInterface).getJavaClass(); + } + + private void setDataBinding(Interface interfaze) { + List operations = interfaze.getOperations(); + for (Operation operation : operations) { + operation.setDataBinding(JSONDataBinding.NAME); + DataType> inputType = operation.getInputType(); + if (inputType != null) { + List logical = inputType.getLogical(); + for (DataType inArg : logical) { + if (!SimpleJavaDataBinding.NAME.equals(inArg.getDataBinding())) { + inArg.setDataBinding(JSONDataBinding.NAME); + } + } + } + DataType outputType = operation.getOutputType(); + if (outputType != null) { + if (!SimpleJavaDataBinding.NAME.equals(outputType.getDataBinding())) { + outputType.setDataBinding(JSONDataBinding.NAME); + } + } + } + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java new file mode 100644 index 0000000000..346a51e5e7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java @@ -0,0 +1,316 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jsonrpc.provider; + +import java.io.BufferedReader; +import java.io.CharArrayWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.List; + +import javax.servlet.ServletConfig; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.json.JSONArray; +import org.json.JSONObject; +import org.osoa.sca.ServiceRuntimeException; + +import com.metaparadigm.jsonrpc.JSONRPCBridge; +import com.metaparadigm.jsonrpc.JSONRPCResult; +import com.metaparadigm.jsonrpc.JSONRPCServlet; + +/** + * Servlet that handles JSON-RPC requests invoking SCA services. + * + * There is an instance of this Servlet for each + * + * @version $Rev$ $Date$ + */ +public class JSONRPCServiceServlet extends JSONRPCServlet { + private static final long serialVersionUID = 1L; + + transient MessageFactory messageFactory; + + transient Binding binding; + transient String serviceName; + transient Object serviceInstance; + transient RuntimeComponentService componentService; + transient InterfaceContract serviceContract; + transient Class serviceInterface; + + public JSONRPCServiceServlet(MessageFactory messageFactory, + Binding binding, + RuntimeComponentService componentService, + InterfaceContract serviceContract, + Class serviceInterface, + Object serviceInstance) { + this.messageFactory = messageFactory; + this.binding = binding; + this.serviceName = binding.getName(); + this.componentService = componentService; + this.serviceContract = serviceContract; + this.serviceInterface = serviceInterface; + this.serviceInstance = serviceInstance; + } + + /** + * Override to do nothing as the JSONRPCServlet is setup by the + * service method in this class. + */ + @Override + public void init(ServletConfig config) { + } + + @Override + public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { + if ("smd".equals(request.getQueryString())) { + handleSMDRequest(request, response); + } else { + try { + handleServiceRequest(request, response); + + } catch(RuntimeException re) { + if (re.getCause() instanceof javax.security.auth.login.FailedLoginException) { + response.sendError(HttpServletResponse.SC_FORBIDDEN); + }else if (re.getCause() instanceof javax.security.auth.login.LoginException) { + response.setHeader("WWW-Authenticate", "BASIC realm=\"" + "ldap-realm" + "\""); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } + } finally { + HttpSession session = request.getSession(false); + if (session != null) { + session.removeAttribute("JSONRPCBridge"); + } + } + } + } + + private void handleServiceRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { + // Encode using UTF-8, although We are actually ASCII clean as + // all unicode data is JSON escaped using backslash u. This is + // less data efficient for foreign character sets but it is + // needed to support naughty browsers such as Konqueror and Safari + // which do not honour the charset set in the response + response.setContentType("text/plain;charset=utf-8"); + OutputStream out = response.getOutputStream(); + + // Decode using the charset in the request if it exists otherwise + // use UTF-8 as this is what all browser implementations use. + // The JSON-RPC-Java JavaScript client is ASCII clean so it + // although here we can correctly handle data from other clients + // that do not escape non ASCII data + String charset = request.getCharacterEncoding(); + if (charset == null) { + charset = "UTF-8"; + } + BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), charset)); + + // Read the request + CharArrayWriter data = new CharArrayWriter(); + char[] buf = new char[4096]; + int ret; + while ((ret = in.read(buf, 0, 4096)) != -1) { + data.write(buf, 0, ret); + } + + JSONObject jsonReq = null; + String method = null; + try { + jsonReq = new JSONObject(data.toString()); + method = jsonReq.getString("method"); + } catch (Exception e) { + //FIXME Exceptions are not handled correctly here + // They should be reported to the client JavaScript as proper + // JavaScript exceptions. + throw new RuntimeException("Unable to parse request", e); + } + + + // check if it's a system request + // or a method invocation + byte[] bout; + if (method.startsWith("system.")) { + bout = handleJSONRPCSystemInvocation(request, response, data.toString()); + } else { + bout = handleJSONRPCMethodInvocation(request, response, jsonReq); + } + + // Send response to client + out.write(bout); + out.flush(); + out.close(); + } + + /** + * handles requests for the SMD descriptor for a service + */ + protected void handleSMDRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, UnsupportedEncodingException { + String serviceUrl = request.getRequestURL().toString(); + String smd = JavaToSmd.interfaceToSmd(serviceInterface, serviceUrl); + + response.setContentType("text/plain;charset=utf-8"); + OutputStream out = response.getOutputStream(); + byte[] bout = smd.getBytes("UTF-8"); + out.write(bout); + out.flush(); + out.close(); + } + + protected byte[] handleJSONRPCSystemInvocation(HttpServletRequest request, HttpServletResponse response, String requestData) throws IOException, + UnsupportedEncodingException { + /* + * Create a new bridge for every request to avoid all the problems with + * JSON-RPC-Java storing the bridge in the session + */ + HttpSession session = request.getSession(); + + JSONRPCBridge jsonrpcBridge = new JSONRPCBridge(); + jsonrpcBridge.registerObject("Service", serviceInstance, serviceInterface); + session.setAttribute("JSONRPCBridge", jsonrpcBridge); + + org.json.JSONObject jsonReq = null; + com.metaparadigm.jsonrpc.JSONRPCResult jsonResp = null; + try { + jsonReq = new org.json.JSONObject(requestData); + } catch (java.text.ParseException e) { + throw new RuntimeException("Unable to parse request", e); + } + + String method = jsonReq.getString("method"); + if ((method != null) && (method.indexOf('.') < 0)) { + jsonReq.putOpt("method", "Service" + "." + method); + } + + // invoke the request + jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq); + + return jsonResp.toString().getBytes("UTF-8"); + } + + protected byte[] handleJSONRPCMethodInvocation(HttpServletRequest request, HttpServletResponse response, JSONObject jsonReq) throws IOException, + UnsupportedEncodingException { + + String method = null; + Object[] args = null; + Object id = null; + try { + // Extract the method + method = jsonReq.getString("method"); + if ((method != null) && (method.indexOf('.') < 0)) { + jsonReq.putOpt("method", "Service" + "." + method); + } + + // Extract the arguments + JSONArray array = jsonReq.getJSONArray("params"); + args = new Object[array.length()]; + for (int i = 0; i < args.length; i++) { + args[i] = array.get(i); + } + id = jsonReq.get("id"); + + } catch (Exception e) { + throw new RuntimeException("Unable to find json method name", e); + } + + // invoke the request + RuntimeWire wire = componentService.getRuntimeWire(binding, serviceContract); + Operation jsonOperation = findOperation(method); + Object result = null; + + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + requestMessage.setOperation(jsonOperation); + + requestMessage.getHeaders().add(request); + + requestMessage.setBody(args); + + //result = wire.invoke(jsonOperation, args); + Message responseMessage = null; + try { + responseMessage = wire.getInvocationChain(jsonOperation).getHeadInvoker().invoke(requestMessage); + } catch (RuntimeException re) { + if (re.getCause() instanceof javax.security.auth.login.LoginException) { + throw re; + } else { + //some other exception + JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, re); + return errorResult.toString().getBytes("UTF-8"); + } + } + + if (!responseMessage.isFault()) { + //successful execution of the invocation + try { + result = responseMessage.getBody(); + JSONObject jsonResponse = new JSONObject(); + jsonResponse.put("result", result); + jsonResponse.putOpt("id", id); + //get response to send to client + return jsonResponse.toString().getBytes("UTF-8"); + } catch (Exception e) { + throw new ServiceRuntimeException("Unable to create JSON response", e); + } + } else { + //exception thrown while executing the invocation + Throwable exception = (Throwable)responseMessage.getBody(); + JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, exception ); + return errorResult.toString().getBytes("UTF-8"); + } + + } + + /** + * Find the operation from the component service contract + * @param componentService + * @param method + * @return + */ + private Operation findOperation(String method) { + if (method.contains(".")) { + method = method.substring(method.lastIndexOf(".") + 1); + } + + List operations = serviceContract.getInterface().getOperations(); + //componentService.getBindingProvider(binding).getBindingInterfaceContract().getInterface().getOperations(); + + + Operation result = null; + for (Operation o : operations) { + if (o.getName().equalsIgnoreCase(method)) { + result = o; + break; + } + } + + return result; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JavaToSmd.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JavaToSmd.java new file mode 100644 index 0000000000..64339fda7b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JavaToSmd.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.sca.binding.jsonrpc.provider; + +import java.lang.reflect.Method; + +/** + * Utility class to create a Simple Method Description (SMD) descriptor + * from a Java class. See http://dojo.jot.com/SMD. + * + * TODO: Change to work from the Tuscany Interface instead of a Java class + * + * @version $Rev$ $Date$ + */ +class JavaToSmd { + + static String interfaceToSmd(Class klazz, String serviceUrl) { + String name = klazz.getSimpleName(); + Method[] methods = klazz.getMethods(); + + StringBuffer smdSb = new StringBuffer(); + smdSb.append("{\"SMDVersion\":\".1\",\"objectName\":\"" + name + "\",\"serviceType\":\"JSON-RPC\",\"serviceURL\":\""+ serviceUrl + "\",\"methods\":["); + for (int i = 0; i < methods.length; i++) { + if (i != 0) smdSb.append(","); + Class[] params = methods[i].getParameterTypes(); + smdSb.append("{\"name\":\""+methods[i].getName() + "\",\"parameters\":["); + for (int j = 0; j < params.length; j++) { + if (j != 0) smdSb.append(","); + // right now Dojo doesn't look at the type value, so we'll default it to STRING + // also, since we can't introspect the method parameter names we'll just create an incrementing parameter name + smdSb.append("{\"name\":\"param" + j + "\",\"type\":\"STRING\"}"); + } + smdSb.append("]}"); + } + smdSb.append("]}"); + + return smdSb.toString(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/ScaDomainScriptServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/ScaDomainScriptServlet.java new file mode 100644 index 0000000000..999588abf1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/ScaDomainScriptServlet.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jsonrpc.provider; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Servlet to handle requests for the scaDomain.js script. + * + * This script wrappers the JSON-RPC-Java jsonrpc.js script + * adding in at the bottom the JavaScript to create and initialize + * the variables representing the SCA services. + * + * @version $Rev$ $Date$ + */ +public class ScaDomainScriptServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected transient List serviceNames; + + public ScaDomainScriptServlet() { + serviceNames = new ArrayList(); + } + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + + ServletOutputStream os = response.getOutputStream(); + + os.println(); + os.println("/* Apache Tuscany scaDomain.js Header */"); + os.println(); + + writeJSONRPCJavaScript(os); + writeScaDomainCode(os, request.getServletPath()); + } + + /** + * Creates a JavaScript variable within the scaDomain script for each SCA service and + * initializes its value with the JSON-RPC client to invoke the serverside service. + */ + protected void writeScaDomainCode(ServletOutputStream out, String path) throws IOException { + out.println(); + out.println("/* Apache Tuscany scaDomain.js Footer */"); + out.println(); + out.println("function scaDomain() {}"); + + // remove the leading slash '/' character + path = path.substring(1); + + for (String serviceName : serviceNames) { + out.println(); + + // A slight hack to make the service function available with a variable named 'serviceName' + // to do that the JSONRpcClient is added to the scaDomain and then the service function is got from that + out.println("scaDomain." + serviceName + " = " + "new JSONRpcClient(\"" + serviceName + "\");"); + out.println(serviceName + " = scaDomain." + serviceName + ".Service;"); + } + + out.println(); + out.println("/** End of Apache Tuscany scaDomain.js */"); + out.println(); + } + + /** + * Reads the jsonrpc.js script from the classpath and adds its contents to the output stream. + */ + protected void writeJSONRPCJavaScript(ServletOutputStream os) throws IOException { + URL url = getClass().getResource("jsonrpc.js"); + InputStream is = url.openStream(); + int i; + while ((i = is.read()) != -1) { + os.write(i); + } + } + + public void addService(String serviceName) { + serviceNames.add(serviceName); + } + + public void removeService(String serviceName) { + serviceNames.remove(serviceName); + } + + public List getServiceNames() { + return serviceNames; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..4767358e7a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.jsonrpc.provider.JSONRPCBindingProviderFactory;model=org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/provider/jsonrpc.js b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/provider/jsonrpc.js new file mode 100644 index 0000000000..d837bab91c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/provider/jsonrpc.js @@ -0,0 +1,493 @@ +/* + * JSON-RPC JavaScript client + * + * $Id: jsonrpc.js,v 1.36.2.3 2006/03/08 15:09:37 mclark Exp $ + * + * Copyright (c) 2003-2004 Jan-Klaas Kollhof + * Copyright (c) 2005 Michael Clark, Metaparadigm Pte Ltd + * + * This code is based on Jan-Klaas' JavaScript o lait library (jsolait). + * + * 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. + * + */ + +/* + * Modifications for Apache Tuscany: + * - JSONRpcClient_createMethod changed so callback is last arg + */ + +/* escape a character */ + +escapeJSONChar = +function escapeJSONChar(c) +{ + if(c == "\"" || c == "\\") return "\\" + c; + else if (c == "\b") return "\\b"; + else if (c == "\f") return "\\f"; + else if (c == "\n") return "\\n"; + else if (c == "\r") return "\\r"; + else if (c == "\t") return "\\t"; + var hex = c.charCodeAt(0).toString(16); + if(hex.length == 1) return "\\u000" + hex; + else if(hex.length == 2) return "\\u00" + hex; + else if(hex.length == 3) return "\\u0" + hex; + else return "\\u" + hex; +}; + + +/* encode a string into JSON format */ + +escapeJSONString = +function escapeJSONString(s) +{ + /* The following should suffice but Safari's regex is b0rken + (doesn't support callback substitutions) + return "\"" + s.replace(/([^\u0020-\u007f]|[\\\"])/g, + escapeJSONChar) + "\""; + */ + + /* Rather inefficient way to do it */ + var parts = s.split(""); + for(var i=0; i < parts.length; i++) { + var c =parts[i]; + if(c == '"' || + c == '\\' || + c.charCodeAt(0) < 32 || + c.charCodeAt(0) >= 128) + parts[i] = escapeJSONChar(parts[i]); + } + return "\"" + parts.join("") + "\""; +}; + + +/* Marshall objects to JSON format */ + +toJSON = function toJSON(o) +{ + if(o == null) { + return "null"; + } else if(o.constructor == String) { + return escapeJSONString(o); + } else if(o.constructor == Number) { + return o.toString(); + } else if(o.constructor == Boolean) { + return o.toString(); + } else if(o.constructor == Date) { + return '{javaClass: "java.util.Date", time: ' + o.valueOf() +'}'; + } else if(o.constructor == Array) { + var v = []; + for(var i = 0; i < o.length; i++) v.push(toJSON(o[i])); + return "[" + v.join(", ") + "]"; + } else { + var v = []; + for(attr in o) { + if(o[attr] == null) v.push("\"" + attr + "\": null"); + else if(typeof o[attr] == "function"); /* skip */ + else v.push(escapeJSONString(attr) + ": " + toJSON(o[attr])); + } + return "{" + v.join(", ") + "}"; + } +}; + + +/* JSONRpcClient constructor */ + +JSONRpcClient = +function JSONRpcClient_ctor(serverURL, user, pass, objectID) +{ + this.serverURL = serverURL; + this.user = user; + this.pass = pass; + this.objectID = objectID; + + /* Add standard methods */ + if(this.objectID) { + this._addMethods(["listMethods"]); + var req = this._makeRequest("listMethods", []); + } else { + this._addMethods(["system.listMethods"]); + var req = this._makeRequest("system.listMethods", []); + } + var m = this._sendRequest(req); + this._addMethods(m); +}; + + +/* JSONRpcCLient.Exception */ + +JSONRpcClient.Exception = +function JSONRpcClient_Exception_ctor(code, message, javaStack) +{ + this.code = code; + var name; + if(javaStack) { + this.javaStack = javaStack; + var m = javaStack.match(/^([^:]*)/); + if(m) name = m[0]; + } + if(name) this.name = name; + else this.name = "JSONRpcClientException"; + this.message = message; +}; + +JSONRpcClient.Exception.CODE_REMOTE_EXCEPTION = 490; +JSONRpcClient.Exception.CODE_ERR_CLIENT = 550; +JSONRpcClient.Exception.CODE_ERR_PARSE = 590; +JSONRpcClient.Exception.CODE_ERR_NOMETHOD = 591; +JSONRpcClient.Exception.CODE_ERR_UNMARSHALL = 592; +JSONRpcClient.Exception.CODE_ERR_MARSHALL = 593; + +JSONRpcClient.Exception.prototype = new Error(); + +JSONRpcClient.Exception.prototype.toString = +function JSONRpcClient_Exception_toString(code, msg) +{ + return this.name + ": " + this.message; +}; + + +/* Default top level exception handler */ + +JSONRpcClient.default_ex_handler = +function JSONRpcClient_default_ex_handler(e) { alert(e); }; + + +/* Client settable variables */ + +JSONRpcClient.toplevel_ex_handler = JSONRpcClient.default_ex_handler; +JSONRpcClient.profile_async = false; +JSONRpcClient.max_req_active = 1; +JSONRpcClient.requestId = 1; + + +/* JSONRpcClient implementation */ + +JSONRpcClient.prototype._createMethod = +function JSONRpcClient_createMethod(methodName) +{ + var fn=function() + { + var args = []; + var callback = null; + for(var i=0;i 0) { + var res = JSONRpcClient.async_responses.shift(); + if(res.canceled) continue; + if(res.profile) res.profile.dispatch = new Date(); + try { + res.cb(res.result, res.ex, res.profile); + } catch(e) { + JSONRpcClient.toplevel_ex_handler(e); + } + } + + while(JSONRpcClient.async_requests.length > 0 && + JSONRpcClient.num_req_active < JSONRpcClient.max_req_active) { + var req = JSONRpcClient.async_requests.shift(); + if(req.canceled) continue; + req.client._sendRequest.call(req.client, req); + } +}; + +JSONRpcClient.kick_async = +function JSONRpcClient_kick_async() +{ + if(JSONRpcClient.async_timeout == null) + JSONRpcClient.async_timeout = + setTimeout(JSONRpcClient._async_handler, 0); +}; + +JSONRpcClient.cancelRequest = +function JSONRpcClient_cancelRequest(requestId) +{ + /* If it is in flight then mark it as canceled in the inflight map + and the XMLHttpRequest callback will discard the reply. */ + if(JSONRpcClient.async_inflight[requestId]) { + JSONRpcClient.async_inflight[requestId].canceled = true; + return true; + } + + /* If its not in flight yet then we can just mark it as canceled in + the the request queue and it will get discarded before being sent. */ + for(var i in JSONRpcClient.async_requests) { + if(JSONRpcClient.async_requests[i].requestId == requestId) { + JSONRpcClient.async_requests[i].canceled = true; + return true; + } + } + + /* It may have returned from the network and be waiting for its callback + to be dispatched, so mark it as canceled in the response queue + and the response will get discarded before calling the callback. */ + for(var i in JSONRpcClient.async_responses) { + if(JSONRpcClient.async_responses[i].requestId == requestId) { + JSONRpcClient.async_responses[i].canceled = true; + return true; + } + } + + return false; +}; + +JSONRpcClient.prototype._makeRequest = +function JSONRpcClient_makeRequest(methodName, args, cb) +{ + var req = {}; + req.client = this; + req.requestId = JSONRpcClient.requestId++; + + var obj = {}; + obj.id = req.requestId; + if (this.objectID) + obj.method = ".obj#" + this.objectID + "." + methodName; + else + obj.method = methodName; + obj.params = args; + + if (cb) req.cb = cb; + if (JSONRpcClient.profile_async) + req.profile = { "submit": new Date() }; + req.data = toJSON(obj); + + return req; +}; + +JSONRpcClient.prototype._sendRequest = +function JSONRpcClient_sendRequest(req) +{ + if(req.profile) req.profile.start = new Date(); + + /* Get free http object from the pool */ + var http = JSONRpcClient.poolGetHTTPRequest(); + JSONRpcClient.num_req_active++; + + /* Send the request */ + if (typeof(this.user) == "undefined") { + http.open("POST", this.serverURL, (req.cb != null)); + } else { + http.open("POST", this.serverURL, (req.cb != null), this.user, this.pass); + } + + /* setRequestHeader is missing in Opera 8 Beta */ + try { http.setRequestHeader("Content-type", "text/plain"); } catch(e) {} + + /* Construct call back if we have one */ + if(req.cb) { + var self = this; + http.onreadystatechange = function() { + if(http.readyState == 4) { + http.onreadystatechange = function () {}; + var res = { "cb": req.cb, "result": null, "ex": null}; + if (req.profile) { + res.profile = req.profile; + res.profile.end = new Date(); + } + try { res.result = self._handleResponse(http); } + catch(e) { res.ex = e; } + if(!JSONRpcClient.async_inflight[req.requestId].canceled) + JSONRpcClient.async_responses.push(res); + delete JSONRpcClient.async_inflight[req.requestId]; + JSONRpcClient.kick_async(); + } + }; + } else { + http.onreadystatechange = function() {}; + } + + JSONRpcClient.async_inflight[req.requestId] = req; + + try { + http.send(req.data); + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + if(!req.cb) return this._handleResponse(http); +}; + +JSONRpcClient.prototype._handleResponse = +function JSONRpcClient_handleResponse(http) +{ + /* Get the charset */ + if(!this.charset) { + this.charset = JSONRpcClient._getCharsetFromHeaders(http); + } + + /* Get request results */ + var status, statusText, data; + try { + status = http.status; + statusText = http.statusText; + data = http.responseText; + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + JSONRpcClient.kick_async(); + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + /* Return http object to the pool; */ + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + + /* Unmarshall the response */ + if(status != 200) { + throw new JSONRpcClient.Exception(status, statusText); + } + var obj; + try { + eval("obj = " + data); + } catch(e) { + throw new JSONRpcClient.Exception(550, "error parsing result"); + } + if(obj.error) + throw new JSONRpcClient.Exception(obj.error.code, obj.error.msg, + obj.error.trace); + var res = obj.result; + + /* Handle CallableProxy */ + if(res && res.objectID && res.JSONRPCType == "CallableReference") + return new JSONRpcClient(this.serverURL, this.user, + this.pass, res.objectID); + + return res; +}; + + +/* XMLHttpRequest wrapper code */ + +/* XMLHttpRequest pool globals */ +JSONRpcClient.http_spare = []; +JSONRpcClient.http_max_spare = 8; + +JSONRpcClient.poolGetHTTPRequest = +function JSONRpcClient_pool_getHTTPRequest() +{ + if(JSONRpcClient.http_spare.length > 0) { + return JSONRpcClient.http_spare.pop(); + } + return JSONRpcClient.getHTTPRequest(); +}; + +JSONRpcClient.poolReturnHTTPRequest = +function JSONRpcClient_poolReturnHTTPRequest(http) +{ + if(JSONRpcClient.http_spare.length >= JSONRpcClient.http_max_spare) + delete http; + else + JSONRpcClient.http_spare.push(http); +}; + +JSONRpcClient.msxmlNames = [ "MSXML2.XMLHTTP.5.0", + "MSXML2.XMLHTTP.4.0", + "MSXML2.XMLHTTP.3.0", + "MSXML2.XMLHTTP", + "Microsoft.XMLHTTP" ]; + +JSONRpcClient.getHTTPRequest = +function JSONRpcClient_getHTTPRequest() +{ + /* Mozilla XMLHttpRequest */ + try { + JSONRpcClient.httpObjectName = "XMLHttpRequest"; + return new XMLHttpRequest(); + } catch(e) {} + + /* Microsoft MSXML ActiveX */ + for (var i=0;i < JSONRpcClient.msxmlNames.length; i++) { + try { + JSONRpcClient.httpObjectName = JSONRpcClient.msxmlNames[i]; + return new ActiveXObject(JSONRpcClient.msxmlNames[i]); + } catch (e) {} + } + + /* None found */ + JSONRpcClient.httpObjectName = null; + throw new JSONRpcClient.Exception(0, "Can't create XMLHttpRequest object"); +}; + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java new file mode 100644 index 0000000000..4b159fb563 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.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 bean; + +public class TestBean { + private String testString; + private String[] testStringArray; + private int testInt; + + + public String getTestString() { + return testString; + } + + public void setTestString(String testString) { + this.testString = testString; + } + + public String[] getTestStringArray() { + return testStringArray; + } + + public void setStringArray(String[] stringArray) { + this.testStringArray = stringArray; + } + + public int getTestInt() { + return testInt; + } + + public void setTestInt(int testInt) { + this.testInt = testInt; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java new file mode 100644 index 0000000000..580af6cf31 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.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 echo; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.osoa.sca.annotations.Remotable; + +import bean.TestBean; + +/** + * Interface of our sample JSONRPC service. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Echo { + + String echo(String msg); + + void echoRuntimeException() throws RuntimeException; + + void echoBusinessException() throws EchoBusinessException; + + int echoInt(int param); + + boolean echoBoolean(boolean param); + + Map echoMap(HashMap map); + + TestBean echoBean(TestBean testBean); + + List echoList(ArrayList list); + + String [] echoArrayString(String[] stringArray); + + int [] echoArrayInt(int[] intArray); + + Set echoSet(HashSet set); + + void get\u03a9\u03bb\u03c0(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoBusinessException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoBusinessException.java new file mode 100644 index 0000000000..bf8c7d2c8a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoBusinessException.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 echo; + +public class EchoBusinessException extends Exception { + private static final long serialVersionUID = 7234119326657905710L; + + public EchoBusinessException(String message) + { + super(message); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java new file mode 100644 index 0000000000..2f4880286f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package echo; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import bean.TestBean; + +/** + * A simple client component that uses a reference with an JSONRPC binding. + * + * @version $Rev$ $Date$ + */ +public class EchoComponentImpl implements Echo { + + public String echo(String msg) { + System.out.println("Echo: "+ msg); + return "echo: " + msg; + } + + public void echoBusinessException() throws EchoBusinessException { + throw new EchoBusinessException("Business Exception"); + + } + + public void echoRuntimeException() throws RuntimeException { + throw new RuntimeException("Runtime Exception"); + } + + public int echoInt(int param) { + int value = param; + return value; + } + + public boolean echoBoolean(boolean param) { + boolean value = param; + return value; + } + + public Map echoMap(HashMap param) { + Map map = new HashMap(); + map = param; + return map; + } + + public TestBean echoBean(TestBean testBean1) { + TestBean testBean = new TestBean(); + testBean.setTestString(testBean1.getTestString()); + testBean.setTestInt(testBean1.getTestInt()); + return testBean; + } + + public List echoList(ArrayList param){ + List list = new ArrayList(); + for(Iterator itr = param.iterator();itr.hasNext();) + { + list.add(itr.next()); + } + return list; + } + + public String[] echoArrayString(String[] stringArray) { + return stringArray; + } + + public int[] echoArrayInt(int[] intArray) { + return intArray; + } + + public Set echoSet(HashSet param){ + Set set = new HashSet(); + set = param; + return set; + + } + + + public void get\u03a9\u03bb\u03c0() { + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java new file mode 100644 index 0000000000..6d156fcdf5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jsonrpc; + +import java.io.ByteArrayInputStream; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.json.JSONObject; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.meterware.httpunit.PostMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +/** + * @version $Rev$ $Date$ + */ +public class JSONRPCDataTypeTestCase { + + private static final String SERVICE_PATH = "/EchoService"; + private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH; + private SCADomain domain; + + @Before + public void setUp() throws Exception { + domain = SCADomain.newInstance("JSONRPCBinding.composite"); + } + + @After + public void tearDown() throws Exception { + domain.close(); + } + + @Test + public void testInt() throws Exception { + JSONObject jsonRequest = new JSONObject( + "{ \"method\": \"echoInt\", \"params\": [12345], \"id\": 4}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest(SERVICE_URL, + new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonResp = new JSONObject(response.getText()); + + Assert.assertEquals(12345, jsonResp.getInt("result")); + } + + @Test + public void testBoolean() throws Exception { + JSONObject jsonRequest = new JSONObject( + "{ \"method\": \"echoBoolean\", \"params\": [true], \"id\": 5}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest(SERVICE_URL, + new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonResp = new JSONObject(response.getText()); + + Assert.assertEquals(true, jsonResp.getBoolean("result")); + } + + @Test + public void testMap() throws Exception { + JSONObject jsonRequest = new JSONObject( + "{ \"method\": \"echoMap\", \"params\": [ {\"javaClass\": \"java.util.HashMap\", \"map\": { \"Binding\": \"JSON-RPC\"}}], \"id\": 6}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest(SERVICE_URL, + new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonResp = new JSONObject(response.getText()); + + Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getJSONObject("map").getString("Binding")); + } + + @Test + public void testBean() throws Exception { + JSONObject jsonRequest = new JSONObject( + "{ \"method\": \"echoBean\", \"params\": [ {\"javaClass\": \"bean.TestBean\", \"testString\": \"JSON-RPC\", \"testInt\":1234}], \"id\": 7}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest(SERVICE_URL, + new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonResp = new JSONObject(response.getText()); + + Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getString("testString")); + } + + @Test + public void testList() throws Exception { + JSONObject jsonRequest = new JSONObject( + "{ \"method\": \"echoList\", \"params\": [ {\"javaClass\": \"java.util.ArrayList\", \"list\": [0,1,2,3,4]}], \"id\": 8}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest(SERVICE_URL, + new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonResp = new JSONObject(response.getText()); + + Assert.assertEquals(0, jsonResp.getJSONObject("result").getJSONArray("list").get(0)); + } + + @Test + public void testArrayString() throws Exception { + JSONObject jsonRequest = new JSONObject( + "{\"params\":[[\"1\",\"2\"]],\"method\":\"echoArrayString\",\"id\":9}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest(SERVICE_URL, + new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonResp = new JSONObject(response.getText()); + + Assert.assertEquals(1, jsonResp.getJSONArray("result").getInt(0)); + } + + + @Test + public void testArrayInt() throws Exception { + JSONObject jsonRequest = new JSONObject( + "{\"params\":[[1,2]],\"method\":\"echoArrayInt\",\"id\":10}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest(SERVICE_URL, + new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonResp = new JSONObject(response.getText()); + + Assert.assertEquals(1, jsonResp.getJSONArray("result").getInt(0)); + } + + + @Test + public void testSet() throws Exception { + JSONObject jsonRequest = new JSONObject( + "{ \"method\": \"echoSet\", \"params\": [ {\"javaClass\": \"java.util.HashSet\", \"set\": {\"1\": \"red\", \"2\": \"blue\"}}],\"id\": 11}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest(SERVICE_URL, + new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonResp = new JSONObject(response.getText()); + + Assert.assertEquals("red", jsonResp.getJSONObject("result").getJSONObject("set").getString("red")); + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java new file mode 100644 index 0000000000..52518e1bbc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jsonrpc; + +import java.io.ByteArrayInputStream; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.json.JSONObject; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.meterware.httpunit.PostMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +/** + * @version $Rev$ $Date$ + */ +public class JSONRPCExceptionTestCase{ + + private static final String SERVICE_PATH = "/EchoService"; + + private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH; + + private SCADomain domain; + + @Before + public void setUp() throws Exception { + domain = SCADomain.newInstance("JSONRPCBinding.composite"); + } + + @After + public void tearDown() throws Exception { + domain.close(); + } + + @Test + public void testRuntimeException() throws Exception{ + JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoRuntimeException\", \"params\": [], \"id\": 2}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonErr = new JSONObject(response.getText()).getJSONObject("error"); + + Assert.assertEquals("Runtime Exception", jsonErr.getString("msg")); + } + + @Test + public void testBusinessException() throws Exception{ + JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoBusinessException\", \"params\": [], \"id\": 3}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonErr = new JSONObject(response.getText()).getJSONObject("error"); + + Assert.assertEquals("Business Exception", jsonErr.getString("msg")); + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java new file mode 100644 index 0000000000..67d3eda6b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.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.sca.binding.jsonrpc; + +import java.io.ByteArrayInputStream; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.json.JSONObject; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.meterware.httpunit.PostMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +/** + * @version $Rev$ $Date$ + */ +public class JSONRPCServiceTestCase{ + + private static final String SERVICE_PATH = "/EchoService"; + + private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH; + + private SCADomain domain; + + @Before + public void setUp() throws Exception { + domain = SCADomain.newInstance("JSONRPCBinding.composite"); + } + + @After + public void tearDown() throws Exception { + domain.close(); + } + + @Test + public void testJSONRPCBinding() throws Exception { + JSONObject jsonRequest = new JSONObject("{ \"method\": \"echo\", \"params\": [\"Hello JSON-RPC\"], \"id\": 1}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + + JSONObject jsonResp = new JSONObject(response.getText()); + Assert.assertEquals("echo: Hello JSON-RPC", jsonResp.getString("result")); + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java new file mode 100644 index 0000000000..64c2dd31f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.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.sca.binding.jsonrpc; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +/** + * @version $Rev$ $Date$ + */ +public class JSONRPCSmdTestCase { + + private static final String SERVICE_PATH = "/EchoService"; + + private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH; + + private static final String SMD_URL = SERVICE_URL + "?smd"; + + private static SCADomain domain; + + @Before + public void setUp() throws Exception { + domain = SCADomain.newInstance("JSONRPCBinding.composite"); + } + + @After + public void tearDown() throws Exception { + domain.close(); + } + + @Test + /** + * This test make sure the JSON-RPC Binding can handle special characters when generating SMD + */ + public void testJSONRPCSmdSpecialCharacters() throws Exception { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest(SMD_URL); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + Assert.assertNotNull(response.getText()); + + //System.out.println(">>>SMD:" + response.getText()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite new file mode 100644 index 0000000000..978fdcfa7f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/pom.xml new file mode 100644 index 0000000000..3a6dda7bbf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/pom.xml @@ -0,0 +1,78 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-jsonrpc + Apache Tuscany SCA JSON-RPC Binding Model + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + junit + junit + 4.5 + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.jsonrpc + ${pom.name} + org.apache.tuscany.sca.binding.jsonrpc* + org.apache.tuscany.sca.assembly.xml,* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java new file mode 100644 index 0000000000..ce86365980 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.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.sca.binding.jsonrpc; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * A model for the JSONRPC binding. + * + * @version $Rev$ $Date$ + */ +public interface JSONRPCBinding extends Binding, PolicySetAttachPoint { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingFactory.java new file mode 100644 index 0000000000..707a9d7103 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingFactory.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.sca.binding.jsonrpc; + + +/** + * Factory for the JSON RPC binding model. + * + * @version $Rev$ $Date$ +*/ +public interface JSONRPCBindingFactory { + + /** + * Creates a new JSON RPC Binding + * @return a new JSON RPC Binding + */ + JSONRPCBinding createJSONRPCBinding(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/impl/JSONRPCBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/impl/JSONRPCBindingFactoryImpl.java new file mode 100644 index 0000000000..625457a668 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/impl/JSONRPCBindingFactoryImpl.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.sca.binding.jsonrpc.impl; + +import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; +import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBindingFactory; + + +/** + * Factory for the JSON RPC binding model. + * + * @version $Rev$ $Date$ +*/ +public class JSONRPCBindingFactoryImpl implements JSONRPCBindingFactory { + + public JSONRPCBinding createJSONRPCBinding() { + return new JSONRPCBindingImpl(); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/impl/JSONRPCBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/impl/JSONRPCBindingImpl.java new file mode 100644 index 0000000000..1ee3631a98 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/impl/JSONRPCBindingImpl.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.sca.binding.jsonrpc.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; + +import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; + +/** + * A model for the JSONRPC binding. + * + * @version $Rev$ $Date$ + */ +public class JSONRPCBindingImpl implements JSONRPCBinding { + private String name; + private String uri; + + + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isUnresolved() { + // The binding is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + //Policy related getters/setters + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBindingFactory new file mode 100644 index 0000000000..8b9662997d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for model factory +org.apache.tuscany.sca.binding.jsonrpc.impl.JSONRPCBindingFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..0f39251068 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.jsonrpc,model=org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding,factory=org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBindingFactory diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/pom.xml new file mode 100644 index 0000000000..709f611a52 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/pom.xml @@ -0,0 +1,150 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-notification + Apache Tuscany SCA Notification Binding Extension + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-core + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-implementation-notification + 1.6-SNAPSHOT + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + javax.servlet + servlet-api + 2.5 + provided + + + org.apache.tuscany.sca + tuscany-databinding-axiom + 1.6-SNAPSHOT + runtime + + + org.apache.ws.commons.axiom + axiom-api + + + xerces + xercesImpl + + + 1.2.7 + + + + xerces + xercesImpl + 2.8.1 + runtime + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + junit + junit + 4.5 + test + + + org.easymock + easymock + 2.2 + test + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.7 + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.notification + ${pom.name} + org.apache.tuscany.sca.binding.notification* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/DefaultNotificationBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/DefaultNotificationBindingFactory.java new file mode 100644 index 0000000000..8e6a78551a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/DefaultNotificationBindingFactory.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.sca.binding.notification; + +/** + * Creates runtime artifacts for the notification binding + * + * @version $Rev$ $Date$ + */ +public class DefaultNotificationBindingFactory implements NotificationBindingFactory { + + public NotificationBinding createNotificationBinding() { + return new NotificationBindingImpl(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBinding.java new file mode 100644 index 0000000000..940a69784b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBinding.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.sca.binding.notification; + +import java.net.URI; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * @version $Rev$ $Date$ + */ +public interface NotificationBinding extends Binding { + + String getNtmAddress(); + + void setNtmAddress(String ntm); + + URI getNotificationType(); + + void setNotificationType(URI notificationType); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingFactory.java new file mode 100644 index 0000000000..31a8b26c02 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingFactory.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.sca.binding.notification; + +/** + * @version $Rev$ $Date$ + */ +public interface NotificationBindingFactory { + + NotificationBinding createNotificationBinding(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingImpl.java new file mode 100644 index 0000000000..f4c210ba7c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingImpl.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.sca.binding.notification; + +import java.net.URI; + +/** + * @version $Rev$ $Date$ + */ +public class NotificationBindingImpl implements NotificationBinding { + private String name; + private String uri; + protected String ntmAddress; + protected URI notificationType; + + @Override + public Object clone() { + return this; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public String getNtmAddress() { + return ntmAddress; + } + + public void setNtmAddress(String ntmAddress) { + this.ntmAddress = ntmAddress; + } + + public URI getNotificationType() { + return notificationType; + } + + public void setNotificationType(URI notificationType) { + this.notificationType = notificationType; + } + + public void setUnresolved(boolean unresolved) { + } + + public boolean isUnresolved() { + return false; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingModuleActivator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingModuleActivator.java new file mode 100644 index 0000000000..7fdeee189b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingModuleActivator.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.binding.notification.encoding.DefaultEncodingRegistry; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.host.http.ExtensibleServletHost; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; + +/** + * @version $Rev$ $Date$ + */ +public class NotificationBindingModuleActivator implements ModuleActivator { + + private NotificationBindingProcessor bindingProcessor; + + private DefaultEncodingRegistry encodingRegistry; + private ServletHost servletHost; + + + public void start(ExtensionPointRegistry registry) { + encodingRegistry = new DefaultEncodingRegistry(); + servletHost = new ExtensibleServletHost(registry.getExtensionPoint(ServletHostExtensionPoint.class)); + + AssemblyFactory assemblyFactory = new DefaultAssemblyFactory(); + PolicyFactory policyFactory = new DefaultPolicyFactory(); + DefaultNotificationBindingFactory bindingFactory = new DefaultNotificationBindingFactory(); + bindingProcessor = new NotificationBindingProcessor(assemblyFactory, policyFactory, bindingFactory); + StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + processors.addArtifactProcessor(bindingProcessor); + + NotificationBindingProviderFactory nbpf = new NotificationBindingProviderFactory(servletHost, + encodingRegistry); + ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + providerFactories.addProviderFactory(nbpf); + } + + public void stop(ExtensionPointRegistry registry) { + encodingRegistry.stop(); + StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + processors.removeArtifactProcessor(bindingProcessor); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java new file mode 100644 index 0000000000..892700779f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification; + +import java.net.URI; +import java.net.URISyntaxException; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * @version $Rev$ $Date$ + */ +public class NotificationBindingProcessor implements StAXArtifactProcessor { + + protected static final QName BINDING_NOTIFICATION = new QName(Constants.SCA10_TUSCANY_NS, "binding.notification"); + + private NotificationBindingFactory bindingFactory; + + public NotificationBindingProcessor(AssemblyFactory assemblyFactory, + PolicyFactory policyFactory, + NotificationBindingFactory bindingFactory) { + this.bindingFactory = bindingFactory; + } + + public QName getArtifactType() { + return BINDING_NOTIFICATION; + } + + public Class getModelType() { + return NotificationBinding.class; + } + + public NotificationBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + assert BINDING_NOTIFICATION.equals(reader.getName()); + String bindingUri = reader.getAttributeValue(null, "uri"); + String name = reader.getAttributeValue(null, "name"); + String ntm = reader.getAttributeValue(null, "ntm"); + String notificationType = reader.getAttributeValue(null, "notificationType"); + + NotificationBinding binding = bindingFactory.createNotificationBinding(); + if (name != null) { + binding.setName(name); + } + if (bindingUri != null) { + binding.setURI(bindingUri); + } + if (ntm != null) { + binding.setNtmAddress(ntm); + } + if (notificationType != null) { + try { + binding.setNotificationType(new URI(notificationType)); + } catch(URISyntaxException e) { + throw new ContributionReadException(e); + } + } + return binding; + } + + public void write(NotificationBinding notificationBinding, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + + //FIXME Implement this method + } + + public void resolve(NotificationBinding notificationBinding, ModelResolver resolver) throws ContributionResolveException { + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProviderFactory.java new file mode 100644 index 0000000000..e5ea616fdb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProviderFactory.java @@ -0,0 +1,342 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification; + +import java.net.InetAddress; +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.binding.notification.encoding.AbstractEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerConsumerReferenceEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerID; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerIDEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerProducerReferenceEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.BrokersEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.ConnectionOverrideEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.ConnectionOverrideResponseEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.ConsumerReferenceEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingRegistry; +import org.apache.tuscany.sca.binding.notification.encoding.EndConsumersEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.EndProducersEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.EndpointAddressEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.EndpointReference; +import org.apache.tuscany.sca.binding.notification.encoding.EndpointReferenceEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NeighborBrokerConsumersEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NeighborsEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewBrokerAckEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewBrokerEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewBrokerResponseEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewConsumerEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewConsumerResponseEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewProducerEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewProducerResponseEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.ReferencePropertiesEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.RemoveBrokerEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.RemovedBrokerEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.ReplaceBrokerConnectionEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.SubscribeEnDeCoder; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * The runtime representation of the notification reference binding + * + * @version $Rev$ $Date$ + */ +public class NotificationBindingProviderFactory implements BindingProviderFactory, + NotificationBrokerManager { + private static final String DEFAULT_PORT = "8083"; + + private ServletHost servletHost; + private NotificationTypeManagerImpl notificationTypeManager; + private EncodingRegistry encodingRegistry; + private String httpUrl; + private Map referenceBindingProviders; + private Map serviceBindingProviders; + + private static NotificationBindingProviderFactory factoryInstance = null; + + public NotificationBindingProviderFactory(ServletHost servletHost, EncodingRegistry encodingRegistry) { + this.servletHost = servletHost; + this.encodingRegistry = encodingRegistry; + this.referenceBindingProviders = new HashMap(); + this.serviceBindingProviders = new HashMap(); + + factoryInstance = this; + } + + public Class getModelType() { + return NotificationBinding.class; + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + NotificationBinding binding) { + init(); + URI notificationType = binding.getNotificationType(); + if (!validReferenceBinding(binding)) { + throw new RuntimeException("Binding not valid"); + } + NotificationReferenceBindingProvider referenceBindingProvider = referenceBindingProviders.get(notificationType); + if (referenceBindingProvider == null) { + referenceBindingProvider = + new NotificationReferenceBindingProvider(binding, component, reference, servletHost, + notificationTypeManager, encodingRegistry, httpUrl, this); + referenceBindingProviders.put(notificationType, referenceBindingProvider); + } + return referenceBindingProvider; + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + NotificationBinding binding) { + init(); + URI notificationType = binding.getNotificationType(); + if (!validServiceBinding(binding)) { + throw new RuntimeException("Binding not valid"); + } + NotificationServiceBindingProvider serviceBindingProvider = serviceBindingProviders.get(notificationType); + if (serviceBindingProvider == null) { + serviceBindingProvider = + new NotificationServiceBindingProvider(binding, component, service, servletHost, + notificationTypeManager, encodingRegistry, httpUrl, this); + serviceBindingProviders.put(notificationType, serviceBindingProvider); + } + return serviceBindingProvider; + } + + private boolean validServiceBinding(NotificationBinding binding) { + URI notificationType = binding.getNotificationType(); + NotificationReferenceBindingProvider referenceBindingProvider = referenceBindingProviders.get(notificationType); + if (referenceBindingProvider != null) { + return validBinding(binding, referenceBindingProvider.getBinding()); + } + return true; + } + + private boolean validReferenceBinding(NotificationBinding binding) { + URI notificationType = binding.getNotificationType(); + NotificationServiceBindingProvider serviceBindingProvider = serviceBindingProviders.get(notificationType); + if (serviceBindingProvider != null) { + return validBinding(binding, serviceBindingProvider.getBinding()); + } + return true; + } + + private boolean validBinding(NotificationBinding binding1, NotificationBinding binding2) { + String binding1NtmAddress = binding1.getNtmAddress(); + String binding2NtmAddress = binding2.getNtmAddress(); + if (binding1NtmAddress == null && binding2NtmAddress == null) { + return true; + } else if (binding1NtmAddress == null || binding2NtmAddress == null) { + return false; + } else { + return binding1NtmAddress.equals(binding2NtmAddress); + } + } + + /* + * These methods are intended to be called by the binding providers' start + * methods. By the time this happens, both referenceBindingProvider != null && + * serviceBindingProvider != null, if they are ever going to be + */ + public void serviceProviderStarted(URI notificationType, + NotificationServiceBindingProvider serviceBindingProvider, + URL remoteNtmUrl) { + NotificationReferenceBindingProvider referenceBindingProvider = referenceBindingProviders.get(notificationType); + if (referenceBindingProvider == null) { + serviceBindingProvider.deployConsumer(); + } else if (referenceBindingProvider.isStarted()) { + String brokerID = BrokerID.generate(); + deployBroker(notificationType, serviceBindingProvider, referenceBindingProvider, brokerID, remoteNtmUrl); + } + } + + public void referenceProviderStarted(URI notificationType, + NotificationReferenceBindingProvider referenceBindingProvider, + URL remoteNtmUrl) { + NotificationServiceBindingProvider serviceBindingProvider = serviceBindingProviders.get(notificationType); + if (serviceBindingProvider == null) { + referenceBindingProvider.deployProducer(); + } else if (serviceBindingProvider.isStarted()) { + String brokerID = BrokerID.generate(); + deployBroker(notificationType, serviceBindingProvider, referenceBindingProvider, brokerID, remoteNtmUrl); + } + } + + private void deployBroker(URI notificationType, + NotificationServiceBindingProvider serviceBindingProvider, + NotificationReferenceBindingProvider referenceBindingProvider, + String brokerID, + URL remoteNtmUrl) { + URL consumerUrl = serviceBindingProvider.getURL(); + URL producerUrl = referenceBindingProvider.getURL(); + List consumerList = new ArrayList(); + List producerList = new ArrayList(); + boolean firstBroker = + notificationTypeManager.newBroker(notificationType, + consumerUrl, + producerUrl, + brokerID, + remoteNtmUrl, + consumerList, + producerList); + if (firstBroker) { + serviceBindingProvider.deployBroker(brokerID, null, producerList); + referenceBindingProvider.deployBroker(brokerID, null, consumerList); + if (!consumerList.isEmpty() || !producerList.isEmpty()) { + notificationTypeManager.newBrokerAck(remoteNtmUrl); + } + } else { + // returned lists contain broker consumers and producers and are the + // same length + int index = consumerList.size() - 1; + // establish connection with picked broker + EndpointReference brokerConsumerEPR = consumerList.get(index); + EndpointReference brokerProducerEPR = producerList.get(index); + serviceBindingProvider.deployBroker(brokerID, brokerProducerEPR, null); + referenceBindingProvider.deployBroker(brokerID, brokerConsumerEPR, null); + } + } + + public void replaceConsumersBrokerConnection(URI notificationType, EndpointReference chosenBrokerProducerEpr) { + NotificationServiceBindingProvider serviceBindingProvider = serviceBindingProviders.get(notificationType); + if (serviceBindingProvider == null) { + throw new RuntimeException("Missing service binding provider for [" + notificationType + "]"); + } + serviceBindingProvider.replaceBrokerConnection(chosenBrokerProducerEpr); + } + + public static void removeBroker(URI notificationType) { + if (factoryInstance == null) { + throw new RuntimeException("Missing factory instance"); + } + NotificationReferenceBindingProvider referenceBindingProvider = + factoryInstance.referenceBindingProviders.get(notificationType); + NotificationServiceBindingProvider serviceBindingProvider = + factoryInstance.serviceBindingProviders.get(notificationType); + if (referenceBindingProvider == null || serviceBindingProvider == null) { + throw new RuntimeException("Not a broker for [" + notificationType + "]"); + } + referenceBindingProvider.undeployBroker(serviceBindingProvider.getURL()); + } + + private String getBaseURI() { + if (httpUrl == null) { + // Allow priviledged access to read system property. Requires PropertyPermision in security policy. + String httpPort = AccessController.doPrivileged(new PrivilegedAction() { + public String run() { + return System.getProperty("notification.httpPort"); + } + }); + + if (httpPort == null) { + httpPort = DEFAULT_PORT; + } + String localHost = null; + try { + localHost = InetAddress.getLocalHost().getCanonicalHostName(); + } catch (Exception e) { + e.printStackTrace(); + localHost = "localhost"; + } + httpUrl = "http://" + localHost + ((httpPort != null) ? (":" + httpPort) : ""); + } + return httpUrl; + } + + @SuppressWarnings("unchecked") + public void init() { + if (notificationTypeManager == null) { + AbstractEnDeCoder subscribeEnDeCoder = new SubscribeEnDeCoder(encodingRegistry); + subscribeEnDeCoder.start(); + AbstractEnDeCoder consumerReferenceEnDeCoder = new ConsumerReferenceEnDeCoder(encodingRegistry); + consumerReferenceEnDeCoder.start(); + AbstractEnDeCoder endpointAddressEnDeCoder = new EndpointAddressEnDeCoder(encodingRegistry); + endpointAddressEnDeCoder.start(); + AbstractEnDeCoder newConsumerEnDeCoder = new NewConsumerEnDeCoder(encodingRegistry); + newConsumerEnDeCoder.start(); + AbstractEnDeCoder newProducerEnDeCoder = new NewProducerEnDeCoder(encodingRegistry); + newProducerEnDeCoder.start(); + AbstractEnDeCoder newConsumerResponseEnDeCoder = new NewConsumerResponseEnDeCoder(encodingRegistry); + newConsumerResponseEnDeCoder.start(); + AbstractEnDeCoder newProducerResponseEnDeCoder = new NewProducerResponseEnDeCoder(encodingRegistry); + newProducerResponseEnDeCoder.start(); + AbstractEnDeCoder newBrokerEnDeCoder = new NewBrokerEnDeCoder(encodingRegistry); + newBrokerEnDeCoder.start(); + AbstractEnDeCoder brokerConsumerReferenceEnDeCoder = new BrokerConsumerReferenceEnDeCoder(encodingRegistry); + brokerConsumerReferenceEnDeCoder.start(); + AbstractEnDeCoder brokerProducerReferenceEnDeCoder = new BrokerProducerReferenceEnDeCoder(encodingRegistry); + brokerProducerReferenceEnDeCoder.start(); + AbstractEnDeCoder newBrokerResponseEnDeCoder = new NewBrokerResponseEnDeCoder(encodingRegistry); + newBrokerResponseEnDeCoder.start(); + AbstractEnDeCoder brokersEnDeCoder = new BrokersEnDeCoder(encodingRegistry); + brokersEnDeCoder.start(); + AbstractEnDeCoder brokerEnDeCoder = new BrokerEnDeCoder(encodingRegistry); + brokerEnDeCoder.start(); + AbstractEnDeCoder endConsumersEnDeCoder = new EndConsumersEnDeCoder(encodingRegistry); + endConsumersEnDeCoder.start(); + AbstractEnDeCoder endProducersEnDeCoder = new EndProducersEnDeCoder(encodingRegistry); + endProducersEnDeCoder.start(); + AbstractEnDeCoder endpointReferenceEnDeCoder = new EndpointReferenceEnDeCoder(encodingRegistry); + endpointReferenceEnDeCoder.start(); + AbstractEnDeCoder referencePropertiesEnDeCoder = new ReferencePropertiesEnDeCoder(encodingRegistry); + referencePropertiesEnDeCoder.start(); + AbstractEnDeCoder brokerIDEnDeCoder = new BrokerIDEnDeCoder(encodingRegistry); + brokerIDEnDeCoder.start(); + AbstractEnDeCoder connectionOverrideEnDeCoder = new ConnectionOverrideEnDeCoder(encodingRegistry); + connectionOverrideEnDeCoder.start(); + AbstractEnDeCoder connectionOverrideResponseEnDeCoder = + new ConnectionOverrideResponseEnDeCoder(encodingRegistry); + connectionOverrideResponseEnDeCoder.start(); + AbstractEnDeCoder newBrokerAckEnDeCoder = new NewBrokerAckEnDeCoder(encodingRegistry); + newBrokerAckEnDeCoder.start(); + AbstractEnDeCoder neighborBrokerConsumersEnDeCoder = new NeighborBrokerConsumersEnDeCoder(encodingRegistry); + neighborBrokerConsumersEnDeCoder.start(); + AbstractEnDeCoder removeBrokerEnDeCoder = new RemoveBrokerEnDeCoder(encodingRegistry); + removeBrokerEnDeCoder.start(); + AbstractEnDeCoder removedBrokerEnDeCoder = new RemovedBrokerEnDeCoder(encodingRegistry); + removedBrokerEnDeCoder.start(); + AbstractEnDeCoder neighborsEnDeCoder = new NeighborsEnDeCoder(encodingRegistry); + neighborsEnDeCoder.start(); + AbstractEnDeCoder replaceBrokerConnectionEnDeCoder = new ReplaceBrokerConnectionEnDeCoder(encodingRegistry); + replaceBrokerConnectionEnDeCoder.start(); + + notificationTypeManager = new NotificationTypeManagerImpl(); + notificationTypeManager.setServletHost(servletHost); + notificationTypeManager.setEncodingRegistry(encodingRegistry); + notificationTypeManager.init(); + + getBaseURI(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBrokerManager.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBrokerManager.java new file mode 100644 index 0000000000..8a6d57e825 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBrokerManager.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.sca.binding.notification; + +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.binding.notification.encoding.EndpointReference; + +/** + * @version $Rev$ $Date$ + */ +public interface NotificationBrokerManager { + + void serviceProviderStarted(URI notificationType, + NotificationServiceBindingProvider serviceBindingProvider, + URL remoteNtmUrl); + + void referenceProviderStarted(URI notificationType, + NotificationReferenceBindingProvider referenceBindingProvider, + URL remoteNtmUrl); + + void replaceConsumersBrokerConnection(URI notificationType, EndpointReference chosenBrokerProducerEpr); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingInvoker.java new file mode 100644 index 0000000000..8980fa26ff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingInvoker.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification; + +import java.io.OutputStream; +import java.util.HashMap; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.notification.NotificationReferenceBindingProvider.SubscriberInfo; +import org.apache.tuscany.sca.binding.notification.encoding.Constants; +import org.apache.tuscany.sca.binding.notification.util.IOUtils; +import org.apache.tuscany.sca.binding.notification.util.IOUtils.IOUtilsException; +import org.apache.tuscany.sca.binding.notification.util.IOUtils.Writeable; +import org.apache.tuscany.sca.implementation.notification.ImmutableMessage; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Turns invoke into remote message fan-out + * + * @version $Rev$ $Date$ + */ +public class NotificationReferenceBindingInvoker implements Invoker { + + private static final Message RESPONSE = new ImmutableMessage(); + private Operation operation; + + private NotificationReferenceBindingProvider notificationReferenceBindingProvider; + + public NotificationReferenceBindingInvoker(Operation operation, + NotificationReferenceBindingProvider notificationReferenceBindingProvider) { + this.operation = operation; + this.notificationReferenceBindingProvider = notificationReferenceBindingProvider; + } + + public Message invoke(Message msg) { + Object payload = msg.getBody(); + if (payload == null) { + throw new RuntimeException("Message body is null"); + } + Writeable writeable = null; + String incomingBrokerID = null; + if (payload.getClass().isArray()) { + Object[] bodyArray = (Object[])payload; + if (bodyArray.length == 3) { + writeable = getWriteableFromByteArray((byte[])bodyArray[1]); + incomingBrokerID = (String)bodyArray[2]; + } else if (bodyArray.length == 1) { + writeable = getWriteableFromPayload(bodyArray[0]); + } else { + throw new RuntimeException("Invalid body array size"); + } + } else { + writeable = getWriteableFromPayload(payload); + } + + try { + for (SubscriberInfo subscriber : notificationReferenceBindingProvider.getSubscribers()) { + // check for each subscriber's broker id and skip if equal + if (incomingBrokerID != null && subscriber.brokerID != null && incomingBrokerID.equals(subscriber.brokerID)) { + continue; + } + HashMap headers = new HashMap(); + headers.put(IOUtils.Notification_Operation, operation.getName()); + String brokerID = notificationReferenceBindingProvider.getBrokerID(); + if (brokerID != null) { + headers.put(Constants.Broker_ID, brokerID); + } + IOUtils.sendHttpRequest(subscriber.address, headers, writeable, null); + } + } catch(Exception e) { + e.printStackTrace(); + throw new RuntimeException("Sender caught exception", e); + } + return RESPONSE; + } + + private Writeable getWriteableFromPayload(Object payload) throws RuntimeException { + if (!(payload instanceof OMElement)) { + throw new RuntimeException("payload not OMElement"); + } + final OMElement element = (OMElement)payload; + Writeable writeable = new Writeable() { + public void write(OutputStream os) throws IOUtilsException { + try { + element.serialize(os); + os.flush(); + } catch(Exception e) { + throw new IOUtilsException(e); + } + } + }; + return writeable; + } + + private Writeable getWriteableFromByteArray(final byte[] payload) { + Writeable writeable = new Writeable() { + public void write(OutputStream os) throws IOUtilsException { + try { + os.write(payload); + os.flush(); + } catch(Exception e) { + throw new IOUtilsException(e); + } + } + }; + return writeable; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingProvider.java new file mode 100644 index 0000000000..c1a8162836 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingProvider.java @@ -0,0 +1,338 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification; + +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.notification.encoding.Broker; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerID; +import org.apache.tuscany.sca.binding.notification.encoding.ConnectionOverride; +import org.apache.tuscany.sca.binding.notification.encoding.Constants; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingObject; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingRegistry; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingUtils; +import org.apache.tuscany.sca.binding.notification.encoding.EndpointReference; +import org.apache.tuscany.sca.binding.notification.encoding.ReplaceBrokerConnection; +import org.apache.tuscany.sca.binding.notification.encoding.Subscribe; +import org.apache.tuscany.sca.binding.notification.util.NotificationServlet; +import org.apache.tuscany.sca.binding.notification.util.URIUtil; +import org.apache.tuscany.sca.binding.notification.util.NotificationServlet.NotificationServletStreamHandler; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * The runtime representation of the notification reference binding + * + * @version $Rev$ $Date$ + */ +public class NotificationReferenceBindingProvider + implements ReferenceBindingProvider, NotificationServletStreamHandler { + + private static final String producerPathBase = "/producer"; + private NotificationReferenceBindingInvoker invoker; + private RuntimeComponentReference reference; + private NotificationBinding notificationBinding; + private ServletHost servletHost; + private NotificationTypeManager ntm; + private EncodingRegistry encodingRegistry; + private URI notificationType; + private URL myUrl; + private URL remoteNtmUrl; + private boolean started; + private NotificationBrokerManager brokerManager; + + private List subscribers; + private String brokerID; + + public NotificationReferenceBindingProvider(NotificationBinding notificationBinding, + RuntimeComponent component, + RuntimeComponentReference reference, + ServletHost servletHost, + NotificationTypeManager ntm, + EncodingRegistry encodingRegistry, + String httpUrl, + NotificationBrokerManager brokerManager) { + this.invoker = null; + this.notificationBinding = notificationBinding; + this.reference = reference; + this.servletHost = servletHost; + this.ntm = ntm; + this.encodingRegistry = encodingRegistry; + this.notificationType = notificationBinding.getNotificationType(); + String ntmAddress = notificationBinding.getNtmAddress(); + String notificationTypePath = URIUtil.getPath(notificationType); + try { + this.myUrl = new URL(httpUrl + producerPathBase + notificationTypePath); + this.remoteNtmUrl = null; + if (ntmAddress != null && notificationType != null) { + remoteNtmUrl = new URL(ntmAddress + notificationTypePath); + } + } catch(Exception e) { + throw new RuntimeException(e); + } + this.started = false; + this.brokerManager = brokerManager; + + URI uri = URI.create(component.getURI() + "/" + notificationBinding.getName()); + notificationBinding.setURI(uri.toString()); + Interface interfaze = reference.getInterfaceContract().getInterface(); + interfaze.resetDataBinding(OMElement.class.getName()); + for (Operation operation : interfaze.getOperations()) { + operation.setNonBlocking(false); + } + + this.subscribers = new ArrayList(); + this.brokerID = null; + } + + public NotificationBinding getBinding() { + return notificationBinding; + } + + public URL getURL() { + return myUrl; + } + + public boolean isStarted() { + return started; + } + + public void setBrokerID(String brokerID) { + this.brokerID = brokerID; + } + + public String getBrokerID() { + return brokerID; + } + + public Invoker createInvoker(Operation operation) { + if (invoker == null) { + invoker = new NotificationReferenceBindingInvoker(operation, this); + } + return invoker; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + if (started) { + return; + } + + brokerManager.referenceProviderStarted(notificationType, this, remoteNtmUrl); + started = true; + } + + public void stop() { + } + + public void deployProducer() { + List consumerList = new ArrayList(); + String sequenceType; + try { + sequenceType = ntm.newProducer(notificationType, myUrl, remoteNtmUrl, consumerList); + } catch(Exception e) { + throw new RuntimeException(e); + } + if (Constants.EndConsumers.equals(sequenceType)) { + for (URL consumerUrl : consumerList) { + addSubscriberUrl(consumerUrl); + } + } else if (Constants.BrokerConsumers.equals(sequenceType)) { + // Pick a broker consumer, for now the first one + URL consumerUrl = consumerList.get(0); + addSubscriberUrl(consumerUrl); + } + + servletHost.addServletMapping(myUrl.toString(), new NotificationServlet(this)); + } + + public void deployBroker(String brokerID, EndpointReference brokerConsumerEPR, List consumerList) { + if (brokerConsumerEPR != null) { + addSubscriber(brokerConsumerEPR); + } + if (consumerList != null && !consumerList.isEmpty()) { + for (EndpointReference consumerEPR : consumerList) { + addSubscriber(consumerEPR); + } + } + setBrokerID(brokerID); + servletHost.addServletMapping(myUrl.toString(), new NotificationServlet(this)); + } + + public void undeployBroker(URL brokerConsumerUrl) { + EndpointReference brokerConsumerEpr = EncodingUtils.createEndpointReference(brokerConsumerUrl, getBrokerID()); + ntm.removeBroker(brokerConsumerEpr, getNeighborBrokerConsumerEprs(), remoteNtmUrl); + removeBrokerSubscribers(); + } + + public void handle(Map headers, ServletInputStream istream, int contentLength, ServletOutputStream ostream) { + + try { + EncodingObject eo = EncodingUtils.decodeFromStream(encodingRegistry, istream); + if (eo instanceof Subscribe) { + Subscribe sub = (Subscribe)eo; + addSubscriber(sub.getConsumerReference().getReference()); + } else if (eo instanceof ConnectionOverride) { + ConnectionOverride co = (ConnectionOverride)eo; + replaceSubscribers(co.getBrokerConsumerReference().getReference()); + } else if (eo instanceof ReplaceBrokerConnection) { + ReplaceBrokerConnection rbc = (ReplaceBrokerConnection)eo; + URL removedBrokerConsumerEpr = rbc.getRemovedBroker().getReference().getEndpointAddress().getAddress(); + if (rbc.getNeighbors() != null) { + int choice = rbc.getNeighbors().getBrokerSequence().size() - 1; + Broker chosenBroker = rbc.getNeighbors().getBrokerSequence().get(choice); + replaceBrokerSubscriber(removedBrokerConsumerEpr, + chosenBroker.getBrokerConsumerReference().getReference()); + brokerManager.replaceConsumersBrokerConnection(notificationType, + chosenBroker.getBrokerProducerReference().getReference()); + } else { + replaceBrokerSubscriber(removedBrokerConsumerEpr, null); + } + } else { + throw new RuntimeException("Unknown encoding object"); + } + } catch(Throwable e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + public synchronized List getSubscribers() { + return subscribers; + } + + private void addSubscriberUrl(URL subscriberUrl) { + addSubscriber(subscriberUrl, null); + } + + private void addSubscriber(EndpointReference subscriberEPR) { + BrokerID brokerID = null; + if (subscriberEPR.getReferenceProperties() != null) { + brokerID = subscriberEPR.getReferenceProperties().getProperty(BrokerID.class); + } + addSubscriber(subscriberEPR.getEndpointAddress().getAddress(), (brokerID != null ? brokerID.getID() : null)); + } + + private void addSubscriber(URL address, String brokerID) { + synchronized(this) { + SubscriberInfo si = new SubscriberInfo(address); + si.brokerID = brokerID; + if (subscribers == null) { + subscribers = new ArrayList(); + } + subscribers.add(si); + } + } + + private void replaceSubscribers(EndpointReference brokerConsumerEPR) { + synchronized(this) { + subscribers = null; + } + addSubscriber(brokerConsumerEPR); + } + + private void replaceBrokerSubscriber(URL removedBrokerConsumerUrl, EndpointReference chosenBrokerConsumerEpr) { + synchronized(this) { + if (subscribers == null) { + throw new RuntimeException("No subscribers"); + } + SubscriberInfo siToRemove = null; + for (SubscriberInfo si : subscribers) { + if (si.address.equals(removedBrokerConsumerUrl)) { + siToRemove = si; + } + } + if (siToRemove == null) { + throw new RuntimeException("Can't find info for broker to remove [" + removedBrokerConsumerUrl + "]"); + } + if (!subscribers.remove(siToRemove)) { + throw new RuntimeException("Can't remove info for [" + siToRemove.address + "]"); + } + } + if (chosenBrokerConsumerEpr != null) { + addSubscriber(chosenBrokerConsumerEpr); + } + } + + private List getNeighborBrokerConsumerEprs() { + synchronized(this) { + if (subscribers == null) { + throw new RuntimeException("No subscribers"); + } + List neighborBrokerConsumerEprs = new ArrayList(); + for(SubscriberInfo si : subscribers) { + if (si.brokerID != null) { + neighborBrokerConsumerEprs.add(EncodingUtils.createEndpointReference(si.address, si.brokerID)); + } + } + + return neighborBrokerConsumerEprs; + } + } + + private void removeBrokerSubscribers() { + synchronized(this) { + if (subscribers == null) { + throw new RuntimeException("No subscribers"); + } + List sisToRemove = new ArrayList(); + for (SubscriberInfo si : subscribers) { + if (si.brokerID != null) { + sisToRemove.add(si); + } + } + for(SubscriberInfo si : sisToRemove) { + if (!subscribers.remove(si)) { + throw new RuntimeException("Can't remove broker subscriber [" + si.address + "]"); + } + } + } + } + + class SubscriberInfo { + public URL address; + public String brokerID; + + public SubscriberInfo(URL address) { + this.address = address; + this.brokerID = null; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationServiceBindingProvider.java new file mode 100644 index 0000000000..4511fb454b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationServiceBindingProvider.java @@ -0,0 +1,317 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerConsumerReference; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerID; +import org.apache.tuscany.sca.binding.notification.encoding.ConnectionOverride; +import org.apache.tuscany.sca.binding.notification.encoding.Constants; +import org.apache.tuscany.sca.binding.notification.encoding.ConsumerReference; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingRegistry; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingUtils; +import org.apache.tuscany.sca.binding.notification.encoding.EndpointAddress; +import org.apache.tuscany.sca.binding.notification.encoding.EndpointReference; +import org.apache.tuscany.sca.binding.notification.encoding.ReferenceProperties; +import org.apache.tuscany.sca.binding.notification.encoding.Subscribe; +import org.apache.tuscany.sca.binding.notification.util.IOUtils; +import org.apache.tuscany.sca.binding.notification.util.NotificationServlet; +import org.apache.tuscany.sca.binding.notification.util.URIUtil; +import org.apache.tuscany.sca.binding.notification.util.IOUtils.IOUtilsException; +import org.apache.tuscany.sca.binding.notification.util.IOUtils.Writeable; +import org.apache.tuscany.sca.binding.notification.util.NotificationServlet.NotificationServletStreamHandler; +import org.apache.tuscany.sca.core.invocation.MessageImpl; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * The runtime representation of the local service binding + * + * @version $Rev$ $Date$ + */ +public class NotificationServiceBindingProvider + implements ServiceBindingProvider, NotificationServletStreamHandler { + + private RuntimeWire wire; + private NotificationBinding notificationBinding; + private RuntimeComponentService service; + private ServletHost servletHost; + private NotificationTypeManager ntm; + private EncodingRegistry encodingRegistry; + private URI notificationType; + private URL myUrl; + private URL remoteNtmUrl; + private static final String consumerPathBase = "/consumer"; + private boolean started; + private NotificationBrokerManager brokerManager; + private String brokerID; + + public NotificationServiceBindingProvider(NotificationBinding notificationBinding, + RuntimeComponent component, + RuntimeComponentService service, + ServletHost servletHost, + NotificationTypeManager ntm, + EncodingRegistry encodingRegistry, + String httpUrl, + NotificationBrokerManager brokerManager) { + this.notificationBinding = notificationBinding; + this.service = service; + this.servletHost = servletHost; + this.ntm = ntm; + this.encodingRegistry = encodingRegistry; + this.notificationType = notificationBinding.getNotificationType(); + String ntmAddress = notificationBinding.getNtmAddress(); + String notificationTypePath = URIUtil.getPath(notificationType); + try { + this.myUrl = new URL(httpUrl + consumerPathBase + notificationTypePath); + remoteNtmUrl = null; + if (ntmAddress != null && notificationType != null) { + remoteNtmUrl = new URL(ntmAddress + notificationTypePath); + } + } catch(Exception e) { + throw new RuntimeException(e); + } + this.started = false; + this.brokerManager = brokerManager; + this.brokerID = null; + + URI uri = URI.create(component.getURI() + "/" + notificationBinding.getName()); + notificationBinding.setURI(uri.toString()); + Interface interfaze = service.getInterfaceContract().getInterface(); + interfaze.resetDataBinding(OMElement.class.getName()); + for (Operation operation : interfaze.getOperations()) { + operation.setNonBlocking(false); + } + } + + public NotificationBinding getBinding() { + return notificationBinding; + } + + public boolean isStarted() { + return started; + } + + public URL getURL() { + return myUrl; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + if (started) { + return; + } + + RuntimeComponentService componentService = (RuntimeComponentService) service; + wire = componentService.getRuntimeWire(notificationBinding); + + for (InvocationChain ch : wire.getInvocationChains()) { + ch.setAllowsPassByReference(true); + } + + brokerManager.serviceProviderStarted(notificationType, this, remoteNtmUrl); + started = true; + } + + public void stop() { + } + + public void deployConsumer() { + WriteableSubscribe ws = new WriteableSubscribe(myUrl, null); + List producerList = new ArrayList(); + String sequenceType = ntm.newConsumer(notificationType, myUrl, remoteNtmUrl, producerList); + if (Constants.EndProducers.equals(sequenceType)) { + for (URL producerUrl : producerList) { + subscribeWithProducer(producerUrl, null, ws); + } + } else if (Constants.BrokerProducers.equals(sequenceType)) { + // Pick a broker producer, for now the first one + URL producerUrl = producerList.get(0); + subscribeWithProducer(producerUrl, null, ws); + } + + servletHost.addServletMapping(myUrl.toString(), new NotificationServlet(this)); + } + + protected void subscribeWithProducer(URL producerUrl, String brokerID, WriteableSubscribe ws) { + if (ws == null) { + ws = new WriteableSubscribe(myUrl, brokerID); + } + try { + IOUtils.sendHttpRequest(producerUrl, Constants.SUBSCRIBE_OP, ws, null); + } catch(Exception e) { + throw new RuntimeException(e); + } + } + + public void deployBroker(String brokerID, EndpointReference brokerProducerEPR, List producerList) { + if (brokerProducerEPR != null) { + subscribeWithProducer(brokerProducerEPR.getEndpointAddress().getAddress(), brokerID, null); + } + this.brokerID = brokerID; + if (producerList != null && !producerList.isEmpty()) { + WriteableConnectionOverride wco = new WriteableConnectionOverride(myUrl, brokerID); + for (EndpointReference producerEPR : producerList) { + try { + IOUtils.sendHttpRequest(producerEPR.getEndpointAddress().getAddress(), Constants.CONNECTION_OVERRIDE_OP, wco, null); + } catch(Exception e) { + throw new RuntimeException(e); + } + } + } + servletHost.addServletMapping(myUrl.toString(), new NotificationServlet(this)); + } + + public void replaceBrokerConnection(EndpointReference chosenBrokerProducerEpr) { + if (brokerID == null) { + throw new RuntimeException("Missing broker id"); + } + URL producerUrl = chosenBrokerProducerEpr.getEndpointAddress().getAddress(); + subscribeWithProducer(producerUrl, brokerID, null); + } + + public void handle(Map headers, ServletInputStream istream, int contentLength, ServletOutputStream ostream) { + String opHeader = headers.get(IOUtils.Notification_Operation); + String incomingBrokerID = headers.get(Constants.Broker_ID); + if (opHeader == null) { + throw new RuntimeException("Missing operation header"); + } + if (wire == null) { + throw new RuntimeException("Missing wire"); + } + InvocationChain chain = null; + for (InvocationChain ch : wire.getInvocationChains()) { + // We may want to use more than just the op name + if(ch.getTargetOperation().getName().equals(opHeader)) { + chain = ch; + break; + } + } + if (chain == null) { + throw new RuntimeException("Can't find invocation chain match for [" + opHeader + "]"); + } + byte[] payload = null; + try { + payload = IOUtils.readFully(istream, contentLength); + } catch(IOException e) { + throw new RuntimeException(e); + } + Object[] args = getArgsFromByteArray(payload, incomingBrokerID); + + invoke(chain, args); + + // Doing nothing to ostream is equivalent to returning null + } + + private Object[] getArgsFromByteArray(byte[] payload, String incomingBrokerID) { + try { + StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(payload)); + OMElement element = builder.getDocumentElement(); + return new Object[] { element }; + } catch(Exception e) { + throw new RuntimeException(e); + } + } + + protected void invoke(InvocationChain chain, Object[] args) { + Message msg = new MessageImpl(); + msg.setBody(args); + chain.getHeadInvoker().invoke(msg); + } + + class WriteableSubscribe implements Writeable { + + private Subscribe sub; + + public WriteableSubscribe(URL url, String brokerID) { + EndpointAddress epa = new EndpointAddress(); + epa.setAddress(url); + EndpointReference epr = new EndpointReference(); + epr.setEndpointAddress(epa); + if (brokerID != null) { + BrokerID cbi = new BrokerID(); + cbi.setID(brokerID); + ReferenceProperties crp = new ReferenceProperties(); + crp.addProperty(cbi); + epr.setReferenceProperties(crp); + } + ConsumerReference cr = new ConsumerReference(); + cr.setReference(epr); + sub = new Subscribe(); + sub.setConsumerReference(cr); + } + + public void write(OutputStream os) throws IOUtilsException { + EncodingUtils.encodeToStream(encodingRegistry, sub, os); + } + } + + class WriteableConnectionOverride implements Writeable { + + private ConnectionOverride connectionOverride; + + public WriteableConnectionOverride(URL brokerConsumerUrl, String brokerID) { + EndpointAddress epa = new EndpointAddress(); + epa.setAddress(brokerConsumerUrl); + EndpointReference brokerConsumerEPR = new EndpointReference(); + brokerConsumerEPR.setEndpointAddress(epa); + BrokerID cbi = new BrokerID(); + cbi.setID(brokerID); + ReferenceProperties crp = new ReferenceProperties(); + crp.addProperty(cbi); + brokerConsumerEPR.setReferenceProperties(crp); + BrokerConsumerReference brokerConsumerReference = new BrokerConsumerReference(); + brokerConsumerReference.setReference(brokerConsumerEPR); + connectionOverride = new ConnectionOverride(); + connectionOverride.setBrokerConsumerReference(brokerConsumerReference); + } + + public void write(OutputStream os) throws IOUtilsException { + EncodingUtils.encodeToStream(encodingRegistry, connectionOverride, os); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManager.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManager.java new file mode 100644 index 0000000000..101d05f9cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManager.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.sca.binding.notification; + +import java.net.URI; +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.sca.binding.notification.encoding.EndpointReference; + +/** + * @version $Rev$ $Date$ + */ +public interface NotificationTypeManager { + + String newConsumer(URI notificationType, URL consumerUrl, URL remoteNtmUrl, List producerList); + String newProducer(URI notificationType, URL producerUrl, URL remoteNtmUrl, List consumerList); + boolean newBroker(URI notificationType, + URL consumerUrl, + URL producerUrl, + String brokerID, + URL remoteNtmUrl, + List consumerList, + List producerList); + void newBrokerAck(URL remoteNtmUrl); + void removeBroker(EndpointReference brokerConsumerEpr, List neighborBrokerConsumerEprs, URL remoteNtmUrl); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManagerImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManagerImpl.java new file mode 100644 index 0000000000..527cfbd667 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManagerImpl.java @@ -0,0 +1,669 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; + +import org.apache.tuscany.sca.binding.notification.encoding.Broker; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerConsumerReference; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerID; +import org.apache.tuscany.sca.binding.notification.encoding.BrokerProducerReference; +import org.apache.tuscany.sca.binding.notification.encoding.Brokers; +import org.apache.tuscany.sca.binding.notification.encoding.Constants; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingException; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingObject; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingRegistry; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingUtils; +import org.apache.tuscany.sca.binding.notification.encoding.EndConsumers; +import org.apache.tuscany.sca.binding.notification.encoding.EndProducers; +import org.apache.tuscany.sca.binding.notification.encoding.EndpointAddress; +import org.apache.tuscany.sca.binding.notification.encoding.EndpointReference; +import org.apache.tuscany.sca.binding.notification.encoding.EndpointReferenceWrapper; +import org.apache.tuscany.sca.binding.notification.encoding.NeighborBrokerConsumers; +import org.apache.tuscany.sca.binding.notification.encoding.Neighbors; +import org.apache.tuscany.sca.binding.notification.encoding.NewBroker; +import org.apache.tuscany.sca.binding.notification.encoding.NewBrokerAck; +import org.apache.tuscany.sca.binding.notification.encoding.NewBrokerResponse; +import org.apache.tuscany.sca.binding.notification.encoding.NewConsumer; +import org.apache.tuscany.sca.binding.notification.encoding.NewConsumerResponse; +import org.apache.tuscany.sca.binding.notification.encoding.NewProducer; +import org.apache.tuscany.sca.binding.notification.encoding.NewProducerResponse; +import org.apache.tuscany.sca.binding.notification.encoding.RemoveBroker; +import org.apache.tuscany.sca.binding.notification.encoding.RemovedBroker; +import org.apache.tuscany.sca.binding.notification.encoding.ReplaceBrokerConnection; +import org.apache.tuscany.sca.binding.notification.util.IOUtils; +import org.apache.tuscany.sca.binding.notification.util.NotificationServlet; +import org.apache.tuscany.sca.binding.notification.util.URIUtil; +import org.apache.tuscany.sca.binding.notification.util.IOUtils.IOUtilsException; +import org.apache.tuscany.sca.binding.notification.util.IOUtils.ReadableContinuation; +import org.apache.tuscany.sca.binding.notification.util.IOUtils.Writeable; +import org.apache.tuscany.sca.binding.notification.util.NotificationServlet.NotificationServletStreamHandler; +import org.apache.tuscany.sca.host.http.ServletHost; + +/** + * A notification type manager serves as a registry of producers and consumers, or brokers, for + * any notification type. This class implements an interface that allows a reference provider + * (a producer), a service provider (a consumer), or both (a broker, via the provider factory), + * to access locally the ntm for its notification type, regardless of whether the ntm resides + * locally or remotely. + * At a given host there is only one reference provider and/or one service provider for any given + * notification type. So, if the ntm for a notification type resides locally, then it is invoked + * exclusively by either a reference provider (newProducer), a service provider (newConsumer), or + * a provider factory (newBroker). And since these invocations occur when the providers are being + * created then all three of consumerLists, producerLists and brokerLists must be null when these + * invocations occur. + * + * @version $Rev$ $Date$ + */ +public class NotificationTypeManagerImpl implements NotificationTypeManager { + + private static final String ntmPathBase = "/ntm"; + + private ServletHost servletHost; + private EncodingRegistry encodingRegistry; + private Map ntmHandlers; + + public NotificationTypeManagerImpl() { + } + + public void setServletHost(ServletHost servletHost) { + this.servletHost = servletHost; + } + + public void setEncodingRegistry(EncodingRegistry encodingRegistry) { + this.encodingRegistry = encodingRegistry; + } + + public void init() { + ntmHandlers = new HashMap(); + } + + public String newConsumer(URI notificationType, URL consumerUrl, URL remoteNtmUrl, List producerListResult) { + if (ntmUrlIsRemote(consumerUrl, remoteNtmUrl)) { + try { + WriteableEPW wEPW = new WriteableEPW(new NewConsumer(), consumerUrl); + InputStreamDecoder isd = new InputStreamDecoder(); + NewConsumerResponse ncr = + (NewConsumerResponse)IOUtils.sendHttpRequest(remoteNtmUrl, Constants.NEW_CONSUMER_OP, wEPW, isd); + String sequenceType = ncr.getSequenceType(); + if (Constants.EndProducers.equals(sequenceType) || Constants.BrokerProducers.equals(sequenceType)) { + for (EndpointReference epr : ncr.getReferenceSequence()) { + producerListResult.add(epr.getEndpointAddress().getAddress()); + } + } + return sequenceType; + } catch(Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } else { + NotificationTypeManagerHandler ntmHandler = ntmHandlers.get(notificationType); + if (ntmHandler != null) { + throw new RuntimeException("Trying to deploy local consumer with existing local producer, consumer or broker"); + } + + createNtmHandler(consumerUrl.getAuthority(), notificationType, consumerUrl, null, null); + + return Constants.NoProducers; + } + } + + private void createNtmHandler(String ntmUriAuthority, URI notificationType, URL consumerUrl, URL producerUrl, BrokerStruct broker) { + String ntmUri = "http://" + ntmUriAuthority + ntmPathBase + URIUtil.getPath(notificationType); + NotificationTypeManagerHandler ntmh = new NotificationTypeManagerHandler(notificationType, consumerUrl, producerUrl, broker); + ntmHandlers.put(notificationType, ntmh); + servletHost.addServletMapping(ntmUri, new NotificationServlet(ntmh)); + } + + public String newProducer(URI notificationType, URL producerUrl, URL remoteNtmUrl, List consumerListResult) { + if (ntmUrlIsRemote(producerUrl, remoteNtmUrl)) { + try { + WriteableEPW wEPW = new WriteableEPW(new NewProducer(), producerUrl); + InputStreamDecoder isd = new InputStreamDecoder(); + NewProducerResponse npr = + (NewProducerResponse)IOUtils.sendHttpRequest(remoteNtmUrl, Constants.NEW_PRODUCER_OP, wEPW, isd); + String sequenceType = npr.getSequenceType(); + if (Constants.EndConsumers.equals(sequenceType) || Constants.BrokerConsumers.equals(sequenceType)) { + for (EndpointReference epr : npr.getReferenceSequence()) { + consumerListResult.add(epr.getEndpointAddress().getAddress()); + } + } + return sequenceType; + } catch(Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } else { + NotificationTypeManagerHandler ntmHandler = ntmHandlers.get(notificationType); + if (ntmHandler != null) { + throw new RuntimeException("Trying to deploy local producer with existing local producer, consumer or broker"); + } + + createNtmHandler(producerUrl.getAuthority(), notificationType, null, producerUrl, null); + + return Constants.NoConsumers; + } + } + + public boolean newBroker(URI notificationType, + URL consumerUrl, + URL producerUrl, + String brokerID, + URL remoteNtmUrl, + List consumerListResult, + List producerListResult) { + String ntmUriAuthority = producerUrl.getAuthority(); + if (!ntmUriAuthority.equals(consumerUrl.getAuthority())) { + throw new RuntimeException("Producer url and consumer url do not match"); + } + if (ntmUrlIsRemote(producerUrl, remoteNtmUrl)) { + try { + WriteableNewBroker wnb = new WriteableNewBroker(consumerUrl, producerUrl, brokerID); + InputStreamDecoder isd = new InputStreamDecoder(); + NewBrokerResponse nbr = + (NewBrokerResponse)IOUtils.sendHttpRequest(remoteNtmUrl, Constants.NEW_BROKER_OP, wnb, isd); + if (nbr.isFirstBroker()) { + if (nbr.getEndConsumers().getSequenceType().equals(Constants.EndConsumers)) { + for (EndpointReference epr : nbr.getEndConsumers().getReferenceSequence()) { + consumerListResult.add(epr); + } + } + if (nbr.getEndProducers().getSequenceType().equals(Constants.EndProducers)) { + for (EndpointReference epr : nbr.getEndProducers().getReferenceSequence()) { + producerListResult.add(epr); + } + } + } else { + for (Broker broker : nbr.getBrokers().getBrokerSequence()) { + consumerListResult.add(broker.getBrokerConsumerReference().getReference()); + producerListResult.add(broker.getBrokerProducerReference().getReference()); + } + } + return nbr.isFirstBroker(); + } catch(Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } else { + NotificationTypeManagerHandler ntmHandler = ntmHandlers.get(notificationType); + if (ntmHandler != null) { + throw new RuntimeException("Trying to deploy local broker with existing local producer, consumer or broker"); + } + + BrokerStruct broker = new BrokerStruct(consumerUrl, producerUrl, brokerID); + createNtmHandler(ntmUriAuthority, notificationType, null, null, broker); + + return true; + } + } + + private boolean ntmUrlIsRemote(URL localUrl, URL ntmUrl) { + if (ntmUrl == null) { + return false; + } + if (localUrl.getPort() != ntmUrl.getPort()) { + return true; + } + String remoteNtmUrlAuthority = ntmUrl.getAuthority(); + if (remoteNtmUrlAuthority.indexOf("localhost") >= 0) { + return false; + } + return !localUrl.getAuthority().equals(remoteNtmUrlAuthority); + } + + public void newBrokerAck(URL remoteNtmUrl) { + try { + IOUtils.sendHttpRequest(remoteNtmUrl, Constants.NEW_BROKER_ACK_OP, new WriteableNewBrokerAck(), null); + } catch(Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + public void removeBroker(EndpointReference brokerConsumerEpr, List neighborBrokerConsumerEprs, URL remoteNtmUrl) { + WriteableRemoveBroker wrb = new WriteableRemoveBroker(brokerConsumerEpr, neighborBrokerConsumerEprs); + + try { + IOUtils.sendHttpRequest(remoteNtmUrl, Constants.REMOVE_BROKER_OP, wrb, null); + } catch(Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + private class NotificationTypeManagerHandler implements NotificationServletStreamHandler { + + private URI notificationType; + List consumerList; + List producerList; + List brokerList; + private NotificationTypeLock notificationTypeLock; + private BrokerStruct pendingBroker; + + public NotificationTypeManagerHandler(URI notificationType) { + this.notificationType = notificationType; + this.notificationTypeLock = new NotificationTypeLock(); + this.pendingBroker = null; + } + + public NotificationTypeManagerHandler(URI notificationType, URL consumerUrl, URL producerUrl, BrokerStruct broker) { + this(notificationType); + if (consumerUrl != null) { + addConsumer(consumerUrl); + } else if (producerUrl != null) { + addProducer(producerUrl); + } else if (broker != null) { + addBroker(broker); + } + } + + private void addConsumer(URL consumerUrl) { + if (consumerList == null) { + consumerList = new ArrayList(); + } + consumerList.add(consumerUrl); + } + + private void addProducer(URL producerUrl) { + if (producerList == null) { + producerList = new ArrayList(); + } + producerList.add(producerUrl); + } + + private void addBroker(BrokerStruct broker) { + if (brokerList == null) { + brokerList = new ArrayList(); + } + brokerList.add(broker); + } + + public void handle(Map headers, ServletInputStream istream, int contentLength, ServletOutputStream ostream) { + String opHeader = headers.get(IOUtils.Notification_Operation); + EncodingObject eo = null; + try { + eo = EncodingUtils.decodeFromStream(encodingRegistry, istream); + } catch(EncodingException e) { + throw new RuntimeException(e); + } + + if (Constants.NEW_CONSUMER_OP.equals(opHeader)) { + handleNewConsumer((NewConsumer)eo, ostream); + } else if(Constants.NEW_PRODUCER_OP.equals(opHeader)) { + handleNewProducer((NewProducer)eo, ostream); + } else if(Constants.NEW_BROKER_OP.equals(opHeader)) { + handleNewBroker((NewBroker)eo, ostream); + } else if (Constants.NEW_BROKER_ACK_OP.equals(opHeader)) { + handleNewBrokerAck(); + } else if (Constants.REMOVE_BROKER_OP.equals(opHeader)) { + handleRemoveBroker((RemoveBroker)eo); + } + } + + private void handleNewConsumer(NewConsumer nc, ServletOutputStream ostream) { + synchronized(notificationTypeLock) { + if (notificationTypeLock.isLocked) { + try { notificationTypeLock.wait(); } catch(InterruptedException e) {} + } + URL consumerUrl = nc.getReference().getEndpointAddress().getAddress(); + if (brokerList == null) { + addConsumer(consumerUrl); + } + + NewConsumerResponse ncr = new NewConsumerResponse(); + if (producerList != null) { + ncr.setSequenceType(Constants.EndProducers); + for (URL producerUrl : producerList) { + ncr.addReferenceToSequence(EncodingUtils.createEndpointReference(producerUrl, null)); + } + } else if(brokerList != null) { + ncr.setSequenceType(Constants.BrokerProducers); + for (BrokerStruct broker : brokerList) { + ncr.addReferenceToSequence(EncodingUtils.createEndpointReference(broker.producerUrl, null)); + } + } else { + ncr.setSequenceType(Constants.NoProducers); + } + try { + EncodingUtils.encodeToStream(encodingRegistry, ncr, ostream); + } catch(IOUtilsException e) { + throw new RuntimeException(e); + } + } + } + + private void handleNewProducer(NewProducer np, ServletOutputStream ostream) { + synchronized(notificationTypeLock) { + if (notificationTypeLock.isLocked) { + try { notificationTypeLock.wait(); } catch(InterruptedException e) {} + } + URL producerUrl = np.getReference().getEndpointAddress().getAddress(); + if (brokerList == null) { + addProducer(producerUrl); + } + + NewProducerResponse npr = new NewProducerResponse(); + if (consumerList != null) { + npr.setSequenceType(Constants.EndConsumers); + for (URL consumerUrl : consumerList) { + npr.addReferenceToSequence(EncodingUtils.createEndpointReference(consumerUrl, null)); + } + } else if(brokerList != null) { + npr.setSequenceType(Constants.BrokerConsumers); + for (BrokerStruct broker : brokerList) { + npr.addReferenceToSequence(EncodingUtils.createEndpointReference(broker.consumerUrl, null)); + } + } else { + npr.setSequenceType(Constants.NoConsumers); + } + try { + EncodingUtils.encodeToStream(encodingRegistry, npr, ostream); + } catch(IOUtilsException e) { + throw new RuntimeException(e); + } + } + } + + private void handleNewBroker(NewBroker nb, ServletOutputStream ostream) { + synchronized(notificationTypeLock) { + if (notificationTypeLock.isLocked) { + try { notificationTypeLock.wait(); } catch(InterruptedException e) {} + } + NewBrokerResponse nbr = new NewBrokerResponse(); + if (consumerList != null || producerList != null || brokerList == null) { + nbr.setFirstBroker(true); + EndConsumers endConsumers = new EndConsumers(); + if (consumerList != null) { + endConsumers.setSequenceType(Constants.EndConsumers); + for (URL consumerUrl : consumerList) { + endConsumers.addReferenceToSequence(EncodingUtils.createEndpointReference(consumerUrl, null)); + } + } else { + endConsumers.setSequenceType(Constants.NoConsumers); + } + nbr.setEndConsumers(endConsumers); + EndProducers endProducers = new EndProducers(); + if (producerList != null) { + endProducers.setSequenceType(Constants.EndProducers); + for (URL producerUrl : producerList) { + endProducers.addReferenceToSequence(EncodingUtils.createEndpointReference(producerUrl, null)); + } + } else { + endProducers.setSequenceType(Constants.NoProducers); + } + nbr.setEndProducers(endProducers); + } else { + nbr.setFirstBroker(false); + Brokers brokers = new Brokers(); + for (BrokerStruct brokerStruct : brokerList) { + Broker brokerElt = new Broker(); + BrokerConsumerReference bcr = new BrokerConsumerReference(); + bcr.setReference(EncodingUtils.createEndpointReference(brokerStruct.consumerUrl, brokerStruct.brokerID)); + brokerElt.setBrokerConsumerReference(bcr); + + BrokerProducerReference bpr = new BrokerProducerReference(); + bpr.setReference(EncodingUtils.createEndpointReference(brokerStruct.producerUrl, brokerStruct.brokerID)); + brokerElt.setBrokerProducerReference(bpr); + brokers.addBrokerToSequence(brokerElt); + } + nbr.setBrokers(brokers); + } + EndpointReference consumerEPR = nb.getBrokerConsumerReference().getReference(); + URL consumerUrl = consumerEPR.getEndpointAddress().getAddress(); + BrokerID consumerBrokerID = consumerEPR.getReferenceProperties().getProperty(BrokerID.class); + EndpointReference producerEPR = nb.getBrokerProducerReference().getReference(); + URL producerUrl = producerEPR.getEndpointAddress().getAddress(); + BrokerID producerBrokerID = producerEPR.getReferenceProperties().getProperty(BrokerID.class); + if (consumerBrokerID == null || + producerBrokerID == null || + !consumerBrokerID.getID().equals(producerBrokerID.getID())) { + throw new RuntimeException("Producer and consumer broker ids do not match"); + } + // only add broker if consumerList == null && producerList == null + // otherwise, make it a pending broker and wait for ack + // TODO block for a configurable amount of time + BrokerStruct broker = new BrokerStruct(consumerUrl, producerUrl, consumerBrokerID.getID()); + if (consumerList == null && producerList == null) { + addBroker(broker); + } else { + pendingBroker = broker; + notificationTypeLock.isLocked = true; + } + try { + EncodingUtils.encodeToStream(encodingRegistry, nbr, ostream); + } catch(IOUtilsException e) { + throw new RuntimeException(e); + } + } + } + + private void handleNewBrokerAck() { + synchronized(notificationTypeLock) { + if (!notificationTypeLock.isLocked) { + notificationTypeLock.notifyAll(); + throw new RuntimeException("Notification type should be locked"); + } + if (brokerList != null) { + notificationTypeLock.isLocked = false; + notificationTypeLock.notifyAll(); + throw new RuntimeException("Can't add pending broker to non-empty broker list"); + } + if (pendingBroker == null) { + notificationTypeLock.isLocked = false; + notificationTypeLock.notifyAll(); + throw new RuntimeException("Missing pending broker"); + } + addBroker(pendingBroker); + consumerList = null; + producerList = null; + pendingBroker = null; + notificationTypeLock.isLocked = false; + notificationTypeLock.notifyAll(); + } + } + + private void handleRemoveBroker(RemoveBroker rb) { + synchronized(notificationTypeLock) { + if (notificationTypeLock.isLocked) { + try { notificationTypeLock.wait(); } catch(InterruptedException e) {} + } + + if (brokerList == null) { + throw new RuntimeException("No broker to remove for [" + notificationType + "]"); + } + + NeighborBrokerConsumers nbcs = rb.getNeighborBrokerConsumers(); + EndpointReference rbEpr = rb.getBrokerConsumerReference().getReference(); + if (nbcs != null && nbcs.getReferenceSequence() != null) { + List neighborBrokers = new ArrayList(); + for (EndpointReference neighborBrokerConsumerEpr : nbcs.getReferenceSequence()) { + BrokerStruct neighborBrokerStruct = null; + URL neighborBrokerConsumerEprUrl = neighborBrokerConsumerEpr.getEndpointAddress().getAddress(); + for (BrokerStruct brokerStruct : brokerList) { + if (brokerStruct.consumerUrl.equals(neighborBrokerConsumerEprUrl)) { + neighborBrokerStruct = brokerStruct; + break; + } + } + if (neighborBrokerStruct == null) { + throw new RuntimeException("Can't find neighbor broker for consumer EPR [" + + neighborBrokerConsumerEprUrl + "]"); + } + BrokerConsumerReference bcr = new BrokerConsumerReference(); + bcr.setReference(EncodingUtils.createEndpointReference(neighborBrokerStruct.consumerUrl, neighborBrokerStruct.brokerID)); + BrokerProducerReference bpr = new BrokerProducerReference(); + bpr.setReference(EncodingUtils.createEndpointReference(neighborBrokerStruct.producerUrl, neighborBrokerStruct.brokerID)); + Broker neighborBroker = new Broker(); + neighborBroker.setBrokerConsumerReference(bcr); + neighborBroker.setBrokerProducerReference(bpr); + neighborBrokers.add(neighborBroker); + } + int lastIndex = neighborBrokers.size() - 1; + for (int index = lastIndex; index >= 0; index--) { + List writeableNeighborBrokers = ((index > 0) ? neighborBrokers.subList(0, index) : null); + WriteableReplaceBrokerConnection wrbc = new WriteableReplaceBrokerConnection(rbEpr, writeableNeighborBrokers); + URL targetUrl = + neighborBrokers.get(index).getBrokerProducerReference().getReference().getEndpointAddress().getAddress(); + try { + IOUtils.sendHttpRequest(targetUrl, Constants.REPLACE_BROKER_CONNECTION_OP, wrbc, null); + } catch(Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + } + + BrokerStruct removedBrokerStruct = null; + URL rbEprUrl = rbEpr.getEndpointAddress().getAddress(); + for (BrokerStruct brokerSruct : brokerList) { + if (brokerSruct.consumerUrl.equals(rbEprUrl)) { + removedBrokerStruct = brokerSruct; + break; + } + } + if (removedBrokerStruct == null) { + throw new RuntimeException("Can't find broker to remove for EPR [" + rbEprUrl + "]"); + } + if(!brokerList.remove(removedBrokerStruct)) { + throw new RuntimeException("Broker was not removed"); + } + } + } + } + + class NotificationTypeLock { + public boolean isLocked; + } + + class WriteableEPW implements Writeable { + private EndpointReferenceWrapper epw; + + public WriteableEPW(EndpointReferenceWrapper epw, URL url) { + EndpointAddress epa = new EndpointAddress(); + epa.setAddress(url); + EndpointReference epr = new EndpointReference(); + epr.setEndpointAddress(epa); + epw.setReference(epr); + this.epw = epw; + } + + public void write(OutputStream os) throws IOUtilsException { + EncodingUtils.encodeToStream(encodingRegistry, epw, os); + } + } + + class InputStreamDecoder implements ReadableContinuation { + + public Object read(InputStream istream) throws IOUtilsException { + try { + return EncodingUtils.decodeFromStream(encodingRegistry, istream); + } catch(EncodingException e) { + throw new IOUtilsException(e); + } + } + } + + class BrokerStruct { + public URL consumerUrl; + public URL producerUrl; + public String brokerID; + + public BrokerStruct(URL consumerUrl, URL producerUrl, String brokerID) { + this.consumerUrl = consumerUrl; + this.producerUrl = producerUrl; + this.brokerID = brokerID; + } + } + + class WriteableNewBroker implements Writeable { + private NewBroker newBroker; + + public WriteableNewBroker(URL consumerUrl, URL producerUrl, String brokerID) { + newBroker = new NewBroker(); + BrokerConsumerReference bcr = new BrokerConsumerReference(); + bcr.setReference(EncodingUtils.createEndpointReference(consumerUrl, brokerID)); + newBroker.setBrokerConsumerReference(bcr); + + BrokerProducerReference bpr = new BrokerProducerReference(); + bpr.setReference(EncodingUtils.createEndpointReference(producerUrl, brokerID)); + newBroker.setBrokerProducerReference(bpr); + } + + public void write(OutputStream os) throws IOUtilsException { + EncodingUtils.encodeToStream(encodingRegistry, newBroker, os); + } + } + + class WriteableNewBrokerAck implements Writeable { + public void write(OutputStream os) throws IOUtilsException { + EncodingUtils.encodeToStream(encodingRegistry, new NewBrokerAck(), os); + } + } + + class WriteableRemoveBroker implements Writeable { + private RemoveBroker removeBroker; + + public WriteableRemoveBroker(EndpointReference brokerConsumerEpr, List neighborBrokerConsumerEprs) { + removeBroker = new RemoveBroker(); + BrokerConsumerReference brokerConsumerReference = new BrokerConsumerReference(); + brokerConsumerReference.setReference(brokerConsumerEpr); + removeBroker.setBrokerConsumerReference(brokerConsumerReference); + if (neighborBrokerConsumerEprs != null) { + NeighborBrokerConsumers neighborBrokerConsumers = new NeighborBrokerConsumers(); + neighborBrokerConsumers.setReferenceSequence(neighborBrokerConsumerEprs); + neighborBrokerConsumers.setSequenceType(Constants.BrokerConsumers); + removeBroker.setNeighborBrokerConsumers(neighborBrokerConsumers); + } + } + + public void write(OutputStream os) throws IOUtilsException { + EncodingUtils.encodeToStream(encodingRegistry, removeBroker, os); + } + } + + class WriteableReplaceBrokerConnection implements Writeable { + private ReplaceBrokerConnection replaceBrokerConnection; + + public WriteableReplaceBrokerConnection(EndpointReference removedBrokerEpr, List brokerSequence) { + replaceBrokerConnection = new ReplaceBrokerConnection(); + RemovedBroker removedBroker = new RemovedBroker(); + removedBroker.setReference(removedBrokerEpr); + replaceBrokerConnection.setRemovedBroker(removedBroker); + if (brokerSequence != null) { + Neighbors neighbors = new Neighbors(); + neighbors.setBrokerSequence(brokerSequence); + replaceBrokerConnection.setNeighbors(neighbors); + } + } + + public void write(OutputStream os) throws IOUtilsException { + EncodingUtils.encodeToStream(encodingRegistry, replaceBrokerConnection, os); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBroker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBroker.java new file mode 100644 index 0000000000..e99845d886 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBroker.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.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractBroker implements EncodingObject { + + private BrokerProducerReference brokerProducerReference; + private BrokerConsumerReference brokerConsumerReference; + + public BrokerProducerReference getBrokerProducerReference() { + return this.brokerProducerReference; + } + + public void setBrokerProducerReference(BrokerProducerReference brokerProducerReference) { + this.brokerProducerReference = brokerProducerReference; + } + + public BrokerConsumerReference getBrokerConsumerReference() { + return this.brokerConsumerReference; + } + + public void setBrokerConsumerReference(BrokerConsumerReference brokerConsumerReference) { + this.brokerConsumerReference = brokerConsumerReference; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBrokerEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBrokerEnDeCoder.java new file mode 100644 index 0000000000..76eb204f21 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBrokerEnDeCoder.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public abstract class AbstractBrokerEnDeCoder extends AbstractEnDeCoder { + + public AbstractBrokerEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(B encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + QName qName = getEncodingObjectQName(); + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, qName.getLocalPart(), qName.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, qName.getNamespaceURI()); + registry.encode(encodingObject.getBrokerConsumerReference(), writer); + registry.encode(encodingObject.getBrokerProducerReference(), writer); + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public B decode(XMLStreamReader reader) throws EncodingException { + + try { + B brokerElement = getEncodingObjectType().newInstance(); + boolean haveBCR = false; + boolean haveBPR = false; + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + if (encodingObject instanceof BrokerConsumerReference && !haveBCR) { + brokerElement.setBrokerConsumerReference((BrokerConsumerReference)encodingObject); + haveBCR = true; + } else if(encodingObject instanceof BrokerProducerReference && !haveBPR) { + brokerElement.setBrokerProducerReference((BrokerProducerReference)encodingObject); + haveBPR = true; + } else { + throw new EncodingException("Invalid encoding object"); + } + break; + case END_ELEMENT: + if (!haveBCR) { + throw new EncodingException("Missing broker consumer reference"); + } + if (!haveBPR) { + throw new EncodingException("Missing broker producer reference"); + } + return brokerElement; + } + } + } catch (Exception ex) { + throw new EncodingException(ex); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractEnDeCoder.java new file mode 100644 index 0000000000..536801016c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public abstract class AbstractEnDeCoder implements + EnDeCoder { + + protected EncodingRegistry registry; + + protected AbstractEnDeCoder(EncodingRegistry registry) { + + this.registry = registry; + } + + public void start() { + Class encodingType = getEncodingObjectType(); + QName encodingQName = getEncodingObjectQName(); + + registry.registerEnDeCoder(encodingType, encodingQName, this); + } + + public void stop() { + Class encodingType = getEncodingObjectType(); + QName encodingQName = getEncodingObjectQName(); + + registry.unregisterEnDeCoder(encodingType, encodingQName); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Broker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Broker.java new file mode 100644 index 0000000000..3b2aacef4c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Broker.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class Broker extends AbstractBroker { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReference.java new file mode 100644 index 0000000000..94357cd98d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReference.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class BrokerConsumerReference extends EndpointReferenceWrapper { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReferenceEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReferenceEnDeCoder.java new file mode 100644 index 0000000000..66f0a198e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReferenceEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class BrokerConsumerReferenceEnDeCoder extends EndpointReferenceWrapperEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.BrokerConsumerReference); + + public BrokerConsumerReferenceEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return BrokerConsumerReference.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerEnDeCoder.java new file mode 100644 index 0000000000..e6e6b05a42 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class BrokerEnDeCoder extends AbstractBrokerEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.Broker); + + public BrokerEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return Broker.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerID.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerID.java new file mode 100644 index 0000000000..7c53d529a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerID.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.sca.binding.notification.encoding; + +import java.util.UUID; + +/** + * @version $Rev$ $Date$ + */ +public class BrokerID implements EncodingObject { + + private String id; + + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + public static String generate() { + return UUID.randomUUID().toString(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerIDEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerIDEnDeCoder.java new file mode 100644 index 0000000000..a500a2a854 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerIDEnDeCoder.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class BrokerIDEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.BrokerID); + + public BrokerIDEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(BrokerID encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, QNAME.getLocalPart(), QNAME.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, QNAME.getNamespaceURI()); + writer.writeCharacters(encodingObject.getID()); + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public BrokerID decode(XMLStreamReader reader) throws EncodingException { + + try { + BrokerID brokerIDElement = new BrokerID(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + break; + case XMLStreamConstants.CHARACTERS: + if (reader.hasText()) { + String id = reader.getText(); + brokerIDElement.setID(id); + } else { + throw new EncodingException("Broker ID missing value"); + } + break; + case END_ELEMENT: + return brokerIDElement; + } + } + } catch (XMLStreamException ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return BrokerID.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReference.java new file mode 100644 index 0000000000..a6a2b15a15 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReference.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class BrokerProducerReference extends EndpointReferenceWrapper { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReferenceEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReferenceEnDeCoder.java new file mode 100644 index 0000000000..209416c203 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReferenceEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class BrokerProducerReferenceEnDeCoder extends EndpointReferenceWrapperEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.BrokerProducerReference); + + public BrokerProducerReferenceEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return BrokerProducerReference.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Brokers.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Brokers.java new file mode 100644 index 0000000000..24395ee0a6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Brokers.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.sca.binding.notification.encoding; + +import java.util.ArrayList; +import java.util.List; + +/** + * @version $Rev$ $Date$ + */ +public class Brokers implements EncodingObject { + + private List brokerSequence; + + public List getBrokerSequence() { + return brokerSequence; + } + + public void addBrokerToSequence(Broker broker) { + if(this.brokerSequence == null) { + this.brokerSequence = new ArrayList(); + } + this.brokerSequence.add(broker); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokersEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokersEnDeCoder.java new file mode 100644 index 0000000000..1dba2533d2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokersEnDeCoder.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class BrokersEnDeCoder extends AbstractEnDeCoder { + + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.Brokers); + + public BrokersEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(Brokers encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + QName qName = getEncodingObjectQName(); + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, qName.getLocalPart(), qName.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, qName.getNamespaceURI()); + if (encodingObject.getBrokerSequence() != null) { + for (Broker broker : encodingObject.getBrokerSequence()) { + registry.encode(broker, writer); + } + } + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public Brokers decode(XMLStreamReader reader) throws EncodingException { + + try { + Brokers brokersElement = new Brokers(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + brokersElement.addBrokerToSequence((Broker)encodingObject); + break; + case END_ELEMENT: + return brokersElement; + } + } + } catch (XMLStreamException ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return Brokers.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverride.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverride.java new file mode 100644 index 0000000000..5783d0de02 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverride.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.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class ConnectionOverride implements EncodingObject { + + private BrokerConsumerReference brokerConsumerReference; + + public BrokerConsumerReference getBrokerConsumerReference() { + return this.brokerConsumerReference; + } + + public void setBrokerConsumerReference(BrokerConsumerReference brokerConsumerReference) { + this.brokerConsumerReference = brokerConsumerReference; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideEnDeCoder.java new file mode 100644 index 0000000000..bec3e6ff29 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class ConnectionOverrideEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.ConnectionOverride); + + public ConnectionOverrideEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(ConnectionOverride encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, QNAME.getLocalPart(), QNAME.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, QNAME.getNamespaceURI()); + registry.encode(encodingObject.getBrokerConsumerReference(), writer); + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public ConnectionOverride decode(XMLStreamReader reader) throws EncodingException { + + try { + ConnectionOverride connectionOverrideElement = new ConnectionOverride(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + connectionOverrideElement.setBrokerConsumerReference((BrokerConsumerReference)encodingObject); + break; + case END_ELEMENT: + return connectionOverrideElement; + } + } + } catch (Exception ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return ConnectionOverride.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponse.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponse.java new file mode 100644 index 0000000000..91ba05404a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponse.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class ConnectionOverrideResponse implements EncodingObject { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponseEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponseEnDeCoder.java new file mode 100644 index 0000000000..9012aaeb25 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponseEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class ConnectionOverrideResponseEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.ConnectionOverrideResponse); + + public ConnectionOverrideResponseEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(ConnectionOverrideResponse encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, QNAME.getLocalPart(), QNAME.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, QNAME.getNamespaceURI()); + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public ConnectionOverrideResponse decode(XMLStreamReader reader) throws EncodingException { + + try { + ConnectionOverrideResponse connectionOverrideResponseElement = new ConnectionOverrideResponse(); + while (true) { + switch (reader.next()) { + case END_ELEMENT: + return connectionOverrideResponseElement; + } + } + } catch (Exception ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return ConnectionOverrideResponse.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Constants.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Constants.java new file mode 100644 index 0000000000..ca64c15305 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Constants.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.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public interface Constants { + + String NOTIFICATION_NS = "http://docs.oasis-open.org/wsn/b-2"; + String NOTIFICATION_PREFIX = "wsnt"; + String ADDRESSING_NS = "http://schemas.xmlsoap.org/ws/2004/08/addressing"; + String ADDRESSING_PREFIX = "wsa"; + String Subscribe = "Subscribe"; + String ConsumerReference = "ConsumerReference"; + String Address = "Address"; + String ReferenceProperties = "ReferenceProperties"; + String EndpointReference = "EndpointReference"; + String BrokerID = "BrokerID"; + String NewConsumer = "NewConsumer"; + String NewProducer = "NewProducer"; + String NewConsumerResponse = "NewConsumerResponse"; + String NewProducerResponse = "NewProducerResponse"; + String ConsumerSequenceType = "ConsumerSequenceType"; + String EndConsumers = "EndConsumers"; + String BrokerConsumers = "BrokerConsumers"; + String NoConsumers = "NoConsumers"; + String ProducerSequenceType = "ProducerSequenceType"; + String EndProducers = "EndProducers"; + String BrokerProducers = "BrokerProducers"; + String NoProducers = "NoProducers"; + String Broker = "Broker"; + String NewBroker = "NewBroker"; + String NewBrokerAck = "NewBrokerAck"; + String BrokerConsumerReference = "BrokerConsumerReference"; + String BrokerProducerReference = "BrokerProducerReference"; + String NewBrokerResponse = "NewBrokerResponse"; + String FirstBroker = "FirstBroker"; + String Brokers = "Brokers"; + String ConnectionOverride = "ConnectionOverride"; + String ConnectionOverrideResponse = "ConnectionOverrideResponse"; + String NeighborBrokerConsumers = "NeighborBrokerConsumers"; + String RemoveBroker = "RemoveBroker"; + String RemovedBroker = "RemovedBroker"; + String Neighbors = "Neighbors"; + String ReplaceBrokerConnection = "ReplaceBrokerConnection"; + + String SUBSCRIBE_OP = "subscribe"; + String CONNECTION_OVERRIDE_OP = "connectionOverride"; + String NEW_CONSUMER_OP = "newConsumer"; + String NEW_PRODUCER_OP = "newProducer"; + String NEW_BROKER_OP = "newBroker"; + String NEW_BROKER_ACK_OP = "newBrokerAck"; + String REMOVE_BROKER_OP = "removeBroker"; + String REPLACE_BROKER_CONNECTION_OP = "replaceBrokerConnection"; + + String Broker_ID = "brokerID"; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReference.java new file mode 100644 index 0000000000..1c678a2b96 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReference.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class ConsumerReference extends EndpointReferenceWrapper { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReferenceEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReferenceEnDeCoder.java new file mode 100644 index 0000000000..8c6f684425 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReferenceEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class ConsumerReferenceEnDeCoder extends EndpointReferenceWrapperEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.ConsumerReference); + + public ConsumerReferenceEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return ConsumerReference.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/DefaultEncodingRegistry.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/DefaultEncodingRegistry.java new file mode 100644 index 0000000000..5b28aedcf9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/DefaultEncodingRegistry.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.sca.binding.notification.encoding; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class DefaultEncodingRegistry implements EncodingRegistry { + + private final Map, EnDeCoder> encoderRegistry = + new ConcurrentHashMap, EnDeCoder>(); + + private final Map decoderRegistry = new ConcurrentHashMap(); + + public DefaultEncodingRegistry() { + } + + public void registerEnDeCoder(Class encodingClass, QName qname, EnDeCoder enDeCoder) { + + encoderRegistry.put(encodingClass, enDeCoder); + decoderRegistry.put(qname, enDeCoder); + } + + public void unregisterEnDeCoder(Class encodingClass, QName qname) { + + encoderRegistry.remove(encodingClass); + decoderRegistry.remove(qname); + } + + @SuppressWarnings("unchecked") + public void encode(EncodingObject encodingObject, XMLStreamWriter writer) throws EncodingException { + + EnDeCoder encoder = encoderRegistry.get(encodingObject.getClass()); + if (encoder == null) { + throw new EncodingException("No encoder defined for " + encodingObject.getClass()); + } + encoder.encode(encodingObject, writer); + } + + public EncodingObject decode(XMLStreamReader reader) throws EncodingException { + + QName qname = reader.getName(); + + EnDeCoder decoder = decoderRegistry.get(qname); + if (decoder == null) { + throw new EncodingException("No decoder defined for " + qname); + } + return decoder.decode(reader); + } + + public void stop() { + encoderRegistry.clear(); + decoderRegistry.clear(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EnDeCoder.java new file mode 100644 index 0000000000..bf6094582e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public interface EnDeCoder { + + /** + * Encodes an object to the specified stream writer. + * + * @param encodingObject Object to be serialized. + * @param writer Stream writer to which the infoset is serialized. + * @throws EncodingException In case of any encoding error. + */ + void encode(E encodingObject, XMLStreamWriter writer) throws EncodingException; + + /** + * Decodes an XML stream to an object. + * + * @param reader XML stream from where the encoded XML is read. + * @return Encoding object. + * @throws EncodingException In case of any encoding error. + */ + E decode(XMLStreamReader reader) throws EncodingException; + + /** + * Gets the qualified name of the XML fragment for the Encoding + * object. + * + * @return Qualified name of the XML fragment. + */ + QName getEncodingObjectQName(); + + /** + * Returns the type of the encoding object. + * + * @return Encoding object type. + */ + Class getEncodingObjectType(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingException.java new file mode 100644 index 0000000000..ee12161903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingException.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.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +@SuppressWarnings("serial") +public class EncodingException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Initializes the exception message. + * + * @param message Message for the exception. + */ + public EncodingException(String message) { + super(message); + } + + /** + * Initializes the root cause. + * + * @param cause Root cause for the exception. + */ + public EncodingException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingObject.java new file mode 100644 index 0000000000..bf94da374c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingObject.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public interface EncodingObject { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingRegistry.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingRegistry.java new file mode 100644 index 0000000000..92f10cd4b3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingRegistry.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public interface EncodingRegistry { + + /** + * Registers an en/de coder. + * + * @param Encoding object type. + * @param encodingClass Encoding object class. + * @param qname Qualified name of the root element of the encoded XML. + * @param enDeCoder Encoding object enDeCoder. + */ + void registerEnDeCoder(Class encodingClass, QName qname, EnDeCoder enDeCoder); + + void unregisterEnDeCoder(Class encodingClass, QName qname); + + /** + * Encodes an object. + * + * @param encodingObject Encoding object to be encoded. + * @param writer Writer to which encoded information is written. + */ + void encode(EncodingObject encodingObject, XMLStreamWriter writer) throws EncodingException; + + /** + * Decodes an XML stream to an encoding object. + * + * @param reader Reader from which encoded information is read. + * @return Encoding object from the encoded stream. + */ + EncodingObject decode(XMLStreamReader reader) throws EncodingException; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingUtils.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingUtils.java new file mode 100644 index 0000000000..264566aae4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingUtils.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.sca.binding.notification.encoding; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.binding.notification.util.IOUtils.IOUtilsException; + +/** + * @version $Rev$ $Date$ + */ +public class EncodingUtils { + + private static XMLOutputFactory xof = XMLOutputFactory.newInstance(); + private static XMLInputFactory xif = XMLInputFactory.newInstance(); + + public static void encodeToStream(EncodingRegistry encodingRegistry, + EncodingObject eo, + OutputStream os) throws IOUtilsException { + try { + XMLStreamWriter writer = xof.createXMLStreamWriter(os); + encodingRegistry.encode(eo, writer); + writer.flush(); + writer.close(); + } catch(Exception e) { + throw new IOUtilsException(e); + } + } + + public static EncodingObject decodeFromStream(EncodingRegistry encodingRegistry, + InputStream istream) throws EncodingException { + EncodingObject eo = null; + try { + XMLStreamReader reader = xif.createXMLStreamReader(istream); + reader.next(); + eo = encodingRegistry.decode(reader); + reader.close(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + + return eo; + } + + public static EndpointReference createEndpointReference(URL address, String brokerID) { + EndpointAddress epa = new EndpointAddress(); + epa.setAddress(address); + EndpointReference epr = new EndpointReference(); + epr.setEndpointAddress(epa); + if (brokerID != null) { + BrokerID bi = new BrokerID(); + bi.setID(brokerID); + ReferenceProperties rp = new ReferenceProperties(); + rp.addProperty(bi); + epr.setReferenceProperties(rp); + } + return epr; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumers.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumers.java new file mode 100644 index 0000000000..8066184da9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumers.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class EndConsumers extends EndpointReferenceSequence { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumersEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumersEnDeCoder.java new file mode 100644 index 0000000000..5e3afc8195 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumersEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class EndConsumersEnDeCoder extends EndpointReferenceSequenceEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.EndConsumers); + + public EndConsumersEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return EndConsumers.class; + } + + @Override + protected void encodeSequenceTypeAttribute(EndConsumers encodingObject, XMLStreamWriter writer) throws EncodingException { + try { + writer.writeAttribute(Constants.ConsumerSequenceType, encodingObject.getSequenceType()); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + @Override + protected String decodeSequenceTypeAttribute(XMLStreamReader reader) { + return reader.getAttributeValue(null, Constants.ConsumerSequenceType); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducers.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducers.java new file mode 100644 index 0000000000..b43ad5c214 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducers.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class EndProducers extends EndpointReferenceSequence { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducersEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducersEnDeCoder.java new file mode 100644 index 0000000000..3840b1caf9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducersEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class EndProducersEnDeCoder extends EndpointReferenceSequenceEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.EndProducers); + + public EndProducersEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return EndProducers.class; + } + + @Override + protected void encodeSequenceTypeAttribute(EndProducers encodingObject, XMLStreamWriter writer) throws EncodingException { + try { + writer.writeAttribute(Constants.ProducerSequenceType, encodingObject.getSequenceType()); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + @Override + protected String decodeSequenceTypeAttribute(XMLStreamReader reader) { + return reader.getAttributeValue(null, Constants.ProducerSequenceType); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddress.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddress.java new file mode 100644 index 0000000000..f2a36d89db --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddress.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.sca.binding.notification.encoding; + +import java.net.URL; + +/** + * @version $Rev$ $Date$ + */ +public class EndpointAddress implements EncodingObject { + + private URL address; + + public URL getAddress() { + return address; + } + + public void setAddress(URL address) { + this.address = address; + } + + public void setAddress(String addressText) throws EncodingException { + try { + this.address = new URL(addressText); + } catch(Exception e) { + throw new EncodingException(e); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddressEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddressEnDeCoder.java new file mode 100644 index 0000000000..8195c80c49 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddressEnDeCoder.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class EndpointAddressEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.ADDRESSING_NS, Constants.Address); + + public EndpointAddressEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(EndpointAddress encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + writer.writeStartElement(Constants.ADDRESSING_PREFIX, QNAME.getLocalPart(), QNAME.getNamespaceURI()); + writer.writeNamespace(Constants.ADDRESSING_PREFIX, QNAME.getNamespaceURI()); + writer.writeCharacters(encodingObject.getAddress().toString()); + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public EndpointAddress decode(XMLStreamReader reader) throws EncodingException { + + try { + EndpointAddress endpointAddressElement = new EndpointAddress(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + break; + case XMLStreamConstants.CHARACTERS: + if (reader.hasText()) { + String address = reader.getText(); + endpointAddressElement.setAddress(address); + } else { + throw new EncodingException("Endpoint address is missing address"); + } + break; + case END_ELEMENT: + return endpointAddressElement; + } + } + } catch (XMLStreamException ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return EndpointAddress.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReference.java new file mode 100644 index 0000000000..beba8fdc9b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReference.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.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class EndpointReference implements EncodingObject { + + private EndpointAddress endpointAddress; + private ReferenceProperties referenceProperties; + + public EndpointAddress getEndpointAddress() { + return this.endpointAddress; + } + + public void setEndpointAddress(EndpointAddress endpointAddress) { + this.endpointAddress = endpointAddress; + } + + public ReferenceProperties getReferenceProperties() { + return this.referenceProperties; + } + + public void setReferenceProperties(ReferenceProperties referenceProperties) { + this.referenceProperties = referenceProperties; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceEnDeCoder.java new file mode 100644 index 0000000000..cfc747f59e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class EndpointReferenceEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.ADDRESSING_NS, Constants.EndpointReference); + + public EndpointReferenceEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(EndpointReference encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + writer.writeStartElement(Constants.ADDRESSING_PREFIX, QNAME.getLocalPart(), QNAME.getNamespaceURI()); + writer.writeNamespace(Constants.ADDRESSING_PREFIX, QNAME.getNamespaceURI()); + registry.encode(encodingObject.getEndpointAddress(), writer); + if (encodingObject.getReferenceProperties() != null) { + registry.encode(encodingObject.getReferenceProperties(), writer); + } + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public EndpointReference decode(XMLStreamReader reader) throws EncodingException { + + try { + EndpointReference endpointReferenceElement = new EndpointReference(); + boolean haveEPA = false; + boolean haveRP = false; + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + if (encodingObject instanceof EndpointAddress && !haveEPA) { + endpointReferenceElement.setEndpointAddress((EndpointAddress)encodingObject); + haveEPA = true; + } else if(encodingObject instanceof ReferenceProperties && !haveRP) { + endpointReferenceElement.setReferenceProperties((ReferenceProperties)encodingObject); + haveRP = true; + } else { + throw new EncodingException("Invalid encoding object"); + } + break; + case END_ELEMENT: + if (!haveEPA) { + throw new EncodingException("Missing endpoint address"); + } + return endpointReferenceElement; + } + } + } catch (Exception ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return EndpointReference.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequence.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequence.java new file mode 100644 index 0000000000..a9c901a431 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequence.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.sca.binding.notification.encoding; + +import java.util.ArrayList; +import java.util.List; + +/** + * @version $Rev$ $Date$ + */ +public class EndpointReferenceSequence implements EncodingObject { + + private List referenceSequence; + private String sequenceType; + + public List getReferenceSequence() { + return referenceSequence; + } + + public void addReferenceToSequence(EndpointReference address) { + if(this.referenceSequence == null) { + this.referenceSequence = new ArrayList(); + } + this.referenceSequence.add(address); + } + + public void setReferenceSequence(List referenceSequence) { + this.referenceSequence = referenceSequence; + } + + public String getSequenceType() { + return this.sequenceType; + } + + public void setSequenceType(String sequenceType) { + this.sequenceType = sequenceType; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequenceEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequenceEnDeCoder.java new file mode 100644 index 0000000000..864de25fd6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequenceEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public abstract class EndpointReferenceSequenceEnDeCoder extends AbstractEnDeCoder { + + public EndpointReferenceSequenceEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(ERS encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + QName qName = getEncodingObjectQName(); + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, qName.getLocalPart(), qName.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, qName.getNamespaceURI()); + encodeSequenceTypeAttribute(encodingObject, writer); + if (encodingObject.getReferenceSequence() != null) { + for (EndpointReference endpointReference : encodingObject.getReferenceSequence()) { + registry.encode(endpointReference, writer); + } + } + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + protected abstract void encodeSequenceTypeAttribute(ERS encodingObject, XMLStreamWriter writer) throws EncodingException; + + public ERS decode(XMLStreamReader reader) throws EncodingException { + + try { + ERS endpointReferenceSequenceElement = null; + try { + endpointReferenceSequenceElement = getEncodingObjectType().newInstance(); + } catch(Exception e) { + throw new EncodingException(e); + } + String sequenceType = decodeSequenceTypeAttribute(reader); + endpointReferenceSequenceElement.setSequenceType(sequenceType); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + endpointReferenceSequenceElement.addReferenceToSequence((EndpointReference)encodingObject); + break; + case END_ELEMENT: + return endpointReferenceSequenceElement; + } + } + } catch (XMLStreamException ex) { + throw new EncodingException(ex); + } + } + + protected abstract String decodeSequenceTypeAttribute(XMLStreamReader reader); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapper.java new file mode 100644 index 0000000000..b3f2c060fb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapper.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.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class EndpointReferenceWrapper implements EncodingObject { + + private EndpointReference reference; + + public EndpointReference getReference() { + return reference; + } + + public void setReference(EndpointReference reference) { + this.reference = reference; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapperEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapperEnDeCoder.java new file mode 100644 index 0000000000..979a6e8e34 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapperEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public abstract class EndpointReferenceWrapperEnDeCoder extends AbstractEnDeCoder { + + public EndpointReferenceWrapperEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(ERW encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + QName qName = getEncodingObjectQName(); + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, qName.getLocalPart(), qName.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, qName.getNamespaceURI()); + registry.encode(encodingObject.getReference(), writer); + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public ERW decode(XMLStreamReader reader) throws EncodingException { + + try { + ERW endpointReferenceWrapperElement = null; + try { + endpointReferenceWrapperElement = getEncodingObjectType().newInstance(); + } catch(Exception e) { + throw new EncodingException(e); + } + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + endpointReferenceWrapperElement.setReference((EndpointReference)encodingObject); + break; + case END_ELEMENT: + return endpointReferenceWrapperElement; + } + } + } catch (XMLStreamException ex) { + throw new EncodingException(ex); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumers.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumers.java new file mode 100644 index 0000000000..902fd823cd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumers.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class NeighborBrokerConsumers extends EndpointReferenceSequence { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumersEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumersEnDeCoder.java new file mode 100644 index 0000000000..ad149e3e4f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumersEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class NeighborBrokerConsumersEnDeCoder extends EndpointReferenceSequenceEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.NeighborBrokerConsumers); + + public NeighborBrokerConsumersEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return NeighborBrokerConsumers.class; + } + + @Override + protected void encodeSequenceTypeAttribute(NeighborBrokerConsumers encodingObject, XMLStreamWriter writer) throws EncodingException { + try { + writer.writeAttribute(Constants.ConsumerSequenceType, encodingObject.getSequenceType()); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + @Override + protected String decodeSequenceTypeAttribute(XMLStreamReader reader) { + return reader.getAttributeValue(null, Constants.ConsumerSequenceType); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Neighbors.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Neighbors.java new file mode 100644 index 0000000000..42f9e74a27 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Neighbors.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.sca.binding.notification.encoding; + +import java.util.ArrayList; +import java.util.List; + +/** + * @version $Rev$ $Date$ + */ +public class Neighbors implements EncodingObject { + + private List brokerSequence; + + public List getBrokerSequence() { + return brokerSequence; + } + + public void addBrokerToSequence(Broker broker) { + if(this.brokerSequence == null) { + this.brokerSequence = new ArrayList(); + } + this.brokerSequence.add(broker); + } + + public void setBrokerSequence(List brokerSequence) { + this.brokerSequence = brokerSequence; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborsEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborsEnDeCoder.java new file mode 100644 index 0000000000..fa05e2d7bd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborsEnDeCoder.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class NeighborsEnDeCoder extends AbstractEnDeCoder { + + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.Neighbors); + + public NeighborsEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(Neighbors encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + QName qName = getEncodingObjectQName(); + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, qName.getLocalPart(), qName.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, qName.getNamespaceURI()); + if (encodingObject.getBrokerSequence() != null) { + for (Broker broker : encodingObject.getBrokerSequence()) { + registry.encode(broker, writer); + } + } + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public Neighbors decode(XMLStreamReader reader) throws EncodingException { + + try { + Neighbors neighborsElement = new Neighbors(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + neighborsElement.addBrokerToSequence((Broker)encodingObject); + break; + case END_ELEMENT: + return neighborsElement; + } + } + } catch (XMLStreamException ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return Neighbors.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBroker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBroker.java new file mode 100644 index 0000000000..92578af219 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBroker.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class NewBroker extends AbstractBroker { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAck.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAck.java new file mode 100644 index 0000000000..48c34ba74f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAck.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class NewBrokerAck implements EncodingObject { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAckEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAckEnDeCoder.java new file mode 100644 index 0000000000..c9a3f1da79 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAckEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class NewBrokerAckEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.NewBrokerAck); + + public NewBrokerAckEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(NewBrokerAck encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, QNAME.getLocalPart(), QNAME.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, QNAME.getNamespaceURI()); + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public NewBrokerAck decode(XMLStreamReader reader) throws EncodingException { + + try { + NewBrokerAck newBrokerAck = new NewBrokerAck(); + while (true) { + switch (reader.next()) { + case END_ELEMENT: + return newBrokerAck; + } + } + } catch (Exception ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return NewBrokerAck.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerEnDeCoder.java new file mode 100644 index 0000000000..6e57ad41de --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class NewBrokerEnDeCoder extends AbstractBrokerEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.NewBroker); + + public NewBrokerEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return NewBroker.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponse.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponse.java new file mode 100644 index 0000000000..6f34fc0b7c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponse.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.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class NewBrokerResponse implements EncodingObject { + + private EndProducers endProducers; + private EndConsumers endConsumers; + private Brokers brokers; + private boolean firstBroker; + + public EndProducers getEndProducers() { + return this.endProducers; + } + + public void setEndProducers(EndProducers endProducers) { + this.endProducers = endProducers; + } + + public EndConsumers getEndConsumers() { + return this.endConsumers; + } + + public void setEndConsumers(EndConsumers endConsumers) { + this.endConsumers = endConsumers; + } + + public Brokers getBrokers() { + return this.brokers; + } + + public void setBrokers(Brokers brokers) { + this.brokers = brokers; + } + + public boolean isFirstBroker() { + return this.firstBroker; + } + + public void setFirstBroker(boolean firstBroker) { + this.firstBroker = firstBroker; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponseEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponseEnDeCoder.java new file mode 100644 index 0000000000..2ad969e1a6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponseEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class NewBrokerResponseEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.NewBrokerResponse); + + public NewBrokerResponseEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(NewBrokerResponse encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + QName qName = getEncodingObjectQName(); + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, qName.getLocalPart(), qName.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, qName.getNamespaceURI()); + writer.writeAttribute(Constants.FirstBroker, String.valueOf(encodingObject.isFirstBroker())); + if (encodingObject.isFirstBroker()) { + registry.encode(encodingObject.getEndConsumers(), writer); + registry.encode(encodingObject.getEndProducers(), writer); + } else { + registry.encode(encodingObject.getBrokers(), writer); + } + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public NewBrokerResponse decode(XMLStreamReader reader) throws EncodingException { + + try { + NewBrokerResponse newBrokerResponseElement = new NewBrokerResponse(); + boolean firstBroker = Boolean.parseBoolean(reader.getAttributeValue(null, Constants.FirstBroker)); + newBrokerResponseElement.setFirstBroker(firstBroker); + boolean haveEC = false; + boolean haveEP = false; + boolean haveB = false; + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + if (encodingObject instanceof EndProducers && !haveEP && firstBroker) { + newBrokerResponseElement.setEndProducers((EndProducers)encodingObject); + haveEP = true; + } else if(encodingObject instanceof EndConsumers && !haveEC && firstBroker) { + newBrokerResponseElement.setEndConsumers((EndConsumers)encodingObject); + haveEC = true; + } else if(encodingObject instanceof Brokers && !haveB && !firstBroker) { + newBrokerResponseElement.setBrokers((Brokers)encodingObject); + haveB = true; + } else { + throw new EncodingException("Invalid encoding object"); + } + break; + case END_ELEMENT: + if (!haveEP && firstBroker) { + throw new EncodingException("Missing end producers"); + } + if (!haveEC && firstBroker) { + throw new EncodingException("Missing end consumers"); + } + if (!haveB && !firstBroker) { + throw new EncodingException("Missing brokers"); + } + return newBrokerResponseElement; + } + } + } catch (Exception ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return NewBrokerResponse.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumer.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumer.java new file mode 100644 index 0000000000..a47e1f4e55 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumer.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class NewConsumer extends EndpointReferenceWrapper { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerEnDeCoder.java new file mode 100644 index 0000000000..8eac326019 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class NewConsumerEnDeCoder extends EndpointReferenceWrapperEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.NewConsumer); + + public NewConsumerEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return NewConsumer.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponse.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponse.java new file mode 100644 index 0000000000..60fb23be02 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponse.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class NewConsumerResponse extends EndpointReferenceSequence { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponseEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponseEnDeCoder.java new file mode 100644 index 0000000000..fbcd041621 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponseEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class NewConsumerResponseEnDeCoder extends EndpointReferenceSequenceEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.NewConsumerResponse); + + public NewConsumerResponseEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return NewConsumerResponse.class; + } + + @Override + protected void encodeSequenceTypeAttribute(NewConsumerResponse encodingObject, XMLStreamWriter writer) throws EncodingException { + try { + writer.writeAttribute(Constants.ProducerSequenceType, encodingObject.getSequenceType()); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + @Override + protected String decodeSequenceTypeAttribute(XMLStreamReader reader) { + return reader.getAttributeValue(null, Constants.ProducerSequenceType); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducer.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducer.java new file mode 100644 index 0000000000..aa9180dcd7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducer.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class NewProducer extends EndpointReferenceWrapper { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerEnDeCoder.java new file mode 100644 index 0000000000..38cf9e9467 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class NewProducerEnDeCoder extends EndpointReferenceWrapperEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.NewProducer); + + public NewProducerEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return NewProducer.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponse.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponse.java new file mode 100644 index 0000000000..49a4259333 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponse.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class NewProducerResponse extends EndpointReferenceSequence { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponseEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponseEnDeCoder.java new file mode 100644 index 0000000000..74d10fe02d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponseEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class NewProducerResponseEnDeCoder extends EndpointReferenceSequenceEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.NewProducerResponse); + + public NewProducerResponseEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return NewProducerResponse.class; + } + + @Override + protected void encodeSequenceTypeAttribute(NewProducerResponse encodingObject, XMLStreamWriter writer) throws EncodingException { + try { + writer.writeAttribute(Constants.ConsumerSequenceType, encodingObject.getSequenceType()); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + @Override + protected String decodeSequenceTypeAttribute(XMLStreamReader reader) { + return reader.getAttributeValue(null, Constants.ConsumerSequenceType); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferenceProperties.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferenceProperties.java new file mode 100644 index 0000000000..2ee9320f20 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferenceProperties.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.sca.binding.notification.encoding; + +import java.util.ArrayList; +import java.util.List; + +/** + * @version $Rev$ $Date$ + */ +public class ReferenceProperties implements EncodingObject { + + private List properties; + + public List getProperties() { + return properties; + } + + public void addProperty(EncodingObject property) { + if(this.properties == null) { + this.properties = new ArrayList(); + } + this.properties.add(property); + } + + @SuppressWarnings("unchecked") + public E getProperty(Class propertyType) { + if (this.properties == null) { + return null; + } + for (EncodingObject eo : properties) { + if (propertyType.isInstance(eo)) { + return (E)eo; + } + } + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferencePropertiesEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferencePropertiesEnDeCoder.java new file mode 100644 index 0000000000..9d06dfea97 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferencePropertiesEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class ReferencePropertiesEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.ADDRESSING_NS, Constants.ReferenceProperties); + + public ReferencePropertiesEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(ReferenceProperties encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + writer.writeStartElement(Constants.ADDRESSING_PREFIX, QNAME.getLocalPart(), QNAME.getNamespaceURI()); + writer.writeNamespace(Constants.ADDRESSING_PREFIX, QNAME.getNamespaceURI()); + if (encodingObject.getProperties() != null) { + for (EncodingObject property : encodingObject.getProperties()) { + registry.encode(property, writer); + } + } + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public ReferenceProperties decode(XMLStreamReader reader) throws EncodingException { + + try { + ReferenceProperties referencePropertiesElement = new ReferenceProperties(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject property = registry.decode(reader); + referencePropertiesElement.addProperty(property); + break; + case END_ELEMENT: + return referencePropertiesElement; + } + } + } catch (XMLStreamException ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return ReferenceProperties.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBroker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBroker.java new file mode 100644 index 0000000000..39050d158c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBroker.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.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class RemoveBroker implements EncodingObject { + + private BrokerConsumerReference brokerConsumerReference; + private NeighborBrokerConsumers neighborBrokerConsumers; + + public BrokerConsumerReference getBrokerConsumerReference() { + return this.brokerConsumerReference; + } + + public void setBrokerConsumerReference(BrokerConsumerReference brokerConsumerReference) { + this.brokerConsumerReference = brokerConsumerReference; + } + + public NeighborBrokerConsumers getNeighborBrokerConsumers() { + return this.neighborBrokerConsumers; + } + + public void setNeighborBrokerConsumers(NeighborBrokerConsumers neighborBrokerConsumers) { + this.neighborBrokerConsumers = neighborBrokerConsumers; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBrokerEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBrokerEnDeCoder.java new file mode 100644 index 0000000000..97834ea0a9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBrokerEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class RemoveBrokerEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.RemoveBroker); + + public RemoveBrokerEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(RemoveBroker encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, QNAME.getLocalPart(), QNAME.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, QNAME.getNamespaceURI()); + registry.encode(encodingObject.getBrokerConsumerReference(), writer); + if (encodingObject.getNeighborBrokerConsumers() != null) { + registry.encode(encodingObject.getNeighborBrokerConsumers(), writer); + } + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public RemoveBroker decode(XMLStreamReader reader) throws EncodingException { + + try { + RemoveBroker removeBrokerElement = new RemoveBroker(); + boolean haveBCR = false; + boolean haveNBC = false; + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + if (encodingObject instanceof BrokerConsumerReference && !haveBCR) { + removeBrokerElement.setBrokerConsumerReference((BrokerConsumerReference)encodingObject); + haveBCR = true; + } else if(encodingObject instanceof NeighborBrokerConsumers && !haveNBC) { + removeBrokerElement.setNeighborBrokerConsumers((NeighborBrokerConsumers)encodingObject); + haveNBC = true; + } else { + throw new EncodingException("Invalid encoding object"); + } + break; + case END_ELEMENT: + if (!haveBCR) { + throw new EncodingException("Missing broker consumer reference"); + } + return removeBrokerElement; + } + } + } catch (Exception ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return RemoveBroker.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBroker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBroker.java new file mode 100644 index 0000000000..047c5e9a58 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBroker.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class RemovedBroker extends EndpointReferenceWrapper { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBrokerEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBrokerEnDeCoder.java new file mode 100644 index 0000000000..25f92c38c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBrokerEnDeCoder.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.sca.binding.notification.encoding; + +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class RemovedBrokerEnDeCoder extends EndpointReferenceWrapperEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.RemovedBroker); + + public RemovedBrokerEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + + public QName getEncodingObjectQName() { + return QNAME; + } + + + public Class getEncodingObjectType() { + return RemovedBroker.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnection.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnection.java new file mode 100644 index 0000000000..8145c6b170 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnection.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.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class ReplaceBrokerConnection implements EncodingObject { + + private RemovedBroker removedBroker; + private Neighbors neighbors; + + public RemovedBroker getRemovedBroker() { + return this.removedBroker; + } + + public void setRemovedBroker(RemovedBroker removedBroker) { + this.removedBroker = removedBroker; + } + + public Neighbors getNeighbors() { + return this.neighbors; + } + + public void setNeighbors(Neighbors neighbors) { + this.neighbors = neighbors; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnectionEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnectionEnDeCoder.java new file mode 100644 index 0000000000..000f6690c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnectionEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class ReplaceBrokerConnectionEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.ReplaceBrokerConnection); + + public ReplaceBrokerConnectionEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(ReplaceBrokerConnection encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, QNAME.getLocalPart(), QNAME.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, QNAME.getNamespaceURI()); + registry.encode(encodingObject.getRemovedBroker(), writer); + if (encodingObject.getNeighbors() != null) { + registry.encode(encodingObject.getNeighbors(), writer); + } + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public ReplaceBrokerConnection decode(XMLStreamReader reader) throws EncodingException { + + try { + ReplaceBrokerConnection replaceBrokerConnectionElement = new ReplaceBrokerConnection(); + boolean haveRB = false; + boolean haveN = false; + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + if (encodingObject instanceof RemovedBroker && !haveRB) { + replaceBrokerConnectionElement.setRemovedBroker((RemovedBroker)encodingObject); + haveRB = true; + } else if(encodingObject instanceof Neighbors && !haveN) { + replaceBrokerConnectionElement.setNeighbors((Neighbors)encodingObject); + haveN = true; + } else { + throw new EncodingException("Invalid encoding object"); + } + break; + case END_ELEMENT: + if (!haveRB) { + throw new EncodingException("Missing removed broker"); + } + return replaceBrokerConnectionElement; + } + } + } catch (Exception ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return ReplaceBrokerConnection.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Subscribe.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Subscribe.java new file mode 100644 index 0000000000..aca5c70641 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Subscribe.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.sca.binding.notification.encoding; + +/** + * @version $Rev$ $Date$ + */ +public class Subscribe implements EncodingObject { + + private ConsumerReference consumerReference; + + public ConsumerReference getConsumerReference() { + return consumerReference; + } + + public void setConsumerReference(ConsumerReference consumerReference) { + this.consumerReference = consumerReference; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/SubscribeEnDeCoder.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/SubscribeEnDeCoder.java new file mode 100644 index 0000000000..04ee132b3e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/SubscribeEnDeCoder.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.sca.binding.notification.encoding; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class SubscribeEnDeCoder extends AbstractEnDeCoder { + + // QName for the root element + public static final QName QNAME = new QName(Constants.NOTIFICATION_NS, Constants.Subscribe); + + public SubscribeEnDeCoder(EncodingRegistry registry) { + super(registry); + } + + public void encode(Subscribe encodingObject, XMLStreamWriter writer) throws EncodingException { + + try { + writer.writeStartElement(Constants.NOTIFICATION_PREFIX, QNAME.getLocalPart(), QNAME.getNamespaceURI()); + writer.writeNamespace(Constants.NOTIFICATION_PREFIX, QNAME.getNamespaceURI()); + registry.encode(encodingObject.getConsumerReference(), writer); + writer.writeEndElement(); + } catch(XMLStreamException e) { + throw new EncodingException(e); + } + } + + public Subscribe decode(XMLStreamReader reader) throws EncodingException { + + try { + Subscribe subscribeElement = new Subscribe(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + EncodingObject encodingObject = registry.decode(reader); + subscribeElement.setConsumerReference((ConsumerReference)encodingObject); + break; + case END_ELEMENT: + return subscribeElement; + } + } + } catch (XMLStreamException ex) { + throw new EncodingException(ex); + } + } + + + public QName getEncodingObjectQName() { + + return QNAME; + } + + + public Class getEncodingObjectType() { + + return Subscribe.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/IOUtils.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/IOUtils.java new file mode 100644 index 0000000000..daac727cb6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/IOUtils.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.util; + +import java.io.ByteArrayOutputStream; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +/** + * @version $Rev$ $Date$ + */ +public class IOUtils { + + // FIXME: For some reason, tomcat converts the header names to be lower case, see TUSCANY-1791 + public static final String Notification_Source = "notification-source"; + public static final String Notification_Target = "notification-target"; + public static final String Notification_Operation = "notification-operation"; + + public static final int DEF_BLOCK_SIZE = 512; + + public static Object sendHttpRequest(URL targetURL, + String opName, + Writeable wbody, + ReadableContinuation rcont) throws Exception { + if (opName == null) { + opName = ""; + } + Map headers = new HashMap(); + headers.put(Notification_Operation, opName); + return sendHttpRequest(targetURL, headers, wbody, rcont); + } + + public static Object sendHttpRequest(URL targetURL, + Map headers, + Writeable wbody, + ReadableContinuation rcont) throws Exception { + + String targetUri = targetURL.toString(); + String sourceUri = ""; + + final HttpURLConnection con = (HttpURLConnection) targetURL.openConnection(); + con.setRequestMethod("POST"); + //con.setRequestProperty("Content-Length", Integer.toString(sbody.getBytes().length)); + con.setAllowUserInteraction(false); + con.setInstanceFollowRedirects(false); + if (targetUri != null) { + con.setRequestProperty(Notification_Target, targetUri); + } + + if (sourceUri != null) { + con.setRequestProperty(Notification_Source, sourceUri); + } + + for (String key : headers.keySet()) { + con.setRequestProperty(key, headers.get(key)); + } + con.setDoOutput(true); + con.setDoInput(true); + con.connect(); + Object response = null; + try { + if (wbody != null) { + OutputStream ost = con.getOutputStream(); + wbody.write(ost); + } else { + throw new IOUtilsException("Missing writeable body"); + } + final int rc = con.getResponseCode(); + switch (rc) { + case HttpURLConnection.HTTP_OK: + if (rcont != null) { + InputStream ist = con.getInputStream(); + response = rcont.read(ist); + } + break; + case HttpURLConnection.HTTP_NO_CONTENT: + break; + default: + throw new RuntimeException("Unexpected response code: " + rc); + } + } finally { + con.disconnect(); + } + return response; + } + + public interface Writeable { + void write(OutputStream os) throws IOUtilsException; + } + + public interface ReadableContinuation { + Object read(InputStream is) throws IOUtilsException; + } + + @SuppressWarnings("serial") + public static class IOUtilsException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public IOUtilsException(String message) { + super(message); + } + + public IOUtilsException(Throwable cause) { + super(cause); + } + } + + public static byte [] readFully(final InputStream ist, int len) throws IOException { + ByteArrayOutputStream baost = new ByteArrayOutputStream(); + copyStream(ist,baost,len); + return baost.toByteArray(); + } + + public static int copyStream(final InputStream ist, final OutputStream ost) throws IOException { + return copyStream(ist, ost, -1, 0); + } + + public static int copyStream(final InputStream ist, final OutputStream ost, int length) throws IOException { + return copyStream(ist, ost, length, 0); + } + + public static int copyStream(final InputStream ist, final OutputStream ost, final int length, int blockSize) throws IOException { + + int cbCopied = 0; + if (blockSize <= 0) { + blockSize = DEF_BLOCK_SIZE; + } + + final byte[] block = new byte[blockSize]; + boolean done = length == 0; + while (!done) { + try { + // determine how many bytes to read + final int cbToRead = length == -1 ? block.length : (Math.min(length - cbCopied, block.length)); + final int cbRead = ist.read(block, 0, cbToRead); + if (cbRead == -1) { + done = true; + } else { + ost.write(block, 0, cbRead); + cbCopied += cbRead; + done = cbCopied == length; + } + } catch (final EOFException e) { + done = true; + } + } + ost.flush(); + return cbCopied; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/NotificationServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/NotificationServlet.java new file mode 100644 index 0000000000..f780514eda --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/NotificationServlet.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.util; + +import java.io.IOException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * Receives notification in HTTP request and dispatches it down the wire + * + * @version $Rev$ $Date$ + */ +@SuppressWarnings("serial") +public class NotificationServlet extends HttpServlet { + + /** + * + */ + private static final long serialVersionUID = 1L; + private NotificationServletHandler handler; + private NotificationServletStreamHandler servletStreamHandler; + + public NotificationServlet(NotificationServletHandler handler) { + this.handler = handler; + this.servletStreamHandler = null; + } + + public NotificationServlet(NotificationServletStreamHandler servletStreamHandler) { + this.handler = null; + this.servletStreamHandler = servletStreamHandler; + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { + HashMap headers = new HashMap(); + Enumeration headerNames = request.getHeaderNames(); + while (headerNames.hasMoreElements()) { + String headerName = (String)headerNames.nextElement(); + headers.put(headerName, request.getHeader(headerName)); + } + if (handler != null) { + byte[] requestBody = IOUtils.readFully(request.getInputStream(), request.getContentLength()); + byte[] handlersResponse = handler.handle(headers, requestBody); + if (handlersResponse != null) { + response.getOutputStream().write(handlersResponse); + response.getOutputStream().flush(); + } + } else { + try { + servletStreamHandler.handle(headers, request.getInputStream(), request.getContentLength(), response.getOutputStream()); + } catch(RuntimeException e) { + e.printStackTrace(); + } + } + } + + public interface NotificationServletHandler { + byte[] handle(Map headers, byte[] payload); + } + + public interface NotificationServletStreamHandler { + void handle(Map headers, ServletInputStream istream, int contentLength, ServletOutputStream ostream); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/URIUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/URIUtil.java new file mode 100644 index 0000000000..42ccd5cdac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/URIUtil.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.sca.binding.notification.util; + +import java.net.URI; + +/** + * @version $Rev$ $Date$ + */ +public class URIUtil { + + public static String getPath(URI uri) { + String path = null; + + if (uri.isOpaque()) { + path = "/" + uri.getSchemeSpecificPart(); + } else if (uri.isAbsolute()) { + path = uri.getPath(); + } else { + path = "/" + uri.getPath(); + } + + return path; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..5e5ce97054 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.binding.notification.NotificationBindingModuleActivator diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/AxiomTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/AxiomTestCase.java new file mode 100644 index 0000000000..3d328339a7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/AxiomTestCase.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.sca.binding.notification.encoding; + +import java.io.ByteArrayInputStream; +import java.io.StringWriter; + +import junit.framework.TestCase; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.junit.Assert; + +public class AxiomTestCase extends TestCase { + + private static String wsnt = "http://docs.oasis-open.org/wsn/b-2"; + private static String wsa = "http://schemas.xmlsoap.org/ws/2004/08/addressing"; + private static String testUrl1 = "http://localhost:8081/test"; + private static String testUrl2 = "http://localhost:8082/test"; + private static String testNewProducerResponse = + "" + + "" + testUrl1 + "" + + "" + testUrl2 + "" + + ""; + + public void testAxiom() { + try { + StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(testNewProducerResponse.getBytes())); + OMElement element = builder.getDocumentElement(); + Assert.assertNotNull(element); + + StringWriter sw = new StringWriter(); + element.serialize(sw); + sw.flush(); + Assert.assertEquals(sw.toString(),testNewProducerResponse); + } catch(Throwable e) { + e.printStackTrace(); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingTestCase.java new file mode 100644 index 0000000000..3dcd2b9b00 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingTestCase.java @@ -0,0 +1,470 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.notification.encoding; + +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Iterator; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class EncodingTestCase extends TestCase { + + private static String wsnt = "http://docs.oasis-open.org/wsn/b-2"; + private static String wsa = "http://schemas.xmlsoap.org/ws/2004/08/addressing"; + private static String testUrl = "http://localhost:8080/test"; + private static String testUrl1 = "http://localhost:8081/test"; + private static String testUrl2 = "http://localhost:8082/test"; + private static String bid1 = "UUID1"; + private static String bid2 = "UUID2"; + private static String testSubscribe = + "" + + "" + + "" + + "" + testUrl + "" + + "" + + "" + + ""; + private static String testNewConsumerResponse = + "" + + "" + + "" + testUrl + "" + + "" + + ""; + private static String testNewProducerResponse = + "" + + "" + + "" + testUrl1 + "" + + "" + + "" + + "" + testUrl2 + "" + + "" + + ""; + private static String testNoProducersResponse = + ""; + private static String testNewBroker = + "" + + "" + + "" + + "" + testUrl1 + "" + + "" + + "" + bid1 + "" + + "" + + "" + + "" + + "" + + "" + + "" + testUrl2 + "" + + "" + + "" + bid2 + "" + + "" + + "" + + "" + + ""; + private static String testNewBrokerResponse1 = + "" + + "" + + "" + + "" + testUrl1 + "" + + "" + + "" + + "" + testUrl2 + "" + + "" + + "" + + "" + + ""; + private static String testNewBrokerResponse2 = + "" + + "" + + "" + + "" + + "" + + "" + testUrl1 + "" + + "" + + "" + bid1 + "" + + "" + + "" + + "" + + "" + + "" + + "" + testUrl2 + "" + + "" + + "" + bid2 + "" + + "" + + "" + + "" + + "" + + "" + + ""; + private static String testRemoveBroker = + "" + + "" + + "" + + "" + testUrl + "" + + "" + + "" + bid1 + "" + + "" + + "" + + "" + + "" + + "" + + "" + testUrl1 + "" + + "" + + "" + + "" + testUrl2 + "" + + "" + + "" + + ""; + private static String testReplaceBrokerConnection = + "" + + "" + + "" + + "" + testUrl + "" + + "" + + "" + bid1 + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + testUrl1 + "" + + "" + + "" + bid1 + "" + + "" + + "" + + "" + + "" + + "" + + "" + testUrl2 + "" + + "" + + "" + bid2 + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + public void testSubscribe() throws Exception { + DefaultEncodingRegistry der = new DefaultEncodingRegistry(); + SubscribeEnDeCoder sed = new SubscribeEnDeCoder(der); + sed.start(); + ConsumerReferenceEnDeCoder cred = new ConsumerReferenceEnDeCoder(der); + cred.start(); + EndpointReferenceEnDeCoder epred = new EndpointReferenceEnDeCoder(der); + epred.start(); + EndpointAddressEnDeCoder eaed = new EndpointAddressEnDeCoder(der); + eaed.start(); + + XMLInputFactory xif = XMLInputFactory.newInstance(); + XMLStreamReader reader = xif.createXMLStreamReader(new StringReader(testSubscribe)); + reader.next(); + Subscribe subscribe = (Subscribe)der.decode(reader); + Assert.assertEquals(subscribe.getConsumerReference().getReference().getEndpointAddress().getAddress().toString(), testUrl); + + XMLOutputFactory xof = XMLOutputFactory.newInstance(); + StringWriter testWriter = new StringWriter(); + XMLStreamWriter writer = xof.createXMLStreamWriter(testWriter); + der.encode(subscribe, writer); + writer.flush(); + String encoded = testWriter.toString(); + Assert.assertEquals(encoded, testSubscribe); + } + + public void testNewConsumerResponse() throws Exception { + DefaultEncodingRegistry der = new DefaultEncodingRegistry(); + NewConsumerResponseEnDeCoder ncred = new NewConsumerResponseEnDeCoder(der); + ncred.start(); + EndpointReferenceEnDeCoder epred = new EndpointReferenceEnDeCoder(der); + epred.start(); + EndpointAddressEnDeCoder eaed = new EndpointAddressEnDeCoder(der); + eaed.start(); + + XMLInputFactory xif = XMLInputFactory.newInstance(); + XMLStreamReader reader = xif.createXMLStreamReader(new StringReader(testNewConsumerResponse)); + reader.next(); + NewConsumerResponse newConsumerResponse = (NewConsumerResponse)der.decode(reader); + Assert.assertEquals(newConsumerResponse.getSequenceType(), "EndProducers"); + Assert.assertEquals(newConsumerResponse.getReferenceSequence().iterator().next().getEndpointAddress().getAddress().toString(), + testUrl); + + XMLOutputFactory xof = XMLOutputFactory.newInstance(); + StringWriter testWriter = new StringWriter(); + XMLStreamWriter writer = xof.createXMLStreamWriter(testWriter); + der.encode(newConsumerResponse, writer); + writer.flush(); + String encoded = testWriter.toString(); + Assert.assertEquals(encoded, testNewConsumerResponse); + } + + public void testNoProducersResponse() throws Exception { + DefaultEncodingRegistry der = new DefaultEncodingRegistry(); + NewConsumerResponseEnDeCoder ncred = new NewConsumerResponseEnDeCoder(der); + ncred.start(); + EndpointReferenceEnDeCoder epred = new EndpointReferenceEnDeCoder(der); + epred.start(); + EndpointAddressEnDeCoder eaed = new EndpointAddressEnDeCoder(der); + eaed.start(); + + XMLInputFactory xif = XMLInputFactory.newInstance(); + XMLStreamReader reader = xif.createXMLStreamReader(new StringReader(testNoProducersResponse)); + reader.next(); + NewConsumerResponse newConsumerResponse = (NewConsumerResponse)der.decode(reader); + Assert.assertEquals(newConsumerResponse.getSequenceType(), "NoProducers"); + + XMLOutputFactory xof = XMLOutputFactory.newInstance(); + StringWriter testWriter = new StringWriter(); + XMLStreamWriter writer = xof.createXMLStreamWriter(testWriter); + der.encode(newConsumerResponse, writer); + writer.flush(); + String encoded = testWriter.toString(); + Assert.assertEquals(encoded, testNoProducersResponse); + } + + public void testNewProducerResponse() throws Exception { + DefaultEncodingRegistry der = new DefaultEncodingRegistry(); + NewProducerResponseEnDeCoder npred = new NewProducerResponseEnDeCoder(der); + npred.start(); + EndpointReferenceEnDeCoder epred = new EndpointReferenceEnDeCoder(der); + epred.start(); + EndpointAddressEnDeCoder eaed = new EndpointAddressEnDeCoder(der); + eaed.start(); + + XMLInputFactory xif = XMLInputFactory.newInstance(); + XMLStreamReader reader = xif.createXMLStreamReader(new StringReader(testNewProducerResponse)); + reader.next(); + NewProducerResponse newProducerResponse = (NewProducerResponse)der.decode(reader); + Assert.assertEquals(newProducerResponse.getSequenceType(), "EndConsumers"); + Iterator it = newProducerResponse.getReferenceSequence().iterator(); + it.next(); + Assert.assertEquals(it.next().getEndpointAddress().getAddress().toString(), testUrl2); + + XMLOutputFactory xof = XMLOutputFactory.newInstance(); + StringWriter testWriter = new StringWriter(); + XMLStreamWriter writer = xof.createXMLStreamWriter(testWriter); + der.encode(newProducerResponse, writer); + writer.flush(); + String encoded = testWriter.toString(); + Assert.assertEquals(encoded, testNewProducerResponse); + } + + public void testNewBroker() throws Exception { + DefaultEncodingRegistry der = new DefaultEncodingRegistry(); + NewBrokerEnDeCoder nbed = new NewBrokerEnDeCoder(der); + nbed.start(); + BrokerConsumerReferenceEnDeCoder bcred = new BrokerConsumerReferenceEnDeCoder(der); + bcred.start(); + EndpointReferenceEnDeCoder epred = new EndpointReferenceEnDeCoder(der); + epred.start(); + EndpointAddressEnDeCoder eaed = new EndpointAddressEnDeCoder(der); + eaed.start(); + ReferencePropertiesEnDeCoder rped = new ReferencePropertiesEnDeCoder(der); + rped.start(); + BrokerIDEnDeCoder bied = new BrokerIDEnDeCoder(der); + bied.start(); + BrokerProducerReferenceEnDeCoder bpred = new BrokerProducerReferenceEnDeCoder(der); + bpred.start(); + + XMLInputFactory xif = XMLInputFactory.newInstance(); + XMLStreamReader reader = xif.createXMLStreamReader(new StringReader(testNewBroker)); + reader.next(); + NewBroker newBroker = (NewBroker)der.decode(reader); + Assert.assertEquals(newBroker.getBrokerConsumerReference().getReference().getEndpointAddress().getAddress().toString(), + testUrl1); + Assert.assertEquals(newBroker.getBrokerProducerReference().getReference().getEndpointAddress().getAddress().toString(), + testUrl2); + + XMLOutputFactory xof = XMLOutputFactory.newInstance(); + StringWriter testWriter = new StringWriter(); + XMLStreamWriter writer = xof.createXMLStreamWriter(testWriter); + der.encode(newBroker, writer); + writer.flush(); + String encoded = testWriter.toString(); + Assert.assertEquals(encoded, testNewBroker); + } + + public void testNewBrokerRespnse1() throws Exception { + DefaultEncodingRegistry der = new DefaultEncodingRegistry(); + NewBrokerResponseEnDeCoder nbred = new NewBrokerResponseEnDeCoder(der); + nbred.start(); + EndProducersEnDeCoder epred = new EndProducersEnDeCoder(der); + epred.start(); + EndConsumersEnDeCoder ecred = new EndConsumersEnDeCoder(der); + ecred.start(); + EndpointReferenceEnDeCoder ered = new EndpointReferenceEnDeCoder(der); + ered.start(); + EndpointAddressEnDeCoder eaed = new EndpointAddressEnDeCoder(der); + eaed.start(); + + XMLInputFactory xif = XMLInputFactory.newInstance(); + XMLStreamReader reader = xif.createXMLStreamReader(new StringReader(testNewBrokerResponse1)); + reader.next(); + NewBrokerResponse newBrokerResponse = (NewBrokerResponse)der.decode(reader); + Assert.assertFalse(!newBrokerResponse.isFirstBroker()); + Assert.assertEquals(newBrokerResponse.getEndProducers().getSequenceType(), "NoProducers"); + Assert.assertEquals(newBrokerResponse.getEndConsumers().getSequenceType(), "EndConsumers"); + Assert.assertEquals(newBrokerResponse.getEndConsumers().getReferenceSequence().get(0).getEndpointAddress().getAddress().toString(), + testUrl1); + + XMLOutputFactory xof = XMLOutputFactory.newInstance(); + StringWriter testWriter = new StringWriter(); + XMLStreamWriter writer = xof.createXMLStreamWriter(testWriter); + der.encode(newBrokerResponse, writer); + writer.flush(); + String encoded = testWriter.toString(); + Assert.assertEquals(encoded, testNewBrokerResponse1); + } + + public void testNewBrokerRespnse2() throws Exception { + DefaultEncodingRegistry der = new DefaultEncodingRegistry(); + NewBrokerResponseEnDeCoder nbred = new NewBrokerResponseEnDeCoder(der); + nbred.start(); + BrokersEnDeCoder bsed = new BrokersEnDeCoder(der); + bsed.start(); + BrokerEnDeCoder bed = new BrokerEnDeCoder(der); + bed.start(); + BrokerConsumerReferenceEnDeCoder bcred = new BrokerConsumerReferenceEnDeCoder(der); + bcred.start(); + BrokerProducerReferenceEnDeCoder bpred = new BrokerProducerReferenceEnDeCoder(der); + bpred.start(); + EndpointReferenceEnDeCoder epred = new EndpointReferenceEnDeCoder(der); + epred.start(); + EndpointAddressEnDeCoder eaed = new EndpointAddressEnDeCoder(der); + eaed.start(); + ReferencePropertiesEnDeCoder rped = new ReferencePropertiesEnDeCoder(der); + rped.start(); + BrokerIDEnDeCoder bied = new BrokerIDEnDeCoder(der); + bied.start(); + + XMLInputFactory xif = XMLInputFactory.newInstance(); + XMLStreamReader reader = xif.createXMLStreamReader(new StringReader(testNewBrokerResponse2)); + reader.next(); + NewBrokerResponse newBrokerResponse = (NewBrokerResponse)der.decode(reader); + Assert.assertFalse(newBrokerResponse.isFirstBroker()); + Assert.assertEquals(newBrokerResponse.getBrokers().getBrokerSequence().get(0) + .getBrokerConsumerReference().getReference().getEndpointAddress().getAddress().toString(), + testUrl1); + Assert.assertEquals(newBrokerResponse.getBrokers().getBrokerSequence().get(0) + .getBrokerProducerReference().getReference().getEndpointAddress().getAddress().toString(), + testUrl2); + + XMLOutputFactory xof = XMLOutputFactory.newInstance(); + StringWriter testWriter = new StringWriter(); + XMLStreamWriter writer = xof.createXMLStreamWriter(testWriter); + der.encode(newBrokerResponse, writer); + writer.flush(); + String encoded = testWriter.toString(); + Assert.assertEquals(encoded, testNewBrokerResponse2); + } + + public void testRemoveBroker() throws Exception { + DefaultEncodingRegistry der = new DefaultEncodingRegistry(); + RemoveBrokerEnDeCoder rbed = new RemoveBrokerEnDeCoder(der); + rbed.start(); + BrokerConsumerReferenceEnDeCoder bcred = new BrokerConsumerReferenceEnDeCoder(der); + bcred.start(); + EndpointReferenceEnDeCoder epred = new EndpointReferenceEnDeCoder(der); + epred.start(); + EndpointAddressEnDeCoder eaed = new EndpointAddressEnDeCoder(der); + eaed.start(); + ReferencePropertiesEnDeCoder rped = new ReferencePropertiesEnDeCoder(der); + rped.start(); + BrokerIDEnDeCoder bied = new BrokerIDEnDeCoder(der); + bied.start(); + NeighborBrokerConsumersEnDeCoder nbced = new NeighborBrokerConsumersEnDeCoder(der); + nbced.start(); + + XMLInputFactory xif = XMLInputFactory.newInstance(); + XMLStreamReader reader = xif.createXMLStreamReader(new StringReader(testRemoveBroker)); + reader.next(); + RemoveBroker removeBroker = (RemoveBroker)der.decode(reader); + Assert.assertEquals(removeBroker.getBrokerConsumerReference().getReference().getEndpointAddress().getAddress().toString(), + testUrl); + NeighborBrokerConsumers neighborBrokerConsumers = removeBroker.getNeighborBrokerConsumers(); + Assert.assertEquals(neighborBrokerConsumers.getSequenceType(), "BrokerConsumers"); + Iterator it = neighborBrokerConsumers.getReferenceSequence().iterator(); + it.next(); + Assert.assertEquals(it.next().getEndpointAddress().getAddress().toString(), testUrl2); + + XMLOutputFactory xof = XMLOutputFactory.newInstance(); + StringWriter testWriter = new StringWriter(); + XMLStreamWriter writer = xof.createXMLStreamWriter(testWriter); + der.encode(removeBroker, writer); + writer.flush(); + String encoded = testWriter.toString(); + Assert.assertEquals(encoded, testRemoveBroker); + } + + public void testReplaceBrokerConnection() throws Exception { + DefaultEncodingRegistry der = new DefaultEncodingRegistry(); + ReplaceBrokerConnectionEnDeCoder rbced = new ReplaceBrokerConnectionEnDeCoder(der); + rbced.start(); + RemovedBrokerEnDeCoder rbed = new RemovedBrokerEnDeCoder(der); + rbed.start(); + EndpointReferenceEnDeCoder epred = new EndpointReferenceEnDeCoder(der); + epred.start(); + EndpointAddressEnDeCoder eaed = new EndpointAddressEnDeCoder(der); + eaed.start(); + ReferencePropertiesEnDeCoder rped = new ReferencePropertiesEnDeCoder(der); + rped.start(); + BrokerIDEnDeCoder bied = new BrokerIDEnDeCoder(der); + bied.start(); + BrokerEnDeCoder bed = new BrokerEnDeCoder(der); + bed.start(); + BrokerConsumerReferenceEnDeCoder bcred = new BrokerConsumerReferenceEnDeCoder(der); + bcred.start(); + BrokerProducerReferenceEnDeCoder bpred = new BrokerProducerReferenceEnDeCoder(der); + bpred.start(); + NeighborsEnDeCoder nced = new NeighborsEnDeCoder(der); + nced.start(); + + XMLInputFactory xif = XMLInputFactory.newInstance(); + XMLStreamReader reader = xif.createXMLStreamReader(new StringReader(testReplaceBrokerConnection)); + reader.next(); + ReplaceBrokerConnection replaceBrokerConnection = (ReplaceBrokerConnection)der.decode(reader); + Assert.assertEquals(replaceBrokerConnection.getRemovedBroker().getReference().getEndpointAddress().getAddress().toString(), + testUrl); + Neighbors neighbors = replaceBrokerConnection.getNeighbors(); + Assert.assertEquals(neighbors.getBrokerSequence().get(0) + .getBrokerConsumerReference().getReference().getEndpointAddress().getAddress().toString(), + testUrl1); + Assert.assertEquals(neighbors.getBrokerSequence().get(0) + .getBrokerProducerReference().getReference().getEndpointAddress().getAddress().toString(), + testUrl2); + + XMLOutputFactory xof = XMLOutputFactory.newInstance(); + StringWriter testWriter = new StringWriter(); + XMLStreamWriter writer = xof.createXMLStreamWriter(testWriter); + der.encode(replaceBrokerConnection, writer); + writer.flush(); + String encoded = testWriter.toString(); + Assert.assertEquals(encoded, testReplaceBrokerConnection); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/pom.xml new file mode 100644 index 0000000000..367b434afc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/pom.xml @@ -0,0 +1,99 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-rmi-runtime + Apache Tuscany SCA RMI Binding Extension + + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-rmi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-rmi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + cglib + cglib-nodep + 2.2 + + + + org.apache.tuscany.sca + tuscany-node-impl + 1.6-SNAPSHOT + test + + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.rmi + ${pom.name} + org.apache.tuscany.sca.binding.rmi* + * + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIBindingProviderFactory.java new file mode 100644 index 0000000000..746aa4dac1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIBindingProviderFactory.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.sca.binding.rmi.provider; + +import org.apache.tuscany.sca.binding.rmi.RMIBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.rmi.ExtensibleRMIHost; +import org.apache.tuscany.sca.host.rmi.RMIHost; +import org.apache.tuscany.sca.host.rmi.RMIHostExtensionPoint; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * + */ +public class RMIBindingProviderFactory implements BindingProviderFactory { + private RMIHost rmiHost; + + public RMIBindingProviderFactory(ExtensionPointRegistry registry) { + super(); + RMIHostExtensionPoint hosts = registry.getExtensionPoint(RMIHostExtensionPoint.class); + rmiHost = new ExtensibleRMIHost(hosts); + } + + public Class getModelType() { + return RMIBinding.class; + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + RMIBinding binding) { + return new RMIReferenceBindingProvider(component, reference, binding, rmiHost); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + RMIBinding binding) { + return new RMIServiceBindingProvider(component, service, binding, rmiHost); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceBindingProvider.java new file mode 100644 index 0000000000..d09ea1f903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceBindingProvider.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.sca.binding.rmi.provider; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.binding.rmi.RMIBinding; +import org.apache.tuscany.sca.host.rmi.RMIHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.osoa.sca.ServiceRuntimeException; + +/** + * InvokerFactory that creates RMIReferenceInvoker instances for the + * RMIBinding. + * + * @version $Rev$ $Date$ + */ +public class RMIReferenceBindingProvider implements ReferenceBindingProvider { + private RuntimeComponentReference reference; + private RMIHost rmiHost; + private RMIBinding binding; + + public RMIReferenceBindingProvider(RuntimeComponent rc, RuntimeComponentReference rcr, RMIBinding binding, RMIHost rmiHost) { + this.reference = rcr; + this.rmiHost = rmiHost; + this.binding = binding; + } + + public Invoker createInvoker(Operation operation) { + try { + + Class iface = ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass(); + Method remoteMethod = JavaInterfaceUtil.findMethod(iface, operation); + + return new RMIReferenceInvoker(rmiHost, binding.getHost(), binding.getPort(), binding.getServiceName(), remoteMethod); + + } catch (NoSuchMethodException e) { + throw new ServiceRuntimeException(operation.toString(), e); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + } + + public void stop() { + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceInvoker.java new file mode 100644 index 0000000000..d300cb7d05 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceInvoker.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.rmi.provider; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.Remote; + +import org.apache.tuscany.sca.host.rmi.RMIHost; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; + +/** + * Invoker for RMI References. + * + * @version $Rev$ $Date$ + */ +public class RMIReferenceInvoker implements Invoker, DataExchangeSemantics { + + private RMIHost rmiHost; + private String host; + private String port; + private String svcName; + private Method remoteMethod; + private Remote proxy; + + public RMIReferenceInvoker(RMIHost rmiHost, String host, String port, String svcName, Method remoteMethod) { + this.rmiHost = rmiHost; + this.remoteMethod = remoteMethod; + this.host = host; + this.port = port; + this.svcName = svcName; + } + + public Message invoke(Message msg) { + try { + + Object[] args = msg.getBody(); + Object resp = invokeTarget(args); + msg.setBody(resp); + + } catch (InvocationTargetException e) { + msg.setFaultBody(e.getCause()); + } catch (Throwable e) { + msg.setFaultBody(e); + } + + return msg; + } + + public Object invokeTarget(final Object payload) throws InvocationTargetException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException { + if (proxy == null) { + proxy = rmiHost.findService(host, port, svcName); + // proxy = Naming.lookup(serviceURI); + } + + remoteMethod = proxy.getClass().getMethod(remoteMethod.getName(), remoteMethod.getParameterTypes()); + + if (payload != null && !payload.getClass().isArray()) { + return remoteMethod.invoke(proxy, payload); + } else { + return remoteMethod.invoke(proxy, (Object[])payload); + } + } + + public boolean allowsPassByReference() { + // RMI always pass by value + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java new file mode 100644 index 0000000000..c237654c74 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.rmi.provider; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.Remote; +import java.rmi.server.UnicastRemoteObject; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; + +import net.sf.cglib.asm.ClassWriter; +import net.sf.cglib.asm.Type; +import net.sf.cglib.core.Constants; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +import org.apache.tuscany.sca.binding.rmi.RMIBinding; +import org.apache.tuscany.sca.host.rmi.RMIHost; +import org.apache.tuscany.sca.host.rmi.RMIHostException; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Implementation of a Service for the RMIBinding. + * + * @version $Rev$ $Date$ + */ +public class RMIServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponent component; + private RuntimeComponentService service; + private RMIBinding binding; + private RMIHost rmiHost; + private RuntimeWire wire; + + public RMIServiceBindingProvider(RuntimeComponent rc, RuntimeComponentService rcs, RMIBinding binding, RMIHost rmiHost) { + this.component = rc; + this.service = rcs; + this.binding = binding; + this.rmiHost = rmiHost; + } + + public void start() { + // URI uri = URI.create(component.getURI() + "/" + binding.getName()); + // binding.setURI(uri.toString()); + + wire = service.getRuntimeWire(binding); + Interface serviceInterface = service.getInterfaceContract().getInterface(); + + Remote rmiProxy = createRmiService(serviceInterface); + + try { + + rmiHost.registerService(binding.getServiceName(), getPort(binding.getPort()), rmiProxy); + + } catch (RMIHostException e) { + throw new ServiceRuntimeException(e); + } + } + + public void stop() { + rmiHost.unregisterService(binding.getServiceName(), getPort(binding.getPort())); + } + + protected int getPort(String port) { + int portNumber = RMIHost.RMI_DEFAULT_PORT; + if (port != null && port.length() > 0) { + portNumber = Integer.decode(port); + if (portNumber == -1) { + portNumber = RMIHost.RMI_DEFAULT_PORT; + } + } + return portNumber; + } + + protected Remote createRmiService(final Interface serviceInterface) { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(UnicastRemoteObject.class); + enhancer.setCallback(new MethodInterceptor() { + public Object intercept(Object arg0, Method method, Object[] args, MethodProxy arg3) throws Throwable { + try { + return invokeTarget(JavaInterfaceUtil.findOperation(method, serviceInterface.getOperations()), args); + } catch (InvocationTargetException e) { + final Throwable cause = e.getCause(); + for (Class declaredType : method.getExceptionTypes()) { + if (declaredType.isInstance(cause)) { + throw e; + } + } + + if (cause.getCause() != null) { + // TUSCANY-2545: don't inlcude nested cause object + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Field field = Throwable.class.getDeclaredField("cause"); + field.setAccessible(true); + field.set(cause, null); + field.setAccessible(false); + return null; + } + }); + } + + throw cause; + } + } + }); + Class targetJavaInterface = getTargetJavaClass(serviceInterface); + if (!Remote.class.isAssignableFrom(targetJavaInterface)) { + RMIServiceClassLoader classloader = new RMIServiceClassLoader(targetJavaInterface.getClassLoader()); + final byte[] byteCode = generateRemoteInterface(targetJavaInterface); + targetJavaInterface = classloader.defineClass(targetJavaInterface.getName(), byteCode); + enhancer.setClassLoader(classloader); + } + enhancer.setInterfaces(new Class[] {targetJavaInterface}); + return (Remote)enhancer.create(); + } + + protected Object invokeTarget(Operation op, Object[] args) throws InvocationTargetException { + return wire.invoke(op, args); + } + + /** + * if the interface of the component whose serviceBindings must be exposed as RMI Service, does not + * implement java.rmi.Remote, then generate such an interface. This method will stop with just + * generating the bytecode. Defining the class from the byte code must be the responsibility of the + * caller of this method, since it requires a ClassLoader to be created to define and load this interface. + */ + protected byte[] generateRemoteInterface(Class serviceInterface) { + String interfazeName = serviceInterface.getName(); + ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); + + String simpleName = serviceInterface.getSimpleName(); + cw.visit(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT + Constants.ACC_INTERFACE, interfazeName + .replace('.', '/'), null, "java/lang/Object", new String[] {"java/rmi/Remote"}); + + StringBuffer argsAndReturn = null; + Method[] methods = serviceInterface.getMethods(); + for (Method method : methods) { + argsAndReturn = new StringBuffer("("); + Class[] paramTypes = method.getParameterTypes(); + Class returnType = method.getReturnType(); + + for (Class paramType : paramTypes) { + argsAndReturn.append(Type.getType(paramType)); + } + argsAndReturn.append(")"); + argsAndReturn.append(Type.getType(returnType)); + + cw.visitMethod(Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT, + method.getName(), + argsAndReturn.toString(), + null, + new String[] {"java/rmi/RemoteException"}); + } + cw.visitEnd(); + return cw.toByteArray(); + } + + protected Class getTargetJavaClass(Interface targetInterface) { + // TODO: right now assume that the target is always a Java + // Implementation. Need to figure out + // how to generate Java Interface in cases where the target is not a + // Java Implementation + return ((JavaInterface)targetInterface).getJavaClass(); + } + + protected class RMIServiceClassLoader extends ClassLoader { + public RMIServiceClassLoader(ClassLoader parent) { + super(parent); + } + + public Class defineClass(String name, byte[] byteArray) { + return super.defineClass(name, byteArray, 0, byteArray.length); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..b188c24a20 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.rmi.provider.RMIBindingProviderFactory;model=org.apache.tuscany.sca.binding.rmi.RMIBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloException.java new file mode 100644 index 0000000000..cbc860ecc6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloException.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 helloworld; + +/** + * @version $Rev$ $Date$ + */ +public class HelloException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 2570611055132507470L; + + /** + * + */ + public HelloException() { + } + + /** + * @param message + */ + public HelloException(String message) { + super(message); + } + + /** + * @param cause + */ + public HelloException(Throwable cause) { + super(cause); + } + + /** + * @param message + * @param cause + */ + public HelloException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000000..0a1f4283db --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldImpl.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 helloworld; + +import org.osoa.sca.annotations.Service; + + +/** + * This class implements the HelloWorld service. + * + * @version $Rev$ $Date$ + */ +@Service(HelloWorldService.class) +public class HelloWorldImpl implements HelloWorldService { + + public String sayHello(String name) { + return "Hello from the RMI Service to - " + name; + } + + public String sayHi(String name, String greeter) throws HelloException { + if (name == null || greeter == null) { + throw new HelloException("Invalid name or greeter: name=" + name + " greeter=" + greeter); + } + return "Hi from " + greeter + " in RMI Service to - " + name; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldRmiImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldRmiImpl.java new file mode 100644 index 0000000000..5b20d17c83 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldRmiImpl.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 helloworld; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service. + * + * @version $Rev$ $Date$ + */ +@Service(HelloWorldRmiService.class) +public class HelloWorldRmiImpl implements HelloWorldRmiService { + private HelloWorldService extService; + + public HelloWorldService getExtService() { + return extService; + } + + @Reference + public void setExtService(HelloWorldService extService) { + this.extService = extService; + } + + public String sayRmiHello(String name) { + return extService.sayHello(name) + " thro the RMI Reference"; + } + + public String sayRmiHi(String name, String greeter) throws HelloException { + return extService.sayHi(name, greeter) + " thro the RMI Reference"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldRmiService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldRmiService.java new file mode 100644 index 0000000000..461c176e1e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldRmiService.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 helloworld; + +/** + * This is the business interface of the HelloWorld greetings service. + * + * @version $Rev$ $Date$ + */ +public interface HelloWorldRmiService { + + String sayRmiHello(String name); + String sayRmiHi(String name, String greeter) throws HelloException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..3b705d2c97 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/helloworld/HelloWorldService.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 helloworld; + +/** + * This is the business interface of the HelloWorld greetings service. + * + * @version $Rev$ $Date$ + */ +public interface HelloWorldService { + + String sayHello(String name); + String sayHi(String name, String greeter) throws HelloException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java new file mode 100644 index 0000000000..a3c4ae4010 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.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.sca.binding.rmi; + +import helloworld.HelloException; +import helloworld.HelloWorldRmiService; +import junit.framework.Assert; + +import org.apache.tuscany.sca.node.SCAClient; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests for the RMIBinding. + * + * @version $Rev$ $Date$ + */ +public class BindingTestCase { + private static HelloWorldRmiService helloWorldRmiService; + private static SCANode node; + + @Test + public void testRmiService() { + String msg = helloWorldRmiService.sayRmiHello("Tuscany World!"); + System.out.println(msg); + Assert.assertEquals("Hello from the RMI Service to - Tuscany World! thro the RMI Reference", msg); + + try { + msg = helloWorldRmiService.sayRmiHi("Tuscany World!", "Apache World"); + System.out.println(msg); + Assert.assertEquals("Hi from Apache World in RMI Service to - Tuscany World! thro the RMI Reference", msg); + } catch (HelloException e) { + Assert.fail(e.getMessage()); + } + try { + msg = helloWorldRmiService.sayRmiHi(null, "Apache World"); + Assert.fail("HelloException should have been thrown"); + } catch (HelloException e) { + System.out.println("Expected exception :" + e.getClass().getName()); + } + } + + @BeforeClass + public static void init() throws Exception { + try { + node = SCANodeFactory.newInstance().createSCANodeFromClassLoader("RMIBindingTest.composite", BindingTestCase.class.getClassLoader()); + node.start(); + helloWorldRmiService = ((SCAClient) node).getService(HelloWorldRmiService.class, "HelloWorldRmiServiceComponent"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void destroy() throws Exception { + node.stop(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/HelloWorldImpl.componentType b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/HelloWorldImpl.componentType new file mode 100644 index 0000000000..224a68f88d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/HelloWorldImpl.componentType @@ -0,0 +1,23 @@ + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/HelloWorldRmiImpl.componentType b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/HelloWorldRmiImpl.componentType new file mode 100644 index 0000000000..a83e7e6d1d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/HelloWorldRmiImpl.componentType @@ -0,0 +1,27 @@ + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/RMIBindingTest.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/RMIBindingTest.composite new file mode 100644 index 0000000000..65aec1681d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi-runtime/src/test/resources/RMIBindingTest.composite @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/pom.xml new file mode 100644 index 0000000000..bbd08bc2e3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/pom.xml @@ -0,0 +1,93 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-rmi + Apache Tuscany SCA RMI Binding Extension + + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-rmi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + cglib + cglib-nodep + 2.2 + + + + org.apache.tuscany.sca + tuscany-node-impl + 1.6-SNAPSHOT + test + + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.rmi + ${pom.name} + org.apache.tuscany.sca.binding.rmi* + * + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java new file mode 100644 index 0000000000..4ef3822b5b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.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.sca.binding.rmi; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * RMI Binding model + */ +public interface RMIBinding extends Binding { + + /** + * @return the host name of the RMI Service + */ + String getHost(); + + /** + * @return the port number for the RMI Service + */ + String getPort(); + + /** + * @return returns the RMI Service Name + */ + String getServiceName(); + + /** + * @param rmiHostName the hostname of the RMI Service + */ + void setHost(String rmiHostName); + + /** + * @param rmiPort the port number for the RMI Service + */ + void setPort(String rmiPort); + + /** + * Sets the service name for the RMI Server + * + * @param rmiServiceName the name of the RMI service + */ + void setServiceName(String rmiServiceName); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingFactory.java new file mode 100644 index 0000000000..ecfd45def3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingFactory.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.sca.binding.rmi; + +/** + * Factory to create RMIBinding instances + */ +public interface RMIBindingFactory { + /** + * Create RMIBinding model + * @return + */ + RMIBinding createRMIBinding(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/impl/RMIBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/impl/RMIBindingFactoryImpl.java new file mode 100644 index 0000000000..547fc633a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/impl/RMIBindingFactoryImpl.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.sca.binding.rmi.impl; + +import org.apache.tuscany.sca.binding.rmi.RMIBinding; +import org.apache.tuscany.sca.binding.rmi.RMIBindingFactory; + +/** + * + */ +public class RMIBindingFactoryImpl implements RMIBindingFactory { + public RMIBinding createRMIBinding() { + // TODO Auto-generated method stub + return new RMIBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/impl/RMIBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/impl/RMIBindingImpl.java new file mode 100644 index 0000000000..4acb9783f5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/impl/RMIBindingImpl.java @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.rmi.impl; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.apache.tuscany.sca.binding.rmi.RMIBinding; + +/** + * Represents a binding to an RMI service. + * + * @version $Rev$ $Date$ + */ +public class RMIBindingImpl implements RMIBinding { + private String name; + private String uri; + private String host; + private String port; + private String serviceName; + + /** + * @return the host name of the RMI Service + */ + public String getHost() { + return host; + } + + /** + * @param rmiHostName the hostname of the RMI Service + */ + public void setHost(String rmiHostName) { + this.host = rmiHostName; + } + + /** + * @return the port number for the RMI Service + */ + public String getPort() { + return port; + } + + /** + * @param rmiPort the port number for the RMI Service + */ + public void setPort(String rmiPort) { + this.port = rmiPort; + } + + /** + * @return returns the RMI Service Name + */ + public String getServiceName() { + return serviceName; + } + + /** + * Sets the service name for the RMI Server + * + * @param rmiServiceName the name of the RMI service + */ + public void setServiceName(String rmiServiceName) { + this.serviceName = rmiServiceName; + } + + public String getName() { + return name; + } + + public String getURI() { + compose(); + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + parse(uri); + } + + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + // The sample binding is always resolved + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + /* + rmi://[host][:port][/[object]] + rmi:[/][object] + */ + private void parse(String uriStr) { + if (uriStr == null) { + return; + } + URI uri = URI.create(uriStr); + if (host == null) { + this.host = uri.getHost(); + } + if (port == null) { + this.port = String.valueOf(uri.getPort()); + } + if (serviceName == null) { + String path = uri.getPath(); + if (path != null && path.charAt(0) == '/') { + path = path.substring(1); + } + this.serviceName = path; + } + } + + private void compose() { + if (uri == null) { + int p = -1; + if (port != null && port.length() > 0) { + p = Integer.decode(port); + } + String path = serviceName; + if (path != null) { + path = "/" + path; + } + try { + uri = new URI("rmi", null, host, p, path, null, null).toString(); + } catch (URISyntaxException e) { + throw new IllegalArgumentException(e); + } + } + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rmi.RMIBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rmi.RMIBindingFactory new file mode 100644 index 0000000000..889fcafae2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rmi.RMIBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for model factory +org.apache.tuscany.sca.binding.rmi.impl.RMIBindingFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..d628701a7f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.rmi,model=org.apache.tuscany.sca.binding.rmi.RMIBinding,factory=org.apache.tuscany.sca.binding.rmi.RMIBindingFactory diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/pom.xml new file mode 100644 index 0000000000..227bb1f026 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/pom.xml @@ -0,0 +1,171 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-rss-rome + Apache Tuscany SCA RSS Feed Binding Extension + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-rss + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + + commons-httpclient + commons-httpclient + 3.1 + + + + rome + rome + 0.9 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + commons-codec + commons-codec + 1.3 + + + commons-codec + commons-codec + + + + + + commons-logging + commons-logging + 1.1.1 + + + javax.servlet + servlet-api + + + avalon-framework + avalon-framework + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.rss.rome + ${pom.name} + org.apache.tuscany.sca.binding.rss* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/Collection.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/Collection.java new file mode 100644 index 0000000000..ed86dc4848 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/Collection.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.sca.binding.rss.collection; + +import org.osoa.sca.annotations.Remotable; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; + + +/** + * Provides access to a collection of resources using RSS. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Collection { + + /** + * Get an RSS feed for a collection of resources. + * + * @return the RSS feed + */ + SyndFeed getFeed(); + + /** + * Get an RSS feed for a collection of resources resulting from a query. + * + * @param queryString the query string + * @return the RSS feed + */ + SyndFeed query(String queryString); + + /** + * Retrieves an RSS entry. + * + * @param id The entry ID + * @return The requested entry + * @throws NotFoundException No entry found with the given ID + */ + SyndEntry get(String id) throws NotFoundException; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/MediaCollection.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/MediaCollection.java new file mode 100644 index 0000000000..2213b50b53 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/MediaCollection.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.sca.binding.rss.collection; + +import java.io.InputStream; + +import org.osoa.sca.annotations.Remotable; + +import com.sun.syndication.feed.atom.Entry; + +/** + * Provides access to a collection of resources using Atom. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface MediaCollection extends Collection { + + /** + * Creates a new media entry + * + * @param title + * @param slug + * @param contentType + * @param media + */ + Entry postMedia(String title, String slug, String contentType, InputStream media); + + /** + * Update a media entry. + * + * @param id + * @param contentType + * @param media + * @return + */ + void putMedia(String id, String contentType, InputStream media) throws NotFoundException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/NotFoundException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/NotFoundException.java new file mode 100644 index 0000000000..0912878938 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/collection/NotFoundException.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.sca.binding.rss.collection; + +/** + * Indicates that a resource could not be found. + * + * @version $Rev$ $Date$ + */ +public class NotFoundException extends Exception { + private static final long serialVersionUID = -5046027674128627383L; + + public NotFoundException() { + } + + public NotFoundException(String message) { + super(message); + } + + public NotFoundException(Throwable cause) { + super(cause); + } + + public NotFoundException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingInvoker.java new file mode 100644 index 0000000000..e3a177198c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingInvoker.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.sca.binding.rss.provider; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.XmlReader; + +/** + * Invoker for the RSS binding. + * + * @version $Rev$ $Date$ + */ +class RSSBindingInvoker implements Invoker , DataExchangeSemantics { + private static final Logger logger = Logger.getLogger(RSSBindingInvoker.class.getName()); + + private String uri; + + RSSBindingInvoker(String uri, String feedType) { + this.uri = uri; + } + + public Message invoke(Message msg) { + try { + logger.fine("invoke " + uri); + + // Read an RSS feed into a Synd feed + SyndFeedInput input = new SyndFeedInput(); + SyndFeed feed = input.build(new XmlReader(new URL(uri))); + + //FIXME Support conversion to data-api entries + + msg.setBody(feed); + + } catch (MalformedURLException e) { + msg.setFaultBody(e); + } catch (IllegalArgumentException e) { + msg.setFaultBody(e); + } catch (FeedException e) { + msg.setFaultBody(e); + } catch (IOException e) { + msg.setFaultBody(e); + } + return msg; + } + + public boolean allowsPassByReference() { + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingListenerServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingListenerServlet.java new file mode 100644 index 0000000000..96493a5150 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingListenerServlet.java @@ -0,0 +1,397 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.rss.provider; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.StringTokenizer; +import java.util.logging.Logger; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.commons.codec.binary.Base64; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +import com.sun.syndication.feed.synd.SyndContent; +import com.sun.syndication.feed.synd.SyndContentImpl; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndEntryImpl; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.feed.synd.SyndLink; +import com.sun.syndication.feed.synd.SyndLinkImpl; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedOutput; + +/** + * An RSS binding listener, implemented as a Servlet and + * registered in a Servlet host provided by the SCA hosting runtime. + * + * @version $Rev$ $Date$ + */ +class RSSBindingListenerServlet extends HttpServlet { + private static final Logger logger = Logger.getLogger(RSSBindingListenerServlet.class.getName()); + private static final long serialVersionUID = 1L; + + private RuntimeWire wire; + private Invoker getFeedInvoker; + private Invoker getAllInvoker; + private Invoker queryInvoker; + private MessageFactory messageFactory; + private Mediator mediator; + private DataType itemClassType; + private DataType itemXMLType; + private boolean supportsFeedEntries; + + /** + * Constructs a new binding listener. + * + * @param wire + * @param messageFactory + */ + RSSBindingListenerServlet(RuntimeWire wire, MessageFactory messageFactory, Mediator mediator) { + this.wire = wire; + this.messageFactory = messageFactory; + this.mediator = mediator; + + // Get the invokers for the supported operations + Operation getOperation = null; + for (InvocationChain invocationChain : this.wire.getInvocationChains()) { + invocationChain.setAllowsPassByReference(true); + Operation operation = invocationChain.getTargetOperation(); + String operationName = operation.getName(); + if (operationName.equals("getFeed")) { + getFeedInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("getAll")) { + getAllInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("query")) { + queryInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("get")) { + getOperation = operation; + } + } + + // Determine the collection item type + if (getOperation != null) { + itemXMLType = new DataTypeImpl>(String.class.getName(), String.class, String.class); + Class itemClass = getOperation.getOutputType().getPhysical(); + if (itemClass == SyndEntry.class) { + supportsFeedEntries = true; + } + DataType outputType = getOperation.getOutputType(); + QName qname = outputType.getLogical().getElementName(); + qname = new QName(qname.getNamespaceURI(), itemClass.getSimpleName()); + itemClassType = new DataTypeImpl("java:complexType", itemClass, new XMLType(qname, null)); + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // No authentication required for a get request + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + logger.fine("get " + request.getRequestURI()); + + // Handle an RSS request + if (path == null || path.length() == 0 || path.equals("/")) { + + // Return an RSS feed containing the entries in the collection + SyndFeed feed = null; + if (supportsFeedEntries) { + + // The service implementation supports feed entries, invoke its getFeed operation + Message requestMessage = messageFactory.createMessage(); + Message responseMessage = getFeedInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + feed = (SyndFeed)responseMessage.getBody(); + + } else { + + // The service implementation does not support feed entries, invoke its + // getAll operation to get the data item collection. then create feed entries + // from the data items + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + requestMessage.setBody(new Object[] {request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + responseMessage = getAllInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + org.apache.tuscany.sca.data.collection.Entry[] collection = + (org.apache.tuscany.sca.data.collection.Entry[])responseMessage.getBody(); + if (collection != null) { + // Create the feed + feed = new SyndFeedImpl(); + feed.setTitle("Feed"); + feed.setDescription("Feed description"); + + for (org.apache.tuscany.sca.data.collection.Entry entry: collection) { + SyndEntry feedEntry = createFeedEntry(entry); + feed.getEntries().add(feedEntry); + } + } + } + + // Convert to an RSS feed + if (feed != null) { + response.setContentType("application/rss+xml; charset=utf-8"); + feed.setFeedType("rss_2.0"); + feed.setLink(path); + SyndFeedOutput syndOutput = new SyndFeedOutput(); + try { + syndOutput.output(feed, getWriter(response)); + } catch (FeedException e) { + throw new ServletException(e); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } + + /** + * Create an RSS entry from a data collection entry. + * @param entry + * @return + */ + private SyndEntry createFeedEntry(org.apache.tuscany.sca.data.collection.Entry entry) { + Object key = entry.getKey(); + Object data = entry.getData(); + if (data instanceof Item) { + Item item = (Item)data; + + SyndEntry feedEntry = new SyndEntryImpl(); + feedEntry.setUri(key.toString()); + feedEntry.setTitle(item.getTitle()); + + String value = item.getContents(); + if (value != null) { + SyndContent content = new SyndContentImpl(); + content.setType("text/xml"); + content.setValue(value); + List contents = new ArrayList(); + contents.add(content); + feedEntry.setContents(contents); + } + + String href = item.getLink(); + if (href == null) { + href = key.toString(); + } + SyndLink link = new SyndLinkImpl(); + link.setRel("edit"); + link.setHref(href); + feedEntry.getLinks().add(link); + link = new SyndLinkImpl(); + link.setRel("alternate"); + link.setHref(href); + feedEntry.getLinks().add(link); + feedEntry.setLink(href); + + Date date = item.getDate(); + if (date == null) { + date = new Date(); + } + feedEntry.setPublishedDate(date); + return feedEntry; + + } else if (data != null) { + SyndEntry feedEntry = new SyndEntryImpl(); + feedEntry.setUri(key.toString()); + feedEntry.setTitle("item"); + + // Convert the item to XML + String value = mediator.mediate(data, itemClassType, itemXMLType, null).toString(); + + SyndContent content = new SyndContentImpl(); + content.setType("text/xml"); + content.setValue(value); + List contents = new ArrayList(); + contents.add(content); + feedEntry.setContents(contents); + + SyndLink link = new SyndLinkImpl(); + link.setRel("edit"); + link.setHref(key.toString()); + feedEntry.getLinks().add(link); + link = new SyndLinkImpl(); + link.setRel("alternate"); + link.setHref(key.toString()); + feedEntry.getLinks().add(link); + + feedEntry.setPublishedDate(new Date()); + return feedEntry; + } else { + return null; + } + } + + /** + * Create a data collection entry from an RSS entry. + * @param feedEntry + * @return + */ + private org.apache.tuscany.sca.data.collection.Entry createEntry(SyndEntry feedEntry) { + if (feedEntry != null) { + if (itemClassType.getPhysical() == Item.class) { + String key = feedEntry.getUri(); + + Item item = new Item(); + item.setTitle(feedEntry.getTitle()); + + List contents = feedEntry.getContents(); + if (!contents.isEmpty()) { + SyndContent content = (SyndContent)contents.get(0); + String value = content.getValue(); + item.setContents(value); + } + + for (Object l : feedEntry.getLinks()) { + SyndLink link = (SyndLink)l; + if (link.getRel() == null || "edit".equals(link.getRel())) { + String href = link.getHref(); + if (href.startsWith("null/")) { + href = href.substring(5); + } + item.setLink(href); + break; + } + } + + item.setDate(feedEntry.getPublishedDate()); + + return new org.apache.tuscany.sca.data.collection.Entry(key, item); + + } else { + String key = feedEntry.getUri(); + + // Create the item from XML + List contents = feedEntry.getContents(); + if (contents.isEmpty()) { + return null; + } + SyndContent content = (SyndContent)contents.get(0); + String value = content.getValue(); + Object data = mediator.mediate(value, itemXMLType, itemClassType, null); + + return new org.apache.tuscany.sca.data.collection.Entry(key, data); + } + } else { + return null; + } + } + + + private Writer getWriter(HttpServletResponse response) throws UnsupportedEncodingException, IOException { + Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8"); + return writer; + } + + /** + * Process the authorization header + * + * @param request + * @return + * @throws ServletException + */ + private String processAuthorizationHeader(HttpServletRequest request) throws ServletException { + try { + String authorization = request.getHeader("Authorization"); + if (authorization != null) { + StringTokenizer tokens = new StringTokenizer(authorization); + if (tokens.hasMoreTokens()) { + String basic = tokens.nextToken(); + if (basic.equalsIgnoreCase("Basic")) { + String credentials = tokens.nextToken(); + String userAndPassword = new String(Base64.decodeBase64(credentials.getBytes())); + int colon = userAndPassword.indexOf(":"); + if (colon != -1) { + String user = userAndPassword.substring(0, colon); + String password = userAndPassword.substring(colon + 1); + + // Authenticate the User. + if (authenticate(user, password)) { + return user; + } + } + } + } + } + } catch (Exception e) { + throw new ServletException(e); + } + return null; + } + + /** + * Authenticate a user. + * + * @param user + * @param password + * @return + */ + private boolean authenticate(String user, String password) { + + // TODO Handle this using SCA security policies + //FIXME Why are we using endsWith instead of equals here?? + return ("admin".endsWith(user) && "admin".equals(password)); + } + + /** + * Reject an unauthorized request. + * + * @param response + */ + private void unauthorized(HttpServletResponse response) throws IOException { + response.setHeader("WWW-Authenticate", "BASIC realm=\"Tuscany\""); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java new file mode 100644 index 0000000000..d588f041db --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.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.sca.binding.rss.provider; + +import org.apache.tuscany.sca.binding.rss.RSSBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the RSS binding provider factory. + * + * @version $Rev$ $Date$ + */ +public class RSSBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private Mediator mediator; + private ServletHost servletHost; + + public RSSBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + RSSBinding binding) { + return new RSSReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + RSSBinding binding) { + return new RSSServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator); + } + + public Class getModelType() { + return RSSBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSReferenceBindingProvider.java new file mode 100644 index 0000000000..8a30e9d3fb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSReferenceBindingProvider.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.sca.binding.rss.provider; + +import org.apache.tuscany.sca.binding.rss.RSSBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the RSS binding provider. + * + * @version $Rev$ $Date$ + */ +class RSSReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private RSSBinding binding; + + RSSReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + RSSBinding binding) { + this.reference = reference; + this.binding = binding; + } + + public Invoker createInvoker(Operation operation) { + return new RSSBindingInvoker(binding.getURI(), "rss_2.0"); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSServiceBindingProvider.java new file mode 100644 index 0000000000..4e5429ac83 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSServiceBindingProvider.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.sca.binding.rss.provider; + +import org.apache.tuscany.sca.binding.rss.RSSBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the RSS binding provider. + * + * @version $Rev$ $Date$ + */ +class RSSServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private RSSBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private String servletMapping; + private Mediator mediator; + + RSSServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + RSSBinding binding, + ServletHost servletHost, + MessageFactory messageFactory, + Mediator mediator) { + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.mediator = mediator; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + RuntimeComponentService componentService = (RuntimeComponentService)service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + + RSSBindingListenerServlet servlet = + new RSSBindingListenerServlet(wire, messageFactory, mediator); + + servletMapping = binding.getURI(); + servletHost.addServletMapping(servletMapping, servlet); + + // Save the actual binding URI in the binding + binding.setURI(servletHost.getURLMapping(binding.getURI()).toString()); + } + + public void stop() { + servletHost.removeServletMapping(servletMapping); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..e60dc2855a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.rss.provider.RSSBindingProviderFactory;model=org.apache.tuscany.sca.binding.rss.RSSBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Consumer.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Consumer.java new file mode 100644 index 0000000000..19370285f5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Consumer.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.sca.binding.rss; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Consumer { + + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/feed/Consumer.composite"); + + CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient"); + testService.testCustomerCollection(); + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClient.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClient.java new file mode 100644 index 0000000000..af87155f45 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClient.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.rss; + +public interface CustomerClient { + + void testCustomerCollection() throws Exception; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClientImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClientImpl.java new file mode 100644 index 0000000000..e71156c379 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerClientImpl.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.sca.binding.rss; + +import org.apache.tuscany.sca.binding.rss.collection.Collection; +import org.osoa.sca.annotations.Reference; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; + + +public class CustomerClientImpl implements CustomerClient { + + @Reference + public Collection resourceCollection; + + public void testCustomerCollection() throws Exception { + + System.out.println(">>> get collection"); + SyndFeed feed = resourceCollection.getFeed(); + System.out.println("<<< get collection"); + for (Object o : feed.getEntries()) { + SyndEntry e = (SyndEntry)o; + System.out.println("id = " + e.getUri() + " entry = " + e.getTitle()); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerCollectionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerCollectionImpl.java new file mode 100644 index 0000000000..02d73ab3ae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/CustomerCollectionImpl.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.rss; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.tuscany.sca.binding.rss.collection.Collection; +import org.apache.tuscany.sca.binding.rss.collection.NotFoundException; +import org.osoa.sca.annotations.Scope; + +import com.sun.syndication.feed.synd.SyndContent; +import com.sun.syndication.feed.synd.SyndContentImpl; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndEntryImpl; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.feed.synd.SyndLink; +import com.sun.syndication.feed.synd.SyndLinkImpl; + +@Scope("COMPOSITE") +public class CustomerCollectionImpl implements Collection { + + private Map entries = new HashMap(); + + public CustomerCollectionImpl() { + + for (int i = 0; i < 4; i++) { + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + + SyndEntry entry = new SyndEntryImpl(); + entry.setTitle("customer " + "Jane Doe_" + String.valueOf(i)); + entry.setUri(id); + + SyndContent content = new SyndContentImpl(); + content.setValue("Jane Doe_" + String.valueOf(i)); + content.setType("text"); + entry.setContents(Collections.singletonList(content)); + + List links = new ArrayList(); + SyndLink link = new SyndLinkImpl(); + link.setRel("edit"); + link.setHref("" + id); + links.add(link); + entry.setLinks(links); + + links = new ArrayList(); + link = new SyndLinkImpl(); + link.setRel("alternate"); + link.setHref("" + id); + links.add(link); + entry.setLinks(links); + + entry.setPublishedDate(new Date()); + + entries.put(id, entry); + System.out.println(">>> id=" + id); + } + } + + public SyndFeed getFeed() { + System.out.println(">>> CustomerCollectionImpl.getFeed"); + + SyndFeed feed = new SyndFeedImpl(); + feed.setTitle("customers"); + feed.setDescription("This is a sample feed"); + feed.getEntries().addAll(entries.values()); + return feed; + } + + public SyndFeed query(String queryString) { + System.out.println(">>> CustomerCollectionImpl.query"); + + SyndFeed feed = new SyndFeedImpl(); + feed.setTitle("customers"); + feed.setDescription("This is a sample feed"); + feed.getEntries().addAll(entries.values()); + return feed; + } + + /** + * {@inheritDoc} + */ + public SyndEntry get(String id) throws NotFoundException { + final SyndEntry entry = entries.get(id); + if (id == null) { + throw new NotFoundException("No entry found with ID " + id); + } + + return entry; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Provider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Provider.java new file mode 100644 index 0000000000..ae7b72834e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/Provider.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.sca.binding.rss; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Provider { + + public static void main(String[] args) { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/feed/Provider.composite"); + System.out.println("Provider.composite ready..."); + + try { + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/RSSGetTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/RSSGetTestCase.java new file mode 100644 index 0000000000..cb5c280211 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/java/org/apache/tuscany/sca/binding/rss/RSSGetTestCase.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.sca.binding.rss; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Basic test case that will get the feed entries from an RSS feed. + */ +public class RSSGetTestCase { + protected static SCADomain scaConsumerDomain; + protected static SCADomain scaProviderDomain; + protected static CustomerClient testService; + + @BeforeClass + public static void init() throws Exception { + System.out.println(">>>RSSGetTestCase.init entry"); + scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/rss/Provider.composite"); + scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/rss/Consumer.composite"); + testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient"); + } + + @AfterClass + public static void destroy() throws Exception { + // System.out.println(">>>RSSGetTestCase.destroy entry"); + if (scaConsumerDomain != null) { + scaConsumerDomain.close(); + } + if (scaProviderDomain != null) { + scaProviderDomain.close(); + } + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderDomain); + Assert.assertNotNull(scaConsumerDomain); + Assert.assertNotNull(testService); + } + + @Test + public void testRSSGet() throws Exception { + testService.testCustomerCollection(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Consumer.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Consumer.composite new file mode 100644 index 0000000000..48ab6b94b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Consumer.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Provider.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Provider.composite new file mode 100644 index 0000000000..45718dfedb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss-rome/src/test/resources/org/apache/tuscany/sca/binding/rss/Provider.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/pom.xml new file mode 100644 index 0000000000..d315328f28 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/pom.xml @@ -0,0 +1,98 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-rss + Apache Tuscany SCA RSS Feed Binding Extension + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.rss + ${pom.name} + org.apache.tuscany.sca.binding.rss* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/RSSBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/RSSBinding.java new file mode 100644 index 0000000000..2b4989264c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/RSSBinding.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.sca.binding.rss; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * RSS Feed binding model. + */ +public interface RSSBinding extends Binding { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/RSSBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/RSSBindingFactory.java new file mode 100644 index 0000000000..3e691e636e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/RSSBindingFactory.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.sca.binding.rss; + +/** + * Factory for the RSS binding + * + * @version $Rev$ $Date$ + */ +public interface RSSBindingFactory { + + /** + * Creates a new RSS binding. + * @return the new RSS binding + */ + RSSBinding createRSSBinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/impl/RSSBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/impl/RSSBindingFactoryImpl.java new file mode 100644 index 0000000000..a4e6a8283d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/impl/RSSBindingFactoryImpl.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.sca.binding.rss.impl; + +import org.apache.tuscany.sca.binding.rss.RSSBinding; +import org.apache.tuscany.sca.binding.rss.RSSBindingFactory; + +/** + * Factory for the RSS binding model. + * + * @version $Rev$ $Date$ + */ +public class RSSBindingFactoryImpl implements RSSBindingFactory { + + public RSSBinding createRSSBinding() { + return new RSSBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/impl/RSSBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/impl/RSSBindingImpl.java new file mode 100644 index 0000000000..6158752e7c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/java/org/apache/tuscany/sca/binding/rss/impl/RSSBindingImpl.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.sca.binding.rss.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.rss.RSSBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Implementation of the RSS Feed binding model. + */ +class RSSBindingImpl implements RSSBinding, PolicySetAttachPoint { + + private String name; + private String uri; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rss.RSSBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rss.RSSBindingFactory new file mode 100644 index 0000000000..73c47a3f41 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rss.RSSBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the model factory +org.apache.tuscany.sca.binding.rss.impl.RSSBindingFactoryImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..2d0597ff01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-rss/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.rss,model=org.apache.tuscany.sca.binding.rss.RSSBinding,factory=org.apache.tuscany.sca.binding.rss.RSSBindingFactory diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/pom.xml new file mode 100644 index 0000000000..388cceca7d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/pom.xml @@ -0,0 +1,103 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-sca-axis2 + Apache Tuscany SCA Axis2-based Default Binding Extension + + + + + org.apache.tuscany.sca + tuscany-binding-sca + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2 + 1.6-SNAPSHOT + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-endpoint + 1.6-SNAPSHOT + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.sca.axis2 + ${pom.name} + org.apache.tuscany.sca.binding.sca.axis2* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingInvoker.java new file mode 100644 index 0000000000..e4bb708a01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingInvoker.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.sca.axis2.impl; + +import java.util.logging.Logger; + +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.osoa.sca.ServiceUnavailableException; + + +/** + * A wrapper for the Axis2BindingInvoker that ensures that the URL of the target + * service is correct by looking it up in the service registry if it is not provided + * + * @version $Rev: 563772 $ $Date: 2007-08-08 07:50:49 +0100 (Wed, 08 Aug 2007) $ + */ +public class Axis2SCABindingInvoker implements Interceptor { + + private static final Logger logger = Logger.getLogger(Axis2SCABindingInvoker.class.getName()); + + private Invoker axis2Invoker; + private Axis2SCAReferenceBindingProvider provider; + + public Axis2SCABindingInvoker(Axis2SCAReferenceBindingProvider provider, Invoker axis2Invoker) { + this.axis2Invoker = axis2Invoker; + this.provider = provider; + } + + public void setNext(Invoker next) { + } + + public Invoker getNext() { + return null; + } + + /** + * Fix up the URL for the message. The "to" EndPoint comes from the wire + * target and needs to be replaced with the endpoint from the registry. + * The default URL for an Endpoint URI where there is no + * target component or service information, as in the case of a + * wire crossing a node boundary, is "/" + */ + public Message invoke(Message msg) { + + // make sure that the epr of the target service is set in the TO + // field of the message + EndpointReference to = msg.getTo(); + + // check to see if we either don't have an endpoint set or if the URI + // is dynamic or the target service is marked as unresolved + if ((to == null) || (to.getURI().equals("/") || (to.getContract() == null) || (to.getContract().isUnresolved()))) { + + EndpointReference eprTo = provider.getServiceEndpoint(); + + if ( (eprTo == null) || (eprTo.getURI() == null)) { + throw new ServiceUnavailableException("Endpoint for service: " + provider.getSCABinding().getURI() + + " can't be found for component: " + + provider.getComponent().getName() + + " reference: " + + provider.getComponentReference().getName()); + } + msg.setTo(eprTo); + } + + // make sure that the epr of the callback service (if there is one) is set + // in the callbackReference field of the message. + EndpointReference callbackEPR = msg.getFrom().getReferenceParameters().getCallbackReference(); + + if ((callbackEPR == null) || (callbackEPR.getURI().equals("/"))) { + + callbackEPR = provider.getCallbackEndpoint(); + + if (callbackEPR != null) { + msg.getFrom().getReferenceParameters().setCallbackReference(callbackEPR); + } + } + + // do the axis2 stuff + return axis2Invoker.invoke(msg); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingProviderFactory.java new file mode 100644 index 0000000000..b105696b5d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingProviderFactory.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.sca.binding.sca.axis2.impl; + +import java.util.List; + +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.policy.util.PolicyHandlerDefinitionsLoader; +import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * The factory for the Axis2 based implementation of the distributed sca binding + * + * @version $Rev: 563772 $ $Date: 2007-08-08 07:50:49 +0100 (Wed, 08 Aug 2007) $ + */ +public class Axis2SCABindingProviderFactory implements BindingProviderFactory { + + private ExtensionPointRegistry extensionPoints; + private List policyHandlerClassnames = null; + + public Axis2SCABindingProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + policyHandlerClassnames = PolicyHandlerDefinitionsLoader.loadPolicyHandlerClassnames(); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + DistributedSCABinding binding) { + return new Axis2SCAReferenceBindingProvider(component, reference, binding, + extensionPoints, policyHandlerClassnames); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + DistributedSCABinding binding) { + return new Axis2SCAServiceBindingProvider(component, service, binding, + extensionPoints, policyHandlerClassnames); + } + + public Class getModelType() { + return DistributedSCABinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java new file mode 100644 index 0000000000..48d65cb735 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.axis2.impl; + +import java.net.URI; +import java.util.List; +import java.util.logging.Logger; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.axis2.Axis2ReferenceBindingProvider; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * The reference binding provider for the remote sca binding implementation. Relies on the + * binding-ws-axis implementation for sending messages to remote services to this provider + * just uses the ws-axis provider. + * + * @version $Rev: 563772 $ $Date: 2007-08-08 07:50:49 +0100 (Wed, 08 Aug 2007) $ + */ +public class Axis2SCAReferenceBindingProvider implements ReferenceBindingProvider { + + private static final Logger logger = Logger.getLogger(Axis2SCAReferenceBindingProvider.class.getName()); + + private RuntimeComponent component; + private RuntimeComponentReference reference; + private SCABinding binding; + private Axis2ReferenceBindingProvider axisReferenceBindingProvider; + private WebServiceBinding wsBinding; + + private EndpointReference serviceEPR = null; + private EndpointReference callbackEPR = null; + + public Axis2SCAReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + DistributedSCABinding binding, + ExtensionPointRegistry extensionPoints, + List policyHandlerClassnames) { + + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + ServletHost servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + DataBindingExtensionPoint dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class); + + this.component = component; + this.reference = reference; + this.binding = binding.getSCABinding(); + wsBinding = modelFactories.getFactory(WebServiceBindingFactory.class).createWebServiceBinding(); + wsBinding.setName(this.binding.getName()); + + // Turn the java interface contract into a WSDL interface contract + BindingWSDLGenerator.generateWSDL(component, reference, wsBinding, extensionPoints, null); + + // Set to use the Axiom data binding + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + contract.getInterface().resetDataBinding(OMElement.class.getName()); + + axisReferenceBindingProvider = new Axis2ReferenceBindingProvider(component, + reference, + wsBinding, + modelFactories, + policyHandlerClassnames, + dataBindings); + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public Invoker createInvoker(Operation operation) { + return new Axis2SCABindingInvoker(this, axisReferenceBindingProvider.createInvoker(operation)); + } + + /** + * Uses the distributed domain service discovery feature to locate remote + * service endpoints + * + * @return An EPR for the target service that this reference refers to + */ + public EndpointReference getServiceEndpoint(){ + + if (serviceEPR == null){ + String endpointURL = null; + + if (binding.getURI() != null) { + // check if the binding URI is already resolved if it is use is if not + try { + URI uri = new URI(binding.getURI()); + if (uri.isAbsolute()) { + endpointURL = binding.getURI(); + } + } catch(Exception ex) { + // do nothing + } + } + + serviceEPR = new EndpointReferenceImpl(endpointURL); + } + + return serviceEPR; + } + + + /** + * Retrieves the URI of the callback service (that this reference has created) + * returns null if there is no callback service for the sca binding + * + * @return the callback endpoint + */ + public EndpointReference getCallbackEndpoint(){ + if (callbackEPR == null) { + if (reference.getCallbackService() != null) { + for (Binding callbackBinding : reference.getCallbackService().getBindings()) { + if (callbackBinding instanceof SCABinding) { + callbackEPR = new EndpointReferenceImpl(reference.getName() + "/" + callbackBinding.getName()); + continue; + } + } + } + } + return callbackEPR; + } + + + public SCABinding getSCABinding () { + return binding; + } + + public RuntimeComponent getComponent () { + return component; + } + + public RuntimeComponentReference getComponentReference () { + return reference; + } + + public void start() { + axisReferenceBindingProvider.start(); + } + + public void stop() { + axisReferenceBindingProvider.stop(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java new file mode 100644 index 0000000000..0450d07071 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.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.sca.binding.sca.axis2.impl; + +import java.util.List; +import java.util.logging.Logger; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.axis2.Axis2ServiceProvider; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.work.WorkScheduler; + +/** + * The service binding provider for the remote sca binding implementation. Relies on the + * binding-ws-axis implementation for providing a remote message endpoint for this service + * + * @version $Rev: 563772 $ $Date: 2007-08-08 07:50:49 +0100 (Wed, 08 Aug 2007) $ + */ +public class Axis2SCAServiceBindingProvider implements ServiceBindingProvider { + + private static final Logger logger = Logger.getLogger(Axis2SCAServiceBindingProvider.class.getName()); + + private SCABinding binding; + private Axis2ServiceProvider axisProvider; + private WebServiceBinding wsBinding; + + private boolean started = false; + + + public Axis2SCAServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + DistributedSCABinding binding, + ExtensionPointRegistry extensionPoints, + List policyHandlerClassnames) { + + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + ServletHost servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + MessageFactory messageFactory = modelFactories.getFactory(MessageFactory.class); + DataBindingExtensionPoint dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class); + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + WorkScheduler workScheduler = utilities.getUtility(WorkScheduler.class); + + this.binding = binding.getSCABinding(); + wsBinding = modelFactories.getFactory(WebServiceBindingFactory.class).createWebServiceBinding(); + wsBinding.setName(this.binding.getName()); + wsBinding.setURI(this.binding.getURI()); + + // Turn the java interface contract into a WSDL interface contract + BindingWSDLGenerator.generateWSDL(component, service, wsBinding, extensionPoints, null); + + // Set to use the Axiom data binding + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + contract.getInterface().resetDataBinding(OMElement.class.getName()); + + axisProvider = new Axis2SCAServiceProvider(component, + service, + this.binding, + wsBinding, + servletHost, + messageFactory, + policyHandlerClassnames, + workScheduler); + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + if (started) { + return; + } else { + started = true; + } + + axisProvider.start(); + } + + public void stop() { + if (!started) { + return; + } else { + started = false; + } + + axisProvider.stop(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceProvider.java new file mode 100644 index 0000000000..dd66415cca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceProvider.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.axis2.impl; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.Axis2ServiceProvider; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.work.WorkScheduler; + +/** + * A specialization of the Axis2BindingProvider that just switches in the SCABinding model + * element when it is required. The SCABinding is required as the service binding provider + * finds the service wire based in the binding + * + * @version $Rev: 563772 $ $Date: 2007-08-08 07:50:49 +0100 (Wed, 08 Aug 2007) $ + */ +public class Axis2SCAServiceProvider extends Axis2ServiceProvider { + + private SCABinding binding; + + /** + * Switch in the fake ws binding + * + * @param component + * @param service + * @param binding + * @param wsBinding + * @param servletHost + * @param messageFactory + */ + public Axis2SCAServiceProvider(RuntimeComponent component, + RuntimeComponentService service, + SCABinding binding, + WebServiceBinding wsBinding, + ServletHost servletHost, + MessageFactory messageFactory, + List policyHandlerClassnames, + WorkScheduler workScheduler) { + + super(component, + service, + wsBinding, + servletHost, + messageFactory, + policyHandlerClassnames, + workScheduler); + + this.binding = binding; + } + + /** + * Return the sca binding as wires will be registered against this rather + * than against the wsBinding that the Axis2SCAServiceProvider is + * expecting + * + * @return the binding + */ + @Override + protected Binding getBinding(){ + return binding; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..1b369cde06 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.sca.axis2.impl.Axis2SCABindingProviderFactory;model=org.apache.tuscany.sca.binding.sca.DistributedSCABinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.java new file mode 100644 index 0000000000..40d64be9b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.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.sca.binding.sca.axis2; + + +import junit.framework.Assert; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldClient; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.impl.HelloWorldClientCallbackOnewayRemoteImpl; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AsynchTestCase { + + public static TestNode nodeA; + public static TestNode nodeB; + + @BeforeClass + public static void init() throws Exception { + System.out.println("Setting up nodes"); + + try { + // create and start domains + nodeA = new TestNode("nodeG"); + nodeB = new TestNode("nodeH"); + + nodeA.start(); + nodeB.start(); + + } catch (Exception ex) { + System.err.println("Exception when creating domain " + ex.getMessage()); + ex.printStackTrace(System.err); + throw ex; + } + } + + @AfterClass + public static void destroy() throws Exception { + nodeA.stop(); + nodeB.stop(); + } + + @Test + public void testHelloWorldAsynch() throws Exception { + HelloWorldClient helloWorldClientB; + helloWorldClientB = nodeA.getService(HelloWorldClient.class, "AHelloWorldClientCallbackRemote"); + helloWorldClientB.getGreetings("fred"); + System.out.println("Sleeping ..."); + Thread.sleep(2000); + System.out.println("... Done"); + Assert.assertEquals("callback fred", HelloWorldClientCallbackOnewayRemoteImpl.result ); + + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BindingScaEndpointResolverFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BindingScaEndpointResolverFactoryImpl.java new file mode 100644 index 0000000000..b345e563e3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BindingScaEndpointResolverFactoryImpl.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.sca.binding.sca.axis2; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.endpointresolver.EndpointResolver; +import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory; + +/** + * The factory for creating endpoint Binding providers + * + * @version $Rev$ $Date$ + */ +public class BindingScaEndpointResolverFactoryImpl implements EndpointResolverFactory { + + private ExtensionPointRegistry extensionPoints; + + public BindingScaEndpointResolverFactoryImpl(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + } + + public EndpointResolver createEndpointResolver(Endpoint endpoint, Binding binding) { + + return new BindingScaEndpointResolverImpl(extensionPoints, endpoint, binding); + } + + public Class getModelType() { + return SCABinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BindingScaEndpointResolverImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BindingScaEndpointResolverImpl.java new file mode 100644 index 0000000000..472e85116e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BindingScaEndpointResolverImpl.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.sca.binding.sca.axis2; + + +import java.util.logging.Logger; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.endpointresolver.EndpointResolver; + +/** + * The endpoint resolver allows unresolved endpoints to be plumbed into + * the runtime start and message send processing as a hook to late resolution + * of target services + * + * @version $Rev$ $Date$ + */ +public class BindingScaEndpointResolverImpl implements EndpointResolver { + + private final static Logger logger = Logger.getLogger(BindingScaEndpointResolverImpl.class.getName()); + + private Endpoint endpoint; + private SCABinding binding; + + public BindingScaEndpointResolverImpl(ExtensionPointRegistry extensionPoints, + Endpoint endpoint, + Binding binding) { + this.endpoint = endpoint; + this.binding = (SCABinding)binding; + } + + public void start(){ + // do nothing + } + + public void resolve() { + if (endpoint.isUnresolved()){ + // pretend to resolve the endpoint. In this test case to what we know + // it should be + logger.info("Fixing up endpoint soure binding"); + endpoint.setSourceBinding(endpoint.getCandidateBindings().get(0)); + endpoint.getSourceBinding().setURI("http://localhost:8085/BHelloWorldServiceRemote"); + } + } + + public void stop(){ + // do nothing + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.java new file mode 100644 index 0000000000..76dbc5a5c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.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.sca.binding.sca.axis2; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldClient; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class CallbackTestCase { + + public static TestNode nodeA; + public static TestNode nodeB; + + @BeforeClass + public static void init() throws Exception { + System.out.println("Setting up nodes"); + + try { + // create and start domains + nodeA = new TestNode("nodeE"); + nodeB = new TestNode("nodeF"); + + nodeA.start(); + nodeB.start(); + + } catch (Exception ex) { + System.err.println("Exception when creating domain " + ex.getMessage()); + ex.printStackTrace(System.err); + throw ex; + } + } + + @AfterClass + public static void destroy() throws Exception { + nodeA.stop(); + nodeB.stop(); + } + + //@Test + public void testKeepServerRunning() throws Exception { + System.out.println("press enter to continue"); + System.in.read(); + } + + @Test + public void testHelloWorldCallbackLocal() throws Exception { + HelloWorldClient helloWorldClientB; + helloWorldClientB = nodeB.getService(HelloWorldClient.class, "BHelloWorldClientCallbackLocal"); + Assert.assertEquals("Hello callback fred", helloWorldClientB.getGreetings("fred")); + } + + @Test + public void testHelloWorldCallbackRemote() throws Exception { + HelloWorldClient helloWorldClientA; + helloWorldClientA = nodeA.getService(HelloWorldClient.class, "AHelloWorldClientCallbackRemote"); + Assert.assertEquals("Hello callback fred", helloWorldClientA.getGreetings("fred")); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.java new file mode 100644 index 0000000000..2deb62e6c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.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.sca.binding.sca.axis2; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldClient; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class PromotionTestCase { + + public static TestNode nodeA; + public static TestNode nodeB; + + @BeforeClass + public static void init() throws Exception { + System.out.println("Setting up nodes"); + + try { + // create and start domains + nodeA = new TestNode("nodeC"); + nodeB = new TestNode("nodeD"); + + nodeA.start(); + nodeB.start(); + + } catch (Exception ex) { + System.err.println("Exception when creating domain " + ex.getMessage()); + ex.printStackTrace(System.err); + throw ex; + } + } + + @AfterClass + public static void destroy() throws Exception { + nodeA.stop(); + nodeB.stop(); + } + + @Test + public void testHelloWorldPromotion() throws Exception { + HelloWorldClient helloWorldClientA; + helloWorldClientA = nodeA.getService(HelloWorldClient.class, "AHelloWorldClientRemotePromotion"); + Assert.assertEquals(helloWorldClientA.getGreetings("fred"), "Hello fred"); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java new file mode 100644 index 0000000000..2d2a23d7df --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.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.sca.binding.sca.axis2; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldClient; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.osoa.sca.ServiceUnavailableException; + +public class SimpleTestCase { + + public static TestNode nodeA; + public static TestNode nodeB; + + @BeforeClass + public static void init() throws Exception { + System.out.println("Setting up nodes"); + + try { + // create and start domains + nodeA = new TestNode("nodeA"); + nodeB = new TestNode("nodeB"); + + nodeA.start(); + nodeB.start(); + + } catch (Exception ex) { + System.err.println("Exception when creating domain " + ex.getMessage()); + ex.printStackTrace(System.err); + throw ex; + } + } + + @AfterClass + public static void destroy() throws Exception { + nodeA.stop(); + nodeB.stop(); + } + + @Test + public void testHelloWorldLocal() throws Exception { + HelloWorldClient helloWorldClientA = nodeA.getService(HelloWorldClient.class, "AHelloWorldClientLocal"); + Assert.assertEquals(helloWorldClientA.getGreetings("fred"), "Hello fred"); + + } + + @Test + public void testHelloWorldRemote() throws Exception { + + HelloWorldClient helloWorldClientA; + helloWorldClientA = nodeA.getService(HelloWorldClient.class, "AHelloWorldClientRemote"); + + try { + helloWorldClientA.getGreetings("fred"); + } catch (ServiceUnavailableException ex){ + Assert.fail(); + } + } + + @Test + public void testHelloWorldLocalAndRemote() throws Exception { + HelloWorldClient helloWorldClientA = nodeA.getService(HelloWorldClient.class, "AHelloWorldClientLocalAndRemote"); + HelloWorldClient helloWorldClientB = nodeB.getService(HelloWorldClient.class, "BHelloWorldClientLocalAndRemote"); + Assert.assertEquals(helloWorldClientA.getGreetings("fred"), "Hello fred"); + Assert.assertEquals(helloWorldClientB.getGreetings("fred"), "Hello fred"); + } + + @Test + public void testHelloWorldMultipleServices() throws Exception { + HelloWorldClient helloWorldClientA = nodeA.getService(HelloWorldClient.class, "AHelloWorldClientMultipleServices"); + HelloWorldClient helloWorldClientA2 = nodeA.getService(HelloWorldClient.class, "AHelloWorldClientMultipleServices2"); + HelloWorldClient helloWorldClientB = nodeB.getService(HelloWorldClient.class, "BHelloWorldClientMultipleServices"); + Assert.assertEquals(helloWorldClientA.getGreetings("fred"), "Hello fred"); + Assert.assertEquals(helloWorldClientA2.getGreetings("fred"), "Hello fred"); + Assert.assertEquals(helloWorldClientB.getGreetings("fred"), "Hello fred"); + } + + @Test + public void testHelloWorldMultipleBindings() throws Exception { + HelloWorldClient helloWorldClientA; + helloWorldClientA = nodeA.getService(HelloWorldClient.class, "AHelloWorldClientMultipleBindings"); + Assert.assertEquals(helloWorldClientA.getGreetings("fred"), "Hello fred"); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java new file mode 100644 index 0000000000..e788526069 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java @@ -0,0 +1,232 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.axis2; + +import java.net.URL; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionService; +import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; +import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntime; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentContext; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.ServiceRuntimeException; + +/** + * The very minimum node implementation to get these tests going without creating a dependency on + * any runtime/hosting implementation + * + * @version $Rev: 552343 $ $Date: 2007-09-20 14:53:40 +0100 (Thu, 20 Sep 2007) $ + */ +public class TestNode { + + private static final Logger logger = Logger.getLogger(TestNode.class.getName()); + + private String nodeName; + private ReallySmallRuntime nodeRuntime; + + private ClassLoader cl = TestNode.class.getClassLoader(); + + private Composite nodeComposite = null; + private Composite appComposite = null; + + public TestNode(String nodeName) + throws Exception { + this.nodeName = nodeName; + + try { + + // create and start domainA + nodeRuntime = new ReallySmallRuntime(cl); + nodeRuntime.start(); + + // Create an in-memory domain level composite + AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory(); + nodeComposite = assemblyFactory.createComposite(); + nodeComposite.setName(new QName(Constants.SCA10_NS, "domain")); + nodeComposite.setURI("http://localhost"); + + // add the top level composite into the composite activator + nodeRuntime.getCompositeActivator().setDomainComposite(nodeComposite); + + // add a contribution to the domain + ContributionService contributionService = nodeRuntime.getContributionService(); + + // find the current directory as a URL. This is where our contribution + // will come from + URL contributionURL = Thread.currentThread().getContextClassLoader().getResource(nodeName + "/"); + + // Contribute the SCA application + Contribution contribution = contributionService.contribute("http://calculator", contributionURL, null, false); + appComposite = contribution.getDeployables().get(0); + + // Add the deployable composite to the domain + nodeComposite.getIncludes().add(appComposite); + nodeRuntime.buildComposite(appComposite); + nodeRuntime.getCompositeActivator().activate(appComposite); + + + } catch (Exception ex) { + System.err.println("Exception when creating node " + ex.getMessage()); + ex.printStackTrace(System.err); + throw ex; + } + } + + public void start() { + + try { + nodeRuntime.getCompositeActivator().start(appComposite); + } catch (Exception ex) { + System.err.println("Exception when creating domain " + ex.getMessage()); + ex.printStackTrace(System.err); + } + + } + + public void stop() { + try { + nodeRuntime.stop(); + } catch (Exception ex) { + System.err.println("Exception when creating domain " + ex.getMessage()); + ex.printStackTrace(System.err); + } + } + + public B getService(Class businessInterface, String serviceName) { + ServiceReference serviceReference = getServiceReference(businessInterface, serviceName); + if (serviceReference == null) { + throw new ServiceRuntimeException("Service not found: " + serviceName); + } + return serviceReference.getService(); + } + + private ServiceReference createServiceReference(Class businessInterface, String targetURI) { + try { + AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory(); + Composite composite = assemblyFactory.createComposite(); + composite.setName(new QName(Constants.SCA10_TUSCANY_NS, "default")); + RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent(); + component.setName("default"); + component.setURI("default"); + nodeRuntime.getCompositeActivator().configureComponentContext(component); + composite.getComponents().add(component); + RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference(); + reference.setName("default"); + ModelFactoryExtensionPoint factories = + nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class); + JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class); + InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); + interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface)); + reference.setInterfaceContract(interfaceContract); + component.getReferences().add(reference); + reference.setComponent(component); + SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class); + SCABinding binding = scaBindingFactory.createSCABinding(); + binding.setURI(targetURI); + reference.getBindings().add(binding); + return new ServiceReferenceImpl(businessInterface, component, reference, binding, nodeRuntime + .getProxyFactory(), nodeRuntime.getCompositeActivator()); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + public ServiceReference getServiceReference(Class businessInterface, String name) { + + // Extract the component name + String componentName; + String serviceName; + int i = name.indexOf('/'); + if (i != -1) { + componentName = name.substring(0, i); + serviceName = name.substring(i + 1); + + } else { + componentName = name; + serviceName = null; + } + + // Lookup the component in the domain + + Component component = null; + + for (Composite composite: nodeComposite.getIncludes()) { + for (Component componentLoop: composite.getComponents()) { + if (componentLoop.getName().equals(componentName)) { + component = componentLoop; + break; + } + } + } + if (component == null) { + // The component is not local in the partition, try to create a remote service ref + return createServiceReference(businessInterface, name); + } + RuntimeComponentContext componentContext = null; + + // If the component is a composite, then we need to find the + // non-composite component that provides the requested service + if (component.getImplementation() instanceof Composite) { + for (ComponentService componentService : component.getServices()) { + if (serviceName == null || serviceName.equals(componentService.getName())) { + CompositeService compositeService = (CompositeService)componentService.getService(); + if (compositeService != null) { + if (serviceName != null) { + serviceName = "$promoted$" + component.getName() + "$slash$" + serviceName; + } + componentContext = + ((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext(); + return componentContext.createSelfReference(businessInterface, compositeService + .getPromotedService()); + } + break; + } + } + // No matching service is found + throw new ServiceRuntimeException("Composite service not found: " + name); + } else { + componentContext = ((RuntimeComponent)component).getComponentContext(); + if (serviceName != null) { + return componentContext.createSelfReference(businessInterface, serviceName); + } else { + return componentContext.createSelfReference(businessInterface); + } + } + } + +} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldCallbackRemote.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldCallbackRemote.java new file mode 100644 index 0000000000..1a2788ac74 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldCallbackRemote.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.sca.binding.sca.axis2.helloworld; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface HelloWorldCallbackRemote { + + String getGreetingsCallbackRemote(String s); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldClient.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldClient.java new file mode 100644 index 0000000000..e4d36ac78b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldClient.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.sca.binding.sca.axis2.helloworld; + + +public interface HelloWorldClient { + + String getGreetings(String s); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackOnewayRemote.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackOnewayRemote.java new file mode 100644 index 0000000000..a83fcb3069 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackOnewayRemote.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.sca.binding.sca.axis2.helloworld; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.OneWay; +import org.osoa.sca.annotations.Remotable; + +@Remotable +@Callback(HelloWorldCallbackRemote.class) +public interface HelloWorldServiceCallbackOnewayRemote { + + @OneWay + void getGreetingsRemote(String s); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackRemote.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackRemote.java new file mode 100644 index 0000000000..c41548ec51 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackRemote.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.sca.binding.sca.axis2.helloworld; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.Remotable; + +@Remotable +@Callback(HelloWorldCallbackRemote.class) +public interface HelloWorldServiceCallbackRemote { + + String getGreetingsRemote(String s); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceLocal.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceLocal.java new file mode 100644 index 0000000000..7b8e00eb2a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceLocal.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.sca.binding.sca.axis2.helloworld; + + +public interface HelloWorldServiceLocal { + + String getGreetingsLocal(String s); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote.java new file mode 100644 index 0000000000..62d61e4fff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote.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.sca.binding.sca.axis2.helloworld; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface HelloWorldServiceRemote { + + String getGreetingsRemote(String s); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote2.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote2.java new file mode 100644 index 0000000000..2dcc8cc64b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote2.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.sca.binding.sca.axis2.helloworld; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface HelloWorldServiceRemote2 { + + String getGreetingsRemote2(String s); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackOnewayRemoteImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackOnewayRemoteImpl.java new file mode 100644 index 0000000000..8e7d2f8023 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackOnewayRemoteImpl.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.sca.binding.sca.axis2.helloworld.impl; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldClient; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceCallbackOnewayRemote; +import org.osoa.sca.annotations.Reference; + +public class HelloWorldClientCallbackOnewayRemoteImpl implements HelloWorldClient { + + public static String result; + + @Reference + public HelloWorldServiceCallbackOnewayRemote helloWorldService; + + public String getGreetings(String s) { + helloWorldService.getGreetingsRemote(s); + return null; + } + + public String getGreetingsCallbackRemote(String s) { + result = "callback " + s; + return result; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackRemoteImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackRemoteImpl.java new file mode 100644 index 0000000000..7d07c4ff43 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackRemoteImpl.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.sca.binding.sca.axis2.helloworld.impl; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldClient; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceCallbackRemote; +import org.osoa.sca.annotations.Reference; + +public class HelloWorldClientCallbackRemoteImpl implements HelloWorldClient { + + public static String result; + + @Reference + public HelloWorldServiceCallbackRemote helloWorldService; + + public String getGreetings(String s) { + return helloWorldService.getGreetingsRemote(s); + } + + public String getGreetingsCallbackRemote(String s) { + result = "callback " + s; + return result; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientLocalImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientLocalImpl.java new file mode 100644 index 0000000000..7098f10622 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientLocalImpl.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.sca.binding.sca.axis2.helloworld.impl; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldClient; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceLocal; +import org.osoa.sca.annotations.Reference; + +public class HelloWorldClientLocalImpl implements HelloWorldClient { + + @Reference + public HelloWorldServiceLocal helloWorldService; + + public String getGreetings(String s) { + return helloWorldService.getGreetingsLocal(s); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemote2Impl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemote2Impl.java new file mode 100644 index 0000000000..07ae00bd31 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemote2Impl.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.sca.binding.sca.axis2.helloworld.impl; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldClient; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceRemote2; +import org.osoa.sca.annotations.Reference; + +public class HelloWorldClientRemote2Impl implements HelloWorldClient { + + @Reference + public HelloWorldServiceRemote2 helloWorldService; + + public String getGreetings(String s) { + return helloWorldService.getGreetingsRemote2(s); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemoteImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemoteImpl.java new file mode 100644 index 0000000000..36854cb7b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemoteImpl.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.sca.binding.sca.axis2.helloworld.impl; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldClient; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceRemote; +import org.osoa.sca.annotations.Reference; + +public class HelloWorldClientRemoteImpl implements HelloWorldClient { + + @Reference + public HelloWorldServiceRemote helloWorldService; + + public String getGreetings(String s) { + return helloWorldService.getGreetingsRemote(s); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackOnewayRemoteImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackOnewayRemoteImpl.java new file mode 100644 index 0000000000..fd3e3a1158 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackOnewayRemoteImpl.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.sca.binding.sca.axis2.helloworld.impl; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldCallbackRemote; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceCallbackOnewayRemote; +import org.osoa.sca.annotations.Callback; + + +public class HelloWorldServiceCallbackOnewayRemoteImpl implements HelloWorldServiceCallbackOnewayRemote { + + @Callback + protected HelloWorldCallbackRemote theCallback; + + public void getGreetingsRemote(String s) { + theCallback.getGreetingsCallbackRemote(s); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackRemoteImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackRemoteImpl.java new file mode 100644 index 0000000000..3400e97447 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackRemoteImpl.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.sca.binding.sca.axis2.helloworld.impl; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldCallbackRemote; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceCallbackRemote; +import org.osoa.sca.annotations.Callback; + +public class HelloWorldServiceCallbackRemoteImpl implements HelloWorldServiceCallbackRemote { + + @Callback + protected HelloWorldCallbackRemote theCallback; + + public String getGreetingsRemote(String s) { + return "Hello " + theCallback.getGreetingsCallbackRemote(s); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceLocalImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceLocalImpl.java new file mode 100644 index 0000000000..20dd97b74a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceLocalImpl.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.sca.binding.sca.axis2.helloworld.impl; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceLocal; + +public class HelloWorldServiceLocalImpl implements HelloWorldServiceLocal { + + public String getGreetingsLocal(String s) { + return "Hello " + s; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceMultipleServicesImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceMultipleServicesImpl.java new file mode 100644 index 0000000000..5f8ccf9466 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceMultipleServicesImpl.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.sca.binding.sca.axis2.helloworld.impl; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceLocal; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceRemote; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceRemote2; +import org.osoa.sca.annotations.Service; + +@Service(interfaces={HelloWorldServiceRemote.class, HelloWorldServiceRemote2.class, HelloWorldServiceLocal.class} ) +public class HelloWorldServiceMultipleServicesImpl implements HelloWorldServiceLocal, HelloWorldServiceRemote, HelloWorldServiceRemote2 { + + public String getGreetingsLocal(String s) { + return "Hello " + s; + } + + public String getGreetingsRemote(String s) { + return "Hello " + s; + } + + public String getGreetingsRemote2(String s) { + return "Hello " + s; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceRemoteImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceRemoteImpl.java new file mode 100644 index 0000000000..b25aebd9df --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceRemoteImpl.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.sca.binding.sca.axis2.helloworld.impl; + +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceRemote; + +public class HelloWorldServiceRemoteImpl implements HelloWorldServiceRemote { + + public String getGreetingsRemote(String s) { + return "Hello " + s; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory new file mode 100644 index 0000000000..5e4fd566c3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.sca.axis2.BindingScaEndpointResolverFactoryImpl;model=org.apache.tuscany.sca.assembly.SCABinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeA/HelloWorld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeA/HelloWorld.composite new file mode 100644 index 0000000000..093258051e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeA/HelloWorld.composite @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeA/META-INF/sca-contribution.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeA/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeA/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeB/HelloWorld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeB/HelloWorld.composite new file mode 100644 index 0000000000..8cf7230ed5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeB/HelloWorld.composite @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeB/META-INF/sca-contribution.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeB/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeB/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorld.composite new file mode 100644 index 0000000000..066727f76d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorld.composite @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorldComponent.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorldComponent.composite new file mode 100644 index 0000000000..485e0815d2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorldComponent.composite @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/META-INF/sca-contribution.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeC/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorld.composite new file mode 100644 index 0000000000..a5a4f04cb5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorld.composite @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorldComponent.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorldComponent.composite new file mode 100644 index 0000000000..bf30bdf42d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorldComponent.composite @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/META-INF/sca-contribution.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeD/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeE/HelloWorld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeE/HelloWorld.composite new file mode 100644 index 0000000000..b519793290 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeE/HelloWorld.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeE/META-INF/sca-contribution.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeE/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeE/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeF/HelloWorld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeF/HelloWorld.composite new file mode 100644 index 0000000000..20a6c54e6e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeF/HelloWorld.composite @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeF/META-INF/sca-contribution.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeF/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeF/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeG/HelloWorld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeG/HelloWorld.composite new file mode 100644 index 0000000000..a76008d0c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeG/HelloWorld.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeG/META-INF/sca-contribution.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeG/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d670354a28 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeG/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeH/HelloWorld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeH/HelloWorld.composite new file mode 100644 index 0000000000..0c22af22ab --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeH/HelloWorld.composite @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeH/META-INF/sca-contribution.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeH/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d670354a28 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-axis2/src/test/resources/nodeH/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/pom.xml new file mode 100644 index 0000000000..bfe12f1d0e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/pom.xml @@ -0,0 +1,114 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-sca-corba + + Apache Tuscany SCA CORBA-based Default Binding Extension + + + + + + org.apache.tuscany.sca + tuscany-binding-sca + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-corba + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-corba-runtime + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-corba + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-corba-jse + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-axiom + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws-wsdlgen + 1.6-SNAPSHOT + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + + ${tuscany.version} + + + org.apache.tuscany.sca.binding.sca.corba + + + ${pom.name} + + + org.apache.tuscany.sca.binding.sca.corba* + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCABindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCABindingProviderFactory.java new file mode 100644 index 0000000000..2eee714de6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCABindingProviderFactory.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.sca.binding.sca.corba.impl; + +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.corba.CorbaHost; +import org.apache.tuscany.sca.host.corba.CorbaHostExtensionPoint; +import org.apache.tuscany.sca.host.corba.ExtensibleCorbaHost; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Binding provider factory for SCA default binding over CORBA binding + */ +public class CorbaSCABindingProviderFactory implements BindingProviderFactory { + + private CorbaHostExtensionPoint chep; + private CorbaHost host; + private ExtensionPointRegistry extensions; + + public CorbaSCABindingProviderFactory(ExtensionPointRegistry extensions) { + this.extensions = extensions; + chep = extensions.getExtensionPoint(CorbaHostExtensionPoint.class); + host = new ExtensibleCorbaHost(chep); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + DistributedSCABinding binding) { + return new CorbaSCAReferenceBindingProvider(binding.getSCABinding(), host, component, reference, extensions); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + DistributedSCABinding binding) { + return new CorbaSCAServiceBindingProvider(binding.getSCABinding(), host, component, service, extensions); + } + + public Class getModelType() { + return DistributedSCABinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvocationProxy.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvocationProxy.java new file mode 100644 index 0000000000..a9cc890616 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvocationProxy.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.corba.impl; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationException; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationProxy; +import org.apache.tuscany.sca.binding.corba.impl.service.OperationTypes; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTree; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeCreator; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Invocation proxy for SCA default binding over CORBA binding + */ +public class CorbaSCAInvocationProxy implements InvocationProxy { + + private static final Logger logger = Logger.getLogger(CorbaSCAInvocationProxy.class.getName()); + private RuntimeWire wire; + private Interface componentInterface; + private OperationTypes types = new OperationTypes(); + private MessageFactory messageFactory; + + public CorbaSCAInvocationProxy(RuntimeWire wire, Interface componentInterface, MessageFactory messageFactory) { + this.wire = wire; + this.componentInterface = componentInterface; + this.messageFactory = messageFactory; + try { + List inputType = new ArrayList(); + inputType.add(TypeTreeCreator.createTypeTree(String.class, null)); + types.setInputType(inputType); + types.setOutputType(TypeTreeCreator.createTypeTree(String.class, null)); + } catch (RequestConfigurationException e) { + // ignore - string type should not cause this exception + } + } + + public Object invoke(String operationName, List arguments) throws InvocationException { + try { + OMElement omContent = CorbaSCAInvoker.stringToOM((String)arguments.get(0)); + String componentOperationName = omContent.getQName().getLocalPart(); + Operation componentOperation = null; + for (Operation operation : componentInterface.getOperations()) { + if (operation.getName().equals(componentOperationName)) { + componentOperation = operation; + break; + } + } + if (componentOperation != null) { + Message msg = messageFactory.createMessage(); + msg.setOperation(componentOperation); + Object[] args = new Object[1]; + args[0] = omContent; + msg.setBody(args); + OMElement omResult = (OMElement)wire.invoke(componentOperation, msg); + return omResult.toStringWithConsume(); + } + } catch (XMLStreamException e) { + logger.log(Level.WARNING, "XMLStreamException during handling invocation target exception", e); + } catch (InvocationTargetException e) { + OMElement omException = (OMElement)((FaultException)e.getCause()).getFaultInfo(); + try { + WrappedSCAException wrappedException = new WrappedSCAException(omException.toStringWithConsume()); + InvocationException exception = new InvocationException(wrappedException); + throw exception; + } catch (XMLStreamException xmle) { + logger.log(Level.WARNING, "XMLStreamException during handling invocation target exception", xmle); + } + + } + + return null; + } + + public OperationTypes getOperationTypes(String operationName) { + // ignoring operationName - only one operation for this proxy is allowed + return types; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvoker.java new file mode 100644 index 0000000000..32d5650f37 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvoker.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.sca.binding.sca.corba.impl; + +import java.io.ByteArrayInputStream; +import java.lang.reflect.Method; +import java.util.Map; + +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; +import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaRequest; +import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaResponse; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.omg.CORBA.Object; +import org.osoa.sca.ServiceRuntimeException; + +public class CorbaSCAInvoker implements Invoker { + + private Object remoteObject; + private Class referenceClass; + + public CorbaSCAInvoker(Object remoteObject, + Class referenceClass, + Map operationsMap, + boolean scaBindingRules) { + this.remoteObject = remoteObject; + this.referenceClass = referenceClass; + } + + /** + * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message) + */ + public Message invoke(Message msg) { + try { + DynaCorbaRequest request = new DynaCorbaRequest(remoteObject, "scaService"); + request.setReferenceClass(referenceClass); + request.setOutputType(String.class); + request.addExceptionType(WrappedSCAException.class); + java.lang.Object[] args = msg.getBody(); + OMElement omElement = (OMElement)args[0]; + String arg = omElement.toStringWithConsume(); + request.addArgument(arg); + DynaCorbaResponse response = request.invoke(); + OMElement responseOM = stringToOM((String)response.getContent()); + msg.setBody(responseOM); + } catch (WrappedSCAException e) { + try { + OMElement exceptionOM = stringToOM(e.getFault()); + // AxisFault axisFault = new AxisFault(""); + // axisFault.setDetail(exceptionOM); + FaultException f = new FaultException(e.getMessage(), exceptionOM, e); + f.setFaultName(exceptionOM.getQName()); + msg.setFaultBody(f); + } catch (XMLStreamException e1) { + } + } catch (RequestConfigurationException e) { + throw new ServiceRuntimeException(e); + } catch (Exception e) { + msg.setFaultBody(e); + } + return msg; + } + + /** + * This will help you to create an OMElement from an xml fragment which you have as a string. + * + * @param xmlFragment - the well-formed xml fragment + * @return The OMElement created out of the string xml fragment. + * @throws XMLStreamException + */ + static OMElement stringToOM(String xmlFragment) throws XMLStreamException { + if (xmlFragment != null) { + return new StAXOMBuilder(new ByteArrayInputStream(xmlFragment.getBytes())).getDocumentElement(); + } + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAReferenceBindingProvider.java new file mode 100644 index 0000000000..c578f8bdf4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAReferenceBindingProvider.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.corba.impl; + +import java.util.logging.Logger; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.corba.CorbaHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.omg.CORBA.Object; + +/** + * Reference binding provider for SCA default binding over CORBA binding + */ +public class CorbaSCAReferenceBindingProvider implements ReferenceBindingProvider { + + private static final Logger logger = Logger.getLogger(CorbaSCAReferenceBindingProvider.class.getName()); + + private SCABinding binding; + private CorbaHost host; + private Object remoteObject; + private Class referenceClass; + private InterfaceContract wsdlInterfaceContract; + + public CorbaSCAReferenceBindingProvider(SCABinding binding, + CorbaHost host, + RuntimeComponent component, + RuntimeComponentReference reference, + ExtensionPointRegistry extensions) { + this.binding = binding; + this.host = host; + + WebServiceBindingFactory wsFactory = extensions.getExtensionPoint(WebServiceBindingFactory.class); + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + BindingWSDLGenerator.generateWSDL(component, reference, wsBinding, extensions, null); + wsdlInterfaceContract = wsBinding.getBindingInterfaceContract(); + wsdlInterfaceContract.getInterface().resetDataBinding(OMElement.class.getName()); + } + + public InterfaceContract getBindingInterfaceContract() { + return wsdlInterfaceContract; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public Invoker createInvoker(Operation operation) { + try { + if (remoteObject == null) { + remoteObject = host.lookup(binding.getURI()); + } + return new CorbaSCAInvoker(remoteObject, referenceClass, null, true); + } catch (Exception e) { + logger.warning(e.getMessage()); + } + return null; + } + + public void start() { + + } + + public void stop() { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAServiceBindingProvider.java new file mode 100644 index 0000000000..6e74686b61 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAServiceBindingProvider.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.corba.impl; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.corba.impl.service.DynaCorbaServant; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationProxy; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.host.corba.CorbaHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Service binding provider for SCA default binding over CORBA binding + */ +public class CorbaSCAServiceBindingProvider implements ServiceBindingProvider { + + private SCABinding binding; + private CorbaHost host; + private RuntimeComponentService service; + private DynaCorbaServant servant; + private MessageFactory messageFactory; + private InterfaceContract wsdlInterfaceContract; + + public CorbaSCAServiceBindingProvider(SCABinding binding, + CorbaHost host, + RuntimeComponent component, + RuntimeComponentService service, + ExtensionPointRegistry extensions) { + this.binding = binding; + this.host = host; + this.service = service; + + messageFactory = extensions.getExtensionPoint(MessageFactory.class); + + WebServiceBindingFactory wsFactory = extensions.getExtensionPoint(WebServiceBindingFactory.class); + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + BindingWSDLGenerator.generateWSDL(component, service, wsBinding, extensions, null); + wsdlInterfaceContract = wsBinding.getBindingInterfaceContract(); + wsdlInterfaceContract.getInterface().resetDataBinding(OMElement.class.getName()); + } + + public InterfaceContract getBindingInterfaceContract() { + return wsdlInterfaceContract; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + try { + InvocationProxy proxy = + new CorbaSCAInvocationProxy(service.getRuntimeWire(binding), service.getInterfaceContract() + .getInterface(), messageFactory); + servant = new DynaCorbaServant(proxy, "IDL:org/apache/tuscany/sca/binding/sca/corba/Service:1.0"); + host.registerServant(binding.getURI(), servant); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + public void stop() { + try { + host.unregisterServant(binding.getURI()); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/WrappedSCAException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/WrappedSCAException.java new file mode 100644 index 0000000000..128d5ef159 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/WrappedSCAException.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.sca.binding.sca.corba.impl; + +/** + * Exception holder for SCA default binding over CORBA. Holds fault message in + * XML + */ +public class WrappedSCAException extends Exception { + + private static final long serialVersionUID = 1L; + public String fault; + + /** + * Creates exception holder with null fault message. This no argument + * constructor is needed by CORBA binding. + */ + public WrappedSCAException() { + + } + + /** + * Creates exception holder with fault message + * + * @param fault XML fault message + */ + public WrappedSCAException(String fault) { + this.fault = fault; + } + + public String getFault() { + return fault; + } + + public void setFault(String fault) { + this.fault = fault; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..e07a7cbb95 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-corba/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.sca.corba.impl.CorbaSCABindingProviderFactory;model=org.apache.tuscany.sca.binding.sca.DistributedSCABinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/pom.xml new file mode 100644 index 0000000000..cf8c507af3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/pom.xml @@ -0,0 +1,115 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-sca-jms + Apache Tuscany SCA JMS-based Default Binding Extension + + + + + org.apache.tuscany.sca + tuscany-binding-sca + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-jms-runtime + 1.6-SNAPSHOT + + + + org.apache.activemq + activemq-core + 5.1.0 + + + + backport-util-concurrent + backport-util-concurrent + 3.1 + + + + org.easymock + easymock + 2.2 + test + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-endpoint + 1.6-SNAPSHOT + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.sca.jms + ${pom.name} + org.apache.tuscany.sca.binding.sca.jms* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/AMQJMSResourceFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/AMQJMSResourceFactory.java new file mode 100644 index 0000000000..a484ca5813 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/AMQJMSResourceFactory.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.sca.binding.sca.jms; + +import javax.jms.JMSException; +import javax.naming.NamingException; + +import org.apache.activemq.ActiveMQConnection; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryImpl; + +public class AMQJMSResourceFactory extends JMSResourceFactoryImpl { + + public AMQJMSResourceFactory(String connectionFactoryName, String responseConnectionFactoryName, String initialContextFactoryName, String jndiURL) { + super(connectionFactoryName, responseConnectionFactoryName, initialContextFactoryName, jndiURL); + } + + @Override + protected void createConnection() throws NamingException, JMSException { + super.createConnection(); + ((ActiveMQConnection)connection).setWatchTopicAdvisories(false); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/AMQResourceFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/AMQResourceFactoryExtensionPoint.java new file mode 100644 index 0000000000..6aab7e53f5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/AMQResourceFactoryExtensionPoint.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.sca.binding.sca.jms; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint; + +public class AMQResourceFactoryExtensionPoint implements JMSResourceFactoryExtensionPoint{ + + public JMSResourceFactory createJMSResourceFactory(JMSBinding binding) { + return new AMQJMSResourceFactory(binding.getConnectionFactoryName(), binding.getResponseConnectionFactoryName(), binding.getInitialContextFactoryName(), binding.getJndiURL()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/JMSBroker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/JMSBroker.java new file mode 100644 index 0000000000..28e7ff9797 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/JMSBroker.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.sca.binding.sca.jms; + +import java.net.URI; + +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; + +/** + * The JMS broker for the JMS based SCA binding TODO: configure from a binding.jms in definitions.xml + */ +public class JMSBroker implements ModuleActivator { + + // this is static so that there is only one broker per JVM + // if that wasn't the case then to use the vm: transport each broker + // would need a unique name and clients would need to know the name + private static BrokerService broker; + + public void start(ExtensionPointRegistry arg0) { + if (broker == null) { + broker = new BrokerService(); + broker.setPersistent(false); + broker.setUseJmx(false); + try { + + TransportConnector tc = broker.addConnector("tcp://localhost:0"); + tc.setDiscoveryUri(URI.create("multicast://default")); + + broker.addNetworkConnector("multicast://default"); + + broker.start(); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + } + + public void stop(ExtensionPointRegistry arg0) { + if (broker != null) { + try { + broker.stop(); + broker = null; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + public static BrokerService getBroker() { + return broker; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/JMSSCABindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/JMSSCABindingProviderFactory.java new file mode 100644 index 0000000000..44ab8f3fbf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/java/org/apache/tuscany/sca/binding/sca/jms/JMSSCABindingProviderFactory.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.jms; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.provider.JMSBindingReferenceBindingProvider; +import org.apache.tuscany.sca.binding.jms.provider.JMSBindingServiceBindingProvider; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactoryExtensionPoint; +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.host.jms.JMSHostExtensionPoint; +import org.apache.tuscany.sca.host.jms.JMSServiceListenerFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.work.WorkScheduler; + +/** + * The factory for the JMS based implementation of the distributed sca binding + */ +public class JMSSCABindingProviderFactory implements BindingProviderFactory { + + private WorkScheduler workScheduler; + private ExtensionPointRegistry extensionPoints; + private JMSResourceFactoryExtensionPoint jmsRFEP; + private JMSServiceListenerFactory serviceListenerFactory; + + public JMSSCABindingProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + workScheduler = utilities.getUtility(WorkScheduler.class); + assert workScheduler != null; + jmsRFEP = (JMSResourceFactoryExtensionPoint)extensionPoints.getExtensionPoint(JMSResourceFactoryExtensionPoint.class); + if (jmsRFEP == null) { + jmsRFEP = new AMQResourceFactoryExtensionPoint(); + } + JMSHostExtensionPoint jmsHostExtensionPoint = (JMSHostExtensionPoint)extensionPoints.getExtensionPoint(JMSHostExtensionPoint.class); + serviceListenerFactory = jmsHostExtensionPoint.getJMSServiceListenerFactory(); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + DistributedSCABinding binding) { + JMSBinding jmsBinding = createBinding(binding); + + // FIXME: CREATE_NEVER doesn't work as the dynamically created JNDI destinations + // aren't replicated around the broker cluster. Maybe it needs an AMQ specific + // impl of the Tuscany JMSResourceFactory which uses use physical destinations + // instead of JNDI + // jmsBinding.setDestinationCreate(JMSBindingConstants.CREATE_NEVER); + + JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory(jmsBinding); + return new JMSBindingReferenceBindingProvider(component, reference, jmsBinding, extensionPoints, jmsRF); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + DistributedSCABinding binding) { + JMSBinding jmsBinding = createBinding(binding); + jmsBinding.setDestinationCreate(JMSBindingConstants.CREATE_ALWAYS); + JMSResourceFactory jmsRF = jmsRFEP.createJMSResourceFactory(jmsBinding); + return new JMSBindingServiceBindingProvider(component, service, binding.getSCABinding(), jmsBinding, serviceListenerFactory, extensionPoints, jmsRF); + } + + private JMSBinding createBinding(DistributedSCABinding binding) { + JMSBinding b = new JMSBinding(); + b.setInitialContextFactoryName("org.apache.activemq.jndi.ActiveMQInitialContextFactory"); + b.setJndiURL("vm://localhost"); // TODO: plug in jndi url from definitions.xml + + b.setJMSTimeToLive(9); + + b.setRequestMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME); + b.setResponseMessageProcessorName(JMSBindingConstants.OBJECT_MP_CLASSNAME); + if (binding.getSCABinding().getURI().startsWith("/")) { + b.setDestinationName(binding.getSCABinding().getURI().substring(1)); + } else { + b.setDestinationName(binding.getSCABinding().getURI()); + } + return b; + } + + public Class getModelType() { + return DistributedSCABinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..f1b9825130 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.binding.sca.jms.JMSBroker diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..8e53649af1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.sca.jms.JMSSCABindingProviderFactory;model=org.apache.tuscany.sca.binding.sca.DistributedSCABinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/pom.xml new file mode 100644 index 0000000000..47ccd937fb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/pom.xml @@ -0,0 +1,77 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-sca-xml + Apache Tuscany SCA Default Binding XML Model + + + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-sca + 1.6-SNAPSHOT + + + + org.easymock + easymock + 2.2 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.sca.xml + ${pom.name} + org.apache.tuscany.sca.binding.sca.xml* + org.apache.tuscany.sca.binding.sca.impl,* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java new file mode 100644 index 0000000000..034aaf0339 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.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.sca.binding.sca.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * A processor to read the XML that describes the SCA binding. + * + * @version $Rev$ $Date$ + */ + +public class SCABindingProcessor implements StAXArtifactProcessor, Constants{ + + private SCABindingFactory scaBindingFactory; + private ExtensionFactory extensionFactory; + private PolicyFactory policyFactory; + private IntentAttachPointTypeFactory intentAttachPointTypeFactory; + + private PolicyAttachPointProcessor policyProcessor; + private StAXAttributeProcessor extensionAttributeProcessor; + + private Monitor monitor; + + protected static final String BINDING_SCA = "binding.sca"; + protected static final QName BINDING_SCA_QNAME = new QName(Constants.SCA10_NS, BINDING_SCA); + + public SCABindingProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + this.scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.intentAttachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.extensionAttributeProcessor = extensionAttributeProcessor; + + this.monitor = monitor; + } + + public QName getArtifactType() { + return BINDING_SCA_QNAME; + } + + public Class getModelType() { + return SCABinding.class; + } + + public SCABinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + SCABinding scaBinding = scaBindingFactory.createSCABinding(); + IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType(); + bindingType.setName(getArtifactType()); + bindingType.setUnresolved(true); + ((PolicySetAttachPoint)scaBinding).setType(bindingType); + + // Read policies + policyProcessor.readPolicies(scaBinding, reader); + + // Read binding name + String name = reader.getAttributeValue(null, NAME); + if (name != null) { + scaBinding.setName(name); + } + + // Read binding URI + String uri = reader.getAttributeValue(null, URI); + if (uri != null) { + scaBinding.setURI(uri); + } + + // Handle extended attributes + for (int a = 0; a < reader.getAttributeCount(); a++) { + QName attributeName = reader.getAttributeName(a); + if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { + if( (! Constants.SCA10_NS.equals(attributeName.getNamespaceURI()) && + (! Constants.SCA10_TUSCANY_NS.equals(attributeName.getNamespaceURI()) ))) { + Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); + Extension attributeExtension; + if (attributeValue instanceof Extension) { + attributeExtension = (Extension) attributeValue; + } else { + attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true); + } + scaBinding.getAttributeExtensions().add(attributeExtension); + } + } + } + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && BINDING_SCA_QNAME.equals(reader.getName())) { + break; + } + } + return scaBinding; + } + + public void resolve(SCABinding model, ModelResolver resolver) throws ContributionResolveException { + policyProcessor.resolvePolicies(model, resolver); + } + + public void write(SCABinding scaBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + writer.writeStartElement(Constants.SCA10_NS, BINDING_SCA); + policyProcessor.writePolicyAttributes(scaBinding, writer); + + // Write binding name + if (scaBinding.getName() != null) { + writer.writeAttribute(NAME, scaBinding.getName()); + } + + // Write binding URI + if (scaBinding.getURI() != null) { + writer.writeAttribute(URI, scaBinding.getURI()); + } + + // Write extended attributes + for(Extension extension : scaBinding.getAttributeExtensions()) { + if(extension.isAttribute()) { + extensionAttributeProcessor.write(extension, writer); + } + } + + writer.writeEndElement(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..bc9f9b7d62 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.sca.xml.SCABindingProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#binding.sca,model=org.apache.tuscany.sca.binding.sca.impl.SCABindingImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java new file mode 100644 index 0000000000..a7c7c15eaa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apace.tuscany.sca.binding.sca.xml; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; + +/** + * Test reading WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class ReadTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private CompositeBuilder compositeBuilder; + + @Override + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null); + + } + + public void testReadComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ComponentType componentType = (ComponentType)staxProcessor.read(reader); + assertNotNull(componentType); + + SCABinding referenceSCABinding = (SCABinding) componentType.getReferences().get(0).getBindings().get(0); + assertNotNull(referenceSCABinding); + + SCABinding serviceSCABinding = (SCABinding) componentType.getServices().get(0).getBindings().get(0); + assertNotNull(serviceSCABinding); + + //new PrintUtil(System.out).print(componentType); + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("/Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + + compositeBuilder.build(composite); + + SCABinding referenceSCABinding = (SCABinding) composite.getComponents().get(0).getReferences().get(0).getBindings().get(0); + SCABinding serviceSCABinding = (SCABinding) composite.getComponents().get(1).getServices().get(0).getBindings().get(0); + + Assert.assertNotNull(referenceSCABinding); + Assert.assertNotNull(serviceSCABinding); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadWriteAnyAttributeTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadWriteAnyAttributeTestCase.java new file mode 100644 index 0000000000..b5f9fa4673 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadWriteAnyAttributeTestCase.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.apace.tuscany.sca.binding.sca.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.binding.sca.xml.SCABindingProcessor; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.xml.AnyAttributeProcessor; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadWriteAnyAttributeTestCase { + + private static final QName EXTENDED_ATTRIBUTE = new QName("http://test", "customAttribute"); + + private static final String XML = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + + /** + * Initialize the test environment + * This takes care to register attribute processors when provided + * + * @param attributeProcessor + * @throws Exception + */ + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + + inputFactory = XMLInputFactory.newInstance(); + + StAXAttributeProcessor attributeProcessor = new AnyAttributeProcessor(modelFactories,null); + + StAXAttributeProcessorExtensionPoint staxAttributeProcessorsExtensionPoint = new DefaultStAXAttributeProcessorExtensionPoint(extensionPoints); + staxAttributeProcessorsExtensionPoint.addArtifactProcessor(attributeProcessor); + extensionPoints.addExtensionPoint(staxAttributeProcessorsExtensionPoint); + + + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + StAXAttributeProcessor staxAttributeProcessor = new ExtensibleStAXAttributeProcessor(staxAttributeProcessorsExtensionPoint ,inputFactory, outputFactory, null); + + SCABindingProcessor wsbp = new SCABindingProcessor(modelFactories, null, staxAttributeProcessor, null); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessors.addArtifactProcessor(wsbp); + + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + @After + public void tearDown() throws Exception { + + } + + + @Test + //@Ignore() + public void testReadWriteCompositeWithBindings() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML); + // System.out.println(bos.toString()); + + assertEquals(XML, bos.toString()); + bos.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java new file mode 100644 index 0000000000..db611fa413 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.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.apace.tuscany.sca.binding.sca.xml; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; + +/** + * Test reading/write WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class WriteTestCase extends TestCase { + + private StAXArtifactProcessor staxProcessor; + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + + @Override + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + } + + public void testReadWriteComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType"); + ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + assertNotNull(componentType); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos)); + assertEquals("", + bos.toString()); + } + + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("/Calculator.composite"); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + assertNotNull(composite); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + assertEquals("", + bos.toString()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/resources/Calculator.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/resources/Calculator.composite new file mode 100644 index 0000000000..0be16ec536 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/resources/Calculator.composite @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType new file mode 100644 index 0000000000..55e8926504 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/pom.xml new file mode 100644 index 0000000000..e53377e79e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/pom.xml @@ -0,0 +1,93 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-sca + Apache Tuscany SCA Default Binding Model + + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.6-SNAPSHOT + + + + org.easymock + easymock + 2.2 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.sca + ${pom.name} + org.apache.tuscany.sca.binding.sca* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java new file mode 100644 index 0000000000..167c93e86d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.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.sca.binding.sca; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.SCABinding; + + +/** + * Represents an SCA binding used in the distributed runtime. + * At the moment just provides us with a sensibly named type + * against which the distributed sca binding providers can be registered + * + * @version $Rev: 556322 $ $Date: 2007-07-14 19:53:15 +0100 (Sat, 14 Jul 2007) $ + */ +public interface DistributedSCABinding extends Binding { + + SCABinding getSCABinding(); + void setSCABinding(SCABinding scaBinding); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/SCABindingDefinitionsProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/SCABindingDefinitionsProvider.java new file mode 100644 index 0000000000..bd24d4b14c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/SCABindingDefinitionsProvider.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.sca.binding.sca; + +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedExceptionAction; + +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.provider.SCADefinitionsProvider; +import org.apache.tuscany.sca.provider.SCADefinitionsProviderException; + +/** + * Provider for Policy Intents and PolicySet definitions related to security + * + * @version $Rev$ $Date$ + */ +public class SCABindingDefinitionsProvider implements SCADefinitionsProvider { + private String definitionsFile = "org/apache/tuscany/sca/binding/sca/definitions.xml"; + URLArtifactProcessor urlArtifactProcessor = null; + + public SCABindingDefinitionsProvider(ExtensionPointRegistry registry) { + URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + urlArtifactProcessor = (URLArtifactProcessor)documentProcessors.getProcessor(SCADefinitions.class); + } + + public SCADefinitions getSCADefinition() throws SCADefinitionsProviderException { + // Allow privileged access to load resource. Requires RuntimePermssion in security policy. + final URL definitionsFileUrl = AccessController.doPrivileged(new PrivilegedAction() { + public URL run() { + return getClass().getClassLoader().getResource(definitionsFile); + } + }); + + SCADefinitions scaDefn = null; + try { + final URI uri = new URI(definitionsFile); + // Allow bindings to read properties. Requires PropertyPermission read in security policy. + scaDefn = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public SCADefinitions run() throws ContributionReadException { + return (SCADefinitions)urlArtifactProcessor.read(null, uri, definitionsFileUrl); + } + }); + } catch (Exception e) { + throw new SCADefinitionsProviderException(e); + } + return scaDefn; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java new file mode 100644 index 0000000000..43b0cd8f4e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.sca.impl; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; + +/** + * The Distributed SCA binding wrapper for the SCA binding model object. This is currently + * just used to locate the remote binding extension and pass the SCA binding to the remote + * extension. It isn't used in the model itself + * + * @version $Rev: 564307 $ $Date: 2007-08-09 18:48:29 +0100 (Thu, 09 Aug 2007) $ + */ +public class DistributedSCABindingImpl implements DistributedSCABinding { + + private SCABinding scaBinding; + + /** + * Getter for the wrapped sca binding model object + * + * @return the sca binding model element + */ + public SCABinding getSCABinding(){ + return scaBinding; + } + + /** + * Setter for the wrapped sca binding model element + * + * @param scaBinding the sca binding model element + */ + public void setSCABinding(SCABinding scaBinding){ + this.scaBinding = scaBinding; + } + + + // Operation implementations provided to make this class a + // valid Binding + + /** + * Returns the binding URI. + * + * @return the binding URI + */ + public String getURI(){ + return null; + } + + /** + * Sets the binding URI. + * + * @param uri the binding URI + */ + public void setURI(String uri){ + } + + /** + * Returns the binding name. + * + * @return the binding name + */ + public String getName(){ + return null; + } + + /** + * Sets the binding name. + * + * @param name the binding name + */ + public void setName(String name){ + } + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + public boolean isUnresolved(){ + return false; + } + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + public void setUnresolved(boolean unresolved){ + } + + /** + * Clone the binding + */ + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RemoteBindingHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RemoteBindingHelper.java new file mode 100644 index 0000000000..5ebbea62eb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RemoteBindingHelper.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.sca.binding.sca.impl; + +/** + * TODO: TUSCANY-2578, implement a pluggable mechanism so sca binding impls can + * add their own code to the decision on whether or not to use + * the remote binding provider. + */ +public class RemoteBindingHelper { + + private static boolean alwaysRemote; + static { + try { + Class.forName("org.apache.tuscany.sca.binding.sca.jms.JMSSCABindingProviderFactory"); + Class.forName("javax.jms.IllegalStateException"); + alwaysRemote = true; + } catch (ClassNotFoundException e) { + alwaysRemote = false; + } + } + + public static boolean isTargetRemote() { + return alwaysRemote; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java new file mode 100644 index 0000000000..5c1cefb808 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.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.sca.binding.sca.impl; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * The local SCA Binding provider implementation. It is not currently used. + * + * @version $Rev$ $Date$ + */ +public class RuntimeSCABindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + + public RuntimeSCABindingProvider(RuntimeComponent component, RuntimeComponentReference reference, SCABinding binding) { + this.reference = reference; + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public Invoker createInvoker(Operation operation) { + return null; + } + + public void start() { + } + + public void stop() { + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java new file mode 100644 index 0000000000..5dda74f72e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.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.sca.binding.sca.impl; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * The factory for creating SCA Binding providers + * + * @version $Rev$ $Date$ + */ +public class RuntimeSCABindingProviderFactory implements BindingProviderFactory { + + private ExtensionPointRegistry extensionPoints; + + public RuntimeSCABindingProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + SCABinding binding) { + + return new RuntimeSCAReferenceBindingProvider(extensionPoints, component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + SCABinding binding) { + return new RuntimeSCAServiceBindingProvider(extensionPoints, component, service, binding); + } + + public Class getModelType() { + return SCABinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java new file mode 100644 index 0000000000..fa5a9b062b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java @@ -0,0 +1,252 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.impl; + +import java.net.URI; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.ServiceUnavailableException; + +/** + * The sca reference binding provider mediates between the twin requirements of + * local sca bindings and remote sca bindings. In the local case is does + * very little. When the sca binding model is set as being remote (because a + * reference target can't be resolved in the current model) this binding will + * try and create a remote connection to it + * + * @version $Rev$ $Date$ + */ +public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvider { + + private static final Logger logger = Logger.getLogger(RuntimeSCAReferenceBindingProvider.class.getName()); + + private RuntimeComponent component; + private RuntimeComponentReference reference; + private SCABinding binding; + private boolean started = false; + + private BindingProviderFactory distributedProviderFactory = null; + private ReferenceBindingProvider distributedProvider = null; + + public RuntimeSCAReferenceBindingProvider(ExtensionPointRegistry extensionPoints, + RuntimeComponent component, + RuntimeComponentReference reference, + SCABinding binding) { + this.component = component; + this.reference = reference; + this.binding = binding; + + // look to see if a distributed SCA binding implementation has + // been included on the classpath. This will be needed by the + // provider itself to do it's thing + ProviderFactoryExtensionPoint factoryExtensionPoint = + extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); + distributedProviderFactory = + (BindingProviderFactory)factoryExtensionPoint + .getProviderFactory(DistributedSCABinding.class); + + } + + public boolean isTargetRemote() { + boolean targetIsRemote = false; + + // first look at the target service and see if this has been resolved + OptimizableBinding optimizableBinding = (OptimizableBinding)binding; + + // The decision is based on the results of the wiring process in the assembly model + // The SCA binding is used to represent unresolved reference targets, i.e. those + // reference targets that need resolving at run time. We can tell by lookin if the + // service to which this binding refers is resolved or not. + // + // TODO - When a callback is in operation. A callback reference bindings sometimes has to + // act as though there is a local wire and sometimes as if there is a remote wire + // what are the implications of this here? + + if (RemoteBindingHelper.isTargetRemote()) { + if (reference.getInterfaceContract() != null) { + targetIsRemote = reference.getInterfaceContract().getInterface().isRemotable(); + } else { + targetIsRemote = true; + } + } else if (optimizableBinding.getTargetComponentService() != null) { + if (optimizableBinding.getTargetComponentService().isUnresolved() == true) { + targetIsRemote = true; + } else { + targetIsRemote = false; + } + } else { + // the case where the wire is specified by URI, e.g. callbacks or user specified bindings, and + // look at the provided URI to decide whether it is a local or remote case + try { + URI uri = new URI(binding.getURI()); + if (uri.isAbsolute()) { + targetIsRemote = true; + } else { + targetIsRemote = false; + } + } catch (Exception ex) { + targetIsRemote = false; + } + } + return targetIsRemote; + } + + private ReferenceBindingProvider getDistributedProvider() { + + if (isTargetRemote() || isRemotableCallback()) { + // initialize the remote provider if it hasn't been done already + if (distributedProvider == null) { + if (reference.getInterfaceContract() != null && !reference.getInterfaceContract().getInterface().isRemotable()) { + throw new IllegalStateException("Reference interface not remotable for component: " + component + .getName() + + " and reference: " + + reference.getName()); + } + + if (distributedProviderFactory == null) { + throw new IllegalStateException("No distributed SCA binding available for component: " + component + .getName() + + " and reference: " + + reference.getName()); + } + + // create the remote provider + DistributedSCABinding distributedBinding = new DistributedSCABindingImpl(); + distributedBinding.setSCABinding(binding); + + distributedProvider = + distributedProviderFactory.createReferenceBindingProvider(component, reference, distributedBinding); + } + } + + return distributedProvider; + } + + /* + * This test is needed to make sure the distributed binding provider + * is started and stopped if this is a callback binding that might + * need to make a remote invocation. + */ + private boolean isRemotableCallback() { + if (reference.isCallback() && + reference.getInterfaceContract() != null && + reference.getInterfaceContract().getInterface().isRemotable() && + distributedProviderFactory != null) { + return true; + } else { + return false; + } + } + + public InterfaceContract getBindingInterfaceContract() { + if (isTargetRemote()) { + return getDistributedProvider().getBindingInterfaceContract(); + } else { + if (reference.getReference() != null) { + return reference.getReference().getInterfaceContract(); + } else { + return reference.getInterfaceContract(); + } + } + } + + public boolean supportsOneWayInvocation() { + if (isTargetRemote()) { + return getDistributedProvider().supportsOneWayInvocation(); + } else { + return false; + } + } + + private Invoker getInvoker(RuntimeWire wire, Operation operation) { + EndpointReference target = wire.getTarget(); + if (target != null) { + RuntimeComponentService service = (RuntimeComponentService)target.getContract(); + if (service != null) { // not a callback wire + SCABinding scaBinding = service.getBinding(SCABinding.class); + InvocationChain chain = + service.getInvocationChain(scaBinding, wire.getSource().getInterfaceContract(), operation); + return chain == null ? null : new SCABindingInvoker(chain); + } + } + return null; + } + + public Invoker createInvoker(Operation operation) { + if (isTargetRemote()) { + return getDistributedProvider().createInvoker(operation); + } else { + RuntimeWire wire = reference.getRuntimeWire(binding); + Invoker invoker = getInvoker(wire, operation); + if (invoker == null) { + throw new ServiceUnavailableException("Unable to create SCA binding invoker for local target " + component.getName() + + " reference " + + reference.getName() + + " (bindingURI=" + + binding.getURI() + + " operation=" + + operation.getName() + + ")" ); + } + return invoker; + } + } + + public void start() { + if (started) { + return; + } else { + started = true; + } + + if (getDistributedProvider() != null) { + distributedProvider.start(); + } + } + + public void stop() { + if (!started) { + return; + } else { + started = false; + } + + if (getDistributedProvider() != null) { + distributedProvider.stop(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java new file mode 100644 index 0000000000..8994ba5381 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.impl; + +import java.net.URI; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * The sca service binding provider mediates between the twin requirements of + * local sca bindings and remote sca bindings. In the local case is does + * very little. When the sca binding model is set as being remote this binding will + * try and create a remote service endpoint for remote references to connect to + * + * @version $Rev$ $Date$ + */ +public class RuntimeSCAServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private BindingProviderFactory distributedProviderFactory; + private ServiceBindingProvider distributedProvider; + private DistributedSCABinding distributedBinding; + + public RuntimeSCAServiceBindingProvider(ExtensionPointRegistry extensionPoints, + RuntimeComponent component, + RuntimeComponentService service, + SCABinding binding) { + this.service = service; + // if there is potentially a wire to this service that crosses the node boundary + if (service.getInterfaceContract().getInterface().isRemotable()) { + + // look to see if a distributed SCA binding implementation has + // been included on the classpath. This will be needed by the + // provider itself to do it's thing + ProviderFactoryExtensionPoint factoryExtensionPoint = + extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); + distributedProviderFactory = + (BindingProviderFactory)factoryExtensionPoint + .getProviderFactory(DistributedSCABinding.class); + + // Check the things that will generally be required to set up a + // distributed sca domain reference provider. I.e. make sure that we have a + // - distributed implementation of the sca binding available + // - remotable interface on the service + if (distributedProviderFactory != null) { + + URI serviceURI = null; + try { + serviceURI = new URI(binding.getURI()); + } catch(Exception ex) { + + } + + if (RemoteBindingHelper.isTargetRemote() || ((serviceURI != null) && (serviceURI.isAbsolute()))) { + + // create a nested provider to handle the remote case + distributedBinding = new DistributedSCABindingImpl(); + distributedBinding.setSCABinding(binding); + + distributedProvider = + distributedProviderFactory.createServiceBindingProvider(component, service, distributedBinding); + + + } else { + /* do nothing at the moment as only apps using the node implementation + * will currently have the distributed domain set. + * + throw new IllegalStateException("No distributed domain available for component: "+ + component.getName() + + " and service: " + + service.getName()); + */ + } + } else { + /* do nothing at the moment as all services with remotable interfaces + * are marked as remote + throw new IllegalStateException("No distributed SCA binding available for component: "+ + component.getName() + + " and service: " + + service.getName()); + */ + } + } + } + + public InterfaceContract getBindingInterfaceContract() { + if (distributedProvider != null) { + return distributedProvider.getBindingInterfaceContract(); + } else { + if (service.getService() != null) { + return service.getService().getInterfaceContract(); + } else { + return service.getInterfaceContract(); + } + } + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + if (distributedProvider != null) { + distributedProvider.start(); + } + } + + public void stop() { + if (distributedProvider != null) { + distributedProvider.stop(); + } + + if (distributedBinding != null) { + // reset the binding URI to null so that if the composite containing the component + // with the service/binding is restarted the binding will have the correct URI set + SCABinding scaBinding = distributedBinding.getSCABinding(); + try { + URI tempURI = new URI(scaBinding.getURI()); + if (!tempURI.isAbsolute()){ + scaBinding.setURI(null); + } + } catch (Exception ex){ + scaBinding.setURI(null); + } + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java new file mode 100644 index 0000000000..ea758823a9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.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.sca.binding.sca.impl; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; + +/** + * A factory for the SCA binding model. + * + * @version $Rev$ $Date$ + */ +public class SCABindingFactoryImpl implements SCABindingFactory { + + public SCABindingFactoryImpl (){ + + } + + public SCABinding createSCABinding() { + return new SCABindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java new file mode 100644 index 0000000000..638a263a61 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.sca.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.builder.AutomaticBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * The assembly mode object for an SCA binding. + * + * @version $Rev$ $Date$ + */ +public class SCABindingImpl implements SCABinding, Extensible, PolicySetAttachPoint, OptimizableBinding, AutomaticBinding { + private String name; + private String uri; + private List extensions = new ArrayList(); + private List attributeExtensions = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + + private Component targetComponent; + private ComponentService targetComponentService; + private Binding targetBinding; + private List applicablePolicySets = new ArrayList(); + + private boolean isAutomatic = false; + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + /** + * Constructs a new SCA binding. + */ + protected SCABindingImpl() { + } + + // SCA Binding operations + + /** + * Setters for the binding name. Defaults to the + * name of the service or reference with which the binding is + * associated + * + * @return the binding name + */ + public String getName() { + return name; + } + + /** + * Setter for the binding name + * + * @param name the binding name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Getters for the binding URI. The computed URI for the + * service that the reference is targeting or which the service represents + * depending on whether the biding is associated with a reference or + * service + * + * @return the binding URI + */ + public String getURI() { + return uri; + } + + /** + * Setter for the binding URI + * + * @param uri the binding URI + */ + public void setURI(String uri) { + this.uri = uri; + } + + public List getExtensions() { + return extensions; + } + + public List getAttributeExtensions() { + return attributeExtensions; + } + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + public boolean isUnresolved() { + if (targetComponentService == null){ + return true; + } else { + return targetComponentService.isUnresolved(); + } + } + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + public void setUnresolved(boolean unresolved) { + } + + /** + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + // Wireable binding operations + + /** + * @return the targetComponent + */ + public Component getTargetComponent() { + return targetComponent; + } + + /** + * @param targetComponent the targetComponent to set + */ + public void setTargetComponent(Component targetComponent) { + this.targetComponent = targetComponent; + } + + /** + * @return the targetComponentService + */ + public ComponentService getTargetComponentService() { + return targetComponentService; + } + + /** + * @param targetComponentService the targetComponentService to set + */ + public void setTargetComponentService(ComponentService targetComponentService) { + this.targetComponentService = targetComponentService; + } + + /** + * @return the targetBinding + */ + public Binding getTargetBinding() { + return targetBinding; + } + + /** + * @param targetBinding the targetBinding to set + */ + public void setTargetBinding(Binding targetBinding) { + this.targetBinding = targetBinding; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + + public void setIsAutomatic(boolean isAutomatic){ + this.isAutomatic = isAutomatic; + } + + public boolean getIsAutomatic(){ + return this.isAutomatic; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingInvoker.java new file mode 100644 index 0000000000..52c0f64fe5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingInvoker.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.sca.binding.sca.impl; + +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; + +/** + * @version $Rev$ $Date$ + */ +public class SCABindingInvoker implements Interceptor, DataExchangeSemantics { + private InvocationChain chain; + + /** + * Construct a SCABindingInvoker that delegates to the service invocaiton chain + * @param chain + */ + public SCABindingInvoker(InvocationChain chain) { + super(); + this.chain = chain; + } + + /** + * @see org.apache.tuscany.sca.invocation.Interceptor#getNext() + */ + public Invoker getNext() { + return chain.getHeadInvoker(); + } + + /** + * @see org.apache.tuscany.sca.invocation.Interceptor#setNext(org.apache.tuscany.sca.invocation.Invoker) + */ + public void setNext(Invoker next) { + // NOOP + } + + /** + * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message) + */ + public Message invoke(Message msg) { + return getNext().invoke(msg); + } + + /** + * @see org.apache.tuscany.sca.invocation.DataExchangeSemantics#allowsPassByReference() + */ + public boolean allowsPassByReference() { + return chain.allowsPassByReference(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory new file mode 100644 index 0000000000..4efa03a933 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.binding.sca.impl.SCABindingFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..5c6b8e21fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.sca.impl.RuntimeSCABindingProviderFactory;model=org.apache.tuscany.sca.assembly.SCABinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider new file mode 100644 index 0000000000..22c9a64b05 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for SCA Definitions Providers +org.apache.tuscany.sca.binding.sca.SCABindingDefinitionsProvider \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml new file mode 100644 index 0000000000..8bac9e01c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml @@ -0,0 +1,26 @@ + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java new file mode 100644 index 0000000000..ff396566d6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.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.apace.tuscany.sca.binding.sca; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.assembly.xml.CompositeModelResolver; +import org.apache.tuscany.sca.binding.sca.impl.SCABindingFactoryImpl; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.junit.Before; +import org.junit.Test; + +/** + * SCABindingTestCase + * + * @version $Rev$ $Date$ + */ +public class SCABindingTestCase { + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private CompositeModelResolver resolver; + private CompositeBuilder compositeBuilder; + + @Before + public void init() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + + resolver = new CompositeModelResolver(null, null); + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null); + + } + + @Test + public void testSCABindingFactory() { + SCABindingFactory factory = new SCABindingFactoryImpl(); + Assert.assertNotNull(factory.createSCABinding()); + } + + @Test + public void testBuildModel() { + try{ + InputStream is = getClass().getResourceAsStream("/Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader); + + is.close(); + Assert.assertNotNull(composite); + + resolver.addModel(composite); + + staxProcessor.resolve(composite, resolver); + + compositeBuilder.build(composite); + + SCABinding referenceSCABinding = (SCABinding) composite.getComponents().get(0).getReferences().get(0).getBindings().get(0); + SCABinding serviceSCABinding = (SCABinding) composite.getComponents().get(1).getServices().get(0).getBindings().get(0); + + Assert.assertNotNull(referenceSCABinding); + Assert.assertNotNull(serviceSCABinding); + } catch (Exception ex) { + Assert.fail(ex.getMessage()); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/test/resources/Calculator.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/test/resources/Calculator.composite new file mode 100644 index 0000000000..37b26f3d68 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-sca/src/test/resources/Calculator.composite @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/pom.xml new file mode 100644 index 0000000000..f4fc8033a0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/pom.xml @@ -0,0 +1,149 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-ws-axis2-policy + Apache Tuscany SCA Policy Model for Axis2 Web Service Binding + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy-security + 1.6-SNAPSHOT + + + + org.apache.ws.commons.axiom + axiom-api + + + xerces + xercesImpl + + + javax.mail + mail + + + commons-logging + commons-logging + + + xml-apis + xml-apis + + + 1.2.7 + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.7 + + + + org.apache.axis2 + axis2-kernel + 1.4.1 + + + backport-util-concurrent + backport-util-concurrent + + + xalan + xalan + + + xerces + xercesImpl + + + + + + backport-util-concurrent + backport-util-concurrent + 3.1 + test + + + + org.apache.neethi + neethi + 2.0.4 + + + wsdl4j + wsdl4j + + + org.codehaus.woodstox + wstx-asl + + + + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.6-SNAPSHOT + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.ws.axis2.policy + ${pom.name} + org.apache.tuscany.sca.binding.ws.axis2.policy* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicy.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicy.java new file mode 100644 index 0000000000..8fecb84bb4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicy.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.sca.binding.ws.axis2.policy.authentication.token; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.policy.Policy; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class Axis2TokenAuthenticationPolicy implements Policy { + public static final QName AXIS2_TOKEN_AUTHENTICATION_POLICY_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "axis2TokenAuthentication"); + public static final String AXIS2_TOKEN_AUTHENTICATION_TOKEN_NAME = "tokenName"; + + private QName tokenName; + + public QName getTokenName() { + return tokenName; + } + + public void setTokenName(QName tokenName) { + this.tokenName = tokenName; + } + + public QName getSchemaName() { + return AXIS2_TOKEN_AUTHENTICATION_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.java new file mode 100644 index 0000000000..e8a7872858 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.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.sca.binding.ws.axis2.policy.authentication.token; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class Axis2TokenAuthenticationPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return Axis2TokenAuthenticationPolicy.AXIS2_TOKEN_AUTHENTICATION_POLICY_QNAME; + } + + public Axis2TokenAuthenticationPolicyProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public Axis2TokenAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + Axis2TokenAuthenticationPolicy policy = new Axis2TokenAuthenticationPolicy(); + int event = reader.getEventType(); + QName name = null; + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(getArtifactType()) ) { + policy.setTokenName(getQName(reader, Axis2TokenAuthenticationPolicy.AXIS2_TOKEN_AUTHENTICATION_TOKEN_NAME)); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( getArtifactType().equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(Axis2TokenAuthenticationPolicy policy, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + if ( policy.getTokenName() != null ) { + writer.writeStartElement(prefix, + Axis2TokenAuthenticationPolicy.AXIS2_TOKEN_AUTHENTICATION_TOKEN_NAME, + getArtifactType().getNamespaceURI()); + writer.writeCharacters(policy.getTokenName().toString()); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return Axis2TokenAuthenticationPolicy.class; + } + + public void resolve(Axis2TokenAuthenticationPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProviderFactory.java new file mode 100644 index 0000000000..cef881af30 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProviderFactory.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.sca.binding.ws.axis2.policy.authentication.token; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class Axis2TokenAuthenticationPolicyProviderFactory implements PolicyProviderFactory { + private ExtensionPointRegistry registry; + + public Axis2TokenAuthenticationPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) { + return null;//new TokenAuthenticationImplementationPolicyProvider(component, implementation); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new Axis2TokenAuthenticationReferencePolicyProvider(component, reference, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new Axis2TokenAuthenticationServicePolicyProvider(component, service, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyInterceptor.java new file mode 100644 index 0000000000..c6cd96e647 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyInterceptor.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token; + +import java.util.logging.ConsoleHandler; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.OMText; +import org.apache.axiom.om.impl.llom.util.AXIOMUtil; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeaderString; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.Policy; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class Axis2TokenAuthenticationReferencePolicyInterceptor implements Interceptor { + + private Invoker next; + private Operation operation; + private PolicySet policySet = null; + private String context; + private Axis2TokenAuthenticationPolicy policy; + + public Axis2TokenAuthenticationReferencePolicyInterceptor(String context, Operation operation, PolicySet policySet) { + super(); + this.operation = operation; + this.policySet = policySet; + this.context = context; + init(); + } + + private void init() { + if (policySet != null) { + for (Object policyObject : policySet.getPolicies()){ + if (policyObject instanceof Axis2TokenAuthenticationPolicy){ + policy = (Axis2TokenAuthenticationPolicy)policyObject; + break; + } + } + } + } + + public Message invoke(Message msg) { + // could call out here to some 3rd party system to get credentials + + if ( policy.getTokenName() != null){ + // create Axis representation of header + Axis2SOAPHeaderString header = new Axis2SOAPHeaderString(); + header.setHeaderName(policy.getTokenName()); + header.setHeaderString("SomeWSAuthorizationToken"); + + // add header to Tuscany message + msg.getHeaders().add(header); + } + + return getNext().invoke(msg); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyProvider.java new file mode 100644 index 0000000000..147fd1f42a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyProvider.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class Axis2TokenAuthenticationReferencePolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private RuntimeComponentReference reference; + private Binding binding; + + public Axis2TokenAuthenticationReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.component = component; + this.reference = reference; + this.binding = binding; + } + + private PolicySet findPolicySet() { + if (binding instanceof PolicySetAttachPoint) { + List policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (Axis2TokenAuthenticationPolicy.class.isInstance(p)) { + return ps; + } + } + } + } + return null; + } + + private String getContext() { + return "component.reference: " + component.getURI() + + "#" + + reference.getName() + + "(" + + binding.getClass().getName() + + ")"; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor(Operation operation) { + PolicySet ps = findPolicySet(); + return ps == null ? null : new Axis2TokenAuthenticationReferencePolicyInterceptor(getContext(), operation, ps); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.REFERENCE_POLICY; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyInterceptor.java new file mode 100644 index 0000000000..2928647445 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyInterceptor.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token; + + +import java.security.Principal; + +import javax.security.auth.Subject; + +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicyUtil; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeader; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeaderString; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.SecurityUtil; +import org.apache.tuscany.sca.policy.authentication.token.TokenPrincipal; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class Axis2TokenAuthenticationServicePolicyInterceptor implements Interceptor { + private Invoker next; + private Operation operation; + private PolicySet policySet = null; + private String context; + private Axis2TokenAuthenticationPolicy policy; + + public Axis2TokenAuthenticationServicePolicyInterceptor(String context, Operation operation, PolicySet policySet) { + super(); + this.operation = operation; + this.policySet = policySet; + this.context = context; + init(); + } + + private void init() { + if (policySet != null) { + for (Object policyObject : policySet.getPolicies()){ + if (policyObject instanceof Axis2TokenAuthenticationPolicy){ + policy = (Axis2TokenAuthenticationPolicy)policyObject; + break; + } + } + } + } + + public Message invoke(Message msg) { + + Axis2SOAPHeaderString header = (Axis2SOAPHeaderString)Axis2HeaderPolicyUtil.getHeader(msg, policy.getTokenName()); + + if (header != null) { + System.out.println("Web service received token: " + header.getHeaderString()); + + // call out here to some 3rd party system to do whatever you + // need to turn header credentials into an authenticated principal + + Subject subject = SecurityUtil.getSubject(msg); + Principal principal = new TokenPrincipal(header.getHeaderString()); + subject.getPrincipals().add(principal); + } + + return getNext().invoke(msg); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyProvider.java new file mode 100644 index 0000000000..e3e2a4b9a0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyProvider.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class Axis2TokenAuthenticationServicePolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private RuntimeComponentService service; + private Binding binding; + + public Axis2TokenAuthenticationServicePolicyProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) { + super(); + this.component = component; + this.service = service; + this.binding = binding; + } + + private PolicySet findPolicySet() { + if (binding instanceof PolicySetAttachPoint) { + List policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (Axis2TokenAuthenticationPolicy.class.isInstance(p)) { + return ps; + } + } + } + } + return null; + } + + private String getContext() { + return "component.service: " + component.getURI() + + "#" + + service.getName() + + "(" + + binding.getClass().getName() + + ")"; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor(Operation operation) { + PolicySet ps = findPolicySet(); + return ps == null ? null : new Axis2TokenAuthenticationServicePolicyInterceptor(getContext(), operation, ps); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.SERVICE_POLICY; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicy.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicy.java new file mode 100644 index 0000000000..8d08a3f78e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicy.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.sca.binding.ws.axis2.policy.configuration; + +import java.util.Hashtable; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.policy.Policy; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class Axis2ConfigParamPolicy implements Policy { + public static final QName NAME = new QName(Constants.SCA10_TUSCANY_NS, "wsConfigParam"); + private Map paramElements = new Hashtable(); + + public Map getParamElements() { + return paramElements; + } + + public QName getSchemaName() { + return NAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyHandler.java new file mode 100644 index 0000000000..5ac4e3f5fd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyHandler.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.sca.binding.ws.axis2.policy.configuration; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.Parameter; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.util.PolicyHandler; + + +/** + * Policy handler to handle PolicySet that contain Axis2ConfigParamPolicy instances + * + * @version $Rev$ $Date$ + */ +public class Axis2ConfigParamPolicyHandler implements PolicyHandler { + private PolicySet applicablePolicySet = null; + + public void setUp(Object... context) { + Axis2ConfigParamPolicy axis2ConfigParamPolicy = null; + Parameter configParam = null; + for ( Object contextObject : context ) { + if ( contextObject instanceof ConfigurationContext ) { + ConfigurationContext configContext = (ConfigurationContext)contextObject; + for ( Object policy : applicablePolicySet.getPolicies() ) { + if ( policy instanceof Axis2ConfigParamPolicy ) { + axis2ConfigParamPolicy = (Axis2ConfigParamPolicy)policy; + for ( String paramName : axis2ConfigParamPolicy.getParamElements().keySet() ) { + configParam = new Parameter(paramName, + axis2ConfigParamPolicy.getParamElements().get(paramName).getFirstElement()); + configParam.setParameterElement(axis2ConfigParamPolicy.getParamElements().get(paramName)); + try { + configContext.getAxisConfiguration().addParameter(configParam); + } catch ( AxisFault e ) { + throw new RuntimeException(e); + } + } + } + } + } + } + } + + public void cleanUp(Object... context) { + } + + public void beforeInvoke(Object... context) { + } + + public void afterInvoke(Object... context) { + + } + + public PolicySet getApplicablePolicySet() { + return applicablePolicySet; + } + + public void setApplicablePolicySet(PolicySet applicablePolicySet) { + this.applicablePolicySet = applicablePolicySet; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java new file mode 100644 index 0000000000..6478fbedad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2.policy.configuration; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class Axis2ConfigParamPolicyProcessor implements StAXArtifactProcessor { + public static final QName AXIS2_CONFIG_PARAM_POLICY_QNAME = Axis2ConfigParamPolicy.NAME; + public static final String PARAMETER = "parameter"; + public QName getArtifactType() { + return AXIS2_CONFIG_PARAM_POLICY_QNAME; + } + + public Axis2ConfigParamPolicyProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + public Axis2ConfigParamPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + Axis2ConfigParamPolicy policy = new Axis2ConfigParamPolicy(); + int event = reader.getEventType(); + QName name = null; + OMElement parameterElement = null; + String paramName = null; + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( PARAMETER.equals(name.getLocalPart()) ) { + paramName = reader.getAttributeValue(null, Constants.NAME); + parameterElement = loadElement(reader); + policy.getParamElements().put(paramName, parameterElement); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( AXIS2_CONFIG_PARAM_POLICY_QNAME.equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(Axis2ConfigParamPolicy arg0, XMLStreamWriter arg1) throws ContributionWriteException, + XMLStreamException { + } + + public Class getModelType() { + return Axis2ConfigParamPolicy.class; + } + + public void resolve(Axis2ConfigParamPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + + } + + private OMElement loadElement(XMLStreamReader reader) throws XMLStreamException { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement head = fac.createOMElement(reader.getName()); + OMElement current = head; + while (true) { + switch (reader.next()) { + case XMLStreamConstants.START_ELEMENT: + //since the axis2 code checks against a no namespace we need to generate accordingly + QName name = new QName(reader.getName().getLocalPart()); + OMElement child = fac.createOMElement(name, current); + + int count = reader.getNamespaceCount(); + for (int i = 0; i < count; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + child.declareNamespace(ns, prefix); + } + + if(!"".equals(name.getNamespaceURI())) { + child.declareNamespace(name.getNamespaceURI(), name.getPrefix()); + } + + // add the attributes for this element + count = reader.getAttributeCount(); + for (int i = 0; i < count; i++) { + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String qname = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + + if (ns != null) { + child.addAttribute(qname, value, fac.createOMNamespace(ns, prefix)); + child.declareNamespace(ns, prefix); + } else { + child.addAttribute(qname, value, null); + } + } + current = child; + break; + case XMLStreamConstants.CDATA: + fac.createOMText(current, reader.getText()); + break; + case XMLStreamConstants.CHARACTERS: + fac.createOMText(current, reader.getText()); + break; + case XMLStreamConstants.END_ELEMENT: + if ( current == head ) { + return head; + } else { + current = (OMElement)current.getParent(); + } + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProviderFactory.java new file mode 100644 index 0000000000..21261359cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProviderFactory.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.sca.binding.ws.axis2.policy.configuration; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.Parameter; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.osoa.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class Axis2ConfigParamPolicyProviderFactory implements PolicyProviderFactory { + + public Axis2ConfigParamPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) { + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + return Axis2ConfigParamPolicy.class; + } + + // FIXME: [rfeng] I think this should be refactored into the binding.ws axis2 code + public void setUp(ConfigurationContext configContext, PolicySet ps) { + Axis2ConfigParamPolicy axis2ConfigParamPolicy = null; + Parameter configParam = null; + for (Object policy : ps.getPolicies()) { + if (policy instanceof Axis2ConfigParamPolicy) { + axis2ConfigParamPolicy = (Axis2ConfigParamPolicy)policy; + for (String paramName : axis2ConfigParamPolicy.getParamElements().keySet()) { + configParam = + new Parameter(paramName, axis2ConfigParamPolicy.getParamElements().get(paramName) + .getFirstElement()); + configParam.setParameterElement(axis2ConfigParamPolicy.getParamElements().get(paramName)); + try { + configContext.getAxisConfiguration().addParameter(configParam); + } catch (AxisFault e) { + throw new ServiceRuntimeException(e); + } + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicy.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicy.java new file mode 100644 index 0000000000..244e501901 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicy.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.sca.binding.ws.axis2.policy.header; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.policy.Policy; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class Axis2HeaderPolicy implements Policy { + public static final QName AXIS2_HEADER_POLICY_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "axis2Header"); + public static final String AXIS2_HEADER_NAME = "headerName"; + + private QName headerName; + + public QName getHeaderName() { + return headerName; + } + + public void setHeaderName(QName headerName) { + this.headerName = headerName; + } + + public QName getSchemaName() { + return AXIS2_HEADER_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProcessor.java new file mode 100644 index 0000000000..3466b9def7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProcessor.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2.policy.header; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.logging.Level; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class Axis2HeaderPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return Axis2HeaderPolicy.AXIS2_HEADER_POLICY_QNAME; + } + + public Axis2HeaderPolicyProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public Axis2HeaderPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + Axis2HeaderPolicy policy = new Axis2HeaderPolicy(); + int event = reader.getEventType(); + QName name = null; + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(getArtifactType()) ) { + policy.setHeaderName(getQName(reader, Axis2HeaderPolicy.AXIS2_HEADER_NAME)); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( getArtifactType().equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(Axis2HeaderPolicy policy, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + if ( policy.getHeaderName() != null ) { + writer.writeStartElement(prefix, + Axis2HeaderPolicy.AXIS2_HEADER_NAME, + getArtifactType().getNamespaceURI()); + writer.writeCharacters(policy.getHeaderName().toString()); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return Axis2HeaderPolicy.class; + } + + public void resolve(Axis2HeaderPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProviderFactory.java new file mode 100644 index 0000000000..71833df382 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProviderFactory.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.sca.binding.ws.axis2.policy.header; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class Axis2HeaderPolicyProviderFactory implements PolicyProviderFactory { + private ExtensionPointRegistry registry; + + public Axis2HeaderPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) { + return null;//new TokenAuthenticationImplementationPolicyProvider(component, implementation); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new Axis2HeaderReferencePolicyProvider(component, reference, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new Axis2HeaderServicePolicyProvider(component, service, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyUtil.java new file mode 100644 index 0000000000..98d011a8fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyUtil.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.sca.binding.ws.axis2.policy.header; + + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.invocation.Message; + + +/** + * + * @version $Rev$ $Date$ + */ +public class Axis2HeaderPolicyUtil { + + public static Axis2SOAPHeader getHeader(Message msg, QName headerName){ + + Axis2SOAPHeader axis2Header = null; + + for (Object header : msg.getHeaders()){ + if (header instanceof Axis2SOAPHeader){ + Axis2SOAPHeader tmpHeader = (Axis2SOAPHeader)header; + + if (tmpHeader.getHeaderName().equals(headerName)){ + axis2Header = tmpHeader; + break; + } + } + } + + return axis2Header; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderReferencePolicyInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderReferencePolicyInterceptor.java new file mode 100644 index 0000000000..1b3315bb76 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderReferencePolicyInterceptor.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2.policy.header; + +import java.util.logging.ConsoleHandler; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.OMText; +import org.apache.axiom.om.impl.llom.util.AXIOMUtil; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.Policy; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class Axis2HeaderReferencePolicyInterceptor implements Interceptor { + private Invoker next; + private Operation operation; + private PolicySet policySet = null; + private String context; + private Axis2HeaderPolicy policy; + + public Axis2HeaderReferencePolicyInterceptor(String context, Operation operation, PolicySet policySet) { + super(); + this.operation = operation; + this.policySet = policySet; + this.context = context; + init(); + } + + private void init() { + if (policySet != null) { + for (Object policyObject : policySet.getPolicies()){ + if (policyObject instanceof Axis2HeaderPolicy){ + policy = (Axis2HeaderPolicy)policyObject; + break; + } + } + } + } + + public Message invoke(Message msg) { + // TODO - not yet implemented + + return getNext().invoke(msg); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderReferencePolicyProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderReferencePolicyProvider.java new file mode 100644 index 0000000000..0af5a09d8d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderReferencePolicyProvider.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.policy.header; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class Axis2HeaderReferencePolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private RuntimeComponentReference reference; + private Binding binding; + + public Axis2HeaderReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.component = component; + this.reference = reference; + this.binding = binding; + } + + private PolicySet findPolicySet() { + if (binding instanceof PolicySetAttachPoint) { + List policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (Axis2HeaderPolicy.class.isInstance(p)) { + return ps; + } + } + } + } + return null; + } + + private String getContext() { + return "component.reference: " + component.getURI() + + "#" + + reference.getName() + + "(" + + binding.getClass().getName() + + ")"; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor(Operation operation) { + PolicySet ps = findPolicySet(); + return ps == null ? null : new Axis2HeaderReferencePolicyInterceptor(getContext(), operation, ps); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.REFERENCE_POLICY; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderServicePolicyInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderServicePolicyInterceptor.java new file mode 100644 index 0000000000..a758ca5261 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderServicePolicyInterceptor.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.sca.binding.ws.axis2.policy.header; + + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class Axis2HeaderServicePolicyInterceptor implements Interceptor { + private Invoker next; + private Operation operation; + private PolicySet policySet = null; + private String context; + private Axis2HeaderPolicy policy; + + public Axis2HeaderServicePolicyInterceptor(String context, Operation operation, PolicySet policySet) { + super(); + this.operation = operation; + this.policySet = policySet; + this.context = context; + init(); + } + + private void init() { + if (policySet != null) { + for (Object policyObject : policySet.getPolicies()){ + if (policyObject instanceof Axis2HeaderPolicy){ + policy = (Axis2HeaderPolicy)policyObject; + break; + } + } + } + } + + public Message invoke(Message msg) { + // TODO - not yet implemented + + return getNext().invoke(msg); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderServicePolicyProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderServicePolicyProvider.java new file mode 100644 index 0000000000..126073beb7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderServicePolicyProvider.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.policy.header; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class Axis2HeaderServicePolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private RuntimeComponentService service; + private Binding binding; + + public Axis2HeaderServicePolicyProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) { + super(); + this.component = component; + this.service = service; + this.binding = binding; + } + + private PolicySet findPolicySet() { + if (binding instanceof PolicySetAttachPoint) { + List policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (Axis2HeaderPolicy.class.isInstance(p)) { + return ps; + } + } + } + } + return null; + } + + private String getContext() { + return "component.service: " + component.getURI() + + "#" + + service.getName() + + "(" + + binding.getClass().getName() + + ")"; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor(Operation operation) { + PolicySet ps = findPolicySet(); + return ps == null ? null : new Axis2HeaderServicePolicyInterceptor(getContext(), operation, ps); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.SERVICE_POLICY; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2SOAPHeader.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2SOAPHeader.java new file mode 100644 index 0000000000..7a1f26bf04 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2SOAPHeader.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.sca.binding.ws.axis2.policy.header; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.OMText; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.policy.Policy; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class Axis2SOAPHeader { + + private QName headerName; + + public QName getHeaderName() { + return headerName; + } + + public void setHeaderName(QName headerName) { + this.headerName = headerName; + } + + public OMElement getAsSOAPHeaderBlock(OMFactory factory) { + OMNamespace ns1 = factory.createOMNamespace(headerName.getNamespaceURI(), + headerName.getPrefix()); + OMElement header = ((SOAPFactory)factory).createSOAPHeaderBlock(headerName.getLocalPart(),ns1); + return header; + } + + public void setAsSOAPHeaderBlock(OMElement header) { + headerName = header.getQName(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2SOAPHeaderString.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2SOAPHeaderString.java new file mode 100644 index 0000000000..0eefeac87b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2SOAPHeaderString.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.sca.binding.ws.axis2.policy.header; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.policy.Policy; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class Axis2SOAPHeaderString extends Axis2SOAPHeader { + + private String headerString; + + public String getHeaderString() { + return headerString; + } + + public void setHeaderString(String headerString) { + this.headerString = headerString; + } + + public OMElement getAsSOAPHeaderBlock(OMFactory factory) { + OMElement header = super.getAsSOAPHeaderBlock(factory); + OMText headerText = factory.createOMText(header, headerString); + header.addChild(headerText); + return header; + } + + public void setAsSOAPHeaderBlock(OMElement header) { + super.setAsSOAPHeaderBlock(header); + headerString = header.getText(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSSecurityPolicyHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSSecurityPolicyHandler.java new file mode 100644 index 0000000000..fabc07c7cf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSSecurityPolicyHandler.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.sca.binding.ws.axis2.policy.wspolicy; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.neethi.Policy; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.util.PolicyHandler; + +/** + * Policy handler to handle PolicySet containing Policy (WS-Security-Policy) instances + * + * @version $Rev$ $Date$ + */ +public class WSSecurityPolicyHandler implements PolicyHandler { + private PolicySet applicablePolicySet = null; + + public void setUp(Object... context) { + for ( Object contextObject : context ) { + if ( contextObject instanceof ConfigurationContext ) { + ConfigurationContext configContext = (ConfigurationContext)contextObject; + for ( Object policy : applicablePolicySet.getPolicies() ) { + if ( policy instanceof Policy ) { + Policy wsPolicy = (Policy)policy; + try { + configContext.getAxisConfiguration().applyPolicy(wsPolicy); + + // TUSCANY-2824 + // hack to make service side pick up rampart policies + // "rampartPolicy" comes from RampartMessageData.KEY_RAMPART_POLICY + // but I'm avoiding adding an explicit dependency just yet. + // There must be a proper way of getting rampart to recognize + // these policies + configContext.setProperty("rampartPolicy", wsPolicy); + + } catch ( AxisFault e ) { + throw new RuntimeException(e); + } + } + } + } + } + } + + public void cleanUp(Object... context) { + } + + public void beforeInvoke(Object... context) { + + } + + public void afterInvoke(Object... context) { + + } + + public PolicySet getApplicablePolicySet() { + return applicablePolicySet; + } + + public void setApplicablePolicySet(PolicySet applicablePolicySet) { + this.applicablePolicySet = applicablePolicySet; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..96782b74bf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#wsConfigParam,model=org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy +org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#axis2TokenAuthentication,model=org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicy +org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#axis2Header,model=org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicy diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler new file mode 100644 index 0000000000..9f1e9450ba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# PolicyHandlerClasses to interpret specific PolicyModels against specific QoS infrastructures +# handler classname;qname=;model= +org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicyHandler;intent=http://www.osoa.org/xmlns/sca/1.0#authentication,model=org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy +org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicyHandler;intent=http://www.osoa.org/xmlns/sca/1.0#integrity,model=org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy +org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicyHandler;intent=http://www.osoa.org/xmlns/sca/1.0#confidentiality,model=org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy +org.apache.tuscany.sca.binding.ws.axis2.policy.wspolicy.WSSecurityPolicyHandler;intent=http://www.osoa.org/xmlns/sca/1.0#authentication,model=org.apache.neethi.Policy +org.apache.tuscany.sca.binding.ws.axis2.policy.wspolicy.WSSecurityPolicyHandler;intent=http://www.osoa.org/xmlns/sca/1.0#integrity,model=org.apache.neethi.Policy +org.apache.tuscany.sca.binding.ws.axis2.policy.wspolicy.WSSecurityPolicyHandler;intent=http://www.osoa.org/xmlns/sca/1.0#confidentiality,model=org.apache.neethi.Policy \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory new file mode 100644 index 0000000000..ced48cf236 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the policy extension +org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicyProviderFactory;model=org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicy +org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicyProviderFactory;model=org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicy \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/PolicyReadTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/PolicyReadTestCase.java new file mode 100644 index 0000000000..cf14e54b5f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/PolicyReadTestCase.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.sca.binding.ws.axis2.policy.configuration; + + +import java.io.InputStream; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +import junit.framework.TestCase; + +/** + * + * Test the reading of ws config params policy. + * + * @version $Rev$ $Date$ + */ +public class PolicyReadTestCase extends TestCase { + + public void testPolicyReading() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + + URL url = getClass().getResource("mock_policies.xml"); + + InputStream urlStream = url.openStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); + + Axis2ConfigParamPolicy policy = (Axis2ConfigParamPolicy)staxProcessor.read(reader); + assertEquals(policy.getParamElements().size(), 2); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/mock_policies.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/mock_policies.xml new file mode 100644 index 0000000000..77f750cd0d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2-policy/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/mock_policies.xml @@ -0,0 +1,36 @@ + + + + + + Timestamp Signature + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/security.properties + + + + + Timestamp Signature + TuscanyWsUser + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/security.properties + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.IntegrityPWCBHandler" + + DirectReference + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/pom.xml new file mode 100644 index 0000000000..6912857ebc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/pom.xml @@ -0,0 +1,351 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-binding-ws-axis2 + Apache Tuscany SCA Axis2-based WS Binding Extension + + + + apache.ws + Apache WebServices Repository + http://ws.zones.apache.org/repository/ + legacy + + + + + + org.apache.tuscany.sca + tuscany-core + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-wsdl-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-databinding + 1.6-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-databinding-axiom + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-jaxb-axiom + 1.6-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-host-http + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy-xml-ws + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2-policy + 1.6-SNAPSHOT + + + + org.apache.axis2 + axis2-kernel + 1.4.1 + + + backport-util-concurrent + backport-util-concurrent + + + org.apache.ant + ant + + + org.apache.ant + ant-launcher + + + + + + backport-util-concurrent + backport-util-concurrent + 3.1 + + + + org.apache.axis2 + axis2-java2wsdl + 1.4.1 + + + org.apache.ant + ant + + + org.apache.ant + ant-launcher + + + xom + xom + + + + + + org.apache.axis2 + axis2-codegen + 1.4.1 + runtime + + + stax + stax-api + + + + + + org.apache.neethi + neethi + 2.0.4 + + + org.codehaus.woodstox + wstx-asl + + + + + + commons-httpclient + commons-httpclient + 3.1 + + + + commons-codec + commons-codec + 1.3 + + + commons-codec + commons-codec + + + + + + org.apache.axis2 + axis2-mtompolicy + 1.4.1 + + + + org.apache.santuario + xmlsec + 1.4.2 + + + + org.apache.ws.security + wss4j + 1.5.4 + + + bouncycastle + bcprov-jdk13 + + + bouncycastle + bcprov-jdk15 + + + + + + org.apache.axis2 + mex + 1.41 + impl + + + + org.apache.rampart + rampart-core + 1.4 + + + org.apache.ant + ant-nodeps + + + org.apache.axis2 + addressing + + + org.apache.axis2 + axis2-xmlbeans + + + org.apache.axis2 + mex + + + org.apache.axis2 + axis2-adb + + + org.apache.axis2 + axis2-codegen + + + org.apache.axis2 + axis2-adb-codegen + + + xmlbeans + xbean + + + org.apache.ws.commons.schema + XmlSchema + + + stax + stax-api + + + bouncycastle + bcprov-jdk13 + + + bouncycastle + bcprov-jdk15 + + + + + + javax.servlet + servlet-api + 2.5 + provided + + + + + xalan + xalan + 2.7.0 + optional + + + + xerces + xercesImpl + 2.8.1 + + + + xml-apis + xml-apis + 1.3.03 + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.ws.axis2 + ${pom.name} + org.apache.tuscany.sca.binding.ws.axis2* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java new file mode 100644 index 0000000000..4087bd80a5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java @@ -0,0 +1,300 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2; + +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPBody; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axiom.soap.SOAPHeader; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.addressing.EndpointReferenceHelper; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicy; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingBasicAuthenticationConfigurator; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingHeaderConfigurator; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicy; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.runtime.ReferenceParameters; + +/** + * Axis2BindingInvoker uses an Axis2 OperationClient to invoke a remote web service + * + * @version $Rev$ $Date$ + */ +public class Axis2BindingInvoker implements Invoker, DataExchangeSemantics { + + public static final QName QNAME_WSA_FROM = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_FROM, + AddressingConstants.WSA_DEFAULT_PREFIX); + public static final String TUSCANY_PREFIX = "tuscany"; + public static final QName CALLBACK_ID_REFPARM_QN = + new QName(Constants.SCA10_TUSCANY_NS, "CallbackID", TUSCANY_PREFIX); + public static final QName CONVERSATION_ID_REFPARM_QN = + new QName(Constants.SCA10_TUSCANY_NS, "ConversationID", TUSCANY_PREFIX); + public static long GLOBAL_AXIS_TIMEOUT = 240000L; + + + private Axis2ServiceClient serviceClient; + private QName wsdlOperationName; + private Options options; + private SOAPFactory soapFactory; + private List policyHandlerList = null; + private WebServiceBinding wsBinding; + + private BasicAuthenticationPolicy basicAuthenticationPolicy = null; + private Axis2TokenAuthenticationPolicy axis2TokenAuthenticationPolicy = null; + private List axis2HeaderPolicies = new ArrayList(); + + public Axis2BindingInvoker(Axis2ServiceClient serviceClient, + QName wsdlOperationName, + Options options, + SOAPFactory soapFactory, + List policyHandlerList, + WebServiceBinding wsBinding) { + this.serviceClient = serviceClient; + this.wsdlOperationName = wsdlOperationName; + this.options = options; + this.soapFactory = soapFactory; + this.policyHandlerList = policyHandlerList; + this.wsBinding = wsBinding; + + // find out which policies are active + if (wsBinding instanceof PolicySetAttachPoint) { + List policySets = ((PolicySetAttachPoint)wsBinding).getPolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (BasicAuthenticationPolicy.class.isInstance(p)) { + basicAuthenticationPolicy = (BasicAuthenticationPolicy)p; + } else if (Axis2TokenAuthenticationPolicy.class.isInstance(p)) { + axis2TokenAuthenticationPolicy = (Axis2TokenAuthenticationPolicy)p; + } else if (Axis2HeaderPolicy.class.isInstance(p)) { + axis2HeaderPolicies.add((Axis2HeaderPolicy)p); + }else { + // etc. check for other types of policy being present + } + } + } + } + } + + private static final QName EXCEPTION = new QName("", "Exception"); + + public Message invoke(Message msg) { + try { + Object resp = invokeTarget(msg); + + msg.setBody(resp); + } catch (AxisFault e) { + if (e.getDetail() != null ) { + FaultException f = new FaultException(e.getMessage(), e.getDetail(), e); + f.setFaultName(e.getDetail().getQName()); + msg.setFaultBody(f); + } else { + msg.setFaultBody(e); + } + } catch (Throwable e) { + msg.setFaultBody(e); + } + + return msg; + } + + protected Object invokeTarget(Message msg) throws AxisFault { + final OperationClient operationClient = createOperationClient(msg); + + // ensure connections are tracked so that they can be closed by the reference binding + MessageContext requestMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE); + requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); + requestMC.getOptions().setTimeOutInMilliSeconds(GLOBAL_AXIS_TIMEOUT); + + for ( PolicyHandler policyHandler : policyHandlerList ) { + policyHandler.beforeInvoke(msg, requestMC, operationClient); + } + + // set policy specified headers + for (Axis2HeaderPolicy policy : axis2HeaderPolicies){ + Axis2BindingHeaderConfigurator.setHeader(requestMC, msg, policy.getHeaderName()); + } + + if (basicAuthenticationPolicy != null) { + Axis2BindingBasicAuthenticationConfigurator.setOperationOptions(operationClient, msg, basicAuthenticationPolicy); + } + + if (axis2TokenAuthenticationPolicy != null) { + Axis2BindingHeaderConfigurator.setHeader(requestMC, msg, axis2TokenAuthenticationPolicy.getTokenName()); + } + + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws AxisFault { + operationClient.execute(true); + return null; + } + }); + } catch (PrivilegedActionException e) { + operationClient.complete(requestMC); + throw (AxisFault)e.getException(); + } + + MessageContext responseMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); + + for ( PolicyHandler policyHandler : policyHandlerList ) { + policyHandler.afterInvoke(msg, responseMC, operationClient); + } + + OMElement response = responseMC.getEnvelope().getBody().getFirstElement(); + + // FIXME: [rfeng] We have to pay performance penalty to build the complete OM as the operationClient.complete() will + // release the underlying HTTP connection. + // Force the response to be populated, see https://issues.apache.org/jira/browse/TUSCANY-1541 + if (response != null) { + response.build(); + } + + operationClient.complete(requestMC); + + return response; + } + + @SuppressWarnings("deprecation") + protected OperationClient createOperationClient(Message msg) throws AxisFault { + SOAPEnvelope env = soapFactory.getDefaultEnvelope(); + Object[] args = (Object[])msg.getBody(); + if (args != null && args.length > 0) { + SOAPBody body = env.getBody(); + for (Object bc : args) { + if (bc instanceof OMElement) { + body.addChild((OMElement)bc); + } else { + throw new IllegalArgumentException( + "Can't handle mixed payloads between OMElements and other types."); + } + } + } + final MessageContext requestMC = new MessageContext(); + requestMC.setEnvelope(env); + + // Axis2 operationClients can not be shared so create a new one for each request + final OperationClient operationClient = serviceClient.getServiceClient().createClient(wsdlOperationName); + operationClient.setOptions(options); + + ReferenceParameters parameters = msg.getFrom().getReferenceParameters(); + + // set callback endpoint and callback ID for WS-Addressing header + EndpointReference fromEPR = null; + org.apache.tuscany.sca.runtime.EndpointReference callbackEPR = parameters.getCallbackReference(); + if (callbackEPR != null) { + fromEPR = new EndpointReference(callbackEPR.getBinding().getURI()); + } + Object callbackID = parameters.getCallbackID(); + if (callbackID != null) { + if (fromEPR == null) { + fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL); + } + //FIXME: serialize callback ID to XML in case it is not a string + fromEPR.addReferenceParameter(CALLBACK_ID_REFPARM_QN, callbackID.toString()); + } + + // set conversation ID for WS-Addressing header + Object conversationId = parameters.getConversationID(); + if (conversationId != null) { + if (fromEPR == null) { + fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL); + } + //FIXME: serialize conversation ID to XML in case it is not a string + fromEPR.addReferenceParameter(CONVERSATION_ID_REFPARM_QN, conversationId.toString()); + } + + // add WS-Addressing header + //FIXME: is there any way to use the Axis2 addressing support for this? + if (fromEPR != null) { + SOAPEnvelope sev = requestMC.getEnvelope(); + SOAPHeader sh = sev.getHeader(); + OMElement epr = + EndpointReferenceHelper.toOM(sev.getOMFactory(), + fromEPR, + QNAME_WSA_FROM, + AddressingConstants.Final.WSA_NAMESPACE); + sh.addChild(epr); + requestMC.setFrom(fromEPR); + } + + // Set any message headers required by policy + // Get the header from the tuscany message + // If its not already an OM convert it to OM + // add it to the envelope header + + // if target endpoint was not specified when this invoker was created, + // use dynamically specified target endpoint passed in on this call + if (options.getTo() == null) { + org.apache.tuscany.sca.runtime.EndpointReference ep = msg.getTo(); + if (ep != null) { + requestMC.setTo(new EndpointReference(ep.getURI())); + } else { + throw new RuntimeException("Unable to determine destination endpoint"); + } + } else { + requestMC.setTo(new EndpointReference(options.getTo().getAddress())); + } + + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws AxisFault { + operationClient.addMessageContext(requestMC); + return null; + } + }); + } catch (PrivilegedActionException e) { + throw (AxisFault)e.getException(); + } + return operationClient; + } + + public boolean allowsPassByReference() { + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java new file mode 100644 index 0000000000..b1923bdf3c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2; + +import java.util.List; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandlerDefinitionsLoader; +import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.work.WorkScheduler; + +/** + * Axis2BindingProviderFactory + * + * @version $Rev$ $Date$ + */ + +public class Axis2BindingProviderFactory implements BindingProviderFactory { + + private ModelFactoryExtensionPoint modelFactories; + private List hosts; + private List policyHandlerClassnames = null; + private DataBindingExtensionPoint dataBindings; + private WorkScheduler workScheduler; + + public Axis2BindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + hosts = servletHosts.getServletHosts(); + + modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + policyHandlerClassnames = PolicyHandlerDefinitionsLoader.loadPolicyHandlerClassnames(); + dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class); + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + workScheduler = utilities.getUtility(WorkScheduler.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + WebServiceBinding binding) { + return new Axis2ReferenceBindingProvider(component, reference, binding, + modelFactories, policyHandlerClassnames, dataBindings); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + WebServiceBinding binding) { + ServletHost servletHost = null; + + if (!hosts.isEmpty()) { + servletHost = hosts.get(0); + } + + return new Axis2ServiceBindingProvider(component, service, binding, + servletHost, modelFactories, + policyHandlerClassnames, dataBindings, workScheduler); + } + + public Class getModelType() { + return WebServiceBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java new file mode 100644 index 0000000000..f8d0cf55b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.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.sca.binding.ws.axis2; + +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.util.PolicyHandler; + +/** + * Axis2OneWayBindingInvoker uses an Axis2 OperationClient to invoke a OneWay remote web service. + * + * @version $Rev$ $Date$ + */ +public class Axis2OneWayBindingInvoker extends Axis2BindingInvoker { + + public Axis2OneWayBindingInvoker(Axis2ServiceClient serviceClient, + QName wsdlOperationName, + Options options, + SOAPFactory soapFactory, + List policyHandlerList, + WebServiceBinding wsBinding) { + + super(serviceClient, wsdlOperationName, options, soapFactory, policyHandlerList, wsBinding); + } + + @Override + protected Object invokeTarget(Message msg) throws AxisFault { + OperationClient operationClient = createOperationClient(msg); + + // ensure connections are tracked so that they can be closed by the reference binding + MessageContext requestMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE); + //requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); + Options opt = requestMC.getOptions(); + opt.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); + opt.setUseSeparateListener(true); + opt.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION,Boolean.TRUE); + + operationClient.execute(false); + + // REVIEW it seems ok to return null + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java new file mode 100644 index 0000000000..958d4aa41d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.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.sca.binding.ws.axis2; + +import java.util.List; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.osoa.sca.ServiceRuntimeException; + +public class Axis2ReferenceBindingProvider implements ReferenceBindingProvider { + + private WebServiceBinding wsBinding; + private Axis2ServiceClient axisClient; + + public Axis2ReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + WebServiceBinding wsBinding, + ModelFactoryExtensionPoint modelFactories, + List policyHandlerClassnames, + DataBindingExtensionPoint dataBindings) { + + MessageFactory messageFactory = modelFactories.getFactory(MessageFactory.class); + this.wsBinding = wsBinding; + + // A WSDL document should always be present in the binding + if (wsBinding.getWSDLDocument() == null) { + throw new ServiceRuntimeException("No WSDL document for " + component.getName() + "/" + reference.getName()); + } + + // Set to use the Axiom data binding + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + if (contract.getInterface() != null) { + contract.getInterface().resetDataBinding(OMElement.class.getName()); + } + + axisClient = new Axis2ServiceClient(component, reference, wsBinding, messageFactory, policyHandlerClassnames); + } + + public void start() { + axisClient.start(); + } + + public void stop() { + axisClient.stop(); + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return true; + } + + public Invoker createInvoker(Operation operation) { + return axisClient.createInvoker(operation); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java new file mode 100644 index 0000000000..8a4b64d266 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2; + +import java.util.List; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.osoa.sca.ServiceRuntimeException; + +public class Axis2ServiceBindingProvider implements ServiceBindingProvider { + + private WebServiceBinding wsBinding; + private Axis2ServiceProvider axisProvider; + + public Axis2ServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + WebServiceBinding wsBinding, + ServletHost servletHost, + ModelFactoryExtensionPoint modelFactories, + List policyHandlerClassnames, + DataBindingExtensionPoint dataBindings, + WorkScheduler workScheduler) { + + if (servletHost == null) { + throw new ServiceRuntimeException("No Servlet host is avaible for HTTP web services"); + } + + MessageFactory messageFactory = modelFactories.getFactory(MessageFactory.class); + this.wsBinding = wsBinding; + + // A WSDL document should always be present in the binding + if (wsBinding.getWSDLDocument() == null) { + throw new ServiceRuntimeException("No WSDL document for " + component.getName() + "/" + service.getName()); + } + + // Set to use the Axiom data binding + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + contract.getInterface().resetDataBinding(OMElement.class.getName()); + + axisProvider = new Axis2ServiceProvider(component, service, wsBinding, servletHost, messageFactory, policyHandlerClassnames, workScheduler); + } + + public void start() { + axisProvider.start(); + } + + public void stop() { + axisProvider.stop(); + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java new file mode 100644 index 0000000000..0d3916019f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java @@ -0,0 +1,503 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2; + +import static org.apache.tuscany.sca.binding.ws.axis2.AxisPolicyHelper.SOAP12_INTENT; +import static org.apache.tuscany.sca.binding.ws.axis2.AxisPolicyHelper.isIntentRequired; + +import java.io.IOException; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.Port; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.wsdl.extensions.soap12.SOAP12Address; +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 javax.xml.transform.dom.DOMSource; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.addressing.EndpointReferenceHelper; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.AxisEndpoint; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.description.WSDL11ToAxisServiceBuilder; +import org.apache.axis2.description.WSDL2Constants; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.util.threadpool.ThreadPool; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.params.HttpConnectionManagerParams; +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +import org.apache.tuscany.sca.policy.util.PolicyHandlerUtils; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.xsd.xml.XMLDocumentHelper; +import org.apache.ws.commons.schema.resolver.URIResolver; +import org.osoa.sca.ServiceRuntimeException; + +public class Axis2ServiceClient { + + private RuntimeComponent component; + private AbstractContract contract; + private WebServiceBinding wsBinding; + private ServiceClient serviceClient; + List policyHandlerClassnames = null; + private List policyHandlerList = new ArrayList(); + + public Axis2ServiceClient(RuntimeComponent component, + AbstractContract contract, + WebServiceBinding wsBinding, + MessageFactory messageFactory, + List policyHandlerClassnames) { + + this.component = component; + this.contract = contract; + this.wsBinding = wsBinding; + this.policyHandlerClassnames = policyHandlerClassnames; + } + + protected void start() { + if (serviceClient == null) { + this.serviceClient = createServiceClient(); + } + } + + public ServiceClient getServiceClient() { + return serviceClient; + } + + protected void configurePolicy(ConfigurationContext context, PolicySet ps) throws AxisFault { + if (ps == null) { + return; + } + for (Object policy : ps.getPolicies()) { + if (policy instanceof Axis2ConfigParamPolicy) { + Axis2ConfigParamPolicy axis2ConfigParamPolicy = (Axis2ConfigParamPolicy)policy; + for (Map.Entry param : axis2ConfigParamPolicy.getParamElements().entrySet()) { + Parameter configParam = new Parameter(param.getKey(), param.getValue().getFirstElement()); + configParam.setParameterElement(param.getValue()); + context.getAxisConfiguration().addParameter(configParam); + } + } + } + } + + /** + * Create an Axis2 ServiceClient + */ + protected ServiceClient createServiceClient() { + try { + final boolean isRampartRequired = AxisPolicyHelper.isRampartRequired(wsBinding); + ConfigurationContext configContext; + + try { + // TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); + // Allow privileged access to read properties. Requires PropertyPermission read in + // security policy. + TuscanyAxisConfigurator tuscanyAxisConfigurator = + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public TuscanyAxisConfigurator run() throws AxisFault { + return new TuscanyAxisConfigurator(isRampartRequired); + } + }); + configContext = tuscanyAxisConfigurator.getConfigurationContext(); + // deployRampartModule(); + // configureSecurity(); + } catch (PrivilegedActionException e) { + throw new ServiceRuntimeException(e.getException()); + } + + createPolicyHandlers(); + setupPolicyHandlers(policyHandlerList, configContext); + + Definition definition = wsBinding.getWSDLDocument(); + QName serviceQName = wsBinding.getService().getQName(); + Port port = wsBinding.getPort(); + if (port == null) { + // service has multiple ports, select one port to use + Collection ports = wsBinding.getService().getPorts().values(); + for (Port p : ports) { + // look for a SOAP 1.1 port first + if (p.getExtensibilityElements().get(0) instanceof SOAPAddress) { + port = p; + break; + } + } + if (port == null) { + // no SOAP 1.1 port available, so look for a SOAP 1.2 port + for (Port p : ports) { + if (p.getExtensibilityElements().get(0) instanceof SOAP12Address) { + port = p; + break; + } + } + } + } + AxisService axisService = + createClientSideAxisService(definition, serviceQName, port.getName(), new Options()); + + HttpClient httpClient = (HttpClient)configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); + if (httpClient == null) { + MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); + HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); + connectionManagerParams.setDefaultMaxConnectionsPerHost(2); + connectionManagerParams.setTcpNoDelay(true); + connectionManagerParams.setStaleCheckingEnabled(true); + connectionManagerParams.setLinger(0); + connectionManager.setParams(connectionManagerParams); + httpClient = new HttpClient(connectionManager); + configContext.setThreadPool(new ThreadPool(1, 5)); + configContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); + configContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); + } + + return new ServiceClient(configContext, axisService); + + } catch (AxisFault e) { + throw new RuntimeException(e); // TODO: better exception + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + /** + * URI resolver implementation for XML schema + */ + public static class URIResolverImpl implements URIResolver { + private Definition definition; + + public URIResolverImpl(Definition definition) { + this.definition = definition; + } + + public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace, + java.lang.String schemaLocation, + java.lang.String baseUri) { + try { + if (baseUri == null) { + baseUri = definition.getDocumentBaseURI(); + } + URL url = new URL(new URL(baseUri), schemaLocation); + return XMLDocumentHelper.getInputSource(url); + } catch (IOException e) { + return null; + } + } + } + + /** + * Workaround for https://issues.apache.org/jira/browse/AXIS2-3205 + * @param definition + * @param serviceName + * @return + */ + private static Definition getDefinition(Definition definition, QName serviceName) { + + if (serviceName == null) { + return definition; + } + + if (definition == null) { + return null; + } + Object service = definition.getServices().get(serviceName); + if (service != null) { + return definition; + } + for (Object i : definition.getImports().values()) { + List imports = (List)i; + for (Import imp : imports) { + Definition d = getDefinition(imp.getDefinition(), serviceName); + if (d != null) { + return d; + } + } + } + return null; + } + + /** + * This method is copied from AxisService.createClientSideAxisService to + * work around http://issues.apache.org/jira/browse/WSCOMMONS-228 + * + * @param wsdlDefinition + * @param wsdlServiceName + * @param portName + * @param options + * @return + * @throws AxisFault + */ + @Deprecated + public static AxisService createClientSideAxisService(Definition definition, + QName serviceName, + String portName, + Options options) throws AxisFault { + Definition def = getDefinition(definition, serviceName); + final WSDL11ToAxisServiceBuilder serviceBuilder = new WSDL11ToAxisServiceBuilder(def, serviceName, portName); + serviceBuilder.setServerSide(false); + // [rfeng] Add a custom resolver to work around WSCOMMONS-228 + serviceBuilder.setCustomResolver(new URIResolverImpl(def)); + serviceBuilder.setBaseUri(def.getDocumentBaseURI()); + // [rfeng] + // Allow access to read properties. Requires PropertiesPermission in security policy. + AxisService axisService; + try { + axisService = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public AxisService run() throws AxisFault { + return serviceBuilder.populateService(); + } + }); + } catch ( PrivilegedActionException e ) { + throw (AxisFault) e.getException(); + } + + AxisEndpoint axisEndpoint = (AxisEndpoint)axisService.getEndpoints().get(axisService.getEndpointName()); + options.setTo(new EndpointReference(axisEndpoint.getEndpointURL())); + if (axisEndpoint != null) { + options.setSoapVersionURI((String)axisEndpoint.getBinding().getProperty(WSDL2Constants.ATTR_WSOAP_VERSION)); + } + return axisService; + } + + /* + private static T getExtensibilityElement(List elements, Class type) { + for (Object e : elements) { + if (type.isInstance(e)) { + return type.cast(e); + } + } + return null; + } + */ + + protected void stop() { + if (serviceClient != null) { + // close all connections that we have initiated, so that the jetty server + // can be restarted without seeing ConnectExceptions + HttpClient httpClient = + (HttpClient)serviceClient.getServiceContext().getConfigurationContext() + .getProperty(HTTPConstants.CACHED_HTTP_CLIENT); + if (httpClient != null) + ((MultiThreadedHttpConnectionManager)httpClient.getHttpConnectionManager()).shutdown(); + + serviceClient = null; + } + } + + /** + * Create and configure an Axis2BindingInvoker for each operation + */ + protected Invoker createInvoker(Operation operation) { + Options options = new Options(); + EndpointReference epTo = getWSATOEPR(wsBinding); + if (epTo != null) { + options.setTo(epTo); + } + options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); + + String operationName = operation.getName(); + + String soapAction = getSOAPAction(operationName); + if (soapAction != null && soapAction.length() > 1) { + options.setAction(soapAction); + } + + options.setTimeOutInMilliSeconds(30 * 1000); // 30 seconds + + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + SOAPFactory soapFactory = AccessController.doPrivileged(new PrivilegedAction() { + public SOAPFactory run() { + if (requiresSOAP12()) + return OMAbstractFactory.getSOAP12Factory(); + else + return OMAbstractFactory.getSOAP11Factory(); + + } + }); + QName wsdlOperationQName = new QName(operationName); + if (requiresMTOM()) + { + options.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM, org.apache.axis2.Constants.VALUE_TRUE); + } + Axis2BindingInvoker invoker; + if (operation.isNonBlocking()) { + invoker = new Axis2OneWayBindingInvoker(this, wsdlOperationQName, options, soapFactory, policyHandlerList, wsBinding); + } else { + invoker = new Axis2BindingInvoker(this, wsdlOperationQName, options, soapFactory, policyHandlerList, wsBinding); + } + + return invoker; + } + + private boolean requiresSOAP12() { + return isIntentRequired(wsBinding, SOAP12_INTENT); + } + + private boolean requiresMTOM() { + return isIntentRequired(wsBinding, AxisPolicyHelper.MTOM_INTENT); + } + + protected EndpointReference getWSATOEPR(WebServiceBinding binding) { + EndpointReference epr = getEPR(binding); + if (epr == null) { + epr = getPortLocationEPR(binding); + } else if (epr.getAddress() == null || epr.getAddress().length() < 1) { + EndpointReference bindingEPR = getPortLocationEPR(binding); + if (bindingEPR != null) { + epr.setAddress(bindingEPR.getAddress()); + } + } + return epr; + } + + protected EndpointReference getPortLocationEPR(WebServiceBinding binding) { + String ep = null; + if (binding.getPort() != null) { + List wsdlPortExtensions = binding.getPort().getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + ep = ((SOAPAddress)extension).getLocationURI(); + break; + } + if (extension instanceof SOAP12Address) { + SOAP12Address address = (SOAP12Address)extension; + ep = address.getLocationURI(); + break; + } + } + } + if(ep == null || ep.equals("")) { + ep = binding.getURI(); + } + return ep == null || "".equals(ep) ? null : new EndpointReference(ep); + } + + protected org.apache.axis2.addressing.EndpointReference getEPR(WebServiceBinding wsBinding) { + if (wsBinding.getEndPointReference() == null) { + return null; + } + try { + + XMLStreamReader parser = + XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(wsBinding.getEndPointReference())); + StAXOMBuilder builder = new StAXOMBuilder(parser); + OMElement omElement = builder.getDocumentElement(); + org.apache.axis2.addressing.EndpointReference epr = EndpointReferenceHelper.fromOM(omElement); + return epr; + + } catch (IOException e) { + throw new RuntimeException(e); + } catch (XMLStreamException e) { + throw new RuntimeException(e); + } catch (FactoryConfigurationError e) { + throw new RuntimeException(e); + } + } + + protected String getSOAPAction(String operationName) { + Binding binding = wsBinding.getBinding(); + if (binding != null) { + for (Object o : binding.getBindingOperations()) { + BindingOperation bop = (BindingOperation)o; + if (bop.getName().equalsIgnoreCase(operationName)) { + for (Object o2 : bop.getExtensibilityElements()) { + if (o2 instanceof SOAPOperation) { + return ((SOAPOperation)o2).getSoapActionURI(); + } + } + } + } + } + return null; + } + + private void createPolicyHandlers() throws IllegalAccessException, InstantiationException, ClassNotFoundException { + if (wsBinding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)wsBinding; + PolicyHandler policyHandler = null; + for (PolicySet policySet : policiedBinding.getPolicySets()) { + policyHandler = PolicyHandlerUtils.findPolicyHandler(policySet, policyHandlerClassnames); + if (policyHandler != null) { + policyHandler.setApplicablePolicySet(policySet); + policyHandlerList.add(policyHandler); + } + } + + // code to create policy handlers using the new policy SPI based + // on policy providers +/* + List policyProviders = ((RuntimeComponentReference)contract).getPolicyProviders(wsBinding); + + for (PolicyProvider policyProvider : policyProviders){ + policyHandler = policyProvider.createHandler(); + if (policyHandler != null) { + policyHandlerList.add(policyHandler); + } + } +*/ + } + } + + private void setupPolicyHandlers(List policyHandlers, ConfigurationContext configContext) { + for (PolicyHandler aHandler : policyHandlers) { + aHandler.setUp(configContext); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.java new file mode 100644 index 0000000000..a0cfab9154 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.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.sca.binding.ws.axis2; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractInMessageReceiver; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.policy.util.PolicyHandler; + +public class Axis2ServiceInMessageReceiver extends AbstractInMessageReceiver { + + protected Operation operation; + + private Axis2ServiceProvider provider; + + private List policyHandlerList = null; + + public Axis2ServiceInMessageReceiver(Axis2ServiceProvider provider, Operation operation, List policyHandlerList) { + this.provider = provider; + this.operation = operation; + this.policyHandlerList = policyHandlerList; + } + + public Axis2ServiceInMessageReceiver() { + } + + @Override + public void invokeBusinessLogic(MessageContext inMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = new Object[] {requestOM}; + + /* + for ( PolicyHandler policyHandler : policyHandlerList ) { + policyHandler.beforeInvoke(operation, args, inMC); + } + */ + + provider.invokeTarget(operation, args, inMC); + + /* + for ( PolicyHandler policyHandler : policyHandlerList ) { + policyHandler.afterInvoke(operation, args, inMC); + } + */ + + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + throw new RuntimeException(e); + } catch (Exception e) { + e.printStackTrace(); + throw AxisFault.makeFault(e); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java new file mode 100644 index 0000000000..d467e0b3c8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.osoa.sca.ServiceRuntimeException; + +public class Axis2ServiceInOutSyncMessageReceiver extends AbstractInOutSyncMessageReceiver { + private static final Logger logger = Logger.getLogger(Axis2ServiceInOutSyncMessageReceiver.class.getName()); + + protected Operation operation; + private List policyHandlerList = null; + + private Axis2ServiceProvider provider; + + public Axis2ServiceInOutSyncMessageReceiver(Axis2ServiceProvider provider, Operation operation, List policyHandlerList) { + this.provider = provider; + this.operation = operation; + this.policyHandlerList = policyHandlerList; + } + + public Axis2ServiceInOutSyncMessageReceiver() { + } + + @Override + public void invokeBusinessLogic(MessageContext inMC, MessageContext outMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = null; + + if (requestOM != null) { + args = new Object[] {requestOM}; + } + + /* + for ( PolicyHandler policyHandler : policyHandlerList ) { + policyHandler.beforeInvoke(operation, args, inMC); + } + */ + + OMElement responseOM = (OMElement)provider.invokeTarget(operation, args, inMC); + + /* + for ( PolicyHandler policyHandler : policyHandlerList ) { + policyHandler.afterInvoke(operation, args, inMC, responseOM); + } + */ + + SOAPEnvelope soapEnvelope = getSOAPFactory(inMC).getDefaultEnvelope(); + if (null != responseOM ) { + soapEnvelope.getBody().addChild(responseOM); + } + outMC.setEnvelope(soapEnvelope); + outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE); + + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof FaultException && ((FaultException)t).getFaultInfo() instanceof OMElement) { + OMElement faultDetail = (OMElement)((FaultException)t).getFaultInfo(); + inMC.setProperty(Constants.FAULT_NAME, faultDetail.getQName().getLocalPart()); + AxisFault f = new AxisFault(null, e.getMessage(), "faultNode", "faultRole", faultDetail); + throw f; + } + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + logger.log(Level.SEVERE, e.getMessage(), t); + throw new ServiceRuntimeException(e); + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + throw AxisFault.makeFault(e); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java new file mode 100644 index 0000000000..456001e615 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java @@ -0,0 +1,849 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2; + +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.net.URISyntaxException; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.Port; +import javax.wsdl.Types; +import javax.wsdl.extensions.UnknownExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.soap.SOAPHeader; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.Constants.Configuration; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.deployment.util.Utils; +import org.apache.axis2.description.AxisEndpoint; +import org.apache.axis2.description.AxisOperation; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.description.TransportInDescription; +import org.apache.axis2.description.TransportOutDescription; +import org.apache.axis2.description.WSDL11ToAxisServiceBuilder; +import org.apache.axis2.description.WSDL2Constants; +import org.apache.axis2.description.WSDLToAxisServiceBuilder; +import org.apache.axis2.engine.ListenerManager; +import org.apache.axis2.engine.MessageReceiver; +import org.apache.axis2.transport.jms.JMSConstants; +import org.apache.axis2.transport.jms.JMSUtils; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.Axis2ServiceClient.URIResolverImpl; +import org.apache.tuscany.sca.binding.ws.axis2.jms.JMSListener; +import org.apache.tuscany.sca.binding.ws.axis2.jms.JMSSender; +import org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicy; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingBasicAuthenticationConfigurator; +import org.apache.tuscany.sca.binding.ws.axis2.policy.configurator.Axis2BindingHeaderConfigurator; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicy; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeaderString; +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +import org.apache.tuscany.sca.policy.util.PolicyHandlerUtils; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.apache.tuscany.sca.xsd.XSDefinition; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaExternal; +import org.apache.ws.security.WSSecurityEngineResult; +import org.apache.ws.security.handler.WSHandlerConstants; +import org.apache.ws.security.handler.WSHandlerResult; +import org.osoa.sca.ServiceRuntimeException; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +public class Axis2ServiceProvider { + public static final String IMPORT_TAG = "import"; + public static final String INCLUDE_TAG = "include"; + + private static final Logger logger = Logger.getLogger(Axis2ServiceProvider.class.getName()); + + private RuntimeComponent component; + private AbstractContract contract; + private WebServiceBinding wsBinding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private ConfigurationContext configContext; + private JMSSender jmsSender; + private JMSListener jmsListener; + private List policyHandlerClassnames = null; + private List policyHandlerList = new ArrayList(); + private Map urlMap = new HashMap(); + + private BasicAuthenticationPolicy basicAuthenticationPolicy = null; + private Axis2TokenAuthenticationPolicy axis2TokenAuthenticationPolicy = null; + private List axis2HeaderPolicies = new ArrayList(); + private WorkScheduler workScheduler; + + public static final QName QNAME_WSA_ADDRESS = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_ADDRESS); + public static final QName QNAME_WSA_FROM = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_FROM); + public static final QName QNAME_WSA_REFERENCE_PARAMETERS = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_REFERENCE_PARAMETERS); + + private static final QName TRANSPORT_JMS_QUALIFIED_INTENT = + new QName("http://www.osoa.org/xmlns/sca/1.0", "transport.jms"); + private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; + + //Schema element names + public static final String ELEM_SCHEMA = "schema"; + + //Schema URI + public static final String NS_URI_XSD_1999 = "http://www.w3.org/1999/XMLSchema"; + public static final String NS_URI_XSD_2000 = "http://www.w3.org/2000/10/XMLSchema"; + public static final String NS_URI_XSD_2001 = "http://www.w3.org/2001/XMLSchema"; + + //Schema QNames + public static final QName Q_ELEM_XSD_1999 = new QName(NS_URI_XSD_1999, ELEM_SCHEMA); + public static final QName Q_ELEM_XSD_2000 = new QName(NS_URI_XSD_2000, ELEM_SCHEMA); + public static final QName Q_ELEM_XSD_2001 = new QName(NS_URI_XSD_2001, ELEM_SCHEMA); + public static final List XSD_QNAME_LIST = + Arrays.asList(new QName[] {Q_ELEM_XSD_1999, Q_ELEM_XSD_2000, Q_ELEM_XSD_2001}); + + public Axis2ServiceProvider(RuntimeComponent component, + AbstractContract contract, + WebServiceBinding wsBinding, + ServletHost servletHost, + MessageFactory messageFactory, + List policyHandlerClassnames, + WorkScheduler workScheduler) { + + this.component = component; + this.contract = contract; + this.wsBinding = wsBinding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.policyHandlerClassnames = policyHandlerClassnames; + this.workScheduler = workScheduler; + + final boolean isRampartRequired = AxisPolicyHelper.isRampartRequired(wsBinding); + try { + // TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); + // Allow privileged access to read properties. Requires PropertyPermission read in + // security policy. + TuscanyAxisConfigurator tuscanyAxisConfigurator = + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public TuscanyAxisConfigurator run() throws AxisFault { + return new TuscanyAxisConfigurator(isRampartRequired); + } + }); + configContext = tuscanyAxisConfigurator.getConfigurationContext(); + // deployRampartModule(); + // configureSecurity(); + } catch (PrivilegedActionException e) { + throw new ServiceRuntimeException(e.getException()); + } catch (AxisFault e) { + throw new ServiceRuntimeException(e); // TODO: better exception + } + + configContext.setContextRoot(servletHost.getContextPath()); + + // Enable MTOM if the policy intent is specified. + if (AxisPolicyHelper.isIntentRequired(wsBinding, AxisPolicyHelper.MTOM_INTENT)) { + configContext.getAxisConfiguration().getParameter(Configuration.ENABLE_MTOM).setLocked(false); + configContext.getAxisConfiguration().getParameter(Configuration.ENABLE_MTOM).setValue("true"); + } + + // Update port addresses with runtime information, and create a + // map from endpoint URIs to WSDL ports that eliminates duplicate + // ports for the same endpoint. + for (Object port : wsBinding.getService().getPorts().values()) { + String portAddress = getPortAddress((Port)port); + String endpointURI = computeEndpointURI(portAddress, servletHost); + setPortAddress((Port)port, endpointURI); + urlMap.put(endpointURI, (Port)port); + } + + // find out which policies are active + if (wsBinding instanceof PolicySetAttachPoint) { + List policySets = ((PolicySetAttachPoint)wsBinding).getPolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (BasicAuthenticationPolicy.class.isInstance(p)) { + basicAuthenticationPolicy = (BasicAuthenticationPolicy)p; + } else if (Axis2TokenAuthenticationPolicy.class.isInstance(p)) { + axis2TokenAuthenticationPolicy = (Axis2TokenAuthenticationPolicy)p; + } else if (Axis2HeaderPolicy.class.isInstance(p)) { + axis2HeaderPolicies.add((Axis2HeaderPolicy)p); + } else { + // etc. check for other types of policy being present + } + } + } + } + } + + static String getPortAddress(Port port) { + Object ext = port.getExtensibilityElements().get(0); + if (ext instanceof SOAPAddress) { + return ((SOAPAddress)ext).getLocationURI(); + } + if (ext instanceof SOAP12Address) { + return ((SOAP12Address)ext).getLocationURI(); + } + return null; + } + + static void setPortAddress(Port port, String locationURI) { + Object ext = port.getExtensibilityElements().get(0); + if (ext instanceof SOAPAddress) { + ((SOAPAddress)ext).setLocationURI(locationURI); + } + if (ext instanceof SOAP12Address) { + ((SOAP12Address)ext).setLocationURI(locationURI); + } + } + + private String computeEndpointURI(String uri, ServletHost servletHost) { + + if (uri == null) { + return null; + } + + // pull out the binding intents to see what sort of transport is required + PolicySet transportJmsPolicySet = AxisPolicyHelper.getPolicySet(wsBinding, TRANSPORT_JMS_QUALIFIED_INTENT); + if (transportJmsPolicySet != null){ + if (!uri.startsWith("jms:/")) { + uri = "jms:" + uri; + } + + // construct the rest of the URI based on the policy. All the details are put + // into the URI here rather than being place directly into the Axis configuration + // as the Axis JMS sender relies on parsing the target URI + Axis2ConfigParamPolicy axis2ConfigParamPolicy = null; + for ( Object policy : transportJmsPolicySet.getPolicies() ) { + if ( policy instanceof Axis2ConfigParamPolicy ) { + axis2ConfigParamPolicy = (Axis2ConfigParamPolicy)policy; + Iterator paramIterator = axis2ConfigParamPolicy.getParamElements().get(DEFAULT_QUEUE_CONNECTION_FACTORY).getChildElements(); + + if (paramIterator.hasNext()){ + StringBuffer uriParams = new StringBuffer("?"); + + while (paramIterator.hasNext()){ + OMElement parameter = (OMElement)paramIterator.next(); + uriParams.append(parameter.getAttributeValue(new QName("","name"))); + uriParams.append("="); + uriParams.append(parameter.getText()); + + if (paramIterator.hasNext()){ + uriParams.append("&"); + } + } + + uri = uri + uriParams; + } + } + } + } else { + if (!uri.startsWith("jms:")) { + uri = servletHost.getURLMapping(uri).toString(); + } + } + + return uri; + } + + public void start() { + + try { + createPolicyHandlers(); + for (Map.Entry entry : urlMap.entrySet()) { + AxisService axisService = createAxisService(entry.getKey(), entry.getValue()); + configContext.getAxisConfiguration().addService(axisService); + } + setupPolicyHandlers(policyHandlerList, configContext); + + Axis2ServiceServlet servlet = null; + for (String endpointURL : urlMap.keySet()) { + if (endpointURL.startsWith("http://") || endpointURL.startsWith("https://") || endpointURL.startsWith("/")) { + if (servlet == null) { + servlet = new Axis2ServiceServlet(); + servlet.init(configContext); + } + //[nash] configContext.setContextRoot(endpointURL); + servletHost.addServletMapping(endpointURL, servlet); + } else if (endpointURL.startsWith("jms")) { + logger.log(Level.INFO,"Axis2 JMS URL=" + endpointURL); + + jmsListener = new JMSListener(workScheduler); + jmsSender = new JMSSender(); + ListenerManager listenerManager = configContext.getListenerManager(); + TransportInDescription trsIn = configContext.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_JMS); + + if (trsIn == null){ + trsIn = new TransportInDescription(Constants.TRANSPORT_JMS); + } + + // get JMS transport parameters from the computed URL + Map jmsProps = JMSUtils.getProperties(endpointURL); + + // collect the parameters used to configure the JMS transport + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement parms = fac.createOMElement(DEFAULT_QUEUE_CONNECTION_FACTORY, null); + + for ( String key : jmsProps.keySet() ) { + OMElement param = fac.createOMElement("parameter", null); + param.addAttribute( "name", key, null ); + param.addChild(fac.createOMText(param, jmsProps.get(key))); + parms.addChild(param); + } + + Parameter queueConnectionFactory = new Parameter(DEFAULT_QUEUE_CONNECTION_FACTORY, parms); + trsIn.addParameter( queueConnectionFactory ); + + trsIn.setReceiver(jmsListener); + + configContext.getAxisConfiguration().addTransportIn( trsIn ); + TransportOutDescription trsOut = configContext.getAxisConfiguration().getTransportOut(Constants.TRANSPORT_JMS); + //configContext.getAxisConfiguration().addTransportOut( trsOut ); + trsOut.setSender(jmsSender); + + if (listenerManager == null) { + listenerManager = new ListenerManager(); + listenerManager.init(configContext); + } + listenerManager.addListener(trsIn, true); + jmsSender.init(configContext, trsOut); + jmsListener.init(configContext, trsIn); + jmsListener.start(); + } + } + } catch (AxisFault e) { + throw new RuntimeException(e); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public void stop() { + if ( jmsListener != null ) { + jmsListener.stop(); + jmsListener.destroy(); + } + else { + for (String endpointURL : urlMap.keySet()) { + servletHost.removeServletMapping(endpointURL); + } + } + + servletHost = null; + + if ( jmsSender != null ) + jmsSender.stop(); + + try { + for (String endpointURL : urlMap.keySet()) { + // get the path to the service + URI uriPath = new URI(endpointURL); + String stringURIPath = uriPath.getPath(); + + /* [nash] Need a leading slash for WSDL imports to work with ?wsdl + // remove any "/" from the start of the path + if (stringURIPath.startsWith("/")) { + stringURIPath = stringURIPath.substring(1, stringURIPath.length()); + } + */ + + configContext.getAxisConfiguration().removeService(stringURIPath); + } + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } catch (AxisFault e) { + throw new RuntimeException(e); + } + } + + private AxisService createAxisService(String endpointURL, Port port) throws AxisFault { + AxisService axisService; + if (wsBinding.getWSDLDocument() != null) { + axisService = createWSDLAxisService(endpointURL, port); + } else { + axisService = createJavaAxisService(endpointURL); + } + initAxisOperations(axisService); + return axisService; + } + + /** + * Create an AxisService from the interface class from the SCA service interface + */ + protected AxisService createJavaAxisService(String endpointURL) throws AxisFault { + AxisService axisService = new AxisService(); + String path = URI.create(endpointURL).getPath(); + axisService.setName(path); + axisService.setServiceDescription("Tuscany configured AxisService for service: " + endpointURL); + axisService.setClientSide(false); + Parameter classParam = + new Parameter(Constants.SERVICE_CLASS, ((JavaInterface)contract.getInterfaceContract().getInterface()) + .getJavaClass().getName()); + axisService.addParameter(classParam); + try { + Utils.fillAxisService(axisService, configContext.getAxisConfiguration(), null, null); + } catch (Exception e) { + throw new RuntimeException(e); + } + + return axisService; + } + + /** + * Workaround for https://issues.apache.org/jira/browse/AXIS2-3205 + * @param definition + * @param serviceName + * @return + */ + private static Definition getDefinition(Definition definition, QName serviceName) { + + if (serviceName == null){ + return definition; + } + + if (definition == null) { + return null; + } + Object service = definition.getServices().get(serviceName); + if (service != null) { + return definition; + } + for (Object i : definition.getImports().values()) { + List imports = (List)i; + for (Import imp : imports) { + Definition d = getDefinition(imp.getDefinition(), serviceName); + if (d != null) { + return d; + } + } + } + return null; + } + + /** + * Create an AxisService from the WSDL doc used by ws binding + */ + protected AxisService createWSDLAxisService(String endpointURL, Port port) throws AxisFault { + + Definition definition = wsBinding.getWSDLDocument(); + QName serviceQName = wsBinding.getService().getQName(); + Definition def = getDefinition(definition, serviceQName); + + // TUSCANY-2824 fix the target namespace of the definition to be the same as + // that for the port. Without this Axis fails during policy application + // when it tries to match binding operation names to port type operation + // names + //def.setTargetNamespace(port.getBinding().getPortType().getQName().getNamespaceURI()); + + + final WSDLToAxisServiceBuilder builder = new WSDL11ToAxisServiceBuilder(def, serviceQName, port.getName()); + builder.setServerSide(true); + // [rfeng] Add a custom resolver to work around WSCOMMONS-228 + builder.setCustomResolver(new URIResolverImpl(def)); + builder.setBaseUri(def.getDocumentBaseURI()); + // [rfeng] + // AxisService axisService = builder.populateService(); + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + AxisService axisService; + try { + axisService = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public AxisService run() throws AxisFault { + return builder.populateService(); + } + }); + } catch (PrivilegedActionException e) { + throw (AxisFault)e.getException(); + } + + String name = URI.create(endpointURL).getPath(); + //[nash] HTTP endpoints need a leading slash for WSDL imports to work with ?wsdl + if (endpointURL.startsWith("jms")) { + name = name.startsWith("/") ? name.substring(1) : name; + } + axisService.setName(name); + axisService.setEndpointURL(endpointURL); + axisService.setDocumentation("Tuscany configured AxisService for service: " + endpointURL); + for ( Iterator i = axisService.getEndpoints().values().iterator(); i.hasNext(); ) { + AxisEndpoint ae = (AxisEndpoint)i.next(); + if (endpointURL.startsWith("jms") ) { + Parameter qcf = new Parameter(JMSConstants.CONFAC_PARAM, null); + qcf.setValue(DEFAULT_QUEUE_CONNECTION_FACTORY); + axisService.addParameter(qcf); + break; + } + } + + // Add schema information to the AxisService (needed for "?xsd=" support) + addSchemas(wsBinding.getWSDLDefinition(), axisService); + + // Use the existing WSDL + Parameter wsdlParam = new Parameter(WSDLConstants.WSDL_4_J_DEFINITION, null); + wsdlParam.setValue(definition); + axisService.addParameter(wsdlParam); + Parameter userWSDL = new Parameter("useOriginalwsdl", "true"); + axisService.addParameter(userWSDL); + + // Modify schema imports and includes to add "servicename?xsd=" prefix. + // Axis2 does this for schema extensibility elements, but Tuscany has + // overriden the WSDl4J deserializer to create UnknownExtensibilityElement + // elements in place of these. + modifySchemaImportsAndIncludes(definition, name); + + // Axis2 1.3 has a bug with returning incorrect values for the port + // addresses. To work around this, compute the values here. + Parameter modifyAddr = new Parameter("modifyUserWSDLPortAddress", "false"); + axisService.addParameter(modifyAddr); + + return axisService; + } + + private void addSchemas(WSDLDefinition wsdlDef, AxisService axisService) { + for (XSDefinition xsDef : wsdlDef.getXmlSchemas()) { + if (xsDef.getSchema() != null) { + axisService.addSchema(xsDef.getSchema()); + updateSchemaRefs(xsDef.getSchema(), axisService.getName()); + } + } + for (WSDLDefinition impDef : wsdlDef.getImportedDefinitions()) { + addSchemas(impDef, axisService); + } + } + + private void updateSchemaRefs(XmlSchema parentSchema, String name) { + for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof XmlSchemaExternal) { + XmlSchemaExternal extSchema = (XmlSchemaExternal)obj; + String location = extSchema.getSchemaLocation(); + if (location.length() > 0 && location.indexOf(":/") < 0 && location.indexOf("?xsd=") < 0) { + extSchema.setSchemaLocation(name + "?xsd=" + location); + } + if (extSchema.getSchema() != null) { + updateSchemaRefs(extSchema.getSchema(), name); + } + } + } + } + + private void modifySchemaImportsAndIncludes(Definition definition, String name){ + // adjust the schema locations in types section + Types types = definition.getTypes(); + if (types != null) { + for (Iterator iter = types.getExtensibilityElements().iterator(); iter.hasNext();) { + Object ext = iter.next(); + if (ext instanceof UnknownExtensibilityElement && + XSD_QNAME_LIST.contains(((UnknownExtensibilityElement)ext).getElementType())) { + changeLocations(((UnknownExtensibilityElement)ext).getElement(), name); + } + } + } + for (Iterator iter = definition.getImports().values().iterator(); iter.hasNext();) { + Vector values = (Vector)iter.next(); + for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) { + Import wsdlImport = (Import)valuesIter.next(); + modifySchemaImportsAndIncludes(wsdlImport.getDefinition(), name); + } + } + } + + private void changeLocations(Element element, String name) { + NodeList nodeList = element.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + String tagName = nodeList.item(i).getLocalName(); + if (IMPORT_TAG.equals(tagName) || INCLUDE_TAG.equals(tagName)) { + processImport(nodeList.item(i), name); + } + } + } + + private void processImport(Node importNode, String name) { + NamedNodeMap nodeMap = importNode.getAttributes(); + for (int i = 0; i < nodeMap.getLength(); i++) { + Node attribute = nodeMap.item(i); + if (attribute.getNodeName().equals("schemaLocation")) { + String location = attribute.getNodeValue(); + if (location.indexOf(":/") < 0 & location.indexOf("?xsd=") < 0) { + attribute.setNodeValue(name + "?xsd=" + location); + } + } + } + } + + protected void initAxisOperations(AxisService axisService) { + for (Iterator i = axisService.getOperations(); i.hasNext();) { + AxisOperation axisOp = (AxisOperation)i.next(); + Operation op = getOperation(axisOp); + if (op != null) { + + if (op.isNonBlocking()) { + axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_ONLY); + } else { + axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_OUT); + } + + MessageReceiver msgrec = null; + if (op.isNonBlocking()) { + msgrec = new Axis2ServiceInMessageReceiver(this, op, policyHandlerList); + } else { + msgrec = new Axis2ServiceInOutSyncMessageReceiver(this, op, policyHandlerList); + } + axisOp.setMessageReceiver(msgrec); + } + } + } + + protected Operation getOperation(AxisOperation axisOp) { + String operationName = axisOp.getName().getLocalPart(); + Interface iface = wsBinding.getBindingInterfaceContract().getInterface(); + for (Operation op : iface.getOperations()) { + if (op.getName().equalsIgnoreCase(operationName)) { + return op; + } + } + return null; + } + + // methods for Axis2 message receivers + + public Object invokeTarget(Operation op, Object[] args, MessageContext inMC) throws InvocationTargetException { + String callbackAddress = null; + String callbackID = null; + Object conversationID = null; + + // create a message object and set the args as its body + Message msg = messageFactory.createMessage(); + msg.setBody(args); + msg.setOperation(op); + + //FIXME: can we use the Axis2 addressing support for this? + SOAPHeader header = inMC.getEnvelope().getHeader(); + if (header != null) { + List hdrList = msg.getHeaders(); + Iterator it = header.getChildElements(); + while (it.hasNext()) { + hdrList.add(it.next()); + } + + OMElement from = header.getFirstChildWithName(QNAME_WSA_FROM); + if (from != null) { + OMElement callbackAddrElement = from.getFirstChildWithName(QNAME_WSA_ADDRESS); + if (callbackAddrElement != null) { + if (contract.getInterfaceContract().getCallbackInterface() != null) { + callbackAddress = callbackAddrElement.getText(); + } + } + OMElement params = from.getFirstChildWithName(QNAME_WSA_REFERENCE_PARAMETERS); + if (params != null) { + OMElement convIDElement = + params.getFirstChildWithName(Axis2BindingInvoker.CONVERSATION_ID_REFPARM_QN); + if (convIDElement != null) { + if (isConversational()) { + conversationID = convIDElement.getText(); + } + } + OMElement callbackIDElement = + params.getFirstChildWithName(Axis2BindingInvoker.CALLBACK_ID_REFPARM_QN); + if (callbackIDElement != null) { + callbackID = callbackIDElement.getText(); + } + } + } + + // get policy specified headers + for (Axis2HeaderPolicy policy : axis2HeaderPolicies){ + //Axis2BindingHeaderConfigurator.getHeader(inMC, msg, policy.getHeaderName()); + } + + if (axis2TokenAuthenticationPolicy != null) { + Axis2SOAPHeaderString tokenHeader = new Axis2SOAPHeaderString(); + Axis2BindingHeaderConfigurator.getHeader(inMC, + msg, + axis2TokenAuthenticationPolicy.getTokenName(), + tokenHeader); + } + } + + //fill message with QoS context info + fillQoSContext(msg, inMC); + + // if reference parameters are needed, create a new "From" EPR to hold them + EndpointReference from = null; + ReferenceParameters parameters = null; + if (callbackAddress != null || + callbackID != null || + conversationID != null) { + from = new EndpointReferenceImpl(null); + parameters = from.getReferenceParameters(); + msg.setFrom(from); + } + + // set the reference parameters into the "From" EPR + if (callbackAddress != null) { + parameters.setCallbackReference(new EndpointReferenceImpl(callbackAddress)); + } + if (callbackID != null) { + parameters.setCallbackID(callbackID); + } + if (conversationID != null) { + parameters.setConversationID(conversationID); + } + + for ( PolicyHandler policyHandler : policyHandlerList ) { + policyHandler.beforeInvoke(msg, inMC); + } + + if (basicAuthenticationPolicy != null) { + Axis2BindingBasicAuthenticationConfigurator.parseHTTPHeader(inMC, msg, basicAuthenticationPolicy); + } + + // find the runtime wire and invoke it with the message + RuntimeWire wire = ((RuntimeComponentService)contract).getRuntimeWire(getBinding()); + Object response = wire.invoke(op, msg); + + for ( PolicyHandler policyHandler : policyHandlerList ) { + policyHandler.afterInvoke(response, inMC); + } + + return response; + } + + public boolean isConversational() { + return wsBinding.getBindingInterfaceContract().getInterface().isConversational(); + } + + /** + * Return the binding for this provider as a primitive binding type + * For use when looking up wires registered against the binding. + * + * @return the binding + */ + protected Binding getBinding() { + return wsBinding; + } + + private void setupPolicyHandlers(List policyHandlers, ConfigurationContext configContext) { + for ( PolicyHandler aHandler : policyHandlers ) { + aHandler.setUp(configContext); + } + } + + private void createPolicyHandlers() throws IllegalAccessException, + InstantiationException, + ClassNotFoundException { + if (wsBinding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)wsBinding; + PolicyHandler policyHandler = null; + + for (PolicySet policySet : policiedBinding.getPolicySets()) { + policyHandler = + PolicyHandlerUtils.findPolicyHandler(policySet, policyHandlerClassnames); + + if (policyHandler != null) { + policyHandler.setApplicablePolicySet(policySet); + policyHandlerList.add(policyHandler); + } + } + + // code to create policy handlers using a policy SPI based + // on policy providers +/* + List policyProviders = ((RuntimeComponentService)contract).getPolicyProviders(wsBinding); + + for (PolicyProvider policyProvider : policyProviders){ + policyHandler = policyProvider.createHandler(); + if (policyHandler != null) { + policyHandlerList.add(policyHandler); + } + } +*/ + } + } + + private void fillQoSContext(Message message, MessageContext axis2MsgCtx) { + if ( axis2MsgCtx.getProperty(WSHandlerConstants.RECV_RESULTS) != null && + axis2MsgCtx.getProperty(WSHandlerConstants.RECV_RESULTS) instanceof Vector ) { + Vector recvResults = (Vector)axis2MsgCtx.getProperty(WSHandlerConstants.RECV_RESULTS); + for ( int count1 = 0 ; count1 < recvResults.size() ; ++count1 ) { + if ( recvResults.elementAt(count1) instanceof WSHandlerResult ) { + WSHandlerResult wshr = (WSHandlerResult)recvResults.elementAt(count1); + Vector results = wshr.getResults(); + for ( int count2 = 0 ; count2 < results.size() ; ++count2 ) { + if ( results.elementAt(count2) instanceof WSSecurityEngineResult ) { + WSSecurityEngineResult securityResult = + (WSSecurityEngineResult)wshr.getResults().elementAt(count2); + if ( securityResult.get("principal") != null ) { + message.getHeaders().add(securityResult.get("principal")); + } + } + } + } + } + + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java new file mode 100644 index 0000000000..debb2c5764 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java @@ -0,0 +1,356 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.net.MalformedURLException; +import java.net.SocketException; +import java.net.URI; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Set; +import java.util.Vector; + +import javax.servlet.GenericServlet; +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.TransportInDescription; +import org.apache.axis2.engine.ListenerManager; +import org.apache.axis2.transport.http.AxisServlet; +import org.apache.axis2.transport.http.ListingAgent; +import org.apache.axis2.transport.http.server.HttpUtils; + +/** + * This overrides the Servlet init of the AxisServlet so Tuscany can use + * a single Axis2 ConfigurationContext instance shared between AxisServlet + * instances for each SCA service with a ws binding. + * TODO: need to review if thats really what we want to be doing + * + * @version $Rev$ $Date$ + */ +public class Axis2ServiceServlet extends AxisServlet { + + protected TuscanyListingAgent agent; + + private static final long serialVersionUID = 1L; + private static final ServletConfig DUMMY_CONFIG = createDummyServletConfig(); + + private boolean initCalled = false; + +//JIRA TUSCANY-1561 Port to Axis2 1.3 + private ConfigurationContext tmpconfigContext; + + public void init(ConfigurationContext configContext) { + this.tmpconfigContext = configContext; + try { + //super.init(DUMMY_CONFIG); + init(DUMMY_CONFIG); + } catch (ServletException e) { + throw new RuntimeException(e); + } + agent = new TuscanyListingAgent(configContext); + } + + /** + * Override Axis2 Servlet method to avoid loop when init + * is called after servletConfig already initialized by + * this classes init(ConfigurationContext) method. + */ + @Override + public void init() throws ServletException { + } + + @Override + public void init(ServletConfig config) throws ServletException { + ServletContext servletContext = config.getServletContext(); + servletContext.setAttribute(CONFIGURATION_CONTEXT, tmpconfigContext); + + //super.init(config); + + // A copy of the init method from the base class because we need to replace the + // version of the ListenerManager that is used so that we can get it's + // shutdown hook removed properly. + + // prevent this method from being called more than once per instance + if (initCalled == false) { + initCalled = true; + // We can't call super.init() as it will just call the AxisServlet version + // which we are replacing here. So reflect on the base class and + // set the private config field in the base class. + //super.init(config); + try { + Field field = GenericServlet.class.getDeclaredField("config"); + field.setAccessible(true); + field.set(this, config); + } catch (Exception ex){ + ex.printStackTrace(); + } + + try { + this.servletConfig = config; + //ServletContext servletContext = servletConfig.getServletContext(); + this.configContext = + (ConfigurationContext) servletContext.getAttribute(CONFIGURATION_CONTEXT); + if(configContext == null){ + configContext = initConfigContext(config); + config.getServletContext().setAttribute(CONFIGURATION_CONTEXT, configContext); + } + axisConfiguration = configContext.getAxisConfiguration(); + + ListenerManager listenerManager = new TuscanyListenerManager(); + listenerManager.init(configContext); + TransportInDescription transportInDescription = new TransportInDescription( + Constants.TRANSPORT_HTTP); + transportInDescription.setReceiver(this); + listenerManager.addListener(transportInDescription, true); + listenerManager.start(); + ListenerManager.defaultConfigurationContext = configContext; + super.agent = new ListingAgent(configContext); + + initParams(); + + } catch (Exception e) { + throw new ServletException(e); + } + } + } + + /** + * We've setup the Servlet by passing in a ConfigurationContext on our init method + * override this method to just return that + */ + @Override + protected ConfigurationContext initConfigContext(ServletConfig config) throws ServletException { + return this.tmpconfigContext; + } + + @Override + public ServletConfig getServletConfig() { + return DUMMY_CONFIG; + } + + @Override + public String getServletName() { + return "TuscanyAxis2Servlet"; + } + + /** + * The AxisServlet gets NPE during init without a ServletConfig so this is a mocked up one to prevent that. + */ + private static ServletConfig createDummyServletConfig() { + ServletConfig sc = new ServletConfig() { + + public String getServletName() { + return "TuscanyAxis2DummyServlet"; + } + + public ServletContext getServletContext() { + return new ServletContext() { + + public ServletContext getContext(String uripath) { + return null; + } + + @SuppressWarnings("unused") // it's on the Servlet 2.5 API so we need it + public String getContextPath() { + return null; + } + + public int getMajorVersion() { + return 0; + } + + public int getMinorVersion() { + return 0; + } + + public String getMimeType(String file) { + return null; + } + + public Set getResourcePaths(String path) { + return Collections.emptySet(); + } + + public URL getResource(String path) throws MalformedURLException { + if("/".equals(path)) { + // HACK: To avoid NPE + return new URL("/axis2"); + } + return null; + } + + public InputStream getResourceAsStream(String path) { + return null; + } + + public RequestDispatcher getRequestDispatcher(String path) { + return null; + } + + public RequestDispatcher getNamedDispatcher(String arg0) { + return null; + } + + public Servlet getServlet(String arg0) throws ServletException { + return null; + } + + public Enumeration getServlets() { + return null; + } + + public Enumeration getServletNames() { + return null; + } + + public void log(String arg0) { + } + + public void log(Exception arg0, String arg1) { + } + + public void log(String arg0, Throwable arg1) { + } + + public String getRealPath(String arg0) { + return null; + } + + public String getServerInfo() { + return null; + } + + public String getInitParameter(String arg0) { + return null; + } + + public Enumeration getInitParameterNames() { + return null; + } + + public Object getAttribute(String arg0) { + return null; + } + + public Enumeration getAttributeNames() { + return null; + } + + public void setAttribute(String arg0, Object arg1) { + } + + public void removeAttribute(String arg0) { + } + + public String getServletContextName() { + return null; + } + }; + } + + public String getInitParameter(String arg0) { + return null; + } + + public Enumeration getInitParameterNames() { + return new Vector().elements(); + } + }; + return sc; + } + + @Override + public void destroy() { + try { + super.destroy(); + servletConfig = null; + if (tmpconfigContext.getListenerManager() != null){ + tmpconfigContext.getListenerManager().destroy(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * Override the AxisServlet doGet to use the TuscanyListingAgent for ?wsdl + */ + @Override + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + initContextRoot(request); + + String query = request.getQueryString(); + if ((query != null) && (query.indexOf("wsdl2") >= 0 || + query.indexOf("wsdl") >= 0 || query.indexOf("xsd") >= 0 || + query.indexOf("policy") >= 0)) { + agent.processListService(request, response); + } else { + super.doGet(request, response); + } + } + + /** + + /** + * Override the AxisServlet method so as to not add "/services" into the URL + * and to work with Tuscany service names. can go once moved to Axis2 1.3 + */ + @Override + public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault { + //RUNNING_PORT + String port = (String) configContext.getProperty(ListingAgent.RUNNING_PORT); + if (port == null) { + port = "8080"; + } + if (ip == null) { + try { + ip = HttpUtils.getIpAddress(); + if (ip == null) { + ip = "localhost"; + } + } catch (SocketException e) { +//TUSCANY-1561 Port to Axis2 1.3 +// throw new AxisFault.(e); + throw AxisFault.makeFault(e); + } + } + + URI epURI = URI.create("http://" + ip + ":" + port + "/" + serviceName).normalize(); + + return new EndpointReference[]{new EndpointReference(epURI.toString())}; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/AxisPolicyHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/AxisPolicyHelper.java new file mode 100644 index 0000000000..1f389b422f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/AxisPolicyHelper.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.sca.binding.ws.axis2; + +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * @version $Rev$ $Date$ + */ +public class AxisPolicyHelper { + + public static final String XMLNS_SCA_1_0 = "http://www.osoa.org/xmlns/sca/1.0"; + public static final QName AUTHENTICATION_INTENT = new QName(XMLNS_SCA_1_0, "authentication"); + public static final QName CONFIDENTIALITY_INTENT = new QName(XMLNS_SCA_1_0, "confidentiality"); + public static final QName INTEGRITY_INTENT = new QName(XMLNS_SCA_1_0, "integrity"); + public static final QName MTOM_INTENT = new QName(XMLNS_SCA_1_0, "MTOM"); + public static final QName SOAP12_INTENT = new QName(XMLNS_SCA_1_0, "SOAP12"); + + public static PolicySet getPolicySet(Binding wsBinding, QName intentName) { + PolicySet returnPolicySet = null; + + if (wsBinding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)wsBinding; + for (PolicySet policySet : policiedBinding.getPolicySets()) { + for (Intent intent : policySet.getProvidedIntents()) { + if (intent.getName().equals(intentName)) { + returnPolicySet = policySet; + break; + } + } + } + } + + return returnPolicySet; + } + + public static boolean isIntentRequired(Binding wsBinding, QName intent) { + if (wsBinding instanceof IntentAttachPoint) { + List intents = ((IntentAttachPoint)wsBinding).getRequiredIntents(); + for (Intent i : intents) { + if (intent.equals(i.getName())) { + return true; + } + } + } + return getPolicySet(wsBinding, intent) != null; + } + + public static boolean isRampartRequired(Binding wsBinding) { + return isIntentRequired(wsBinding, AUTHENTICATION_INTENT) || isIntentRequired(wsBinding, INTEGRITY_INTENT) + || isIntentRequired(wsBinding, CONFIDENTIALITY_INTENT); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java new file mode 100644 index 0000000000..bd154dbc67 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java @@ -0,0 +1,207 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.deployment.DeploymentConstants; +import org.apache.axis2.deployment.DeploymentErrorMsgs; +import org.apache.axis2.deployment.DeploymentException; +import org.apache.axis2.deployment.ModuleBuilder; +import org.apache.axis2.deployment.URLBasedAxisConfigurator; +import org.apache.axis2.description.AxisModule; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.axis2.engine.AxisConfigurator; +import org.apache.axis2.i18n.Messages; +import org.apache.axis2.util.Loader; + +/** + * Helps configure Axis2 from a resource in binding.ws.axis2 instead of Axis2.xml + *

TODO: Review: should there be a single global Axis ConfigurationContext + * + * @version $Rev$ $Date$ + */ +public class TuscanyAxisConfigurator extends URLBasedAxisConfigurator implements AxisConfigurator { + + /* these two fields are part of a temporary fix to solve problems that Maven has with including + * rampart-1.4.mar into the classpath and also at the time of Release 1.0 rampart-1.4.mar seems + * to pull in a SNAPSHOT version of rampart-project pom. Hence rampart.mar has been excluded + * as a Maven dependency and has been packed with this module + */ + /************start of fix *********************************************************************/ + private URL axis2_xml = + getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml"); + private URL axis2_repository = null; + private URL rampart_mar_url = + getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.4.mar"); + /************** end of fix *************************************************************/ + + private boolean isRampartRequired; + + public TuscanyAxisConfigurator(boolean isRampartRequired) throws AxisFault { + //super(TuscanyAxisConfigurator.class.getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml"), + // TuscanyAxisConfigurator.class.getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart.mar")); + super(getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml"), + null); + this.isRampartRequired = isRampartRequired; + } + + private static URL getResource(final String name) { + return AccessController.doPrivileged(new PrivilegedAction() { + public URL run() { + return TuscanyAxisConfigurator.class.getResource(name); + } + }); + } + + public ConfigurationContext getConfigurationContext() throws AxisFault { + if (configContext == null) { + configContext = ConfigurationContextFactory.createConfigurationContext(this); + } + return configContext; + } + + /* these three methods are part of a temporary fix to solve problems that Maven has with including + * rampart-1.3.mar into the classpath and also at the time of Release 1.0 rampart-1.3.mar seems + * to pull in a SNAPSHOT version of rampart-project pom. Hence rampart.mar has been excluded + * as a Maven dependency and has been packed with this module + */ + /************start of fix *********************************************************************/ + @Override + public AxisConfiguration getAxisConfiguration() throws AxisFault { + InputStream axis2xmlStream; + try { + if (axis2_xml == null) { + axis2xmlStream = + Loader.getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE); + } else { + axis2xmlStream = axis2_xml.openStream(); + } + axisConfig = populateAxisConfiguration(axis2xmlStream); + if (isRampartRequired) { + axisConfig.addGlobalModuleRef("rampart"); + } + if (axis2_repository == null) { + Parameter axis2repoPara = axisConfig.getParameter(DeploymentConstants.AXIS2_REPO); + if (axis2repoPara != null) { + String repoValue = (String) axis2repoPara.getValue(); + if (repoValue != null && !"".equals(repoValue.trim())) { + if (repoValue.startsWith("file:/")) { + // we treat this case specially , by assuming file is + // located in the local machine + loadRepository(repoValue); + } else { + loadRepositoryFromURL(new URL(repoValue)); + } + } + } else { + //log.info("No repository found , module will be loaded from classpath"); + try { + loadFromClassPath(); + } catch ( Exception e ) { + if (isRampartRequired) { + loadRampartModule(); + } + } + } + + } else { + loadRepositoryFromURL(axis2_repository); + } + + } catch (IOException e) { + throw new AxisFault(e.getMessage()); + } + axisConfig.setConfigurator(this); + return axisConfig; + } + + public void loadRampartModule() throws DeploymentException { + try { + ClassLoader deploymentClassLoader = + org.apache.axis2.deployment.util.Utils.createClassLoader( + new URL[]{rampart_mar_url}, + axisConfig.getModuleClassLoader(), + true, + (File) axisConfig.getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR)); + final AxisModule module = new AxisModule(); + module.setModuleClassLoader(deploymentClassLoader); + module.setParent(axisConfig); + //String moduleFile = fileUrl.substring(0, fileUrl.indexOf(".mar")); + if (module.getName() == null) { + module.setName(org.apache.axis2.util.Utils.getModuleName("rampart-1.4")); + module.setVersion(org.apache.axis2.util.Utils.getModuleVersion("rampart-1.4")); + } + populateModule(module, rampart_mar_url); + module.setFileName(rampart_mar_url); + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws IOException { + addNewModule(module, axisConfig); + return null; + } + }); + } catch (PrivilegedActionException e) { + throw (AxisFault)e.getException(); + } + + org.apache.axis2.util.Utils. + calculateDefaultModuleVersion(axisConfig.getModules(), axisConfig); + axisConfig.validateSystemPredefinedPhases(); + } catch (IOException e) { + throw new DeploymentException(e); + } + } + + private void populateModule(AxisModule module, URL moduleUrl) throws DeploymentException { + try { + ClassLoader classLoader = module.getModuleClassLoader(); + InputStream moduleStream = classLoader.getResourceAsStream("META-INF/module.xml"); + if (moduleStream == null) { + moduleStream = classLoader.getResourceAsStream("meta-inf/module.xml"); + } + if (moduleStream == null) { + throw new DeploymentException( + Messages.getMessage( + DeploymentErrorMsgs.MODULE_XML_MISSING, moduleUrl.toString())); + } + ModuleBuilder moduleBuilder = new ModuleBuilder(moduleStream, module, axisConfig); + moduleBuilder.populateModule(); + } catch (IOException e) { + throw new DeploymentException(e); + } + } + + /************** end of fix *************************************************************/ + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.java new file mode 100644 index 0000000000..34899a4af0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.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.sca.binding.ws.axis2; + +import java.net.URI; +import java.util.HashMap; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.HandlerDescription; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.axis2.engine.RequestURIBasedDispatcher; +import org.apache.axis2.util.JavaUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * A Tuscany specific Axis2 Dispatcher that enables using services + * exposed at the SCA defined service URI instead of /services/ + * + * @version $Rev$ $Date$ + */ +public class TuscanyDispatcher extends RequestURIBasedDispatcher { + + public static final String NAME = "TuscanyDispatcher"; + private static final Log log = LogFactory.getLog(RequestURIBasedDispatcher.class); + private static final boolean isDebugEnabled = log.isDebugEnabled(); + + /* + * (non-Javadoc) + * + * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext) + */ + @Override + public AxisService findService(MessageContext messageContext) throws AxisFault { + EndpointReference toEPR = messageContext.getTo(); + + if (toEPR != null) { + if(isDebugEnabled){ + log.debug("Checking for Service using target endpoint address : " + toEPR.getAddress()); + } + + String path = URI.create(toEPR.getAddress()).getPath(); + + ConfigurationContext configurationContext = messageContext.getConfigurationContext(); + AxisConfiguration registry = configurationContext.getAxisConfiguration(); + + String serviceName = findAxisServiceName(registry, path); + return registry.getService(serviceName); + + } else { + if(isDebugEnabled){ + log.debug("Attempted to check for Service using null target endpoint URI"); + } + return null; + } + } + + @Override + public void initDispatcher() { + init(new HandlerDescription(NAME)); + } + + protected String findAxisServiceName(AxisConfiguration registry, String path) { + HashMap services = registry.getServices(); + if (services == null) { + return null; + } + String[] parts = JavaUtils.split(path, '/'); + String serviceName = ""; + for (int i=parts.length-1; i>=0; i--) { + serviceName = parts[i] + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + serviceName = "/" + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + } + + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListenerManager.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListenerManager.java new file mode 100644 index 0000000000..7d331aa6c8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListenerManager.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Iterator; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.TransportInDescription; +import org.apache.axis2.engine.ListenerManager; +import org.apache.axis2.transport.TransportListener; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * A Tuscany specific Axis2 ListenerManager. Created purely as part of + * TUSCANY-3149 to unregister the ListenerManager from the runtime + * shutown hook + */ +public class TuscanyListenerManager extends ListenerManager { + private static final Log log = LogFactory.getLog(TuscanyListenerManager.class); + + private ListenerManagerShutdownThread shutdownThread = null; + + /** + * To start all the transports + */ + public synchronized void start() { + + ConfigurationContext configctx = getConfigctx(); + + // very nasty! but this is in order to get someone running who keeps + // getting perm gen errors. This will all go away when we move up to Axis2 1.5 + HashMap startedTransports = null; + + try { + Field field = ListenerManager.class.getDeclaredField("startedTransports"); + field.setAccessible(true); + startedTransports = (HashMap)field.get(this); + } catch (Exception ex){ + ex.printStackTrace(); + } + + for (Iterator transportNames = + configctx.getAxisConfiguration().getTransportsIn().values().iterator(); + transportNames.hasNext();) { + try { + TransportInDescription transportIn = (TransportInDescription) transportNames.next(); + TransportListener listener = transportIn.getReceiver(); + if (listener != null && + startedTransports.get(transportIn.getName()) == null) { + listener.init(configctx, transportIn); + listener.start(); + if (startedTransports.get(transportIn.getName()) == null) { + startedTransports.put(transportIn.getName(), listener); + } + } + } catch (Exception e) { + log.info(e.getMessage(), e); + } + } + shutdownThread = new ListenerManagerShutdownThread(this); + Runtime.getRuntime().addShutdownHook(shutdownThread); + } + + public synchronized void stop() throws AxisFault { + super.stop(); + Runtime.getRuntime().removeShutdownHook(shutdownThread); + } + + static class ListenerManagerShutdownThread extends Thread { + ListenerManager listenerManager; + + public ListenerManagerShutdownThread(ListenerManager listenerManager) { + super(); + this.listenerManager = listenerManager; + } + + public void run() { + try { + listenerManager.stop(); + } catch (AxisFault axisFault) { + log.error(axisFault.getMessage(), axisFault); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java new file mode 100644 index 0000000000..bde688c9bf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java @@ -0,0 +1,237 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.axiom.attachments.utils.IOUtils; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.deployment.DeploymentConstants; +import org.apache.axis2.description.AxisDescription; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.description.PolicyInclude; +import org.apache.axis2.transport.http.ListingAgent; +import org.apache.axis2.util.ExternalPolicySerializer; +import org.apache.axis2.util.JavaUtils; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.neethi.Policy; +import org.apache.neethi.PolicyRegistry; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaExternal; + +/** + * A Tuscany specific Axis2 ListingAgent as the Axis2 one does not work + * with the Tuscany service names which include slash ('/') characters. + * Unfortunately it ends up having to copy a fair amount of Axis2 code to do this. + * + * @version $Rev$ $Date$ + */ +public class TuscanyListingAgent extends ListingAgent { + + private static final String LIST_SINGLE_SERVICE_JSP_NAME = + "listSingleService.jsp"; + + public TuscanyListingAgent(ConfigurationContext aConfigContext) { + super(aConfigContext); + } + + /** + * This method overrides the Axis2 listing agent's computation of the + * service name. + */ + @Override + public String extractServiceName(String urlString) { + String serviceName = findAxisServiceName(urlString); + setContextRoot(urlString, serviceName); + return serviceName; + } + + /** + * Override ?xsd processing so that WSDL documents with XSD imports + * and includes work correctly. When we move to Axis2 1.4, we may + * be able to use SchemaSupplier to do this in a cleaner way. Also + * ensure that the correct IP address and port are returned by ?wsdl. + */ + @Override + public void processListService(HttpServletRequest req, + HttpServletResponse res) + throws IOException, ServletException { + + String url = req.getRequestURL().toString(); + String query = req.getQueryString(); + + // for ?wsdl requests, need to update the WSDL with correct IPaddr and port + int wsdl = query.indexOf("wsdl"); + if (wsdl >= 0) { + String serviceName = extractServiceName(url); + HashMap services = configContext.getAxisConfiguration().getServices(); + if ((services != null) && !services.isEmpty()) { + AxisService axisService = (AxisService)services.get(serviceName); + Parameter wsld4jdefinition = axisService.getParameter(WSDLConstants.WSDL_4_J_DEFINITION); + Definition definition = (Definition)wsld4jdefinition.getValue(); + for (Object s : definition.getServices().values()) { + for (Object p : ((Service)s).getPorts().values()) { + String endpointURL = Axis2ServiceProvider.getPortAddress((Port)p); + String modifiedURL = setIPAddress(endpointURL, url); + Axis2ServiceProvider.setPortAddress((Port)p, modifiedURL); + } + } + } + } + + // handle ?xsd requests here + int xsd = query.indexOf("xsd"); + if (xsd >= 0) { + String serviceName = extractServiceName(url); + HashMap services = configContext.getAxisConfiguration().getServices(); + if ((services != null) && !services.isEmpty()) { + Object serviceObj = services.get(serviceName); + if (serviceObj != null) { + String xsds = req.getParameter("xsd"); + if (xsds != null && !"".equals(xsds)) { + // a schema name (perhaps with path) is present + AxisService axisService = (AxisService)serviceObj; + ArrayList schemas = axisService.getSchema(); + for (Object rootSchema : axisService.getSchema()) { + XmlSchema schema = getSchema(((XmlSchema)rootSchema), xsds); + if (schema != null) { + // found the schema + res.setContentType("text/xml"); + OutputStream out = res.getOutputStream(); + schema.write(new OutputStreamWriter(out, "UTF8")); + out.flush(); + out.close(); + return; + } + } + } + } + } + } + + // in all other cases, delegate to the Axis2 code + super.processListService(req, res); + } + + private XmlSchema getSchema(XmlSchema parentSchema, String name) { + for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof XmlSchemaExternal) { + XmlSchemaExternal extSchema = (XmlSchemaExternal)obj; + if (extSchema.getSchemaLocation().endsWith(name)) { + return extSchema.getSchema(); + } else { + XmlSchema schema = getSchema(extSchema.getSchema(), name); + if (schema != null) { + return schema; + } + } + } + } + return null; + } + + private String findAxisServiceName(String path) { + HashMap services = configContext.getAxisConfiguration().getServices(); + if (services == null) { + return null; + } + String[] parts = JavaUtils.split(path, '/'); + String serviceName = ""; + for (int i=parts.length-1; i>=0; i--) { + serviceName = parts[i] + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + serviceName = "/" + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + } + + return null; + } + + /** + * Hack for Tuscany to get ?wsdl working with Tuscany service names + * Can go once moved up to Axis2 1.3 + */ + private void setContextRoot(String filePart, String serviceName) { + String contextRoot = configContext.getContextRoot(); + if (contextRoot != null && contextRoot.length() > 0) { + if (contextRoot.equals("/")) { + configContext.setServicePath("/"); + } else { + int i = filePart.indexOf(contextRoot) + contextRoot.length(); + int j = filePart.lastIndexOf(serviceName); + if (i>=j || (i+1 == j)) { + configContext.setServicePath("/"); + } else { + String mapping = filePart.substring(i+1, j); + configContext.setServicePath(mapping); + } + } + configContext.setContextRoot(contextRoot); + } + } + + private static String setIPAddress(String wsdlURI, String requestURI) { + try { + URI wsdlURIObj = new URI(wsdlURI); + String wsdlHost = wsdlURIObj.getHost(); + int wsdlPort = wsdlURIObj.getPort(); + String wsdlAddr = wsdlHost + (wsdlPort != -1 ? ":" + Integer.toString(wsdlPort) : ""); + URI requestURIObj = new URI(requestURI); + String ipAddr = requestURIObj.getHost(); + int requestPort = requestURIObj.getPort(); + String newAddr = ipAddr + (requestPort != -1 ? ":" + Integer.toString(requestPort) : ""); + return wsdlURI.replace(wsdlAddr, newAddr); + } catch (Exception e) { + // URI string not in expected format, so return the WSDL URI unmodified + return wsdlURI; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/WSBindingDefinitionsProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/WSBindingDefinitionsProvider.java new file mode 100644 index 0000000000..5254a5716c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/WSBindingDefinitionsProvider.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.sca.binding.ws.axis2; + +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; + +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.provider.SCADefinitionsProvider; +import org.apache.tuscany.sca.provider.SCADefinitionsProviderException; + +/** + * Provider for Policy Intents and PolicySet definitions related to security + * + * @version $Rev$ $Date$ + */ +public class WSBindingDefinitionsProvider implements SCADefinitionsProvider { + private String definitionsFile = "org/apache/tuscany/sca/binding/ws/axis2/definitions.xml"; + URLArtifactProcessor urlArtifactProcessor = null; + + public WSBindingDefinitionsProvider(ExtensionPointRegistry registry) { + URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + urlArtifactProcessor = (URLArtifactProcessor)documentProcessors.getProcessor(SCADefinitions.class); + } + + public SCADefinitions getSCADefinition() throws SCADefinitionsProviderException { + final URL definitionsFileUrl = getClass().getClassLoader().getResource(definitionsFile); + SCADefinitions scaDefn = null; + try { + final URI uri = new URI(definitionsFile); + // Allow bindings to read properties. Requires PropertyPermission read in security policy. + scaDefn = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public SCADefinitions run() throws ContributionReadException { + return (SCADefinitions)urlArtifactProcessor.read(null, uri, definitionsFileUrl); + } + }); + } catch (Exception e) { + throw new SCADefinitionsProviderException(e); + } + return scaDefn; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/AxisJMSException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/AxisJMSException.java new file mode 100644 index 0000000000..09a1960ce4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/AxisJMSException.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.sca.binding.ws.axis2.jms; + +public class AxisJMSException extends RuntimeException { + + AxisJMSException() { + super(); + } + + AxisJMSException(String msg) { + super(msg); + } + + AxisJMSException(String msg, Exception e) { + super(msg, e); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSConnectionFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSConnectionFactory.java new file mode 100644 index 0000000000..a96ec0b1c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSConnectionFactory.java @@ -0,0 +1,605 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.jms; + +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.Topic; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; + +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.transport.jms.JMSConstants; +import org.apache.axis2.transport.jms.JMSUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tuscany.sca.work.WorkScheduler; + +/** + * Encapsulate a JMS Connection factory definition within an Axis2.xml + *

+ * More than one JMS connection factory could be defined within an Axis2 XML + * specifying the JMSListener as the transportReceiver. + *

+ * These connection factories are created at the initialization of the + * transportReceiver, and any service interested in using any of these could + * specify the name of the factory and the destination through Parameters named + * JMSConstants.CONFAC_PARAM and JMSConstants.DEST_PARAM as shown below. + *

+ * myQueueConnectionFactory + * TestQueue + *

+ * If a connection factory is defined by a parameter named + * JMSConstants.DEFAULT_CONFAC_NAME in the Axis2 XML, services which does not + * explicitly specify a connection factory will be defaulted to it - if it is + * defined in the Axis2 configuration. + *

+ * e.g. + * + * + * org.apache.activemq.jndi.ActiveMQInitialContextFactory + * tcp://localhost:61616 + * TopicConnectionFactory + * myTopicOne, myTopicTwo + * + * + * org.apache.activemq.jndi.ActiveMQInitialContextFactory + * tcp://localhost:61616 + * QueueConnectionFactory + * myQueueOne, myQueueTwo + * + * + * org.apache.activemq.jndi.ActiveMQInitialContextFactory + * tcp://localhost:61616 + * ConnectionFactory + * myDestinationOne, myDestinationTwo + * + * + */ +public class JMSConnectionFactory { + + private static final Log log = LogFactory.getLog(JMSConnectionFactory.class); + + /** + * The name used for the connection factory definition within Axis2 + */ + private String name = null; + /** + * The JNDI name of the actual connection factory + */ + private String jndiName = null; + /** + * The JNDI name of the actual connection factory username + */ + private String jndiUser = null; + /** + * The JNDI name of the actual connection factory password + */ + private String jndiPass = null; + /** + * Map of destination JNDI names to service names + */ + private Map serviceJNDINameMapping = null; + /** + * Map of destinations to service names + */ + private Map serviceDestinationMapping = null; + /** + * The JMS Sessions listening for messages + */ + private Map jmsSessions = null; + /** + * Properties of the connection factory + */ + private Hashtable properties = null; + /** + * The JNDI Context used + */ + private Context context = null; + /** + * The actual ConnectionFactory instance held within + */ + private ConnectionFactory conFactory = null; + /** + * The JMS Connection is opened. + */ + private Connection connection = null; + /** + * The JMS Message receiver for this connection factory + */ + private JMSMessageReceiver msgRcvr = null; + /** + * The actual password for the connection factory after retrieval from JNDI. + * If this is not supplied, the OS username will be used by default + */ + private String user = null; + /** + * The actual password for the connection factory after retrieval from JNDI. + * If this is not supplied, the OS credentials will be used by default + */ + private String pass = null; + + private WorkScheduler workScheduler; + private boolean consumerRunning; + + /** + * Create a JMSConnectionFactory for the given Axis2 name and JNDI name + * + * @param name the local Axis2 name of the connection factory + * @param jndiName the JNDI name of the actual connection factory used + */ + JMSConnectionFactory(String name, String jndiName, WorkScheduler workScheduler) { + this.name = name; + this.jndiName = jndiName; + serviceJNDINameMapping = new HashMap(); + serviceDestinationMapping = new HashMap(); + properties = new Hashtable(); + jmsSessions = new HashMap(); + this.workScheduler = workScheduler; + } + + /** + * Create a JMSConnectionFactory for the given Axis2 name + * + * @param name the local Axis2 name of the connection factory + */ + JMSConnectionFactory(String name, WorkScheduler workScheduler) { + this(name, null, workScheduler); + } + + /** + * Connect to the actual JMS connection factory specified by the JNDI name + * + * @throws NamingException if the connection factory cannot be found + */ + public void connect() throws NamingException { + if (context == null) { + createInitialContext(); + } + conFactory = (ConnectionFactory) context.lookup(jndiName); + + if (jndiUser != null) + user = (String ) context.lookup(jndiUser); + + if (jndiPass != null) + pass = (String ) context.lookup(jndiPass); + + log.debug("Connected to the actual connection factory : " + jndiName); + } + + /** + * Creates the initial context using the set properties + * + * @throws NamingException + */ + private void createInitialContext() throws NamingException { + context = new InitialContext(properties); + } + + /** + * Set the JNDI connection factory name + * + * @param jndiName + */ + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + /** + * Get the JNDI name of the actual factory username + * + * @return the jndi name of the actual connection factory username + */ + public void setJndiUser(String jndiUser) { + this.jndiUser = jndiUser; + } + + /** + * Get the JNDI name of the actual factory password + * + * @return the jndi name of the actual connection factory password + */ + public void setJndiPass(String jndiPass) { + this.jndiPass = jndiPass; + } + + /** + * Add a listen destination on this connection factory on behalf of the given service + * + * @param destinationJndi destination JNDI name + * @param serviceName the service to which it belongs + */ + public void addDestination(String destinationJndi, String serviceName) { + + serviceJNDINameMapping.put(destinationJndi, serviceName); + String destinationName = getDestinationName(destinationJndi); + + if (destinationName == null) { + log.warn("JMS Destination with JNDI name : " + destinationJndi + " does not exist"); + + Connection con = null; + try { + if ((jndiUser == null) || (jndiPass == null)){ + // Use the OS username and credentials + con = conFactory.createConnection(); + } else{ + // use an explicit username and password + con = conFactory.createConnection(user, pass); + } + Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); + Queue queue = session.createQueue(destinationJndi); + destinationName = queue.getQueueName(); + log.warn("JMS Destination with JNDI name : " + destinationJndi + " created"); + + } catch (JMSException e) { + log.error("Unable to create a Destination with JNDI name : " + destinationJndi, e); + // mark service as faulty + JMSUtils.markServiceAsFaulty( + (String) serviceJNDINameMapping.get(destinationJndi), + "Error looking up JMS destination : " + destinationJndi, + msgRcvr.getAxisConf().getAxisConfiguration()); + + } finally { + if (con != null) { + try { + con.close(); + } catch (JMSException ignore) {} + } + } + } + + serviceDestinationMapping.put(destinationName, serviceName); + log.info("Mapping JNDI name : " + destinationJndi + " and JMS Destination name : " + + destinationName + " against service : " + serviceName); + } + + /** + * Remove listen destination on this connection factory + * + * @param destinationJndi the JMS destination to be removed + * @throws if an error occurs trying to stop listening for messages before removal + */ + public void removeDestination(String destinationJndi) throws JMSException { + // find and save provider specific Destination name before we delete + String providerSpecificDestination = getDestinationName(destinationJndi); + stoplistenOnDestination(destinationJndi); + serviceJNDINameMapping.remove(destinationJndi); + if (providerSpecificDestination != null) { + serviceDestinationMapping.remove(providerSpecificDestination); + } + } + + /** + * Add a property to the connection factory + * + * @param key + * @param value + */ + public void addProperty(String key, String value) { + properties.put(key, value); + } + + /** + * Return the name of the connection factory + * + * @return the Axis2 name of this factory + */ + public String getName() { + return name; + } + + /** + * Get the JNDI name of the actual factory + * + * @return the jndi name of the actual connection factory + */ + public String getJndiName() { + return jndiName; + } + + /** + * Get the JNDI name of the actual factory username + * + * @return the jndi name of the actual connection factory username + */ + public String getJndiUser() { + return jndiUser; + } + + /** + * Get the JNDI name of the actual factory password + * + * @return the jndi name of the actual connection factory password + */ + public String getJndiPass() { + return jndiPass; + } + + + /** + * This is the real password for the connection factory after the JNDI lookup + * + * @return the real password for the connection factory after the JNDI lookup + */ + public String getPass() { + return pass; + } + + /** + * This is the real username for the connection factory after the JNDI lookup + * + * @return the eal username for the connection factory after the JNDI lookup + */ + public String getUser() { + return user; + } + + /** + * Get the actual underlying connection factory + * + * @return actual connection factory + */ + public ConnectionFactory getConFactory() { + return conFactory; + } + + /** + * Get the list of destinations (JNDI) associated with this connection factory + * + * @return destinations to service maping + */ + public Map getDestinations() { + return serviceJNDINameMapping; + } + + /** + * Get the connection factory properties + * + * @return properties + */ + public Hashtable getProperties() { + return properties; + } + + /** + * Begin listening for messages on the list of destinations associated + * with this connection factory. (Called during Axis2 initialization of + * the Transport receivers) + * + * @param msgRcvr the message receiver which will process received messages + * @throws JMSException on exceptions + */ + public void listen(JMSMessageReceiver msgRcvr) throws JMSException { + + // save a reference to the message receiver + this.msgRcvr = msgRcvr; + + log.debug("Connection factory : " + name + " initializing..."); + + if (conFactory == null || context == null) { + handleException( + "Connection factory must be 'connected' before listening"); + } else { + try { + if ((jndiUser == null) || (jndiPass == null)){ + // User the OS username and credentials + connection = conFactory.createConnection(); + } else{ + // use an explicit username and password + connection = conFactory.createConnection(user, pass); + } + } catch (JMSException e) { + handleException("Error creating a JMS connection using the " + + "factory : " + jndiName, e); + } + } + + Iterator iter = serviceJNDINameMapping.keySet().iterator(); + while (iter.hasNext()) { + String destinationJndi = (String) iter.next(); + listenOnDestination(destinationJndi); + } + + // start the connection + if (!consumerRunning) { + connection.start(); + } + log.info("Connection factory : " + name + " initialized..."); + } + + /** + * Listen on the given destination from this connection factory. Used to + * start listening on a destination associated with a newly deployed service + * + * @param destinationJndi the JMS destination to listen on + * @throws JMSException on exception + */ + public void listenOnDestination(String destinationJndi) throws JMSException { + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Destination destination = null; + try { + Object o = context.lookup(destinationJndi); + destination = (Destination) o; + + } catch (NameNotFoundException e) { + log.warn("Cannot find destination : " + destinationJndi + + " Creating a Queue with this name"); + destination = session.createQueue(destinationJndi); + + } catch (NamingException e) { + log.warn("Error looking up destination : " + destinationJndi, e); + // mark service as faulty + JMSUtils.markServiceAsFaulty( + (String) serviceJNDINameMapping.get(destinationJndi), + "Error looking up JMS destination : " + destinationJndi, + this.msgRcvr.getAxisConf().getAxisConfiguration()); + } + + MessageConsumer consumer = session.createConsumer(destination); +// consumer.setMessageListener(this.msgRcvr); replace with new Tuscany method: + registerMessageReceiver(consumer, this.msgRcvr); + jmsSessions.put(destinationJndi, session); + } + + private void registerMessageReceiver(final MessageConsumer consumer, final JMSMessageReceiver messageReceiver) throws JMSException { + + try { + + consumer.setMessageListener(messageReceiver); + + } catch (javax.jms.JMSException e) { + + // setMessageListener not allowed in JEE container so use Tuscany threads + + connection.start(); + consumerRunning = true; + + workScheduler.scheduleWork(new Runnable() { + + public void run() { + try { + while (consumerRunning) { + final Message msg = consumer.receive(); + if (msg != null) { + workScheduler.scheduleWork(new Runnable() { + public void run() { + try { + messageReceiver.onMessage(msg); + } catch (Exception e) { + log.error("Exception on message receiver thread", e); + } + } + }); + } + } + } catch (Exception e) { + log.error("Exception on consumer receive thread", e); + } + } + }); + } + } + + /** + * Stop listening on the given destination - for undeployment of services + * + * @param destinationJndi the JNDI name of the JMS destination + * @throws JMSException on exception + */ + private void stoplistenOnDestination(String destinationJndi) throws JMSException { + ((Session) jmsSessions.get(destinationJndi)).close(); + } + + /** + * Return the service name using this destination + * + * @param destination the destination name + * @return the service which uses the given destination, or null + */ + public String getServiceNameForDestination(String destination) { + + return (String) serviceJNDINameMapping.get(destination); + } + + /** + * Close all connections, sessions etc.. and stop this connection factory + */ + public void stop() { + try { + consumerRunning = false; + connection.close(); + } catch (JMSException e) { + log.warn("Error shutting down connection factory : " + name, e); + } + } + + /** + * Return the provider specific Destination name if any for the destination with the given + * JNDI name + * @param destinationJndi the JNDI name of the destination + * @return the provider specific Destination name or null if cannot be found + */ + public String getDestinationName(String destinationJndi) { + try { + Destination destination = (Destination) context.lookup(destinationJndi); + if (destination != null && destination instanceof Queue) { + return ((Queue) destination).getQueueName(); + } else if (destination != null && destination instanceof Topic) { + return ((Topic) destination).getTopicName(); + } + } catch (JMSException e) { + log.warn("Error reading provider specific JMS destination name for destination " + + "with JNDI name : " + destinationJndi, e); + } catch (NamingException e) { + log.warn("Error looking up destination with JNDI name : " + destinationJndi + + " to map its corresponding provider specific Destination name"); + } + return null; + } + + /** + * Return the EPR for the JMS Destination with the given JNDI name and using + * this connection factory + * @param destination the JNDI name of the JMS Destionation + * @return the EPR + */ + public EndpointReference getEPRForDestination(String destination) { + + StringBuffer sb = new StringBuffer(); + sb.append(JMSConstants.JMS_PREFIX).append(destination); + sb.append("?").append(JMSConstants.CONFAC_JNDI_NAME_PARAM). + append("=").append(getJndiName()); + Iterator props = getProperties().keySet().iterator(); + while (props.hasNext()) { + String key = (String) props.next(); + String value = (String) getProperties().get(key); + sb.append("&").append(key).append("=").append(value); + } + + return new EndpointReference(sb.toString()); + } + + public String getServiceByDestination(String destinationName) { + return (String) serviceDestinationMapping.get(destinationName); + } + + private void handleException(String msg) throws AxisJMSException { + log.error(msg); + throw new AxisJMSException(msg); + } + + private void handleException(String msg, Exception e) throws AxisJMSException { + log.error(msg, e); + throw new AxisJMSException(msg, e); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSListener.java new file mode 100644 index 0000000000..08190fb57c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSListener.java @@ -0,0 +1,527 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.jms; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.StringTokenizer; + +import javax.jms.JMSException; +import javax.naming.Context; +import javax.naming.NamingException; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.context.SessionContext; +import org.apache.axis2.description.AxisModule; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.AxisServiceGroup; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.description.ParameterIncludeImpl; +import org.apache.axis2.description.TransportInDescription; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.axis2.engine.AxisEvent; +import org.apache.axis2.engine.AxisObserver; +import org.apache.axis2.transport.TransportListener; +import org.apache.axis2.transport.jms.JMSConstants; +import org.apache.axis2.transport.jms.JMSUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tuscany.sca.work.WorkScheduler; + +import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService; +import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue; +import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor; +import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit; + +/** + * The JMS Transport listener implementation. A JMS Listner will hold one or + * more JMS connection factories, which would be created at initialization + * time. This implementation does not support the creation of connection + * factories at runtime. This JMS Listener registers with Axis to be notified + * of service deployment/undeployment/start and stop, and enables or disables + * listening for messages on the destinations as appropriate. + *

+ * A Service could state the JMS connection factory name and the destination + * name for use as Parameters in its services.xml as shown in the example + * below. If the connection name was not specified, it will use the connection + * factory named "default" (JMSConstants.DEFAULT_CONFAC_NAME) - if such a + * factory is defined in the Axis2.xml. If the destination name is not specified + * it will default to a JMS queue by the name of the service. If the destination + * should be a Topic, it should be created on the JMS implementation, and + * specified in the services.xml of the service. + *

+ * + * myTopicConnectionFactory + * + * dynamicTopics/something.TestTopic + */ +public class JMSListener implements TransportListener { + + private static final Log log = LogFactory.getLog(JMSListener.class); + + /** + * The maximum number of threads used for the worker thread pool + */ + private static final int WORKERS_MAX_THREADS = 100; + /** + * The keep alive time of an idle worker thread + */ + private static final long WORKER_KEEP_ALIVE = 60L; + /** + * The worker thread timeout time unit + */ + private static final TimeUnit TIME_UNIT = TimeUnit.SECONDS; + + /** + * A Map containing the connection factories managed by this, keyed by name + */ + private Map connectionFactories = new HashMap(); + /** + * A Map of service name to the JMS EPR addresses + */ + private Map serviceNameToEprMap = new HashMap(); + /** + * The Axis2 Configuration context + */ + private ConfigurationContext configCtx = null; + + private ExecutorService workerPool; + + private WorkScheduler workScheduler; + + public JMSListener(WorkScheduler workScheduler) { + this.workScheduler = workScheduler; + } + + /** + * This is the TransportListener initialization method invoked by Axis2 + * + * @param axisConf the Axis configuration context + * @param transprtIn the TransportIn description + */ + public void init(ConfigurationContext axisConf, + TransportInDescription transprtIn) { + + // save reference to the configuration context + this.configCtx = axisConf; + + // initialize the defined connection factories + initializeConnectionFactories(transprtIn); + + // if no connection factories are defined, we cannot listen + if (connectionFactories.isEmpty()) { + log.warn("No JMS connection factories are defined." + + "Will not listen for any JMS messages"); + return; + } + + // iterate through deployed services and validate connection factory + // names, and mark services as faulty where appropriate. + Iterator services = + axisConf.getAxisConfiguration().getServices().values().iterator(); + + while (services.hasNext()) { + AxisService service = (AxisService) services.next(); + if (JMSUtils.isJMSService(service)) { + processService(service); + } + } + + // register to receive updates on services for lifetime management + axisConf.getAxisConfiguration().addObservers(new JMSAxisObserver()); + + log.info("JMS Transport Receiver (Listener) initialized..."); + } + + + /** + * Prepare to listen for JMS messages on behalf of this service + * + * @param service + */ + private void processService(AxisService service) { + JMSConnectionFactory cf = getConnectionFactory(service); + if (cf == null) { + String msg = "Service " + service.getName() + " does not specify" + + "a JMS connection factory or refers to an invalid factory. " + + "This service is being marked as faulty and will not be " + + "available over the JMS transport"; + log.warn(msg); + JMSUtils.markServiceAsFaulty( + service.getName(), msg, service.getAxisConfiguration()); + return; + } + + String destination = JMSUtils.getDestination(service); + + // compute service EPR and keep for later use + serviceNameToEprMap.put(service.getName(), getEPR(cf, destination)); + + // add the specified or implicit destination of this service + // to its connection factory + cf.addDestination(destination, service.getName()); + } + + /** + * Return the connection factory name for this service. If this service + * refers to an invalid factory or defaults to a non-existent default + * factory, this returns null + * + * @param service the AxisService + * @return the JMSConnectionFactory to be used, or null if reference is invalid + */ + private JMSConnectionFactory getConnectionFactory(AxisService service) { + Parameter conFacParam = service.getParameter(JMSConstants.CONFAC_PARAM); + + // validate connection factory name (specified or default) + if (conFacParam != null) { + String conFac = (String) conFacParam.getValue(); + if (connectionFactories.containsKey(conFac)) { + return (JMSConnectionFactory) connectionFactories.get(conFac); + } else { + return null; + } + + } else if (connectionFactories.containsKey(JMSConstants.DEFAULT_CONFAC_NAME)) { + return (JMSConnectionFactory) connectionFactories. + get(JMSConstants.DEFAULT_CONFAC_NAME); + + } else { + return null; + } + } + + /** + * Initialize the defined connection factories, parsing the TransportIn + * descriptions + * + * @param transprtIn The Axis2 Transport in for the JMS + */ + private void initializeConnectionFactories(TransportInDescription transprtIn) { + // iterate through all defined connection factories + Iterator conFacIter = transprtIn.getParameters().iterator(); + + while (conFacIter.hasNext()) { + + Parameter param = (Parameter) conFacIter.next(); + JMSConnectionFactory jmsConFactory = + new JMSConnectionFactory(param.getName(), workScheduler); + + ParameterIncludeImpl pi = new ParameterIncludeImpl(); + try { + pi.deserializeParameters((OMElement) param.getValue()); + } catch (AxisFault axisFault) { + handleException("Error reading Parameters for JMS connection " + + "factory" + jmsConFactory.getName(), axisFault); + } + + // read connection facotry properties + Iterator params = pi.getParameters().iterator(); + + while (params.hasNext()) { + Parameter p = (Parameter) params.next(); + + if (Context.INITIAL_CONTEXT_FACTORY.equals(p.getName())) { + jmsConFactory.addProperty( + Context.INITIAL_CONTEXT_FACTORY, (String) p.getValue()); + } else if (Context.PROVIDER_URL.equals(p.getName())) { + jmsConFactory.addProperty( + Context.PROVIDER_URL, (String) p.getValue()); + } else if (Context.SECURITY_PRINCIPAL.equals(p.getName())) { + jmsConFactory.addProperty( + Context.SECURITY_PRINCIPAL, (String) p.getValue()); + } else if (Context.SECURITY_CREDENTIALS.equals(p.getName())) { + jmsConFactory.addProperty( + Context.SECURITY_CREDENTIALS, (String) p.getValue()); + } else if (JMSConstants.CONFAC_JNDI_NAME_PARAM.equals(p.getName())) { + jmsConFactory.setJndiName((String) p.getValue()); + } else if (JMSConstants.CONFAC_JNDI_NAME_USER.equals(p.getName())) { + jmsConFactory.setJndiUser((String) p.getValue()); + } else if (JMSConstants.CONFAC_JNDI_NAME_PASS.equals(p.getName())) { + jmsConFactory.setJndiPass((String) p.getValue()); + } else if (JMSConstants.DEST_PARAM.equals(p.getName())) { + StringTokenizer st = + new StringTokenizer((String) p.getValue(), " ,"); + while (st.hasMoreTokens()) { + jmsConFactory.addDestination(st.nextToken(), null); + } + } + } + + // connect to the actual connection factory + try { + jmsConFactory.connect(); + connectionFactories.put(jmsConFactory.getName(), jmsConFactory); + } catch (NamingException e) { + handleException("Error connecting to JMS connection factory : " + + jmsConFactory.getJndiName(), e); + } + } + } + + /** + * Get the EPR for the given JMS connection factory and destination + * the form of the URL is + * jms:/?[=&]* + * + * @param cf the Axis2 JMS connection factory + * @param destination the JNDI name of the destination + * @return the EPR as a String + */ + private static String getEPR(JMSConnectionFactory cf, String destination) { + StringBuffer sb = new StringBuffer(); + sb.append(JMSConstants.JMS_PREFIX).append(destination); + sb.append("?").append(JMSConstants.CONFAC_JNDI_NAME_PARAM). + append("=").append(cf.getJndiName()); + Iterator props = cf.getProperties().keySet().iterator(); + while (props.hasNext()) { + String key = (String) props.next(); + String value = (String) cf.getProperties().get(key); + sb.append("&").append(key).append("=").append(value); + } + return sb.toString(); + } + + /** + * Start this JMS Listener (Transport Listener) + * + * @throws AxisFault + */ + public void start() throws AxisFault { + // create thread pool of workers + workerPool = new ThreadPoolExecutor( + 1, + WORKERS_MAX_THREADS, WORKER_KEEP_ALIVE, TIME_UNIT, + new LinkedBlockingQueue(), + new org.apache.axis2.util.threadpool.DefaultThreadFactory( + new ThreadGroup("JMS Worker thread group"), + "JMSWorker")); + + Iterator iter = connectionFactories.values().iterator(); + while (iter.hasNext()) { + JMSConnectionFactory conFac = (JMSConnectionFactory) iter.next(); + JMSMessageReceiver msgRcvr = + new JMSMessageReceiver(conFac, workerPool, configCtx); + + try { + conFac.listen(msgRcvr); + } catch (JMSException e) { + handleException("Error starting connection factory : " + + conFac.getName(), e); + } + } + } + + /** + * Stop this transport listener and shutdown all of the connection factories + */ + public void stop() { + Iterator iter = connectionFactories.values().iterator(); + while (iter.hasNext()) { + ((JMSConnectionFactory) iter.next()).stop(); + } + if (workerPool != null) { + workerPool.shutdown(); + } + } + + /** + * Returns EPRs for the given service and IP. (Picks up precomputed EPR) + * + * @param serviceName service name + * @param ip ignored + * @return the EPR for the service + * @throws AxisFault not used + */ + public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault { + //Strip out the operation name + if (serviceName.indexOf('/') != -1) { + serviceName = serviceName.substring(0, serviceName.indexOf('/')); + } + + String endpointName = (String) serviceNameToEprMap.get(serviceName); + if (endpointName == null){ + if (serviceName.indexOf(".") != -1){ + serviceName = serviceName.substring(0, serviceName.indexOf(".")); + endpointName = (String) serviceNameToEprMap.get(serviceName); + } + } + return new EndpointReference[]{new EndpointReference(endpointName)}; + } + + /** + * Returns the EPR for the given service and IP. (Picks up precomputed EPR) + * + * @param serviceName service name + * @param ip ignored + * @return the EPR for the service + * @throws AxisFault not used + */ + public EndpointReference getEPRForService(String serviceName, String ip) throws AxisFault { + return getEPRsForService(serviceName, ip)[0]; + } + + /** + * Starts listening for messages on this service + * + * @param service the AxisService just deployed + */ + private void startListeningForService(AxisService service) { + processService(service); + JMSConnectionFactory cf = getConnectionFactory(service); + if (cf == null) { + String msg = "Service " + service.getName() + " does not specify" + + "a JMS connection factory or refers to an invalid factory." + + "This service is being marked as faulty and will not be " + + "available over the JMS transport"; + log.warn(msg); + JMSUtils.markServiceAsFaulty( + service.getName(), msg, service.getAxisConfiguration()); + return; + } + + String destination = JMSUtils.getDestination(service); + try { + cf.listenOnDestination(destination); + log.info("Started listening on destination : " + destination + + " for service " + service.getName()); + + } catch (JMSException e) { + handleException( + "Could not listen on JMS for service " + service.getName(), e); + JMSUtils.markServiceAsFaulty( + service.getName(), e.getMessage(), service.getAxisConfiguration()); + } + } + + /** + * Stops listening for messages for the service undeployed + * + * @param service the AxisService just undeployed + */ + private void stopListeningForService(AxisService service) { + + JMSConnectionFactory cf = getConnectionFactory(service); + if (cf == null) { + String msg = "Service " + service.getName() + " does not specify" + + "a JMS connection factory or refers to an invalid factory." + + "This service is being marked as faulty and will not be " + + "available over the JMS transport"; + log.warn(msg); + JMSUtils.markServiceAsFaulty( + service.getName(), msg, service.getAxisConfiguration()); + return; + } + + // remove from the serviceNameToEprMap + serviceNameToEprMap.remove(service.getName()); + + String destination = JMSUtils.getDestination(service); + try { + cf.removeDestination(destination); + } catch (JMSException e) { + handleException( + "Error while terminating listening on JMS destination : " + destination, e); + } + } + + private void handleException(String msg, Exception e) { + log.error(msg, e); + throw new AxisJMSException(msg, e); + } + + /** + * An AxisObserver which will start listening for newly deployed services, + * and stop listening when services are undeployed. + */ + class JMSAxisObserver implements AxisObserver { + + // The initilization code will go here + public void init(AxisConfiguration axisConfig) { + } + + public void serviceUpdate(AxisEvent event, AxisService service) { + + if (JMSUtils.isJMSService(service)) { + switch (event.getEventType()) { + case AxisEvent.SERVICE_DEPLOY : + startListeningForService(service); + break; + case AxisEvent.SERVICE_REMOVE : + stopListeningForService(service); + break; + case AxisEvent.SERVICE_START : + startListeningForService(service); + break; + case AxisEvent.SERVICE_STOP : + stopListeningForService(service); + break; + } + } + } + + public void moduleUpdate(AxisEvent event, AxisModule module) { + } + + //-------------------------------------------------------- + public void addParameter(Parameter param) throws AxisFault { + } + + public void removeParameter(Parameter param) throws AxisFault { + } + + public void deserializeParameters(OMElement parameterElement) throws AxisFault { + } + + public Parameter getParameter(String name) { + return null; + } + + public ArrayList getParameters() { + return null; + } + + public boolean isParameterLocked(String parameterName) { + return false; + } + + public void serviceGroupUpdate(AxisEvent event, AxisServiceGroup serviceGroup) { + } + } + + public ConfigurationContext getConfigurationContext() { + return this.configCtx; + } + + + public SessionContext getSessionContext(MessageContext messageContext) { + return null; + } + + public void destroy() { + this.configCtx = null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSMessageReceiver.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSMessageReceiver.java new file mode 100644 index 0000000000..e9e9f04ab2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSMessageReceiver.java @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.jms; + +import java.io.InputStream; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.Queue; +import javax.jms.Topic; +import javax.naming.Context; +import javax.xml.stream.XMLStreamException; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.addressing.RelatesTo; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.engine.AxisEngine; +import org.apache.axis2.transport.jms.JMSConstants; +import org.apache.axis2.transport.jms.JMSUtils; +import org.apache.axis2.util.MessageContextBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.emory.mathcs.backport.java.util.concurrent.Executor; + +/** + * This is the actual receiver which listens for and accepts JMS messages, and + * hands them over to be processed by a worker thread. An instance of this + * class is created for each JMSConnectionFactory, but all instances may and + * will share the same worker thread pool. + */ +public class JMSMessageReceiver implements MessageListener { + + private static final Log log = LogFactory.getLog(JMSMessageReceiver.class); + + /** + * The thread pool of workers + */ + private Executor workerPool = null; + /** + * The Axis configuration context + */ + private ConfigurationContext axisConf = null; + /** + * A reference to the JMS Connection Factory + */ + private JMSConnectionFactory jmsConFac = null; + + /** + * Create a new JMSMessage receiver + * + * @param jmsConFac the JMS connection factory associated with + * @param workerPool the worker thead pool to be used + * @param axisConf the Axis2 configuration + */ + JMSMessageReceiver(JMSConnectionFactory jmsConFac, + Executor workerPool, ConfigurationContext axisConf) { + this.jmsConFac = jmsConFac; + this.workerPool = workerPool; + this.axisConf = axisConf; + } + + /** + * Return the Axis configuration + * + * @return the Axis configuration + */ + public ConfigurationContext getAxisConf() { + return axisConf; + } + + /** + * Set the worker thread pool + * + * @param workerPool the worker thead pool + */ + public void setWorkerPool(Executor workerPool) { + this.workerPool = workerPool; + } + + /** + * The entry point on the recepit of each JMS message + * + * @param message the JMS message received + */ + public void onMessage(Message message) { + // directly create a new worker and delegate processing + try { + if (log.isDebugEnabled()) { + StringBuffer sb = new StringBuffer(); + sb.append("Received JMS message to destination : " + message.getJMSDestination()); + sb.append("\nMessage ID : " + message.getJMSMessageID()); + sb.append("\nCorrelation ID : " + message.getJMSCorrelationID()); + sb.append("\nReplyTo ID : " + message.getJMSReplyTo()); + log.debug(sb.toString()); + } + } catch (JMSException e) { + e.printStackTrace(); + } + workerPool.execute(new Worker(message)); + } + + /** + * Creates an Axis MessageContext for the received JMS message and + * sets up the transports and various properties + * + * @param message the JMS message + * @return the Axis MessageContext + */ + private MessageContext createMessageContext(Message message) { + + InputStream in = JMSUtils.getInputStream(message); + + try { + MessageContext msgContext = axisConf.createMessageContext(); + + // get destination and create correct EPR + Destination dest = message.getJMSDestination(); + String destinationName = null; + if (dest instanceof Queue) { + destinationName = ((Queue) dest).getQueueName(); + } else if (dest instanceof Topic) { + destinationName = ((Topic) dest).getTopicName(); + } + + String serviceName = jmsConFac.getServiceByDestination(destinationName); + + // hack to get around the crazy Active MQ dynamic queue and topic issues + if (serviceName == null) { + String provider = (String) jmsConFac.getProperties().get( + Context.INITIAL_CONTEXT_FACTORY); + if (provider.indexOf("activemq") != -1) { + serviceName = jmsConFac.getServiceNameForDestination( + ((dest instanceof Queue ? + JMSConstants.ACTIVEMQ_DYNAMIC_QUEUE : + JMSConstants.ACTIVEMQ_DYNAMIC_TOPIC) + destinationName)); + } + } + + + if (serviceName != null) { + // set to bypass dispatching and handover directly to this service + msgContext.setAxisService( + axisConf.getAxisConfiguration().getService(serviceName)); + } + + msgContext.setIncomingTransportName(Constants.TRANSPORT_JMS); + msgContext.setTransportIn( + axisConf.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_JMS)); + + msgContext.setTransportOut( + axisConf.getAxisConfiguration().getTransportOut(Constants.TRANSPORT_JMS)); + // the reply is assumed to be on the JMSReplyTo destination, using + // the same incoming connection factory + + + JMSOutTransportInfo jmsOutTransportInfo; + + if ((jmsConFac.getJndiUser() == null) || (jmsConFac.getJndiPass() == null)) + jmsOutTransportInfo= new JMSOutTransportInfo(jmsConFac.getConFactory(), message.getJMSReplyTo()); + else + jmsOutTransportInfo= new JMSOutTransportInfo(jmsConFac.getConFactory(), jmsConFac.getUser(), jmsConFac.getPass(), message.getJMSReplyTo()); + + msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, jmsOutTransportInfo); + + msgContext.setServerSide(true); + msgContext.setMessageID(message.getJMSMessageID()); + + Destination replyTo = message.getJMSReplyTo(); + String jndiDestinationName = null; + if (replyTo == null) { + Parameter param = msgContext.getAxisService().getParameter(JMSConstants.REPLY_PARAM); + if (param != null && param.getValue() != null) { + jndiDestinationName = (String) param.getValue(); + } + } + + if (jndiDestinationName != null) { + msgContext.setReplyTo(jmsConFac.getEPRForDestination(jndiDestinationName)); + } + + String soapAction = JMSUtils.getProperty(message, JMSConstants.SOAPACTION); + if (soapAction != null) { + msgContext.setSoapAction(soapAction); + } + + msgContext.setEnvelope( + JMSUtils.getSOAPEnvelope(message, msgContext, in)); + + // set correlation id + String correlationId = message.getJMSCorrelationID(); + if (correlationId != null && correlationId.length() > 0) { + msgContext.setProperty(JMSConstants.JMS_COORELATION_ID, correlationId); + msgContext.setRelationships( + new RelatesTo[] { new RelatesTo(correlationId) }); + } + + return msgContext; + + } catch (JMSException e) { + handleException("JMS Exception reading the destination name", e); + } catch (AxisFault e) { + handleException("Axis fault creating the MessageContext", e); + } catch (XMLStreamException e) { + handleException("Error reading the SOAP envelope", e); + } + return null; + } + + private void handleException(String msg, Exception e) { + log.error(msg, e); + throw new AxisJMSException(msg, e); + } + + /** + * The actual Runnable Worker implementation which will process the + * received JMS messages in the worker thread pool + */ + class Worker implements Runnable { + + private Message message = null; + + Worker(Message message) { + this.message = message; + } + + public void run() { + MessageContext msgCtx = createMessageContext(message); + + AxisEngine engine = new AxisEngine(msgCtx.getConfigurationContext()); + try { + log.debug("Delegating JMS message for processing to the Axis engine"); + try { + engine.receive(msgCtx); + } catch (AxisFault e) { + log.debug("Exception occured when receiving the SOAP message", e); + if (msgCtx.isServerSide()) { + MessageContext faultContext = MessageContextBuilder.createFaultMessageContext(msgCtx, e); + engine.sendFault(faultContext); + } + } + } catch (AxisFault af) { + log.error("JMS Worker [" + Thread.currentThread().getName() + + "] Encountered an Axis Fault : " + af.getMessage(), af); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSOutTransportInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSOutTransportInfo.java new file mode 100644 index 0000000000..5fa6542eec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSOutTransportInfo.java @@ -0,0 +1,220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.jms; + +import java.util.Hashtable; + +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; + +import org.apache.axis2.transport.OutTransportInfo; +import org.apache.axis2.transport.jms.JMSConstants; +import org.apache.axis2.transport.jms.JMSUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * The JMS OutTransportInfo + */ +public class JMSOutTransportInfo implements OutTransportInfo { + + private static final Log log = LogFactory.getLog(JMSOutTransportInfo.class); + + private ConnectionFactory connectionFactory = null; + private String connectionFactoryUser = null; + private String connectionFactoryPassword = null; + private Destination destination = null; + + private String contentType = null; + + /** + * Creates an instance using the given connection factory and destination + * + * @param connectionFactory the connection factory + * @param dest the destination + */ + JMSOutTransportInfo(ConnectionFactory connectionFactory, Destination dest) { + this.connectionFactory = connectionFactory; + this.destination = dest; + } + + /** + * Creates an instance using the given connection factory and destination + * + * @param connectionFactory the connection factory + * @param dest the destination + */ + JMSOutTransportInfo(ConnectionFactory connectionFactory, String connectionFactoryUser, String connectionFactoryPassword, Destination dest) { + this.connectionFactory = connectionFactory; + this.connectionFactoryUser = connectionFactoryUser; + this.connectionFactoryPassword = connectionFactoryPassword; + this.destination = dest; + } + + /** + * Creates and instance using the given URL + * + * @param url the URL + */ + JMSOutTransportInfo(String url) { + if (!url.startsWith(JMSConstants.JMS_PREFIX)) { + handleException("Invalid JMS URL : " + url + + " Must begin with the prefix " + JMSConstants.JMS_PREFIX); + } else { + Context context = null; + Hashtable props = JMSUtils.getProperties(url); + try { + context = new InitialContext(props); + } catch (NamingException e) { + handleException("Could not get the initial context", e); + } + + connectionFactory = getConnectionFactory(context, props); + connectionFactoryUser = getConnectionFactoryUser(context, props); + connectionFactoryPassword = getConnectionFactoryPass(context, props); + destination = getDestination(context, url); + } + } + + /** + * Get the referenced ConnectionFactory using the properties from the context + * + * @param context the context to use for lookup + * @param props the properties which contains the JNDI name of the factory + * @return the connection factory + */ + private ConnectionFactory getConnectionFactory(Context context, Hashtable props) { + try { + + String conFacJndiName = (String) props.get(JMSConstants.CONFAC_JNDI_NAME_PARAM); + if (conFacJndiName != null) { + return (ConnectionFactory) context.lookup(conFacJndiName); + } else { + throw new NamingException( + "JMS Connection Factory JNDI name cannot be determined from url"); + } + } catch (NamingException e) { + handleException("Cannot get JMS Connection factory with props : " + props, e); + } + return null; + } + + /** + * Get the referenced ConnectionFactory Username (if supplied) using the properties from the context + * + * @param context the context to use for lookup + * @param props the properties which contains the JNDI name of the factory username + * @return the connection factory username (or null if one is not in the JNDI tree) + */ + private String getConnectionFactoryUser(Context context, Hashtable props) { + try { + + String conFacJndiUser = (String) props.get(JMSConstants.CONFAC_JNDI_NAME_USER); + if (conFacJndiUser != null) { + return (String) context.lookup(conFacJndiUser); + } else { + return null; + } + } catch (NamingException e) { + handleException("Cannot get JMS Connection factory username with props : " + props, e); + } + return null; + } + + /** + * Get the referenced ConnectionFactory Password (if supplied) using the properties from the context + * + * @param context the context to use for lookup + * @param props the properties which contains the JNDI name of the factory password + * @return the connection factory password (or null if one is not in the JNDI tree) + */ + private String getConnectionFactoryPass(Context context, Hashtable props) { + try { + + String conFacJndiPass = (String) props.get(JMSConstants.CONFAC_JNDI_NAME_PASS); + if (conFacJndiPass != null) { + return (String) context.lookup(conFacJndiPass); + } else { + return null; + } + } catch (NamingException e) { + handleException("Cannot get JMS Connection factory password with props : " + props, e); + } + return null; + } + + /** + * Get the JMS destination specified by the given URL from the context + * + * @param context the Context to lookup + * @param url URL + * @return the JMS destination, or null if it does not exist + */ + private Destination getDestination(Context context, String url) { + String destinationName = JMSUtils.getDestination(url); + try { + return (Destination) context.lookup(destinationName); + + } catch (NameNotFoundException e) { + log.warn("Cannot get or lookup JMS destination : " + destinationName + + " from url : " + url + " : " + e.getMessage()); + + } catch (NamingException e) { + handleException("Cannot get JMS destination : " + destinationName + + " from url : " + url, e); + } + return null; + } + + + private void handleException(String s) { + log.error(s); + throw new AxisJMSException(s); + } + + private void handleException(String s, Exception e) { + log.error(s, e); + throw new AxisJMSException(s, e); + } + + public Destination getDestination() { + return destination; + } + + public ConnectionFactory getConnectionFactory() { + return connectionFactory; + } + + public String getConnectionFactoryPassword() { + return connectionFactoryPassword; + } + + public String getConnectionFactoryUser() { + return connectionFactoryUser; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSSender.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSSender.java new file mode 100644 index 0000000000..7caa045015 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/JMSSender.java @@ -0,0 +1,389 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.jms; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.Hashtable; + +import javax.jms.BytesMessage; +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.jms.Topic; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMOutputFormat; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.TransportOutDescription; +import org.apache.axis2.description.WSDL2Constants; +import org.apache.axis2.handlers.AbstractHandler; +import org.apache.axis2.java.security.AccessController; +import org.apache.axis2.transport.TransportSender; +import org.apache.axis2.transport.http.HTTPTransportUtils; +import org.apache.axis2.transport.http.SOAPMessageFormatter; +import org.apache.axis2.transport.jms.JMSConstants; +import org.apache.axis2.transport.jms.JMSUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * The TransportSender for JMS + */ +public class JMSSender extends AbstractHandler implements TransportSender { + + private static final Log log = LogFactory.getLog(JMSSender.class); + + /** + * Performs the actual sending of the JMS message + * + * @param msgContext the message context to be sent + * @throws AxisFault on exception + */ + public InvocationResponse invoke(MessageContext msgContext) throws AxisFault { + + log.debug("JMSSender invoke()"); + + /* Added due to possible bug in Axis2, MTOM enablement is based on msgContext.isDoingMTOM + * However msgContext.isDoingMTOM will always return false unless set programmatically. + * HTTP sets this boolean programmatically by looking up whether enableMTOM has been set + * in axis2.xml or as an option on the client. + */ + msgContext.setDoingMTOM(HTTPTransportUtils.doWriteMTOM(msgContext)); + + JMSOutTransportInfo transportInfo = null; + String targetAddress = null; + + // is there a transport url? which may be different from the WS-A To.. + targetAddress = (String) msgContext.getProperty( + Constants.Configuration.TRANSPORT_URL); + + if (targetAddress != null) { + transportInfo = new JMSOutTransportInfo(targetAddress); + } else if (targetAddress == null && msgContext.getTo() != null && + !msgContext.getTo().hasAnonymousAddress()) { + targetAddress = msgContext.getTo().getAddress(); + + if (!msgContext.getTo().hasNoneAddress()) { + transportInfo = new JMSOutTransportInfo(targetAddress); + } else { + //Don't send the message. + return InvocationResponse.CONTINUE; + } + } else if (msgContext.isServerSide()) { + // get the jms ReplyTo + transportInfo = (JMSOutTransportInfo) + msgContext.getProperty(Constants.OUT_TRANSPORT_INFO); + } + + // get the ConnectionFactory to be used for the send + ConnectionFactory connectionFac = transportInfo.getConnectionFactory(); + + Connection con = null; + try { + String user = transportInfo.getConnectionFactoryUser(); + String password = transportInfo.getConnectionFactoryPassword(); + + if ((user == null) || (password == null)){ + // Use the OS username and credentials + con = connectionFac.createConnection(); + } else{ + // use an explicit username and password + con = connectionFac.createConnection(user, password); + } + + Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); + Message message = createJMSMessage(msgContext, session); + + // get the JMS destination for the message being sent + Destination dest = transportInfo.getDestination(); + + if (dest == null) { + if (targetAddress != null) { + + // if it does not exist, create it + String name = JMSUtils.getDestination(targetAddress); + if (log.isDebugEnabled()) { + log.debug("Creating JMS Destination : " + name); + } + + try { + dest = session.createQueue(name); + } catch (JMSException e) { + handleException("Error creating destination Queue : " + name, e); + } + } else { + handleException("Cannot send reply to unknown JMS Destination"); + } + } + + MessageProducer producer = session.createProducer(dest); + Destination replyDest = null; + + boolean waitForResponse = + msgContext.getOperationContext() != null && + WSDL2Constants.MEP_URI_OUT_IN.equals( + msgContext.getOperationContext().getAxisOperation().getMessageExchangePattern()); + + if (waitForResponse) { + String replyToJNDIName = (String) msgContext.getProperty(JMSConstants.REPLY_PARAM); + if (replyToJNDIName != null && replyToJNDIName.length() > 0) { + Context context = null; + final Hashtable props = JMSUtils.getProperties(targetAddress); + try { + try { + context = (Context) AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public Object run() throws NamingException{ + return new InitialContext(props); + } + } + ) + ; + } catch (PrivilegedActionException e) { + throw (NamingException) e.getException(); + } + } catch (NamingException e) { + handleException("Could not get the initial context", e); + } + + try { + replyDest = (Destination) context.lookup(replyToJNDIName); + + } catch (NameNotFoundException e) { + log.warn("Cannot get or lookup JMS response destination : " + + replyToJNDIName + " : " + e.getMessage() + + ". Attempting to create a Queue named : " + replyToJNDIName); + replyDest = session.createQueue(replyToJNDIName); + + } catch (NamingException e) { + handleException("Cannot get JMS response destination : " + + replyToJNDIName + " : ", e); + } + + } else { + try { + // create temporary queue to receive reply + replyDest = session.createTemporaryQueue(); + } catch (JMSException e) { + handleException("Error creating temporary queue for response"); + } + } + message.setJMSReplyTo(replyDest); + if (log.isDebugEnabled()) { + log.debug("Expecting a response to JMS Destination : " + + (replyDest instanceof Queue ? + ((Queue) replyDest).getQueueName() : ((Topic) replyDest).getTopicName())); + } + } + + try { + log.debug("[" + (msgContext.isServerSide() ? "Server" : "Client") + + "]Sending message to destination : " + dest); + producer.send(message); + producer.close(); + + } catch (JMSException e) { + handleException("Error sending JMS message to destination : " + + dest.toString(), e); + } + + if (waitForResponse) { + try { + // wait for reply + MessageConsumer consumer = session.createConsumer(replyDest); + + long timeout = JMSConstants.DEFAULT_JMS_TIMEOUT; + Long waitReply = (Long) msgContext.getProperty(JMSConstants.JMS_WAIT_REPLY); + if (waitReply != null) { + timeout = waitReply.longValue(); + } + + log.debug("Waiting for a maximum of " + timeout + + "ms for a response message to destination : " + replyDest); + con.start(); + Message reply = consumer.receive(timeout); + + if (reply != null) { + msgContext.setProperty(MessageContext.TRANSPORT_IN, + JMSUtils.getInputStream(reply)); + } else { + log.warn("Did not receive a JMS response within " + + timeout + " ms to destination : " + dest); + } + + } catch (JMSException e) { + handleException("Error reading response from temporary " + + "queue : " + replyDest, e); + } + } + } catch (JMSException e) { + handleException("Error preparing to send message to destination", e); + + } finally { + if (con != null) { + try { + con.close(); // closes all sessions, producers, temp Q's etc + } catch (JMSException e) { + } // ignore + } + } + return InvocationResponse.CONTINUE; + } + + public void cleanup(MessageContext msgContext) throws AxisFault { + // do nothing + } + + public void init(ConfigurationContext confContext, + TransportOutDescription transportOut) throws AxisFault { + // do nothing + } + + public void stop() { + // do nothing + } + + /** + * Create a JMS Message from the given MessageContext and using the given + * session + * + * @param msgContext the MessageContext + * @param session the JMS session + * @return a JMS message from the context and session + * @throws JMSException on exception + */ + private Message createJMSMessage(MessageContext msgContext, Session session) + throws JMSException { + + Message message = null; + String msgType = getProperty(msgContext, JMSConstants.JMS_MESSAGE_TYPE); + + OMElement msgElement = msgContext.getEnvelope(); + if (msgContext.isDoingREST()) { + msgElement = msgContext.getEnvelope().getBody().getFirstElement(); + } + + if (msgType != null && JMSConstants.JMS_BYTE_MESSAGE.equals(msgType)) { + + message = session.createBytesMessage(); + BytesMessage bytesMsg = (BytesMessage) message; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OMOutputFormat format = new OMOutputFormat(); + + /* Added due to possible bug in Axis2, OMOutputFormat's boolean isSOAP11 defaults to true. + * This means that if left untouched all JMS byte messages must be SOAP 1.1 + * We set the boolean here based on the messageContexts value, which is assertained from + * the soap namespace used. This is what HTTP does also. + */ + format.setSOAP11(msgContext.isSOAP11()); + format.setCharSetEncoding( + getProperty(msgContext, Constants.Configuration.CHARACTER_SET_ENCODING)); + format.setDoOptimize(msgContext.isDoingMTOM()); + try { + msgElement.serializeAndConsume(baos, format); + baos.flush(); + } catch (XMLStreamException e) { + handleException("XML serialization error creating BytesMessage", e); + } catch (IOException e) { + handleException("IO Error while creating BytesMessage", e); + } + bytesMsg.writeBytes(baos.toByteArray()); + + /* Added due to possible bug in Axis2, the content type is never set for a JMS byte message. This + * goes unnoticed when MTOM is not used, as the server can handle the message. However once MTOM + * is used a contentType of multipart/related is required. + */ + bytesMsg.setStringProperty(JMSConstants.CONTENT_TYPE, + new SOAPMessageFormatter().getContentType(msgContext, format, null)); + } else { + message = session.createTextMessage(); // default + TextMessage txtMsg = (TextMessage) message; + txtMsg.setText(msgElement.toString()); + } + + // set the JMS correlation ID if specified + String correlationId = getProperty(msgContext, JMSConstants.JMS_COORELATION_ID); + if (correlationId == null && msgContext.getRelatesTo() != null) { + correlationId = msgContext.getRelatesTo().getValue(); + } + + if (correlationId != null) { + message.setJMSCorrelationID(correlationId); + } + + if (msgContext.isServerSide()) { + // set SOAP Action and context type as properties on the JMS message + setProperty(message, msgContext, JMSConstants.SOAPACTION); + setProperty(message, msgContext, JMSConstants.CONTENT_TYPE); + } else { + String action = msgContext.getOptions().getAction(); + if (action != null) { + message.setStringProperty(JMSConstants.SOAPACTION, action); + } + } + + return message; + } + + private void setProperty(Message message, MessageContext msgCtx, String key) { + + String value = getProperty(msgCtx, key); + if (value != null) { + try { + message.setStringProperty(key, value); + } catch (JMSException e) { + log.warn("Couldn't set message property : " + key + " = " + value, e); + } + } + } + + private String getProperty(MessageContext mc, String key) { + return (String) mc.getProperty(key); + } + + private static void handleException(String s) { + log.error(s); + throw new AxisJMSException(s); + } + + private static void handleException(String s, Exception e) { + log.error(s, e); + throw new AxisJMSException(s, e); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/README b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/README new file mode 100644 index 0000000000..5df1751298 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/README @@ -0,0 +1,14 @@ +The classes in this package are a copy of the same classes from the +Axis2 package org.apache.axis2.transport.jms in the Axis2 1.4.1 release. + +The only change is in the listenOnDestination method in JMSConnectionFactory +to use Tuscany threads instead of the setMessageListener call approach when +running in a JEE container where setMessageListener is prohibited. There are +several classes copied in this Tuscany package as many of the constructors +and methods are not public so we can't just subclass to fix the problem. + +In Axis2 1.5 and the new separately released JMS transport will fix this +problem so when we move up to that in Tuscany we can get rid of this package. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingBasicAuthenticationConfigurator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingBasicAuthenticationConfigurator.java new file mode 100644 index 0000000000..0f73320c47 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingBasicAuthenticationConfigurator.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.policy.configurator; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.security.auth.Subject; + +import org.apache.axiom.om.util.Base64; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.transport.http.HttpTransportProperties; +import org.apache.axis2.transport.http.HttpTransportProperties.Authenticator; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.SecurityUtil; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; +import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPrincipal; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Policy handler to handle PolicySet that contain Axis2ConfigParamPolicy instances + * + * @version $Rev$ $Date$ + */ +public class Axis2BindingBasicAuthenticationConfigurator { + + + public static void setOperationOptions(OperationClient operationClient, Message msg, BasicAuthenticationPolicy policy) { + String username = null; + String password = null; + + // get the security context + Subject subject = SecurityUtil.getSubject(msg); + BasicAuthenticationPrincipal principal = SecurityUtil.getPrincipal(subject, + BasicAuthenticationPrincipal.class); + + // could use the security principal to look up basic auth credentials + if ( principal != null ) { + username = ((BasicAuthenticationPrincipal)principal).getName(); + password = ((BasicAuthenticationPrincipal)principal).getPassword(); + } + + if (username == null || password == null ){ + throw new ServiceRuntimeException("Basic authentication username or password is null"); + } + + HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator(); + List auth = new ArrayList(); + auth.add(Authenticator.BASIC); + authenticator.setAuthSchemes(auth); + authenticator.setPreemptiveAuthentication(true); + authenticator.setUsername(username); + authenticator.setPassword(password); + + operationClient.getOptions().setProperty(HTTPConstants.AUTHENTICATE, + authenticator); + } + + public static void parseHTTPHeader(MessageContext messageContext, Message msg, BasicAuthenticationPolicy policy) { + + Map httpHeaderProperties = (Map)messageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); + + String basicAuthString = (String)httpHeaderProperties.get("Authorization"); + String decodedBasicAuthString = null; + String username = null; + String password = null; + + if (basicAuthString != null) { + basicAuthString = basicAuthString.trim(); + + if (basicAuthString.startsWith("Basic ")) { + decodedBasicAuthString = new String(Base64.decode(basicAuthString.substring(6))); + } + + int collonIndex = decodedBasicAuthString.indexOf(':'); + + if (collonIndex == -1){ + username = decodedBasicAuthString; + } else { + username = decodedBasicAuthString.substring(0, collonIndex); + password = decodedBasicAuthString.substring(collonIndex + 1); + } + } + + // get the security context + Subject subject = SecurityUtil.getSubject(msg); + BasicAuthenticationPrincipal principal = null; + try { + principal = new BasicAuthenticationPrincipal(username, + password); + } catch (Exception ex) { + // null test will throw a suitable exceptions + } + + if (principal == null){ + throw new ServiceRuntimeException("User credentials for authentication expected"); + } + + subject.getPrincipals().add(principal); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingHeaderConfigurator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingHeaderConfigurator.java new file mode 100644 index 0000000000..647f934c02 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configurator/Axis2BindingHeaderConfigurator.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.sca.binding.ws.axis2.policy.configurator; + + + +import javax.xml.namespace.QName; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axiom.soap.SOAPHeader; +import org.apache.axis2.context.MessageContext; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicyUtil; +import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeader; +import org.apache.tuscany.sca.invocation.Message; + + +/** + * Policy handler to handle PolicySet that contain Axis2ConfigParamPolicy instances + * + * @version $Rev$ $Date$ + */ +public class Axis2BindingHeaderConfigurator { + + + public static void setHeader(MessageContext messageContext, Message msg, QName headerQName) { + + if (headerQName != null){ + SOAPEnvelope envelope = messageContext.getEnvelope(); + OMFactory factory = envelope.getOMFactory(); + SOAPHeader soapHeader = envelope.getHeader(); + + Axis2SOAPHeader header = Axis2HeaderPolicyUtil.getHeader(msg, headerQName) ; + + if (header != null){ + soapHeader.addChild(header.getAsSOAPHeaderBlock(factory)); + } + } + } + + public static void getHeader(MessageContext messageContext, Message msg, QName headerQName, Axis2SOAPHeader header) { + + SOAPEnvelope sev = messageContext.getEnvelope(); + SOAPHeader sh = sev.getHeader(); + OMElement omHeader = sh.getFirstChildWithName(headerQName); + + header.setAsSOAPHeaderBlock(omHeader); + + msg.getHeaders().add(header); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..a48ff54c77 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.ws.axis2.Axis2BindingProviderFactory;model=org.apache.tuscany.sca.binding.ws.WebServiceBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider new file mode 100644 index 0000000000..370b83f87b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for SCA Definitions Providers +org.apache.tuscany.sca.binding.ws.axis2.WSBindingDefinitionsProvider \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/definitions.xml new file mode 100644 index 0000000000..6bff613a7c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/definitions.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + Communication through this binding requires SOAP + + + + + + Communication through this binding requires SOAP 1.1 + + + + + + Communication through this binding requires SOAP 1.2 + + + + + + Communication through this binding requires MTOM support + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml new file mode 100644 index 0000000000..f75a2e8cdb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml @@ -0,0 +1,504 @@ + + + + + + + + true + false + false + false + + + + + + + + + 30000 + + + + + + true + + + + + + false + + admin + axis2 + + + + + + + + + + + + + + + + + + + + + + + + / + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6060 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + > + + + + + + + + + + + + + HTTP/1.1 + chunked + + + + + + + HTTP/1.1 + chunked + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list new file mode 100644 index 0000000000..e6e70dfd4b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list @@ -0,0 +1 @@ +rampart-1.4.mar \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.4.mar b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.4.mar new file mode 100644 index 0000000000..ec870734a5 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.4.mar differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/services/services.list b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/services/services.list new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceTestCase.java new file mode 100644 index 0000000000..2ce23bf2c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceTestCase.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.sca.binding.ws.axis2; + +import junit.framework.TestCase; + +public class Axis2ReferenceTestCase extends TestCase { + + public void testInvokeService() throws Exception { +// Axis2ReferenceBinding axis2Reference = createAxis2Reference("testWebAppName", "testServiceName"); +// ServiceContract contract = new JavaServiceContract(); +// Operation operation = new Operation("sayHi", null, null, null, false, null, NO_CONVERSATION); +// TargetInvoker targetInvoker = axis2Reference.createTargetInvoker(contract, operation); +// assertNotNull(targetInvoker); +// assertFalse(targetInvoker instanceof Axis2AsyncTargetInvoker); + } + + public void testAsyncTargetInvoker() throws Exception { +// Axis2ReferenceBinding axis2Reference = createAxis2Reference("testWebAppName", "testServiceName"); +// //Create a mocked InboundWire, make the call of ServiceBindingExtension.getInterface() returns a Class +// Wire inboundWire = EasyMock.createNiceMock(Wire.class); +// JavaServiceContract contract = new JavaServiceContract(Greeter.class); +// contract.setCallbackName(""); +// contract.setCallbackClass(GreetingCallback.class); +// Operation callbackOp = +// new Operation("sayHiCallback", null, null, null, true, null, NO_CONVERSATION); +// HashMap> callbackOps = new HashMap>(); +// callbackOps.put("sayHiCallback", callbackOp); +// contract.setCallbackOperations(callbackOps); +// EasyMock.expect(inboundWire.getTargetContract()).andReturn(contract).anyTimes(); +// EasyMock.replay(inboundWire); +// +// axis2Reference.setWire(inboundWire); +// Operation operation = new Operation("sayHi", null, null, null, true, null, NO_CONVERSATION); +// TargetInvoker asyncTargetInvoker = axis2Reference.createTargetInvoker(contract, operation); +// assertNotNull(asyncTargetInvoker); +// assertTrue(asyncTargetInvoker instanceof Axis2AsyncTargetInvoker); + } + +// @SuppressWarnings("unchecked") +// private Axis2ReferenceBinding createAxis2Reference(String webAppName, String serviceName) throws Exception { +// //Create WebServiceBindingDefinition +// String wsdlLocation = "/wsdl/hello_world_doc_lit.wsdl"; +// URL url = getClass().getResource(wsdlLocation); +// assertNotNull("Could not find wsdl " + url.toString(), url); +// +// WSDLFactory factory = WSDLFactory.newInstance(); +// WSDLReader reader = factory.newWSDLReader(); +// reader.setFeature("javax.wsdl.verbose", false); +// InputSource input = new InputSource(url.openStream()); +// Definition wsdlDef = reader.readWSDL(url.toString(), input); +// Service wsdlService = wsdlDef.getService(new QName("http://objectweb.org/hello_world_soap_http", +// "SOAPService")); +// Port port = wsdlService.getPort("SoapPort"); +// WebServiceBindingDefinition wsBinding = +// new WebServiceBindingDefinition(wsdlDef, port, "uri", "portURI", wsdlService); +// //Create a mocked WireService, make the call of ServiceBindingExtension.getServiceInstance() returns a proxy instance. +// // TODO figure out what to do with the service contract +// ServiceContract contract = new WSDLServiceContract(); +// contract.setInterfaceClass(Greeter.class); +// return new Axis2ReferenceBinding(URI.create(serviceName), +// wsBinding, +// contract, +// null, +// null); +// } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceTestCase.java new file mode 100644 index 0000000000..d4d20414e5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceTestCase.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.sca.binding.ws.axis2; + +import junit.framework.TestCase; + +public class Axis2ServiceTestCase extends TestCase { + + public void testInvokeService() throws Exception { +// TestServletHost tomcatHost = new TestServletHost(); +// Axis2ServiceBinding axis2Service = createAxis2Service("testServiceName", tomcatHost, false); +// axis2Service.start(); +// +// if (true) return; +// Servlet servlet = tomcatHost.getMapping("testWebAppName/serviceBindings/testServiceName"); +// assertNotNull(servlet); +// +// //Create mocked HttpRequest and HttpResponse object to test the Axis2Servlet +// //To be done: + + } + + public void testAsyncMessageReceiver() throws Exception { + +// TestServletHost tomcatHost = new TestServletHost(); +// Axis2ServiceBinding axis2Service = createAxis2Service("testServiceName", tomcatHost, true); +// axis2Service.start(); + } + +// @SuppressWarnings("unchecked") +// private Axis2ServiceBinding createAxis2Service(String serviceName, ServletHost tomcatHost, boolean callback) +// throws Exception { +// //Create WebServiceBindingDefinition +// String wsdlLocation = "/wsdl/hello_world_doc_lit.wsdl"; +// URL url = getClass().getResource(wsdlLocation); +// assertNotNull("Could not find wsdl " + url.toString(), url); +// +// WSDLFactory factory = WSDLFactory.newInstance(); +// WSDLReader reader = factory.newWSDLReader(); +// reader.setFeature("javax.wsdl.verbose", false); +// InputSource input = new InputSource(url.openStream()); +// Definition wsdlDef = reader.readWSDL(url.toString(), input); +// Service wsdlService = wsdlDef.getService(new QName("http://objectweb.org/hello_world_soap_http", +// "SOAPService")); +// Port port = wsdlService.getPort("SoapPort"); +// WebServiceBindingDefinition wsBinding = new WebServiceBindingDefinition(wsdlDef, port, "uri", "portURI", wsdlService); +// +// //Create a mocked WireService, make the call of ServiceBindingExtension.getServiceInstance() returns a proxy instance. +//// WireService wireService = EasyMock.createNiceMock(WireService.class); +//// wireService.createProxy(EasyMock.isA(Class.class), EasyMock.isA(Wire.class)); +//// EasyMock.expectLastCall().andReturn(null); +//// EasyMock.replay(wireService); +// +// //Create a mocked InboundWire, make the call of ServiceBindingExtension.getInterface() returns a Class +// Wire inboundWire = EasyMock.createNiceMock(Wire.class); +// JavaServiceContract contract = new JavaServiceContract(Greeter.class); +// Map> opMap = new HashMap>(); +// for (Method m : Greeter.class.getMethods()) { +// opMap.put(m.getName(), new Operation(m.getName(), null, null, null)); +// } +// contract.setOperations(opMap); +// EasyMock.expect(inboundWire.getTargetContract()).andReturn(contract).anyTimes(); +// if (callback) { +// contract.setCallbackName(""); +// } +// EasyMock.replay(inboundWire); +// +// Wire outboundWire = EasyMock.createNiceMock(Wire.class); +// Map, InvocationChain> map = new HashMap, InvocationChain>(); +// EasyMock.expect(outboundWire.getInvocationChains()).andReturn(map).once(); +// EasyMock.replay(outboundWire); +// +// TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); +// ConfigurationContext configurationContext = tuscanyAxisConfigurator.getConfigurationContext(); +// Axis2ServiceBinding axis2Service = +// new Axis2ServiceBinding(URI.create(serviceName), +// contract, +// null, +// wsBinding, +// tomcatHost, +// configurationContext, null); +// axis2Service.setWire(inboundWire); +//// axis2Service.setOutboundWire(outboundWire); +// +// return axis2Service; +// } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Greeter.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Greeter.java new file mode 100644 index 0000000000..767f59646f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Greeter.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.sca.binding.ws.axis2; + +public interface Greeter { + + String sayHi(); + + String greetMe(String requestType); + + void greetMeOneWay(String requestType); + + void greetMeWithCallback(String requestType); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/GreetingCallback.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/GreetingCallback.java new file mode 100644 index 0000000000..e5e76af0b7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/GreetingCallback.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2; + +public interface GreetingCallback { + + void greetMeCallback(String greetMeResponse); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Account.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Account.java new file mode 100644 index 0000000000..4e7c1b0539 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Account.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.sca.binding.ws.axis2.itests; + +import org.osoa.sca.annotations.Remotable; + +/** + * Test ?wsdl works and that the returned WSDL has the correct endpoint + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Account { + + CustomerProfileData getCustomerProfile(String loginID); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/AccountService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/AccountService.java new file mode 100644 index 0000000000..5edb4ddc5a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/AccountService.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.sca.binding.ws.axis2.itests; + +/** + * Test ?wsdl works and that the returned WSDL has the correct endpoint + * + * @version $Rev$ $Date$ + */ +public class AccountService implements Account { + + public CustomerProfileData getCustomerProfile(String loginID) { + return new CustomerProfileData(loginID); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Bar.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Bar.java new file mode 100644 index 0000000000..2dc7d8dee4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Bar.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.sca.binding.ws.axis2.itests; + +import java.io.Serializable; + +public class Bar implements Serializable { + private static final long serialVersionUID = 1249963611910502668L; + + private String s; + private int x; + private Integer y; + + private Boolean b; + + public Boolean getB() { + return b; + } + public void setB(Boolean b) { + this.b = b; + } + public String getS() { + return s; + } + public void setS(String s) { + this.s = s; + } + public int getX() { + return x; + } + public void setX(int x) { + this.x = x; + } + public Integer getY() { + return y; + } + public void setY(Integer y) { + this.y = y; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/CustomerProfileData.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/CustomerProfileData.java new file mode 100644 index 0000000000..5c1ee6a435 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/CustomerProfileData.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests; + +/** + * Test ?wsdl works and that the returned WSDL has the correct endpoint + * + * @version $Rev$ $Date$ + */ +public class CustomerProfileData { + + private String firstName; + private String lastName; + private String address; + private String email; + private String loginID; + private String password; + private int id; + + public CustomerProfileData(String loginID) { + firstName = "John"; + lastName = "Doe"; + address = "345 Main Street"; + email = "john@doe.org"; + this.loginID = loginID; + password = "hello"; + id = 1234; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String firstName) { + this.lastName = lastName; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getLoginID() { + return loginID; + } + + public void setLoginID(String loginID) { + this.loginID = loginID; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Echo.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Echo.java new file mode 100644 index 0000000000..6fccbcfd00 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Echo.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.sca.binding.ws.axis2.itests; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Echo { + + Foo echoFoo(Foo foo); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoComponent.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoComponent.java new file mode 100644 index 0000000000..5e1a4cf259 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoComponent.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.sca.binding.ws.axis2.itests; + +import org.osoa.sca.annotations.Reference; + +public class EchoComponent implements Echo { + + @Reference + public Echo echoWS; + + public Foo echoFoo(Foo foo) { + return echoWS.echoFoo(foo); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoImpl.java new file mode 100644 index 0000000000..d028ced69e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoImpl.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.sca.binding.ws.axis2.itests; + + +public class EchoImpl implements Echo { + + public Foo echoFoo(Foo foo) { + return foo; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Foo.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Foo.java new file mode 100644 index 0000000000..c7b503af17 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Foo.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.sca.binding.ws.axis2.itests; + +import java.io.Serializable; + +public class Foo implements Serializable { + private static final long serialVersionUID = 4879476066850018458L; + + private Bar[] bars; + + public Bar[] getBars() { + return bars; + } + + public void setBars(Bar[] bars) { + this.bars = bars; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.java new file mode 100644 index 0000000000..f474c12af3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.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.sca.binding.ws.axis2.itests; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface HelloWorld { + + String getGreetings(String s); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldComponent.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldComponent.java new file mode 100644 index 0000000000..88705c1a95 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldComponent.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.sca.binding.ws.axis2.itests; + +import org.osoa.sca.annotations.Reference; + +public class HelloWorldComponent implements HelloWorld { + + @Reference + public HelloWorld helloWorldWS; + + public String getGreetings(String s) { + return helloWorldWS.getGreetings(s); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldMultiService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldMultiService.java new file mode 100644 index 0000000000..f30286feea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldMultiService.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.sca.binding.ws.axis2.itests; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; + +public class HelloWorldMultiService implements HelloWorldOM, HelloWorldOM2 { + + public OMElement getGreetings(OMElement requestOM) { + String name = requestOM.getFirstElement().getText(); + + OMFactory omFactory = OMAbstractFactory.getOMFactory(); + OMElement responseOM = omFactory.createOMElement("getGreetingsResponse", "http://helloworld-om", "helloworld"); + OMElement param = omFactory.createOMElement("getGreetingsReturn", "http://helloworld-om", "helloworld"); + responseOM.addChild(param); + param.addChild(omFactory.createOMText("Hello " + name)); + + return responseOM; + } + + public OMElement getGreetings2(OMElement requestOM) { + String name = requestOM.getFirstElement().getText(); + + OMFactory omFactory = OMAbstractFactory.getOMFactory(); + OMElement responseOM = omFactory.createOMElement("getGreetingsResponse", "http://helloworld-om", "helloworld"); + OMElement param = omFactory.createOMElement("getGreetingsReturn", "http://helloworld-om", "helloworld"); + responseOM.addChild(param); + param.addChild(omFactory.createOMText("Hello2 " + name)); + + return responseOM; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDLTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDLTestCase.java new file mode 100644 index 0000000000..7ee48d4451 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDLTestCase.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.sca.binding.ws.axis2.itests ; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class HelloWorldNoWSDLTestCase extends TestCase { + + private SCADomain domain; + + public void testHelloWorld() throws Exception { + HelloWorld helloWorld = domain.getService(HelloWorld.class, "HelloWorldComponent"); + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + /** + * Test a a WS call with a complex type + */ + public void testEchoFoo() throws Exception { + Echo echo = domain.getService(Echo.class, "EchoComponent"); + + Foo f = new Foo(); + Bar b1 = new Bar(); + b1.setS("petra"); + b1.setX(1); + b1.setY(new Integer(2)); + b1.setB(Boolean.TRUE); + Bar b2 = new Bar(); + b2.setS("beate"); + b2.setX(3); + b2.setY(new Integer(4)); + b2.setB(Boolean.FALSE); + f.setBars(new Bar[] { b1, b2} ); + + Foo f2 = echo.echoFoo(f); + + assertEquals("petra", f2.getBars()[0].getS()); + assertEquals(1, f2.getBars()[0].getX()); + assertEquals(2, f2.getBars()[0].getY().intValue()); + assertTrue(f2.getBars()[0].getB().booleanValue()); + assertEquals("beate", f2.getBars()[1].getS()); + assertEquals(3, f2.getBars()[1].getX()); + assertEquals(4, f2.getBars()[1].getY().intValue()); + assertFalse(f2.getBars()[1].getB().booleanValue()); + + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDL.composite"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM.java new file mode 100644 index 0000000000..274f6c8d28 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM.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.sca.binding.ws.axis2.itests; + +import org.apache.axiom.om.OMElement; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface HelloWorldOM { + + OMElement getGreetings(OMElement parmE); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM2.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM2.java new file mode 100644 index 0000000000..bf371430a1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM2.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.sca.binding.ws.axis2.itests; + +import org.apache.axiom.om.OMElement; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface HelloWorldOM2 { + + OMElement getGreetings2(OMElement parmE); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMComponent.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMComponent.java new file mode 100644 index 0000000000..d1cbfb88fd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMComponent.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.sca.binding.ws.axis2.itests; + +import org.apache.axiom.om.OMElement; +import org.osoa.sca.annotations.Reference; + +public class HelloWorldOMComponent implements HelloWorldOM { + + @Reference + public HelloWorldOM helloWorldWS; + + public OMElement getGreetings(OMElement om) { + return helloWorldWS.getGreetings(om); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMService.java new file mode 100644 index 0000000000..71d7bf68fb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMService.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.sca.binding.ws.axis2.itests; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; + +public class HelloWorldOMService implements HelloWorldOM { + + public OMElement getGreetings(OMElement requestOM) { + System.out.println(" **** getGreetings **** "); + String name = requestOM.getFirstElement().getText(); + + OMFactory omFactory = OMAbstractFactory.getOMFactory(); + OMElement responseOM = omFactory.createOMElement("getGreetingsResponse", "http://helloworld-om", "helloworld"); + OMElement param = omFactory.createOMElement("getGreetingsReturn", "http://helloworld-om", "helloworld"); + responseOM.addChild(param); + param.addChild(omFactory.createOMText("Hello " + name)); + + return responseOM; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMTestCase.java new file mode 100644 index 0000000000..e7511027c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMTestCase.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.sca.binding.ws.axis2.itests; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class HelloWorldOMTestCase extends TestCase { + + private SCADomain domain; + private HelloWorldOM helloWorld; + + public void testHelloWorld() throws Exception { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement requestOM = fac.createOMElement("getGreetings", "http://helloworld-om", "helloworld"); + OMElement parmE = fac.createOMElement("name", "http://helloworld-om", "helloworld"); + requestOM.addChild(parmE); + parmE.addChild(fac.createOMText("petra")); + OMElement responseOM = helloWorld.getGreetings(requestOM); + OMElement child = (OMElement)responseOM.getFirstElement(); + Assert.assertEquals("Hello petra", ((OMText)child.getFirstOMChild()).getText()); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.composite"); + helloWorld = domain.getService(HelloWorldOM.class, "HelloWorldComponent"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldService.java new file mode 100644 index 0000000000..017d9bb478 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldService.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.sca.binding.ws.axis2.itests; + +public class HelloWorldService implements HelloWorld { + + public String getGreetings(String s) { + return "Hello " + s; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldTestCase.java new file mode 100644 index 0000000000..a3a43d032f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldTestCase.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.sca.binding.ws.axis2.itests; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class HelloWorldTestCase extends TestCase { + + private SCADomain domain; + private HelloWorld helloWorld; + + public void testCalculator() throws Exception { + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.composite"); + helloWorld = domain.getService(HelloWorld.class, "HelloWorldComponent"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldWSDLMergedTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldWSDLMergedTestCase.java new file mode 100644 index 0000000000..8e17b89f33 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldWSDLMergedTestCase.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.sca.binding.ws.axis2.itests; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class HelloWorldWSDLMergedTestCase extends TestCase { + + private SCADomain domain; + private HelloWorldOM helloWorld; + + public void testHelloWorld() throws Exception { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement requestOM = fac.createOMElement("getGreetings", "http://helloworld-om", "helloworld"); + OMElement parmE = fac.createOMElement("name", "http://helloworld-om", "helloworld"); + requestOM.addChild(parmE); + parmE.addChild(fac.createOMText("petra")); + OMElement responseOM = helloWorld.getGreetings(requestOM); + OMElement child = (OMElement)responseOM.getFirstElement(); + Assert.assertEquals("Hello petra", ((OMText)child.getFirstOMChild()).getText()); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-merged.composite"); + helloWorld = domain.getService(HelloWorldOM.class, "HelloWorldWSDLMergedComponent"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java new file mode 100644 index 0000000000..186d2ad746 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Test ?wsdl works and that the returned WSDL has the correct endpoint + * + * @version $Rev$ $Date$ + */ +public class QuestionMarkWSDLImportTestCase extends TestCase { + + private SCADomain domain; + + /** + * Tests ?wsdl works and returns the correct port endpoint from the WSDL + */ + public void testWSDLImportPortEndpoint() throws Exception { + InputStream inp = new URL("http://localhost:8086/AccountService?wsdl").openStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(inp)); + String line; + while((line = br.readLine()) != null) { + System.out.println(line); + } + br.close(); + + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose", false); + wsdlReader.setFeature("javax.wsdl.importDocuments", true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8086/AccountService?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName("http://account2/AccountService/$promoted$ep1", "AccountService")); + Port port = service.getPort("AccountSoapPort"); + + String endpoint = getEndpoint(port); + assertEquals("http://localhost:8086/AccountService", endpoint); + } + + private String getEndpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-import.composite"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java new file mode 100644 index 0000000000..c0133a712e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Test ?wsdl works and that the returned WSDL has the correct endpoint + * + * @version $Rev: 660340 $ $Date: 2008-05-27 01:08:32 +0100 (Tue, 27 May 2008) $ + */ +public class QuestionMarkWSDLIncludeTestCase extends TestCase { + + private SCADomain domain; + + /** + * Tests ?wsdl works and returns the correct port endpoint from the WSDL + */ + public void testWSDLIncludePortEndpoint() throws Exception { + InputStream inp = new URL("http://localhost:8085/AccountService?wsdl").openStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(inp)); + String line; + while((line = br.readLine()) != null) { + System.out.println(line); + } + br.close(); + + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose", false); + wsdlReader.setFeature("javax.wsdl.importDocuments", true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/AccountService?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName("http://accounts/AccountService/$promoted$ep1", "AccountService")); + Port port = service.getPort("AccountSoapPort"); + + String endpoint = getEndpoint(port); + assertEquals("http://localhost:8085/AccountService", endpoint); + } + + private String getEndpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-include.composite"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java new file mode 100644 index 0000000000..0ca84a910e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Test ?wsdl works and that the returned WSDL has the correct endpoint + * + * @version $Rev$ $Date$ + */ +public class QuestionMarkWSDLTestCase extends TestCase { + + private SCADomain domain; + + /** + * Tests ?wsdl works and returns the correct port endpoint from the WSDL + */ + public void testWSDLPortEndpoint() throws Exception { + InputStream inp = new URL("http://localhost:8085/services/HelloWorldWebService?wsdl").openStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(inp)); + String line; + while((line = br.readLine()) != null) { + System.out.println(line); + } + br.close(); + + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/services/HelloWorldWebService?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName("http://helloworld/HelloWorldService/$promoted$ep1", + "HelloWorldService")); + Port port = service.getPort("HelloWorldSoapPort"); + + String endpoint = getEndpoint(port); + assertEquals("http://localhost:8085/services/HelloWorldWebService", endpoint); + } + + /** + * Tests ?wsdl works and returns the correct port endpoint from binding.ws with a custom URI + */ + public void testCustomEndpoint() throws Exception { + InputStream inp = new URL("http://localhost:8085/foo/bar?wsdl").openStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(inp)); + String line; + while((line = br.readLine()) != null) { + System.out.println(line); + } + br.close(); + + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/foo/bar?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName("http://itests.axis2.ws.binding.sca.tuscany.apache.org/", + "HelloWorldService")); + Port port = service.getPort("HelloWorldPort"); + + String endpoint = getEndpoint(port); + assertEquals("http://localhost:8085/foo/bar", endpoint); + } + + protected String getEndpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl.composite"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/UriPrecedenceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/UriPrecedenceTestCase.java new file mode 100644 index 0000000000..5efbedba4c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/UriPrecedenceTestCase.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.osoa.sca.ServiceRuntimeException; + +/** + * This test verifies that the Endpoint URI specified in the wsdl takes precedence over the URI specified + * in binding. Ref: WS Binding Specification V1.00 - Section 2.1.1 + * + * @version $Rev$ $Date$ + */ +public class UriPrecedenceTestCase extends TestCase { + + private SCADomain domain; + private HelloWorldOM helloWorld; + + public void testUriPrecedence() throws Exception { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement requestOM = fac.createOMElement("getGreetings", "http://helloworld-prec", "helloworld"); + OMElement parmE = fac.createOMElement("name", "http://helloworld-prec", "helloworld"); + requestOM.addChild(parmE); + parmE.addChild(fac.createOMText("petra")); + try { + OMElement responseOM = helloWorld.getGreetings(requestOM); + OMElement child = (OMElement)responseOM.getFirstElement(); + Assert.assertEquals("Hello petra", ((OMText)child.getFirstOMChild()).getText()); + } catch (ServiceRuntimeException e) { + fail("Endpoint URI from wsdl did not take precedence over URI in binding."); + } + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-prec.composite"); + helloWorld = domain.getService(HelloWorldOM.class, "HelloWorldComponent"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/AbstractHelloWorldOMTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/AbstractHelloWorldOMTestCase.java new file mode 100644 index 0000000000..56d0537a44 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/AbstractHelloWorldOMTestCase.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.sca.binding.ws.axis2.itests.endpoints; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.binding.ws.axis2.itests.HelloWorldOM; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public abstract class AbstractHelloWorldOMTestCase extends TestCase { + + private SCADomain domain; + private HelloWorldOM helloWorld; + + public void testCalculator() throws Exception { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement requestOM = fac.createOMElement("getGreetings", "http://helloworld-om", "helloworld"); + OMElement parmE = fac.createOMElement("name", "http://helloworld-om", "helloworld"); + requestOM.addChild(parmE); + parmE.addChild(fac.createOMText("petra")); + OMElement responseOM = helloWorld.getGreetings(requestOM); + OMElement child = (OMElement)responseOM.getFirstElement(); + Assert.assertEquals("Hello petra", ((OMText)child.getFirstOMChild()).getText()); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance(getCompositeName()); + helloWorld = domain.getService(HelloWorldOM.class, "HelloWorldComponent"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + + protected String getCompositeName() { + String className = this.getClass().getName(); + return className.substring(0, className.length() - 8).replace('.', '/') + ".composite"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiServiceTestCase.java new file mode 100644 index 0000000000..661afdddad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiServiceTestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests.endpoints; + +public class DefaultMultiServiceTestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleServiceTestCase.java new file mode 100644 index 0000000000..9b2e0eafa0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleServiceTestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests.endpoints; + +public class DefaultSingleServiceTestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURITestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURITestCase.java new file mode 100644 index 0000000000..98d9a73926 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURITestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests.endpoints; + +public class WSDLExplicitURITestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURITestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURITestCase.java new file mode 100644 index 0000000000..201d11a79f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURITestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests.endpoints; + +public class WSDLRelativeURITestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorldTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorldTestCase.java new file mode 100644 index 0000000000..f5d87cdcee --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorldTestCase.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.sca.binding.ws.axis2.itests.epr; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.binding.ws.axis2.itests.HelloWorld; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class HelloWorldTestCase extends TestCase { + + private SCADomain domain; + private HelloWorld helloWorld; + + public void testCalculator() throws Exception { + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorld.composite"); + helloWorld = domain.getService(HelloWorld.class, "HelloWorldComponent"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferClient.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferClient.java new file mode 100644 index 0000000000..cf5e4947d6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferClient.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.sca.binding.ws.axis2.itests.mtom; + +import javax.activation.DataHandler; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; +import java.awt.Image; +import org.apache.axiom.om.OMElement; +import javax.xml.transform.Source; + +/** + * This client program shows how to create an SCA runtime, start it, + * locate the FileTransfer service and invoke it. + */ +@Service(FileTransferServiceClient.class) +public class FileTransferClient implements FileTransferServiceClient { + + @Reference + public FileTransferService fileTransferService; + + public String uploadImageFileForward (Image attachment) throws Exception { + return fileTransferService.uploadImageFile(attachment); + } + + public String uploadSourceFileForward (Source attachment) throws Exception { + return fileTransferService.uploadSourceFile(attachment); + } + + public String uploadDataHandlerFileForward (DataHandler attachment) throws Exception { + return fileTransferService.uploadDataHandlerFile(attachment); + } + + public String uploadOMElementFileForward (OMElement attachment) throws Exception { + return fileTransferService.uploadOMElementFile(attachment); + } + + public String sendMyExceptionForward (MyException attachment) throws Exception { + return fileTransferService.sendMyException(attachment); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferMTOMTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferMTOMTestCase.java new file mode 100644 index 0000000000..35bf6888e3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferMTOMTestCase.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.sca.binding.ws.axis2.itests.mtom; + +import javax.activation.DataHandler; +import javax.activation.FileDataSource; +import java.awt.Image; + +import javax.xml.namespace.QName; +import javax.xml.transform.Source; +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMText; +import javax.xml.transform.dom.DOMSource; +import org.apache.axiom.om.OMFactory; +import java.awt.image.BufferedImage; + +import junit.framework.TestCase; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.binding.ws.axis2.itests.mtom.FileTransferServiceClient; +import org.apache.tuscany.sca.databinding.xml.String2Node; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class FileTransferMTOMTestCase extends TestCase { + + private SCADomain domain; + private FileTransferServiceClient filetransfer; + + /** + * Runs once before the tests + */ + @BeforeClass + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransferservice.composite"); + filetransfer = domain.getService(FileTransferServiceClient.class, "FileTransferClientComponent"); + } + + /** + * Runs once after the tests + */ + @AfterClass + protected void tearDown() throws Exception { + domain.close(); + } + + @Test + public void testImageFileTransfer() throws Exception { + try { + Image image = new BufferedImage(80, 24, BufferedImage.TYPE_INT_RGB); + assertEquals("File uploaded Sucessfully", filetransfer.uploadImageFileForward(image)); + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + @Test + public void testSourceFileTransfer() throws Exception { + try { + String xml = "ABC"; + Source source = new DOMSource(new String2Node().transform(xml, null)); + assertEquals("File uploaded Sucessfully", filetransfer.uploadSourceFileForward(source)); + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + @Test + public void testDataHandlerFileTransfer() throws Exception { + try { + // For testing purpose lets try uploading LICENSE file. + DataHandler dataHandler = new DataHandler(new FileDataSource("./LICENSE")); + assertEquals("File uploaded Sucessfully", filetransfer.uploadDataHandlerFileForward(dataHandler)); + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + @Test + public void testOMElementFileTransfer() throws Exception { + try { + OMFactory factory = OMAbstractFactory.getOMFactory(); + OMElement imageElement = factory.createOMElement(new QName("image")); + + DataHandler dataHandler = new DataHandler(new FileDataSource("./LICENSE")); + + OMText textData = factory.createOMText(dataHandler, true); + imageElement.addChild(textData); + assertEquals("File uploaded Sucessfully", filetransfer.uploadOMElementFileForward(imageElement)); + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + @Test + public void testSendMyException() throws Exception { + try { + MyException exp = new MyExceptionImpl(); + assertEquals("File uploaded Sucessfully", filetransfer.sendMyExceptionForward(exp)); + } catch (Exception ex){ + ex.printStackTrace(); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferService.java new file mode 100644 index 0000000000..ab7fc9c43a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferService.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.sca.binding.ws.axis2.itests.mtom; + +import org.osoa.sca.annotations.Remotable; +import javax.activation.DataHandler; +import java.awt.Image; +import javax.xml.transform.Source; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.apache.axiom.om.OMElement; + +/** + * This is the business interface of the MTOM FileTransfer service. + */ +@Remotable +public interface FileTransferService { + + public String uploadImageFile(Image attachment) throws Exception; + + public String uploadSourceFile(Source attachment) throws Exception; + + public String uploadDataHandlerFile(DataHandler attachment) throws Exception; + + public String uploadOMElementFile(OMElement attachment) throws Exception; + + //This method uses an user defined interface MyException as parameter type. + public String sendMyException(@XmlJavaTypeAdapter(MyExceptionAdapter.class) MyException attachment) + throws Exception; +} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceClient.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceClient.java new file mode 100644 index 0000000000..5fc95441b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceClient.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.sca.binding.ws.axis2.itests.mtom; + +import javax.activation.DataHandler; +import java.awt.Image; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.transform.Source; +import org.apache.axiom.om.OMElement; + +/** + * This is the client interface of the File Transfer service. + */ +public interface FileTransferServiceClient { + + public String uploadImageFileForward (Image attachment) throws Exception; + + public String uploadSourceFileForward (Source attachment) throws Exception; + + public String uploadDataHandlerFileForward (DataHandler attachment) throws Exception; + + public String uploadOMElementFileForward (OMElement attachment) throws Exception; + + public String sendMyExceptionForward (MyException attachment) throws Exception; +} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceImpl.java new file mode 100644 index 0000000000..cc757e5e33 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/FileTransferServiceImpl.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.sca.binding.ws.axis2.itests.mtom; + +import org.osoa.sca.annotations.Service; +import javax.activation.DataHandler; +import java.awt.Image; +import javax.xml.transform.Source; +import org.apache.axiom.om.OMElement; + +/** + * This class implements the HelloWorld service. + */ +@Service(interfaces={FileTransferService.class}) +public class FileTransferServiceImpl implements FileTransferService { + + public String uploadImageFile(Image attachment) throws Exception { + System.out.println("Content type = " + attachment.toString()); + return "File uploaded Sucessfully"; + } + + public String uploadSourceFile(Source attachment) throws Exception { + System.out.println("Content type = " + attachment.toString()); + return "File uploaded Sucessfully"; + } + + public String uploadDataHandlerFile(DataHandler attachment) throws Exception { + System.out.println("Content type = " + attachment.toString()); + return "File uploaded Sucessfully"; + } + + public String uploadOMElementFile(OMElement attachment) throws Exception { + System.out.println("Content type = " + attachment.toString()); + return "File uploaded Sucessfully"; + } + + public String sendMyException(MyException attachment) throws Exception { + System.out.println("Content type = " + attachment.toString()); + return "File uploaded Sucessfully"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyException.java new file mode 100644 index 0000000000..5ecc22572b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyException.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2.itests.mtom; + +//@XmlJavaTypeAdapter(MyExceptionAdapter.class) +public interface MyException { + + public String getMessage(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyExceptionAdapter.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyExceptionAdapter.java new file mode 100644 index 0000000000..4c4e8a3fcf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyExceptionAdapter.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.sca.binding.ws.axis2.itests.mtom; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +public class MyExceptionAdapter extends XmlAdapter { + public MyException unmarshal(MyExceptionImpl v) { + return v; + } + + public MyExceptionImpl marshal(MyException v) { + return (MyExceptionImpl)v; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyExceptionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyExceptionImpl.java new file mode 100644 index 0000000000..1bd9b9b1a0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/MyExceptionImpl.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.axis2.itests.mtom; + +public class MyExceptionImpl extends Exception implements MyException { + + public String getMessage() { + return "good job......"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/Data.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/Data.java new file mode 100644 index 0000000000..8c1e6b68da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/Data.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.sca.binding.ws.axis2.itests.pojo; + +//import java.io.Serializable; + +public class Data { + + private Data2[] a = null; + private int b = 0; + private float c = 0.0f; + + public Data2[] getA() { + return this.a; + } + + public void setA(Data2[] a) { + this.a = a; + } + + public int getB() { + return this.b; + } + + public void setB(int b) { + this.b = b; + } + + public float getC() { + return this.c; + } + + public void setC(float c) { + this.c = c; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/Data2.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/Data2.java new file mode 100644 index 0000000000..25954a0603 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/Data2.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.sca.binding.ws.axis2.itests.pojo; + +public class Data2 { + + private String[] asdf = null; + + public String[] getAsdf() { + return this.asdf; + } + + public void setAsdf(String[] asdf) { + this.asdf = asdf; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/POJOWSTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/POJOWSTestCase.java new file mode 100644 index 0000000000..35849ef77b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/POJOWSTestCase.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.sca.binding.ws.axis2.itests.pojo; + +import org.apache.tuscany.sca.node.SCAContribution; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; +import org.junit.Test; + +public class POJOWSTestCase { + + @Test + public void testWS() throws Exception { + + SCAContribution contrib = new SCAContribution("c1", "target/test-classes"); + SCANode node = SCANodeFactory.newInstance().createSCANode("org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/test.composite", contrib); + node.start(); + +// try { +// System.out.println("Test server started (press enter to shutdown)"); +// System.in.read(); +// } +// catch (IOException e) { +// System.err.println(e); +// e.printStackTrace(); +// } + + node.stop(); + System.out.println("Test server stopped"); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/TestService.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/TestService.java new file mode 100644 index 0000000000..2becc472b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/TestService.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.sca.binding.ws.axis2.itests.pojo; + +import org.osoa.sca.annotations.Remotable; + + +@Remotable +public interface TestService { + + public boolean printData(Data data); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/TestServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/TestServiceImpl.java new file mode 100644 index 0000000000..1946d67d79 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/TestServiceImpl.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.sca.binding.ws.axis2.itests.pojo; + +import java.util.Arrays; + +import org.osoa.sca.annotations.Service; + +@Service(TestService.class) +public class TestServiceImpl implements TestService { + + public boolean printData(Data data) { + if (data == null) { + System.out.println("data is null"); + return false; + } + + StringBuilder sb = new StringBuilder(256); + sb.append("Data:\n"); + Data2[] a = data.getA(); + if (a != null) { + for (int i = 0; i < a.length; i++) { + sb.append(" a["); + sb.append(i); + sb.append("] = "); + sb.append(Arrays.asList(a[i].getAsdf())); + sb.append("\n"); + } + } else { + sb.append(" a = null"); + } + sb.append("\n b = "); + sb.append(data.getB()); + sb.append("\n c = "); + sb.append(data.getC()); + sb.append("\n"); + + System.out.println(sb.toString()); + + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/package-info.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/package-info.java new file mode 100644 index 0000000000..7c8867530e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// @javax.xml.bind.annotation.XmlSchema(namespace="http://test/server") +package org.apache.tuscany.sca.binding.ws.axis2.itests.pojo; + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/AbstractHelloWorldOMTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/AbstractHelloWorldOMTestCase.java new file mode 100644 index 0000000000..6cdb12c221 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/AbstractHelloWorldOMTestCase.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.sca.binding.ws.axis2.itests.policy.configparams; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.binding.ws.axis2.itests.HelloWorldOM; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public abstract class AbstractHelloWorldOMTestCase extends TestCase { + + private SCADomain domain; + private HelloWorldOM helloWorld; + + public void testHelloWorld() throws Exception { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement requestOM = fac.createOMElement("getGreetings", "http://helloworld-om", "helloworld"); + OMElement parmE = fac.createOMElement("name", "http://helloworld-om", "helloworld"); + requestOM.addChild(parmE); + parmE.addChild(fac.createOMText("petra")); + OMElement responseOM = helloWorld.getGreetings(requestOM); + OMElement child = (OMElement)responseOM.getFirstElement(); + Assert.assertEquals("Hello petra", ((OMText)child.getFirstOMChild()).getText()); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance(getCompositeName()); + helloWorld = domain.getService(HelloWorldOM.class, "HelloWorldComponent"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + + protected String getCompositeName() { + String className = this.getClass().getName(); + return className.substring(0, className.length() - 8).replace('.', '/') + ".composite"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/ClientPWCBHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/ClientPWCBHandler.java new file mode 100644 index 0000000000..67d6f1c56e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/ClientPWCBHandler.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.sca.binding.ws.axis2.itests.policy.configparams; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + * + * @version $Rev$ $Date$ + */ +public class ClientPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Client UserId/Password Handler .... "); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/IntegrityPWCBHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/IntegrityPWCBHandler.java new file mode 100644 index 0000000000..45c5472100 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/IntegrityPWCBHandler.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.sca.binding.ws.axis2.itests.policy.configparams; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + * + * @version $Rev$ $Date$ + */ +public class IntegrityPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Integrity Password Handler .... "); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/ServerPWCBHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/ServerPWCBHandler.java new file mode 100644 index 0000000000..7a4b50cc2c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/ServerPWCBHandler.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.sca.binding.ws.axis2.itests.policy.configparams; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + * + * @version $Rev$ $Date$ + */ +public class ServerPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Server User/Passwd Handler...."); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityAuthenticationTestCaseFIXME.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityAuthenticationTestCaseFIXME.java new file mode 100644 index 0000000000..18a713a243 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityAuthenticationTestCaseFIXME.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests.policy.configparams; + +public class WSSecurityAuthenticationTestCaseFIXME extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.java new file mode 100644 index 0000000000..1fd1b8d48e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.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.sca.binding.ws.axis2.itests.policy.configparams; + +import java.security.Provider; +import java.security.Security; + +public class WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue extends AbstractHelloWorldOMTestCase { + + /** + * @see org.apache.tuscany.sca.binding.ws.axis2.itests.policy.configparams.AbstractHelloWorldOMTestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + // Workaround an issue with IBM JDK + Provider jce = Security.getProvider("IBMJCE"); + if (jce != null) { + // Make sure IBMJCE is used first + Security.removeProvider("IBMJCE"); + Security.insertProviderAt(jce, 1); + } + super.setUp(); + } + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityIntegrityTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityIntegrityTestCase.java new file mode 100644 index 0000000000..824132161c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityIntegrityTestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests.policy.configparams; + +public class WSSecurityIntegrityTestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/AbstractHelloWorldOMTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/AbstractHelloWorldOMTestCase.java new file mode 100644 index 0000000000..458a472479 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/AbstractHelloWorldOMTestCase.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.sca.binding.ws.axis2.itests.policy.mixed; + +import junit.framework.Assert; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.binding.ws.axis2.itests.HelloWorldOM; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public abstract class AbstractHelloWorldOMTestCase { + + private SCADomain domain; + private HelloWorldOM helloWorld; + + @Test + public void testHelloWorld() throws Exception { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement requestOM = fac.createOMElement("getGreetings", "http://helloworld-om", "helloworld"); + OMElement parmE = fac.createOMElement("name", "http://helloworld-om", "helloworld"); + requestOM.addChild(parmE); + parmE.addChild(fac.createOMText("petra")); + OMElement responseOM = helloWorld.getGreetings(requestOM); + OMElement child = (OMElement)responseOM.getFirstElement(); + Assert.assertEquals("Hello petra", ((OMText)child.getFirstOMChild()).getText()); + } + + @Before + public void setUp() throws Exception { + domain = SCADomain.newInstance(getCompositeName()); + helloWorld = domain.getService(HelloWorldOM.class, "HelloWorldComponent"); + } + + @After + public void tearDown() throws Exception { + domain.close(); + } + + protected String getCompositeName() { + String className = this.getClass().getName(); + return className.substring(0, className.length() - 8).replace('.', '/') + ".composite"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/ClientPWCBHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/ClientPWCBHandler.java new file mode 100644 index 0000000000..88fc0d63fa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/ClientPWCBHandler.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.sca.binding.ws.axis2.itests.policy.mixed; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + * + * @version $Rev$ $Date$ + */ +public class ClientPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Client UserId/Password Handler .... "); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + + System.out.println(" **** 1. UserId : " + pwcb.getIdentifer()); + System.out.println(" **** 2. Passwd : " + pwcb.getPassword()); + System.out.println(" **** 3. Usage : " + pwcb.getUsage()); + + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/IntegrityPWCBHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/IntegrityPWCBHandler.java new file mode 100644 index 0000000000..0d8914156f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/IntegrityPWCBHandler.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.sca.binding.ws.axis2.itests.policy.mixed; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + * + * @version $Rev$ $Date$ + */ +public class IntegrityPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Integrity Password Handler .... "); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + + System.out.println(" **** 1. UserId : " + pwcb.getIdentifer()); + System.out.println(" **** 2. Passwd : " + pwcb.getPassword()); + System.out.println(" **** 3. Usage : " + pwcb.getUsage()); + + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/ServerPWCBHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/ServerPWCBHandler.java new file mode 100644 index 0000000000..5840f71057 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/ServerPWCBHandler.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.sca.binding.ws.axis2.itests.policy.mixed; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + * + * @version $Rev$ $Date$ + */ +public class ServerPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Server User/Passwd Handler...."); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + System.out.println(" **** 1. UserId : " + pwcb.getIdentifer()); + System.out.println(" **** 2. Passwd : " + pwcb.getPassword()); + System.out.println(" **** 3. Usage : " + pwcb.getUsage()); + + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/WSSecurityMixedTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/WSSecurityMixedTestCase.java new file mode 100644 index 0000000000..db5b88f9ac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/WSSecurityMixedTestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests.policy.mixed; + +public class WSSecurityMixedTestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/AbstractHelloWorldOMTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/AbstractHelloWorldOMTestCase.java new file mode 100644 index 0000000000..04de589fb1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/AbstractHelloWorldOMTestCase.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.sca.binding.ws.axis2.itests.policy.wspolicy; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.binding.ws.axis2.itests.HelloWorldOM; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public abstract class AbstractHelloWorldOMTestCase extends TestCase { + + private SCADomain domain; + private HelloWorldOM helloWorld; + + public void testHelloWorld() throws Exception { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement requestOM = fac.createOMElement("getGreetings", "http://helloworld-om", "helloworld"); + OMElement parmE = fac.createOMElement("name", "http://helloworld-om", "helloworld"); + requestOM.addChild(parmE); + parmE.addChild(fac.createOMText("petra")); + OMElement responseOM = helloWorld.getGreetings(requestOM); + OMElement child = (OMElement)responseOM.getFirstElement(); + Assert.assertEquals("Hello petra", ((OMText)child.getFirstOMChild()).getText()); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance(getCompositeName()); + helloWorld = domain.getService(HelloWorldOM.class, "HelloWorldComponent"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + + protected String getCompositeName() { + String className = this.getClass().getName(); + return className.substring(0, className.length() - 8).replace('.', '/') + ".composite"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/ClientPWCBHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/ClientPWCBHandler.java new file mode 100644 index 0000000000..cf342653c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/ClientPWCBHandler.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.sca.binding.ws.axis2.itests.policy.wspolicy; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + * + * @version $Rev$ $Date$ + */ +public class ClientPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Client UserId/Password Handler .... "); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/IntegrityPWCBHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/IntegrityPWCBHandler.java new file mode 100644 index 0000000000..84b64d3902 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/IntegrityPWCBHandler.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.sca.binding.ws.axis2.itests.policy.wspolicy; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + * + * @version $Rev$ $Date$ + */ +public class IntegrityPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Integrity Password Handler .... "); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/ServerPWCBHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/ServerPWCBHandler.java new file mode 100644 index 0000000000..04825b6b56 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/ServerPWCBHandler.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.sca.binding.ws.axis2.itests.policy.wspolicy; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + * + * @version $Rev$ $Date$ + */ +public class ServerPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Server User/Passwd Handler...."); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityAuthenticationTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityAuthenticationTestCase.java new file mode 100644 index 0000000000..a439ff4c8f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityAuthenticationTestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests.policy.wspolicy; + +public class WSSecurityAuthenticationTestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.java new file mode 100644 index 0000000000..f37a8deeb7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.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.sca.binding.ws.axis2.itests.policy.wspolicy; + +import java.security.Provider; +import java.security.Security; + +public class WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue extends AbstractHelloWorldOMTestCase { + + /** + * @see org.apache.tuscany.sca.binding.ws.axis2.itests.policy.configparams.AbstractHelloWorldOMTestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + // Workaround an issue with IBM JDK + Provider jce = Security.getProvider("IBMJCE"); + if (jce != null) { + // Make sure IBMJCE is used first + Security.removeProvider("IBMJCE"); + Security.insertProviderAt(jce, 1); + } + super.setUp(); + } + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityIntegrityTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityIntegrityTestCase.java new file mode 100644 index 0000000000..18bbf98628 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityIntegrityTestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests.policy.wspolicy; + +public class WSSecurityIntegrityTestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12TestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12TestCase.java new file mode 100644 index 0000000000..b2ccd7f97d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12TestCase.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.sca.binding.ws.axis2.itests.soap12 ; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.binding.ws.axis2.itests.HelloWorld; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class HelloWorldSOAP12TestCase extends TestCase { + + private SCADomain domain; + + public void testHelloWorld() throws Exception { + HelloWorld helloWorld = domain.getService(HelloWorld.class, "HelloWorldClient"); + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + public void testHelloWorldSOAP() throws Exception { + HelloWorld helloWorld = domain.getService(HelloWorld.class, "HelloWorldClientSOAP"); + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + public void testHelloWorldSOAP11() throws Exception { + HelloWorld helloWorld = domain.getService(HelloWorld.class, "HelloWorldClientSOAP11"); + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + public void testHelloWorldSOAP12() throws Exception { + HelloWorld helloWorld = domain.getService(HelloWorld.class, "HelloWorldClientSOAP12"); + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12.composite"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/QuestionMarkWSDLTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/QuestionMarkWSDLTestCase.java new file mode 100644 index 0000000000..ee866f77ec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/QuestionMarkWSDLTestCase.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests.soap12; + +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Test ?wsdl works and that the returned WSDL has the correct endpoint + * + * @version $Rev$ $Date$ + */ +public class QuestionMarkWSDLTestCase extends TestCase { + + private static boolean newGenerator = true; + private SCADomain domain; + + /** + * Tests ?wsdl returns a soap 1.1 port by default + */ + public void testSOAPDefault() throws Exception { + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/ep1?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName( + "http://itests.axis2.ws.binding.sca.tuscany.apache.org" + (newGenerator ? "/" : ""), + newGenerator ? "HelloWorldService" : "HelloWorld")); + Port port = service.getPort(newGenerator ? "HelloWorldPort" : "HelloWorldSOAP11port_http"); + + String endpoint = getSOAP11Endpoint(port); + assertEquals("http://localhost:8085/ep1", endpoint); + } + + /** + * Tests ?wsdl returns a soap 1.1 port when binding uses requires="SOAP.1_1" + */ + public void testSOAP11Endpoint() throws Exception { + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/ep2?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName( + "http://itests.axis2.ws.binding.sca.tuscany.apache.org" + (newGenerator ? "/" : ""), + newGenerator ? "HelloWorldService" : "HelloWorld")); + Port port = service.getPort(newGenerator ? "HelloWorldPort" : "HelloWorldSOAP11port_http"); + + String endpoint = getSOAP11Endpoint(port); + assertEquals("http://localhost:8085/ep2", endpoint); + } + + /** + * Tests ?wsdl returns a soap 1.2 port when binding uses requires="SOAP.1_2" + */ + public void testSOAP12Endpoint() throws Exception { + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/ep3?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName( + "http://itests.axis2.ws.binding.sca.tuscany.apache.org" + (newGenerator ? "/" : ""), + newGenerator ? "HelloWorldService" : "HelloWorld")); + Port port = service.getPort(newGenerator ? "HelloWorldPort" : "HelloWorldSOAP12port_http"); + + String endpoint = getSOAP12Endpoint(port); + assertEquals("http://localhost:8085/ep3", endpoint); + } + + protected String getSOAP11Endpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + + protected String getSOAP12Endpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAP12Address) { + return ((SOAP12Address) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/questionmark-wsdl.composite"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler new file mode 100644 index 0000000000..32b042402b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# PolicyHandlerClasses to interpret specific PolicyModels against specific QoS infrastructures +# handler classname;qname=;model= +org.apache.tuscany.sca.policy.security.ws.Axis2ConfigParamPolicyHandler;intent=http://tuscany.apache.org/xmlns/sca/1.0#wsAuthentication,model=org.apache.tuscany.sca.policy.security.ws.Axis2ConfigParamPolicy diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.composite new file mode 100644 index 0000000000..5cea469e3d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.composite @@ -0,0 +1,50 @@ + + + + + + + + + + http://localhost:8085/services/HelloWorldWebService + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDL.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDL.composite new file mode 100644 index 0000000000..b11c50b00c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDL.composite @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdata.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdata.xsd new file mode 100644 index 0000000000..f09ed09b6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdata.xsd @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdefs.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdefs.xsd new file mode 100644 index 0000000000..ec67b84851 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdefs.xsd @@ -0,0 +1,27 @@ + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerinfo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerinfo.xsd new file mode 100644 index 0000000000..7c903c6394 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerinfo.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiService.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiService.composite new file mode 100644 index 0000000000..394bf05506 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiService.composite @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleService.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleService.composite new file mode 100644 index 0000000000..c7081b9a72 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleService.composite @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURI.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURI.composite new file mode 100644 index 0000000000..7d3e1d1327 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURI.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURI.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURI.composite new file mode 100644 index 0000000000..c2cd598508 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURI.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/helloworld-om-relative-uri.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/helloworld-om-relative-uri.wsdl new file mode 100644 index 0000000000..fe68755c47 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/helloworld-om-relative-uri.wsdl @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorld.composite new file mode 100644 index 0000000000..47ce6cc1a3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorld.composite @@ -0,0 +1,50 @@ + + + + + + + + + http://localhost:8085/myService + + + + + + + + + + + + + + + + + http://localhost:8085/myService + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-binding.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-binding.wsdl new file mode 100644 index 0000000000..7bf47bc412 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-binding.wsdl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-merged.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-merged.composite new file mode 100644 index 0000000000..dee0effd99 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-merged.composite @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-porttype.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-porttype.wsdl new file mode 100644 index 0000000000..c66fa51c34 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-porttype.wsdl @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-uri.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-uri.wsdl new file mode 100644 index 0000000000..baa223f41c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-uri.wsdl @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.composite new file mode 100644 index 0000000000..8fcbdef33d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.composite @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.wsdl new file mode 100644 index 0000000000..73ca02246d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.wsdl @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-prec.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-prec.composite new file mode 100644 index 0000000000..c506b09bb2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-prec.composite @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-prec.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-prec.wsdl new file mode 100644 index 0000000000..5908c43e7d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-prec.wsdl @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld.wsdl new file mode 100644 index 0000000000..1a2272d7ee --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld.wsdl @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransfer.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransfer.wsdl new file mode 100644 index 0000000000..df52fff9b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransfer.wsdl @@ -0,0 +1,220 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransferservice.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransferservice.composite new file mode 100644 index 0000000000..beba2512da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/mtom/filetransferservice.composite @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/test.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/test.composite new file mode 100644 index 0000000000..029a5e3c65 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/pojo/test.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityAuthentication.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityAuthentication.composite new file mode 100644 index 0000000000..da5bab45e8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityAuthentication.composite @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityConfidentiality.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityConfidentiality.composite new file mode 100644 index 0000000000..13e002be1b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityConfidentiality.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityIntegrity.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityIntegrity.composite new file mode 100644 index 0000000000..2f6fab0d07 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/WSSecurityIntegrity.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/definitions.xml new file mode 100644 index 0000000000..8fa2d3b8c0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/definitions.xml @@ -0,0 +1,101 @@ + + + + + + + + + + UsernameToken + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.configparams.ServerPWCBHandler + + + + + + + + + + UsernameToken + TuscanyWsUser + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.configparams.ClientPWCBHandler" + + PasswordText + + + + + + + + + + Timestamp Signature + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/security.properties + + + + + Timestamp Signature + TuscanyWsUser + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/security.properties + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.configparams.IntegrityPWCBHandler" + + DirectReference + + + + + + + + + + Timestamp Signature Encrypt + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.configparams.IntegrityPWCBHandler + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/security.properties + + + + + Timestamp Signature Encrypt + TuscanyWsUser + TuscanyWsUser + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.configparams.IntegrityPWCBHandler + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/security.properties + DirectReference + SKIKeyIdentifier + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/security.properties b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/security.properties new file mode 100644 index 0000000000..592edf183b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/security.properties @@ -0,0 +1,20 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- +org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin +org.apache.ws.security.crypto.merlin.keystore.type=jks +org.apache.ws.security.crypto.merlin.keystore.password=TuscanyWsUserPasswd +org.apache.ws.security.crypto.merlin.file=org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/tuscanyKeys.jks \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/tuscanyKeys.jks b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/tuscanyKeys.jks new file mode 100644 index 0000000000..0b4f2399f0 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/tuscanyKeys.jks differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/intent/definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/intent/definitions.xml new file mode 100644 index 0000000000..65f8cb67d8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/intent/definitions.xml @@ -0,0 +1,32 @@ + + + + + + + Communitcation thro this binding required Authentication. + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/WSSecurityMixed.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/WSSecurityMixed.composite new file mode 100644 index 0000000000..12b2b18e55 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/WSSecurityMixed.composite @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/definitions.xml new file mode 100644 index 0000000000..871e889835 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/definitions.xml @@ -0,0 +1,323 @@ + + + + + + + + + + UsernameToken + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.mixed.ServerPWCBHandler + + + + + + + + + + UsernameToken + TuscanyWsUser + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.mixed.ClientPWCBHandler" + + PasswordText + + + + + + + + + + Signature + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/security.properties + + + + + + + + + + Signature + TuscanyWsUser + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/security.properties + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.mixed.IntegrityPWCBHandler + DirectReference + + + + + + + + + + UsernameToken Signature + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/security.properties + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.mixed.ServerPWCBHandler + + + + + Signature + TuscanyWsUser + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/security.properties + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.mixed.ServerPWCBHandler + DirectReference + + + + + + + + + + Signature + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/security.properties + + + + + UsernameToken Signature + TuscanyWsUser + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.mixed.ClientPWCBHandler" + + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/security.properties + PasswordText + DirectReference + + + + + + + + + + + + + + + + + TuscanyWsUser + + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.mixed.ClientPWCBHandler + + + + + + + + + + + + + + + + + + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.mixed.ServerPWCBHandler + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TuscanyWsUser + TuscanyWsUser + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.wspolicy.IntegrityPWCBHandler + + + + JKS + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/tuscanyKeys.jks + TuscanyWsUserPasswd + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/security.properties b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/security.properties new file mode 100644 index 0000000000..cb188e6676 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/security.properties @@ -0,0 +1,20 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- +org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin +org.apache.ws.security.crypto.merlin.keystore.type=jks +org.apache.ws.security.crypto.merlin.keystore.password=TuscanyWsUserPasswd +org.apache.ws.security.crypto.merlin.file=org/apache/tuscany/sca/binding/ws/axis2/itests/policy/configparams/tuscanyKeys.jks \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/tuscanyKeys.jks b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/tuscanyKeys.jks new file mode 100644 index 0000000000..0b4f2399f0 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/tuscanyKeys.jks differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityAuthentication.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityAuthentication.composite new file mode 100644 index 0000000000..2a22a0905d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityAuthentication.composite @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityConfidentiality.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityConfidentiality.composite new file mode 100644 index 0000000000..e6f999aad7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityConfidentiality.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityIntegrity.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityIntegrity.composite new file mode 100644 index 0000000000..d9e889768b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/WSSecurityIntegrity.composite @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/definitions.xml new file mode 100644 index 0000000000..bfa9b1a222 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/definitions.xml @@ -0,0 +1,204 @@ + + + + + + + + + + + + + + + + + + TuscanyWsUser + PasswordText + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.wspolicy.ClientPWCBHandler + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TuscanyWsUser + TuscanyWsUser + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.wspolicy.IntegrityPWCBHandler + + + + JKS + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/tuscanyKeys.jks + TuscanyWsUserPasswd + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TuscanyWsUser + TuscanyWsUser + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.wspolicy.IntegrityPWCBHandler + + + JKS + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/tuscanyKeys.jks + TuscanyWsUserPasswd + + + + + + JKS + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/tuscanyKeys.jks + TuscanyWsUserPasswd + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/tuscanyKeys.jks b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/tuscanyKeys.jks new file mode 100644 index 0000000000..d77c889141 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/tuscanyKeys.jks differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import-nested.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import-nested.wsdl new file mode 100644 index 0000000000..41a491361f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import-nested.wsdl @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import.wsdl new file mode 100644 index 0000000000..99a8c6d81d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import.wsdl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-include.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-include.wsdl new file mode 100644 index 0000000000..80e4b62801 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-include.wsdl @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-import.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-import.composite new file mode 100644 index 0000000000..008d42d03d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-import.composite @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-include.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-include.composite new file mode 100644 index 0000000000..7fff56377b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-include.composite @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl.composite new file mode 100644 index 0000000000..c042ae5675 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl.composite @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12.composite new file mode 100644 index 0000000000..fbd4c66c45 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12.composite @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/questionmark-wsdl.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/questionmark-wsdl.composite new file mode 100644 index 0000000000..033a77eea6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/questionmark-wsdl.composite @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/pom.xml new file mode 100644 index 0000000000..36d155610a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/pom.xml @@ -0,0 +1,108 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-ws-wsdlgen + Apache Tuscany SCA Web Service binding WSDL Generator + + + + + org.apache.tuscany.sca + tuscany-binding-ws + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-wsdl-xml + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-java-jaxws + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-xsd + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-xsd-xml + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + junit + junit + 4.5 + test + + + org.apache.tuscany.sca + tuscany-core-databinding + 1.6-SNAPSHOT + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.ws.wsdlgen + ${pom.name} + org.apache.tuscany.sca.binding.ws.wsdlgen* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java new file mode 100644 index 0000000000..6bfd00220e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java @@ -0,0 +1,345 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.wsdlgen; + +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.wsdl.WSDLException; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ResolverExtension; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.impl.InvalidWSDLException; +import org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLInterfaceIntrospectorImpl; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.xsd.XSDFactory; + +/** + * @version $Rev$ $Date$ + */ +public class BindingWSDLGenerator { + private static final Logger logger = Logger.getLogger(BindingWSDLGenerator.class.getName()); + private static final QName SOAP12_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0", "SOAP.1_2"); + + public static boolean printWSDL; // external code sets this to print generated WSDL + + private BindingWSDLGenerator() { + // this class has static methods only and cannot be instantiated + } + + /** + * Log a warning message. + * @param problem + */ + private static void logWarning(Problem problem) { + Logger problemLogger = Logger.getLogger(problem.getSourceClassName(), problem.getBundleName()); + if (problemLogger != null){ + problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null, problem.getMessageId(), problem.getMessageParams()); + } else { + logger.severe("Can't get logger " + problem.getSourceClassName()+ " with bundle " + problem.getBundleName()); + } + } + + /** + * Report a warning. + * @param message + * @param binding + * @param parameters + */ + private static void warning(Monitor monitor, String message, WebServiceBinding wsBinding, String... messageParameters) { + Problem problem = new ProblemImpl(BindingWSDLGenerator.class.getName(), "wsdlgen-validation-messages", Severity.WARNING, wsBinding, message, (Object[])messageParameters); + if (monitor != null) { + monitor.problem(problem); + } else { + logWarning(problem); + } + } + + /** + * Report an error. + * @param message + * @param binding + * @param parameters + */ + private static void error(Monitor monitor, String message, WebServiceBinding wsBinding, String... messageParameters) { + Problem problem = new ProblemImpl(BindingWSDLGenerator.class.getName(), "wsdlgen-validation-messages", Severity.ERROR, wsBinding, message, (Object[])messageParameters); + if (monitor != null) { + monitor.problem(problem); + } else { + throw new WSDLGenerationException(problem.toString(), null, problem); + } + } + + /** + * Report an exception error. + * @param message + * @param binding + * @param exception + */ + private static void error(Monitor monitor, String message, WebServiceBinding wsBinding, Exception ex) { + Problem problem = new ProblemImpl(BindingWSDLGenerator.class.getName(), "wsdlgen-validation-messages", Severity.ERROR, wsBinding, message, ex); + if (monitor != null) { + monitor.problem(problem); + } else { + throw new WSDLGenerationException(problem.toString(), ex, problem); + } + } + + /** + * Report a fatal error. + * @param message + * @param binding + * @param exception + */ + private static void fatal(Monitor monitor, String message, WebServiceBinding wsBinding, String... messageParameters) { + Problem problem = new ProblemImpl(BindingWSDLGenerator.class.getName(), "wsdlgen-validation-messages", Severity.ERROR,wsBinding, message, (Object[])messageParameters); + throw new WSDLGenerationException(problem.toString(), null, problem); + } + + /** + * Report a fatal exception error. + * @param message + * @param binding + * @param exception + */ + private static void fatal(Monitor monitor, String message, WebServiceBinding wsBinding, Exception ex) { + Problem problem = new ProblemImpl(BindingWSDLGenerator.class.getName(), "wsdlgen-validation-messages", Severity.ERROR, wsBinding, message, ex); + throw new WSDLGenerationException(problem.toString(), ex, problem); + } + + /** + * This method can be called from the binding builder or from the runtime. + * Report problems and exceptions in the most appropriate way for both + * of these cases. + */ + public static void generateWSDL(Component component, + AbstractContract contract, + WebServiceBinding wsBinding, + ExtensionPointRegistry extensionPoints, + Monitor monitor) { + try { + createWSDLDocument(component, contract, wsBinding, extensionPoints, monitor); + } catch (WSDLGenerationException ex) { + if (ex.getProblem() != null) { + warning(monitor, "WsdlGenProblem", wsBinding, component.getName(), contract.getName()); + if (monitor != null) { + monitor.problem(ex.getProblem()); + } else { + throw ex; + } + } else if (ex.getCause() instanceof Exception) { + warning(monitor, "WsdlGenException", wsBinding, component.getName(), contract.getName()); + error(monitor, "UnexpectedException", wsBinding, (Exception)ex.getCause()); + } else { // should never happen + throw new IllegalStateException(ex); + } + } catch (RuntimeException ex) { + warning(monitor, "WsdlGenException", wsBinding, component.getName(), contract.getName()); + error(monitor, "UnexpectedException", wsBinding, ex); + } + } + + private static void createWSDLDocument(Component component, + AbstractContract contract, + WebServiceBinding wsBinding, + ExtensionPointRegistry extensionPoints, + Monitor monitor) { + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + DataBindingExtensionPoint dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class); + WSDLFactory wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + XSDFactory xsdFactory = modelFactories.getFactory(XSDFactory.class); + + if (((Contract)contract).getInterfaceContract(wsBinding) == null) { + // can happen if incorrect component service name + fatal(monitor, "MissingInterfaceContract", wsBinding, component.getName(), contract.getName()); + } + + InterfaceContract icontract = wsBinding.getBindingInterfaceContract(); + if (icontract == null) { + icontract = ((Contract)contract).getInterfaceContract(wsBinding).makeUnidirectional(false); + if (icontract instanceof JavaInterfaceContract) { + ModelResolver resolver = component instanceof ResolverExtension ? + ((ResolverExtension)component).getModelResolver() : null; + icontract = createWSDLInterfaceContract( + (JavaInterfaceContract)icontract, + requiresSOAP12(wsBinding), + resolver, + dataBindings, + wsdlFactory, + xsdFactory, + monitor); + } else { + try { + //TUSCANY-2316 Cloning the Interface Contract to avoid overriding data binding information + icontract = (InterfaceContract)icontract.clone(); + } catch (Exception e) { + //ignore + } + } + wsBinding.setBindingInterfaceContract(icontract); + } + + // TODO - fix up the conversational flag and operation sequences in case the contract has come from WSDL + // as we don't yet support requires="conversational" or sca:endConversation annotations + // in WSDL interface descriptions (see section 1.5.4 of the Assembly Specification V1.0) + if (contract.getInterfaceContract().getInterface() != null ) { + icontract.getInterface().setConversational(contract.getInterfaceContract().getInterface().isConversational()); + + for (Operation operation : icontract.getInterface().getOperations()){ + Operation serviceOperation = null; + + for (Operation tmpOp : contract.getInterfaceContract().getInterface().getOperations()){ + if (operation.getName().equals(tmpOp.getName())) { + serviceOperation = tmpOp; + break; + } + } + + if (serviceOperation != null ){ + operation.setConversationSequence(serviceOperation.getConversationSequence()); + } + } + } + + /* + // Look at all the Web Service bindings of the SCA service to see if any + // of them have an existing generated WSDL definitions document. If found, + // use it for this binding as well. If not found, generate a new document. + Definition definition = null; + for (Binding binding : contract.getBindings()) { + if (binding instanceof WebServiceBinding) { + definition = ((WebServiceBinding)binding).getWSDLDocument(); + if (definition != null) { + wsBinding.setWSDLDocument(definition); + break; + } + } + } + */ + // The above code is currently not used. Instead, we only look + // for a WSDL definitions document in this binding and don't + // attempt to share the same document across multiple bindings. + + // generate a WSDL definitions document if needed + Definition definition = wsBinding.getWSDLDocument(); + if (definition == null) { + definition = WSDLServiceGenerator.configureWSDLDefinition(wsBinding, component, contract, monitor); + wsBinding.setWSDLDocument(definition); + } + } + + protected static boolean requiresSOAP12(WebServiceBinding wsBinding) { + if (wsBinding instanceof IntentAttachPoint) { + List intents = ((IntentAttachPoint)wsBinding).getRequiredIntents(); + for (Intent intent : intents) { + if (SOAP12_INTENT.equals(intent.getName())) { + return true; + } + } + } + return false; + } + + /** + * Create a WSDLInterfaceContract from a JavaInterfaceContract + */ + protected static WSDLInterfaceContract createWSDLInterfaceContract(JavaInterfaceContract contract, + boolean requiresSOAP12, + ModelResolver resolver, + DataBindingExtensionPoint dataBindings, + WSDLFactory wsdlFactory, + XSDFactory xsdFactory, + Monitor monitor) { + + WSDLInterfaceContract wsdlContract = wsdlFactory.createWSDLInterfaceContract(); + WSDLInterface wsdlInterface = wsdlFactory.createWSDLInterface(); + wsdlContract.setInterface(wsdlInterface); + + WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); + JavaInterface iface = (JavaInterface)contract.getInterface(); + + Definition def = null; + try { + Interface2WSDLGenerator wsdlGenerator = + new Interface2WSDLGenerator(requiresSOAP12, resolver, dataBindings, xsdFactory, monitor); + def = wsdlGenerator.generate(iface, wsdlDefinition); + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + + // for debugging + if (printWSDL) { + try { + System.out.println("Generated WSDL for Java interface " + iface.getName() + " class " + iface.getJavaClass().getName()); + WSDLWriter writer = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter(); + writer.writeWSDL(def, System.out); + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + wsdlDefinition.setDefinition(def); + wsdlInterface.setWsdlDefinition(wsdlDefinition); + wsdlInterface.setRemotable(true); + wsdlInterface.setConversational(contract.getInterface().isConversational()); + wsdlInterface.setUnresolved(false); + wsdlInterface.setRemotable(true); + PortType portType = (PortType)def.getAllPortTypes().values().iterator().next(); + wsdlInterface.setPortType(portType); + + try { + for (Operation op : iface.getOperations()) { + javax.wsdl.Operation wsdlOp = portType.getOperation(op.getName(), null, null); + wsdlInterface.getOperations().add(WSDLInterfaceIntrospectorImpl.getOperation( + wsdlOp, wsdlDefinition, resolver, xsdFactory)); + } + } catch (InvalidWSDLException e) { + throw new WSDLGenerationException(e); + } + + return wsdlContract; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java new file mode 100644 index 0000000000..bfa882ebf7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java @@ -0,0 +1,1174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.wsdlgen; + +import java.lang.reflect.Method; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.OperationType; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.PortType; +import javax.wsdl.Types; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.schema.Schema; +import javax.wsdl.factory.WSDLFactory; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.XSDefinition; +import org.apache.tuscany.sca.xsd.impl.XSDefinitionImpl; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.apache.ws.commons.schema.XmlSchemaException; +import org.apache.ws.commons.schema.utils.NamespaceMap; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * @version $Rev: 670103 $ $Date: 2008-06-21 01:35:00 +0100 (Sat, 21 Jun 2008) $ + */ +public class Interface2WSDLGenerator { + private static final Logger logger = Logger.getLogger(Interface2WSDLGenerator.class.getName()); + private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; + private static final String SCHEMA_NAME = "schema"; + private static final QName SCHEMA_QNAME = new QName(SCHEMA_NS, SCHEMA_NAME); + private static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + + private static final String ANYTYPE_NAME = "anyType"; + private static final QName ANYTYPE_QNAME = new QName(SCHEMA_NS, ANYTYPE_NAME); + + + private WSDLFactory factory; + private DataBindingExtensionPoint dataBindings; + private WSDLDefinitionGenerator definitionGenerator; + private boolean requiresSOAP12; + private ModelResolver resolver; + private XSDFactory xsdFactory; + private Monitor monitor; + + public Interface2WSDLGenerator(boolean requiresSOAP12, + ModelResolver resolver, + DataBindingExtensionPoint dataBindings, + XSDFactory xsdFactory, + Monitor monitor) throws WSDLException { + super(); + this.requiresSOAP12 = requiresSOAP12; + this.resolver = resolver; + definitionGenerator = new WSDLDefinitionGenerator(requiresSOAP12, false); + this.dataBindings = dataBindings; + this.xsdFactory = xsdFactory; + this.monitor = monitor; + this.factory = WSDLFactory.newInstance(); + } + + /** + * Log a warning message. + * @param problem + */ + private static void logWarning(Problem problem) { + Logger problemLogger = Logger.getLogger(problem.getSourceClassName(), problem.getBundleName()); + if (problemLogger != null){ + problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null, problem.getMessageId(), problem.getMessageParams()); + } else { + logger.severe("Can't get logger " + problem.getSourceClassName()+ " with bundle " + problem.getBundleName()); + } + } + + /** + * Report a warning. + * @param message + * @param binding + * @param parameters + */ + private void warning(String message, Interface interfaze, String... messageParameters) { + Problem problem = new ProblemImpl(this.getClass().getName(), "wsdlgen-validation-messages", Severity.WARNING, interfaze, message, (Object[])messageParameters); + if (monitor != null) { + monitor.problem(problem); + } else { + logWarning(problem); + } + } + + /** + * Report a fatal error. + * @param message + * @param binding + * @param parameters + */ + private void fatal(String message, Interface interfaze, String... messageParameters) { + Problem problem = new ProblemImpl(this.getClass().getName(), "wsdlgen-validation-messages", Severity.ERROR, interfaze, message, (Object[])messageParameters); + throw new WSDLGenerationException(problem.toString(), null, problem); + } + + private XMLTypeHelper getTypeHelper(DataType type, Map helpers) { + if (type == null) { + return null; + } + String db = type.getDataBinding(); + if (db == null) { + return null; + } + if ("java:array".equals(db)) { + DataType dt = (DataType)type.getLogical(); + db = dt.getDataBinding(); + } + return helpers.get(db); + } + + private boolean inputTypesCompatible(DataType wrapperType, DataType> inputType, Map helpers) { + XMLTypeHelper wrapperHelper = getTypeHelper(wrapperType, helpers); + for (DataType dt : inputType.getLogical()) { + if (getTypeHelper(dt, helpers) != wrapperHelper) { + return false; + } + } + return true; + } + + private boolean outputTypeCompatible(DataType wrapperType, DataType outputType, Map helpers) { + if (getTypeHelper(outputType, helpers) != getTypeHelper(wrapperType, helpers)) { + return false; + } else { + return true; + } + } + + private void addDataType(Map> map, DataType type, Map helpers) { + if (type == null) { + return; + } + String db = type.getDataBinding(); + if (db == null) { + return; + } + if ("java:array".equals(db)) { + DataType dt = (DataType)type.getLogical(); + db = dt.getDataBinding(); + } + XMLTypeHelper helper = helpers.get(db); + List types = map.get(helper); + if (types == null) { + types = new ArrayList(); + map.put(helper, types); + } + types.add(type); + } + + private Map> getDataTypes(Interface intf, boolean useWrapper, Map helpers) { + Map> dataTypes = new HashMap>(); + for (Operation op : intf.getOperations()) { + WrapperInfo inputWrapper = op.getInputWrapper(); + DataType dt1 = null; + boolean useInputWrapper = useWrapper & inputWrapper != null; + if (useInputWrapper) { + dt1 = inputWrapper.getWrapperType(); + useInputWrapper &= inputTypesCompatible(dt1, op.getInputType(), helpers); + } + if (useInputWrapper) { + addDataType(dataTypes, dt1, helpers); + } else { + for (DataType dt : op.getInputType().getLogical()) { + addDataType(dataTypes, dt, helpers); + } + } + + DataType dt2 = null; + WrapperInfo outputWrapper = op.getOutputWrapper(); + boolean useOutputWrapper = useWrapper & outputWrapper != null; + if (useOutputWrapper) { + dt2 = outputWrapper.getWrapperType(); + useOutputWrapper &= outputTypeCompatible(dt2, op.getOutputType(), helpers); + } + if (useOutputWrapper) { + addDataType(dataTypes, dt2, helpers); + } else { + dt2 = op.getOutputType(); + addDataType(dataTypes, dt2, helpers); + } + + for (DataType dt3 : op.getFaultTypes()) { + DataType dt4 = dt3.getLogical(); + addDataType(dataTypes, dt4, helpers); + } + } + // Adding classes referenced by @XmlSeeAlso in the java interface + if (intf instanceof JavaInterface) { + JavaInterface javaInterface = (JavaInterface)intf; + Class[] seeAlso = getSeeAlso(javaInterface.getJavaClass()); + if (seeAlso != null) { + for (Class cls : seeAlso) { + DataType dt = new DataTypeImpl(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN); + addDataType(dataTypes, dt, helpers); + } + } + seeAlso = getSeeAlso(javaInterface.getCallbackClass()); + if (seeAlso != null) { + for (Class cls : seeAlso) { + DataType dt = new DataTypeImpl(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN); + addDataType(dataTypes, dt, helpers); + } + } + } + return dataTypes; + } + + private static Class[] getSeeAlso(Class interfaze) { + if (interfaze == null) { + return null; + } + XmlSeeAlso seeAlso = interfaze.getAnnotation(XmlSeeAlso.class); + if (seeAlso == null) { + return null; + } else { + return seeAlso.value(); + } + } + + + public Definition generate(Interface interfaze, WSDLDefinition wsdlDefinition) throws WSDLException { + if (interfaze == null) { + return null; + } + if (interfaze instanceof WSDLInterface) { + return ((WSDLInterface)interfaze).getWsdlDefinition().getDefinition(); + } + JavaInterface iface = (JavaInterface)interfaze; + if (!interfaze.isRemotable()) { + fatal("InterfaceNotRemotable", interfaze, iface.getName()); + } + QName name = getQName(iface); + Definition definition = factory.newDefinition(); + if (requiresSOAP12) { + definition.addNamespace("SOAP12", "http://schemas.xmlsoap.org/wsdl/soap12/"); + } else { + definition.addNamespace("SOAP", "http://schemas.xmlsoap.org/wsdl/soap/"); + } + definition.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/"); + definition.addNamespace("xs", SCHEMA_NS); + + String namespaceURI = name.getNamespaceURI(); + definition.setTargetNamespace(namespaceURI); + definition.setQName(new QName(namespaceURI, name.getLocalPart() + "Service", name.getPrefix())); + definition.addNamespace(name.getPrefix(), namespaceURI); + + PortType portType = definition.createPortType(); + portType.setQName(name); + Binding binding = definitionGenerator.createBinding(definition, portType); + Map helpers = new HashMap(); + Map> wrappers = new HashMap>(); + for (Operation op : interfaze.getOperations()) { + javax.wsdl.Operation operation = generateOperation(definition, op, helpers, wrappers); + portType.addOperation(operation); + String action = ((JavaOperation)op).getAction(); + if ((action == null || "".equals(action)) && !op.isInputWrapperStyle() && op.getInputWrapper() == null) { + // Bare style + action = "urn:" + op.getName(); + } + BindingOperation bindingOp = definitionGenerator.createBindingOperation(definition, operation, action); + binding.addBindingOperation(bindingOp); + } + portType.setUndefined(false); + definition.addPortType(portType); + binding.setUndefined(false); + definition.addBinding(binding); + wsdlDefinition.setBinding(binding); + + // call each helper in turn to populate the wsdl.types element + XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); + + for (Map.Entry> en: getDataTypes(interfaze, false, helpers).entrySet()) { + XMLTypeHelper helper = en.getKey(); + if (helper == null) { + continue; + } + List xsDefinitions = helper.getSchemaDefinitions(xsdFactory, resolver, en.getValue()); + + for (XSDefinition xsDef: xsDefinitions) { + + Document doc = xsDef.getDocument(); + if (doc != null) { + // TUSCANY-2757 and TUSCANY-3267 - flip global wrapper elements with nillable + // set true to be set to false. The JAXB RI seems to be generating this setting + // incorrectly according to the JAXB spec. + NodeList nodes = doc.getFirstChild().getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node aNode = nodes.item(i); + if (aNode.getLocalName() != null && aNode.getLocalName().equals("element")) { + NamedNodeMap attributes = aNode.getAttributes(); + Node nameAttr = attributes.getNamedItem("name"); + if (nameAttr != null) { + QName elementName = new QName(xsDef.getNamespace(), nameAttr.getNodeValue()); + if (wrappers.containsKey(elementName)) { + Node nillable = attributes.getNamedItem("nillable"); + if (nillable != null) { + nillable.setNodeValue("false"); + } + } + } + } + } + } + + loadXSD(schemaCollection, xsDef); + wsdlDefinition.getXmlSchemas().add(xsDef); + } + } + + // remove global wrapper elements with schema definitions from generation list + for (QName wrapperName: new HashSet(wrappers.keySet())) { + if (wsdlDefinition.getXmlSchemaElement(wrapperName) != null) { + wrappers.remove(wrapperName); + } + } + + schemaCollection = new XmlSchemaCollection(); + + // generate schema elements for wrappers that aren't defined in the schemas + if (wrappers.size() > 0) { + int i = 0; + int index = 0; + Map wrapperXSDs = new HashMap(); + Map> prefixMaps = new HashMap>(); + for (Map.Entry> entry: wrappers.entrySet()) { + String targetNS = entry.getKey().getNamespaceURI(); + Document schemaDoc = null; + Element schema = null; + XSDefinition xsDef = wrapperXSDs.get(targetNS); + if (xsDef != null) { + schemaDoc = xsDef.getDocument(); + schema = schemaDoc.getDocumentElement(); + } else { + xsDef = wsdlDefinition.getSchema(targetNS); + if (xsDef != null) { + schemaDoc = xsDef.getDocument(); + schema = schemaDoc.getDocumentElement(); + wrapperXSDs.put(targetNS, xsDef); + Map prefixMap = prefixMaps.get(schema); + if (prefixMap == null){ + prefixMap = new HashMap(); + prefixMaps.put(schema, prefixMap); + String [] prefixes = xsDef.getSchema().getNamespaceContext().getDeclaredPrefixes(); + for (int j = 0; j < prefixes.length; j++){ + prefixMap.put(xsDef.getSchema().getNamespaceContext().getNamespaceURI(prefixes[j]), + prefixes[j]); + } + } + } else { + schemaDoc = createDocument(); + schema = schemaDoc.createElementNS(SCHEMA_NS, "xs:schema"); + // The elementFormDefault should be set to unqualified, see TUSCANY-2388 + schema.setAttribute("elementFormDefault", "unqualified"); + schema.setAttribute("attributeFormDefault", "qualified"); + schema.setAttribute("targetNamespace", targetNS); + schema.setAttributeNS(XMLNS_NS, "xmlns:xs", SCHEMA_NS); + schema.setAttributeNS(XMLNS_NS, "xmlns:tns", targetNS); + schemaDoc.appendChild(schema); + prefixMaps.put(schema, new HashMap()); + xsDef = xsdFactory.createXSDefinition(); + xsDef.setUnresolved(true); + xsDef.setNamespace(targetNS); + xsDef.setDocument(schemaDoc); + // TUSCANY-2465: Set the system id to avoid schema conflict + xsDef.setLocation(URI.create("xsd_" + index + ".xsd")); + index++; + wrapperXSDs.put(targetNS, xsDef); + } + } + Element wrapper = schemaDoc.createElementNS(SCHEMA_NS, "xs:element"); + schema.appendChild(wrapper); + wrapper.setAttribute("name", entry.getKey().getLocalPart()); + if (entry.getValue().size() == 1 && entry.getValue().get(0).getQName() == null) { + // special case for global fault element + QName typeName = entry.getValue().get(0).getType().getQName(); + String nsURI = typeName.getNamespaceURI(); + if ("".equals(nsURI)) { + wrapper.setAttribute("type", typeName.getLocalPart()); + addSchemaImport(schema, "", schemaDoc); + } else if (targetNS.equals(nsURI)) { + wrapper.setAttribute("type", typeName.getLocalPart()); + } else if (SCHEMA_NS.equals(nsURI)) { + wrapper.setAttribute("type", "xs:" + typeName.getLocalPart()); + } else { + Map prefixMap = prefixMaps.get(schema); + String prefix = prefixMap.get(nsURI); + if (prefix == null) { + prefix = "ns" + i++; + while(prefixMap.containsValue(prefix)){ + prefix = "ns" + i++; + } + prefixMap.put(nsURI, prefix); + schema.setAttributeNS(XMLNS_NS, "xmlns:" + prefix, nsURI); + addSchemaImport(schema, nsURI, schemaDoc); + } + wrapper.setAttribute("type", prefix + ":" + typeName.getLocalPart()); + } + } else { + // normal wrapper containing type definition inline + Element complexType = schemaDoc.createElementNS(SCHEMA_NS, "xs:complexType"); + wrapper.appendChild(complexType); + if (entry.getValue().size() > 0) { + Element sequence = schemaDoc.createElementNS(SCHEMA_NS, "xs:sequence"); + complexType.appendChild(sequence); + for (ElementInfo element: entry.getValue()) { + Element xsElement = schemaDoc.createElementNS(SCHEMA_NS, "xs:element"); + if (element.isMany()) { + xsElement.setAttribute("maxOccurs", "unbounded"); + } + xsElement.setAttribute("minOccurs", "0"); + xsElement.setAttribute("name", element.getQName().getLocalPart()); + if (element.isNillable()) { + xsElement.setAttribute("nillable", "true"); + } + QName typeName = element.getType().getQName(); + String nsURI = typeName.getNamespaceURI(); + if ("".equals(nsURI)) { + xsElement.setAttribute("type", typeName.getLocalPart()); + addSchemaImport(schema, "", schemaDoc); + } else if (SCHEMA_NS.equals(nsURI)) { + xsElement.setAttribute("type", "xs:" + typeName.getLocalPart()); + } else { + Map prefixMap = prefixMaps.get(schema); + String prefix = prefixMap.get(nsURI); + if (prefix == null) { + if (targetNS.equals(nsURI)) { + prefix = "tns"; + } else { + prefix = "ns" + i++; + while(prefixMap.containsValue(prefix)){ + prefix = "ns" + i++; + } + addSchemaImport(schema, nsURI, schemaDoc); + } + prefixMap.put(nsURI, prefix); + schema.setAttributeNS(XMLNS_NS, "xmlns:" + prefix, nsURI); + } + xsElement.setAttribute("type", prefix + ":" + typeName.getLocalPart()); + } + sequence.appendChild(xsElement); + } + } + } + } + + // resolve XSDefinitions containing generated wrappers + for (XSDefinition xsDef: wrapperXSDs.values()) { + if (wsdlDefinition.getSchema(xsDef.getNamespace()) == null) { + wsdlDefinition.getXmlSchemas().add(xsDef); + } + + xsDef.setSchema(null); + xsDef.setSchemaCollection(null); + loadXSD(schemaCollection, xsDef); + } + } + + XSDefinition noNamespaceSchema = null; + XSDefinition defaultNamespaceSchema = null; + + for (XSDefinition xsDef: wsdlDefinition.getXmlSchemas()) { + // only apply these changes if we have a DOM to work with + // this will generally come from the JAXB generation. SDO + // just goes straight to generating XmlSchema structures + Document doc = xsDef.getDocument(); + if (doc != null) { + // TUSCANY-3283 find any schema that has been generated without a namespace + // and any schema using the default WSDL schema so that we can + // merge the two together + if (xsDef.getNamespace().equals("")){ + noNamespaceSchema = xsDef; + } + if (xsDef.getNamespace().equals(namespaceURI)){ + defaultNamespaceSchema = xsDef; + } + } + } + + // TUSCANY-3283 merge the no namespace schema into the default namespace schema + if (noNamespaceSchema != null && defaultNamespaceSchema != null){ + // remove the no namespace schema from our list of schema + wsdlDefinition.getXmlSchemas().remove(noNamespaceSchema); + // merge the schema with no namespace into the schema with the default namspace for this WSDL + mergeSchema(noNamespaceSchema, defaultNamespaceSchema, wsdlDefinition.getXmlSchemas()); + + schemaCollection = new XmlSchemaCollection(); + defaultNamespaceSchema.setSchema(null); + defaultNamespaceSchema.setSchemaCollection(null); + loadXSD(schemaCollection, defaultNamespaceSchema); + } + + // push the schema into the WSDL + for (XSDefinition xsDef: wsdlDefinition.getXmlSchemas()){ + addSchemaExtension(xsDef, schemaCollection, wsdlDefinition, definition); + } + + // useful for debugging DOM issues + //System.out.println("======================= Schema DOM =======================" ); + //for (XSDefinition xsDef : wsdlDefinition.getXmlSchemas()) { + // if (xsDef.getDocument() != null) { + // printDOM(xsDef.getDocument()); + // } + //} + + return definition; + } + + /** + * TUSCANY-3283 + * Merge the no namespace schema into the defualt namespace schema + * Relies on being called just after the getSchemaDefinitions call when the XSDefinitions + * have only the DOM information set + * + * @param noNamespaceSchema + * @param defaultNamespaceSchema + * @param xsDefinitions + */ + private void mergeSchema(XSDefinition noNamespaceSchema, XSDefinition defaultNamespaceSchema, Collection xsDefinitions){ + Document fromDoc = noNamespaceSchema.getDocument(); + Document toDoc = defaultNamespaceSchema.getDocument(); + + // merge namespace definitions from the nonamespace schema into the default namespace schema + for(int i = 0; i < fromDoc.getDocumentElement().getAttributes().getLength(); i++){ + Attr attribute = (Attr)fromDoc.getDocumentElement().getAttributes().item(i); + String attribName = attribute.getName(); + if (attribName.startsWith("xmlns:")){ + + String fromPrefix = attribName.substring(attribName.indexOf(":") + 1); + + if (fromPrefix.equals("xs") != true){ + // create a new namespace prefix to prevent clashes + toDoc.getDocumentElement().setAttributeNS("http://www.w3.org/2000/xmlns/", + "xmlns:__" + fromPrefix, + attribute.getValue()); + + // fix up any references to the existing namespace prefix + fixUpNoNamespaceNamespaces(fromDoc, fromPrefix); + } + } + } + + Node toDocFirstChild = toDoc.getDocumentElement().getFirstChild(); + + // merge types from the no namespace schema into the default namespace schema + for(int i = 0; i < fromDoc.getDocumentElement().getChildNodes().getLength(); i++){ + // merge the DOM types + Node node = fromDoc.getDocumentElement().getChildNodes().item(i); + Node newNode = toDoc.importNode(node, true); + + if (newNode.getLocalName() != null && + (newNode.getLocalName().equals("import") || + newNode.getLocalName().equals("include") || + newNode.getLocalName().equals("redefine") || + newNode.getLocalName().equals("annotation") )){ + toDoc.getDocumentElement().insertBefore(newNode, toDocFirstChild); + } else { + toDoc.getDocumentElement().appendChild(newNode); + } + } + + // fix up any references to the types we've just moved + for(int i = 0; i < fromDoc.getDocumentElement().getChildNodes().getLength(); i++){ + Node node = fromDoc.getDocumentElement().getChildNodes().item(i); + + // correct any references to no name types in other schema + if (node.getLocalName() != null && + node.getLocalName().equals("complexType")){ + Node typeName = node.getAttributes().getNamedItem("name"); + fixUpNoNamespaceReferences(xsDefinitions, typeName.getNodeValue(), defaultNamespaceSchema.getNamespace()); + } + } + } + + /** + * TUSCANY-3283 + * Correct any namespace prefixes in the no namespace schema to prevent them from + * clashing when the no namespace schema is merged with the default schema + * + * @param fromSchema + * @param fromPrefix + * @param toPrefix + */ + private void fixUpNoNamespaceNamespaces(Document fromSchema, String fromPrefix){ + NodeList elements = fromSchema.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema","element"); + for (int k = 0; k < elements.getLength(); k++){ + Element element = (Element) elements.item(k); + if (element != null && element.getAttributes() != null) { + Node type = element.getAttributes().getNamedItem("type"); + + if (type != null && + type.getNodeValue().startsWith(fromPrefix)){ + type.setNodeValue("__" + type.getNodeValue()); + } + } + } + } + + /** + * TUSCANY-3283 + * Correct any references in the schema list that used to point to types in the + * no namespace schema + * + * @param fromSchema + * @param toSchema + */ + private void fixUpNoNamespaceReferences(Collection xsDefinitions, String typeName, String defaultNamespace){ + + // fix up any references in any other schema that points to this type + for (XSDefinition xsDef: xsDefinitions) { + + if (xsDef.getDocument() != null){ + // look for any imports of the no namespace schema + Document refSchema = xsDef.getDocument(); + NodeList imports = refSchema.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema","import"); + List importsToDelete = new ArrayList(); + + for (int j = 0; j < imports.getLength(); j++){ + Element _import = (Element)imports.item(j); + + // Fix up the import + if (_import.getAttributes().getLength() == 0){ + if (xsDef.getNamespace().equals(defaultNamespace)){ + // remove the import + //_import.getParentNode().removeChild(_import); + importsToDelete.add(_import); + } else { + // update the import to refer to the default namespace + _import.setAttribute("namespace", defaultNamespace); + } + } + } + + for (Node _import : importsToDelete){ + _import.getParentNode().removeChild(_import); + } + + // look for any type attributes that refer to the + // node being merged + NodeList elements = refSchema.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema","element"); + for (int k = 0; k < elements.getLength(); k++){ + Element element = (Element) elements.item(k); + if (element != null && element.getAttributes() != null) { + Node type = element.getAttributes().getNamedItem("type"); + + if (type != null && + type.getNodeValue().equals(typeName)){ + if (xsDef.getNamespace().equals(defaultNamespace)){ + // just add "tns" in front of the type name as + // we have merged the type into this schema + type.setNodeValue("tns:" + type.getNodeValue()); + } else { + // add a namespace + refSchema.getDocumentElement().setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:__nnns", defaultNamespace); + + // prefix the type name with the namespace + type.setNodeValue("__nnns:" + type.getNodeValue()); + } + } + } + } + } + } + } + + /* + * Just used when debugging DOM problems + */ + private void printDOM(Document document){ + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + Source source = new DOMSource(document); + Result result = new StreamResult(System.out); + transformer.transform(source, result); + } catch (Exception ex){ + ex.toString(); + } + } + + private static void addSchemaImport(Element schema, String nsURI, Document schemaDoc) { + Element imp = schemaDoc.createElementNS(SCHEMA_NS, "xs:import"); + if (!"".equals(nsURI)) { + imp.setAttribute("namespace", nsURI); + } + // Scan all xs:import elements to match namespace + NodeList childNodes = schema.getElementsByTagNameNS(SCHEMA_NS, "import"); + for (int i = 0; i < childNodes.getLength(); i++) { + Node childNode = childNodes.item(i); + if (childNode instanceof Element) { + String ns = ((Element)childNode).getAttributeNS(SCHEMA_NS, "namespace"); + if (nsURI.equals(ns)) { + // The xs:import with the same namespace has been declared + return; + } + } + } + // Try to find the first node after the import elements + Node firstNodeAfterImport = null; + if (childNodes.getLength() > 0) { + firstNodeAfterImport = childNodes.item(childNodes.getLength() - 1).getNextSibling(); + } else { + firstNodeAfterImport = schema.getFirstChild(); + } + + if (firstNodeAfterImport == null) { + schema.appendChild(imp); + } else { + schema.insertBefore(imp, firstNodeAfterImport); + } + } + + private void addSchemaExtension(XSDefinition xsDef, + XmlSchemaCollection schemaCollection, + WSDLDefinition wsdlDefinition, + Definition definition) throws WSDLException { + if (xsDef.getAggregatedDefinitions() != null) { + for (XSDefinition xsd: xsDef.getAggregatedDefinitions()) { + addSchemaExtension(xsd, schemaCollection, wsdlDefinition, definition); + } + } else { + String nsURI = xsDef.getNamespace(); + Document document = xsDef.getDocument(); + if (document == null) { + try { + NamespaceMap prefixMap = new NamespaceMap(); + prefixMap.add("xs", SCHEMA_NS); + prefixMap.add("tns", nsURI); + XmlSchema schemaDef = xsDef.getSchema(); + schemaDef.setNamespaceContext(prefixMap); + Document[] docs = schemaDef.getAllSchemas(); + document = docs[docs.length-1]; + document.setDocumentURI(xsDef.getLocation().toString()); + xsDef.setDocument(document); + } catch (XmlSchemaException e) { + throw new RuntimeException(e); + } + } + //loadXSD(schemaCollection, xsDef); + //wsdlDefinition.getXmlSchemas().add(xsDef); + Element schema = document.getDocumentElement(); + Schema schemaExt = createSchemaExt(definition); + schemaExt.setDocumentBaseURI(document.getDocumentURI()); + schemaExt.setElement(schema); + } + } + + private static void loadXSD(XmlSchemaCollection schemaCollection, XSDefinition definition) { + if (definition.getSchema() != null) { + return; + } + if (definition.getDocument() != null) { + String uri = null; + if (definition.getLocation() != null) { + uri = definition.getLocation().toString(); + } + XmlSchema schema = schemaCollection.read(definition.getDocument(), uri, null); + if (definition.getSchemaCollection() == null) { + definition.setSchemaCollection(schemaCollection); + } + if (definition.getSchema() == null) { + definition.setSchema(schema); + } + } + } + + public Schema createSchemaExt(Definition definition) throws WSDLException { + Types types = definition.getTypes(); + if (types == null) { + types = definition.createTypes(); + definition.setTypes(types); + } + + Schema schemaExt = createSchema(definition); + types.addExtensibilityElement(schemaExt); + + return schemaExt; + } + + public Schema createSchema(Definition definition) throws WSDLException { + return (Schema)definition.getExtensionRegistry().createExtension(Types.class, SCHEMA_QNAME); + } + + private DocumentBuilderFactory documentBuilderFactory; + + public Document createDocument() { + Document document; + try { + if (documentBuilderFactory == null) { + documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(true); + } + document = documentBuilderFactory.newDocumentBuilder().newDocument(); + } catch (ParserConfigurationException ex) { + throw new WSDLGenerationException(ex); + } + // document.setDocumentURI("http://"); + return document; + } + + protected QName getQName(Interface interfaze) { + JavaInterface iface = (JavaInterface)interfaze; + QName qname = iface.getQName(); + if (qname != null) { + return qname; + } else { + Class javaClass = iface.getJavaClass(); + return new QName(JavaXMLMapper.getNamespace(javaClass), javaClass.getSimpleName(), "tns"); + } + } + + public javax.wsdl.Operation generateOperation(Definition definition, + Operation op, + Map helpers, + Map> wrappers) + throws WSDLException { + javax.wsdl.Operation operation = definition.createOperation(); + operation.setName(op.getName()); + operation.setUndefined(false); + + Input input = definition.createInput(); + Message inputMsg = definition.createMessage(); + String namespaceURI = definition.getQName().getNamespaceURI(); + QName inputMsgName = new QName(namespaceURI, op.getName()); + inputMsg.setQName(inputMsgName); + inputMsg.setUndefined(false); + definition.addMessage(inputMsg); + + List elements = null; + // FIXME: By default, java interface is mapped to doc-lit-wrapper style WSDL + if (op.getInputWrapper() != null) { + // Generate doc-lit-wrapper style + inputMsg.addPart(generateWrapperPart(definition, op, helpers, wrappers, true)); + } else { + // Bare style + int i = 0; + for (DataType d : op.getInputType().getLogical()) { + inputMsg.addPart(generatePart(definition, d, "arg" + i)); + elements = new ArrayList(); + ElementInfo element = getElementInfo(d.getPhysical(), d, null, helpers); + elements.add(element); + QName elementName = ((XMLType)d.getLogical()).getElementName(); + wrappers.put(elementName, elements); + i++; + } + } + input.setMessage(inputMsg); + operation.setInput(input); + + if (!op.isNonBlocking()) { + Output output = definition.createOutput(); + Message outputMsg = definition.createMessage(); + QName outputMsgName = new QName(namespaceURI, op.getName() + "Response"); + outputMsg.setQName(outputMsgName); + outputMsg.setUndefined(false); + definition.addMessage(outputMsg); + + if (op.getOutputWrapper() != null) { + outputMsg.addPart(generateWrapperPart(definition, op, helpers, wrappers, false)); + } else { + DataType outputType = op.getOutputType(); + if (outputType != null) { + outputMsg.addPart(generatePart(definition, outputType, "return")); + elements = new ArrayList(); + ElementInfo element = getElementInfo(outputType.getPhysical(), outputType, null, helpers); + elements.add(element); + QName elementName = ((XMLType)outputType.getLogical()).getElementName(); + wrappers.put(elementName, elements); + } + } + output.setMessage(outputMsg); + + operation.setOutput(output); + operation.setStyle(OperationType.REQUEST_RESPONSE); + } else { + operation.setStyle(OperationType.ONE_WAY); + } + + for (DataType faultType: op.getFaultTypes()) { + Fault fault = definition.createFault(); + QName faultName = ((XMLType)faultType.getLogical().getLogical()).getElementName(); + fault.setName(faultName.getLocalPart()); + Message faultMsg = definition.getMessage(faultName); + if (faultMsg == null) { + faultMsg = definition.createMessage(); + faultMsg.setQName(faultName); + faultMsg.setUndefined(false); + definition.addMessage(faultMsg); + faultMsg.addPart(generatePart(definition, faultType.getLogical(), faultName.getLocalPart())); + } + fault.setMessage(faultMsg); + operation.addFault(fault); + if (faultType.getLogical().getPhysical() != faultType.getPhysical()) { + // create special wrapper for type indirection to real fault bean + DataType logical = faultType.getLogical(); + elements = new ArrayList(); + elements.add(getElementInfo(logical.getPhysical(), logical, null, helpers)); + } else { + // convert synthesized fault bean to a wrapper type + for (DataType propDT: op.getFaultBeans().get(faultName)) { + XMLType logical = propDT.getLogical(); + elements = new ArrayList(); + elements.add(getElementInfo(propDT.getPhysical(), propDT, logical.getElementName(), helpers)); + } + } + wrappers.put(faultName, elements); + } + + operation.setUndefined(false); + return operation; + } + + public Part generatePart(Definition definition, DataType arg, String partName) { + Part part = definition.createPart(); + part.setName(partName); + if (arg != null && arg.getLogical() instanceof XMLType) { + XMLType xmlType = (XMLType)arg.getLogical(); + QName elementName = xmlType.getElementName(); + part.setElementName(elementName); + addNamespace(definition, elementName); + if (xmlType.getElementName() == null) { + QName typeName = xmlType.getTypeName(); + part.setTypeName(typeName); + addNamespace(definition, typeName); + } + } + return part; + } + + public Part generateWrapperPart(Definition definition, + Operation operation, + Map helpers, + Map> wrappers, + boolean input) throws WSDLException { + Part part = definition.createPart(); + String partName = input ? operation.getName() : (operation.getName() + "Response"); + part.setName(partName); + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + if ((inputWrapperInfo != null) && (outputWrapperInfo != null)) { + ElementInfo elementInfo = + input ? inputWrapperInfo.getWrapperElement() : outputWrapperInfo.getWrapperElement(); + List elements = + input ? inputWrapperInfo.getChildElements() : outputWrapperInfo.getChildElements(); + QName wrapperName = elementInfo.getQName(); + part.setElementName(wrapperName); + addNamespace(definition, wrapperName); + wrappers.put(wrapperName, elements); + + // FIXME: [rfeng] Ideally, we should try to register the wrappers only. But we are + // expriencing the problem that we cannot handle XSD imports + /* + Class wrapperClass = input ? opWrapper.getInputWrapperClass() : opWrapper.getOutputWrapperClass(); + DataType wrapperDT = input ? opWrapper.getInputWrapperType() : opWrapper.getOutputWrapperType(); + if (wrapperClass != null) { + getElementInfo(wrapperClass, wrapperDT, wrapperName, helpers); + return part; + } + */ + + Method method = ((JavaOperation)operation).getJavaMethod(); + if (input) { + Class[] paramTypes = method.getParameterTypes(); + for (int i = 0; i < paramTypes.length; i++) { + DataType dataType = operation.getInputType().getLogical().get(i); + elements.set(i, getElementInfo(paramTypes[i], dataType, elements.get(i).getQName(), helpers)); + } + } else { + Class returnType = method.getReturnType(); + if (returnType != Void.TYPE) { + DataType dataType = operation.getOutputType(); + elements.set(0, getElementInfo(returnType, dataType, elements.get(0).getQName(), helpers)); + } + } + } + return part; + } + + private ElementInfo getElementInfo(Class javaType, + DataType dataType, + QName name, + Map helpers) { + String db = dataType.getDataBinding(); + while ("java:array".equals(db)) { + dataType = (DataType)dataType.getLogical(); + db = dataType.getDataBinding(); + } + XMLTypeHelper helper = helpers.get(db); + if (helper == null) { + DataBinding dataBinding = dataBindings.getDataBinding(db); + if (dataBinding == null) { + QName element = name; + if (element == null || dataType.getLogical() instanceof XMLType) { + XMLType xmlType = (XMLType)dataType.getLogical(); + if (xmlType.getElementName() != null) { + element = xmlType.getElementName(); + } + } + return new ElementInfo(element, new TypeInfo(ANYTYPE_QNAME, false, null)); + // throw new ServiceRuntimeException("No data binding for " + db); + } + + helper = dataBinding.getXMLTypeHelper(); + if (helper == null) { + // Default to JAXB + helper = helpers.get(JAXBDataBinding.NAME); + if (helper == null) { + helper = dataBindings.getDataBinding(JAXBDataBinding.NAME).getXMLTypeHelper(); + helpers.put(JAXBDataBinding.NAME, helper); + } + } + helpers.put(db, helper); + } + TypeInfo typeInfo = helper.getTypeInfo(javaType.isArray() ? javaType.getComponentType() : javaType, + dataType.getLogical()); + ElementInfo element = new ElementInfo(name, typeInfo); + element.setMany(byte[].class != javaType && javaType.isArray()); + element.setNillable(!javaType.isPrimitive()); + return element; + } + + private static void addNamespace(Definition definition, QName name) { + String namespace = name.getNamespaceURI(); + if (definition.getPrefix(namespace) == null) { + definition.addNamespace("ns" + definition.getNamespaces().size(), namespace); + } + } + + /* + // currently not using the next three methods + public XmlSchemaType getXmlSchemaType(DataType type) { + return null; + } + + // FIXME: WE need to add databinding-specific Java2XSD generation + public Element generateXSD(DataType dataType) { + DataBinding dataBinding = dataBindings.getDataBinding(dataType.getDataBinding()); + if (dataBinding != null) { + // return dataBinding.generateSchema(dataType); + } + return null; + } + + public void generateWrapperElements(Operation op) { + XmlSchemaCollection collection = new XmlSchemaCollection(); + String ns = getQName(op.getInterface()).getNamespaceURI(); + XmlSchema schema = new XmlSchema(ns, collection); + schema.setAttributeFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED)); + schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED)); + + XmlSchemaElement inputElement = new XmlSchemaElement(); + inputElement.setQName(new QName(ns, op.getName())); + XmlSchemaComplexType inputType = new XmlSchemaComplexType(schema); + inputType.setName(""); + XmlSchemaSequence inputSeq = new XmlSchemaSequence(); + inputType.setParticle(inputSeq); + List argTypes = op.getInputType().getLogical(); + for (DataType argType : argTypes) { + XmlSchemaElement child = new XmlSchemaElement(); + Object logical = argType.getLogical(); + if (logical instanceof XMLType) { + child.setName(((XMLType)logical).getElementName().getLocalPart()); + XmlSchemaType type = getXmlSchemaType(argType); + child.setType(type); + } + inputSeq.getItems().add(child); + } + inputElement.setType(inputType); + + XmlSchemaElement outputElement = new XmlSchemaElement(); + outputElement.setQName(new QName(ns, op.getName() + "Response")); + XmlSchemaComplexType outputType = new XmlSchemaComplexType(schema); + outputType.setName(""); + XmlSchemaSequence outputSeq = new XmlSchemaSequence(); + outputType.setParticle(outputSeq); + DataType returnType = op.getOutputType(); + XmlSchemaElement child = new XmlSchemaElement(); + Object logical = returnType.getLogical(); + if (logical instanceof XMLType) { + child.setName(((XMLType)logical).getElementName().getLocalPart()); + XmlSchemaType type = getXmlSchemaType(returnType); + child.setType(type); + } + outputSeq.getItems().add(child); + outputElement.setType(outputType); + + schema.getElements().add(inputElement.getQName(), inputElement); + schema.getElements().add(outputElement.getQName(), outputElement); + + } + */ + + public WSDLFactory getFactory() { + return factory; + } + + public void setFactory(WSDLFactory factory) { + this.factory = factory; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLDefinitionGenerator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLDefinitionGenerator.java new file mode 100644 index 0000000000..989a12d43c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLDefinitionGenerator.java @@ -0,0 +1,316 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.wsdlgen; + +import java.util.Iterator; + +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap.SOAPFault; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.wsdl.extensions.soap12.SOAP12Binding; +import javax.wsdl.extensions.soap12.SOAP12Body; +import javax.wsdl.extensions.soap12.SOAP12Fault; +import javax.wsdl.extensions.soap12.SOAP12Operation; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import org.w3c.dom.Element; + +/** + * + * @version $Rev: 668025 $ $Date: 2008-06-16 01:06:34 +0100 (Mon, 16 Jun 2008) $ + */ +public class WSDLDefinitionGenerator { + private static final String SOAP_NS = "http://schemas.xmlsoap.org/wsdl/soap/"; + public static final QName SOAP_ADDRESS = new QName(SOAP_NS, "address"); + private static final QName SOAP_BINDING = new QName(SOAP_NS, "binding"); + private static final QName SOAP_BODY = new QName(SOAP_NS, "body"); + private static final QName SOAP_FAULT = new QName(SOAP_NS, "fault"); + private static final QName SOAP_OPERATION = new QName(SOAP_NS, "operation"); + private static final String SOAP12_NS = "http://schemas.xmlsoap.org/wsdl/soap12/"; + public static final QName SOAP12_ADDRESS = new QName(SOAP12_NS, "address"); + private static final QName SOAP12_BINDING = new QName(SOAP12_NS, "binding"); + private static final QName SOAP12_BODY = new QName(SOAP12_NS, "body"); + private static final QName SOAP12_FAULT = new QName(SOAP12_NS, "fault"); + private static final QName SOAP12_OPERATION = new QName(SOAP12_NS, "operation"); + + private static final String BINDING_SUFFIX = "Binding"; + private static final String SERVICE_SUFFIX = "Service"; + private static final String PORT_SUFFIX = "Port"; + + private boolean requiresSOAP12; + private boolean requiresJMS; + private QName soapAddress; + private QName soapBinding; + private QName soapBody; + private QName soapFault; + private QName soapOperation; + + public WSDLDefinitionGenerator(boolean requiresSOAP12, boolean requiresJMS) { + super(); + this.requiresSOAP12 = requiresSOAP12; + this.requiresJMS = requiresJMS; + soapAddress = requiresSOAP12 ? SOAP12_ADDRESS : SOAP_ADDRESS; + soapBinding = requiresSOAP12 ? SOAP12_BINDING : SOAP_BINDING; + soapBody = requiresSOAP12 ? SOAP12_BODY : SOAP_BODY; + soapFault = requiresSOAP12 ? SOAP12_FAULT : SOAP_FAULT; + soapOperation = requiresSOAP12 ? SOAP12_OPERATION : SOAP_OPERATION; + } + + public Definition cloneDefinition(WSDLFactory factory, Definition definition) throws WSDLException { + Element root = definition.getDocumentationElement(); + root = (Element)root.cloneNode(true); + WSDLReader reader = factory.newWSDLReader(); + return reader.readWSDL(definition.getDocumentBaseURI(), root); + } + + public Types createTypes(Definition definition) { + Types types = definition.createTypes(); + definition.setTypes(types); + return types; + } + + public Binding createBinding(Definition definition, PortType portType) { + try { + Binding binding = definition.createBinding(); + binding.setPortType(portType); + configureBinding(definition, binding, portType); + ExtensibilityElement bindingExtension = + definition.getExtensionRegistry().createExtension(Binding.class, soapBinding); + if (requiresSOAP12) { + ((SOAP12Binding)bindingExtension).setStyle("document"); + if (requiresJMS){ + ((SOAP12Binding)bindingExtension).setTransportURI("http://schemas.xmlsoap.org/soap/jms"); + } else { + ((SOAP12Binding)bindingExtension).setTransportURI("http://schemas.xmlsoap.org/soap/http"); + } + } else { + ((SOAPBinding)bindingExtension).setStyle("document"); + if (requiresJMS){ + ((SOAPBinding)bindingExtension).setTransportURI("http://schemas.xmlsoap.org/soap/jms"); + } else { + ((SOAPBinding)bindingExtension).setTransportURI("http://schemas.xmlsoap.org/soap/http"); + } + } + binding.addExtensibilityElement(bindingExtension); + return binding; + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + + protected void configureBinding(Definition definition, Binding binding, PortType portType) throws WSDLException { + QName portTypeName = portType.getQName(); + if (portTypeName != null) { + // Choose Binding if available. If this name is in use, insert + // separating underscores until there is no clash. + for (String suffix = BINDING_SUFFIX; ; suffix = "_" + suffix) { + QName name = new QName(definition.getTargetNamespace(), portTypeName.getLocalPart() + suffix); + if (definition.getBinding(name) == null) { + binding.setQName(name); + break; + } + } + } + } + + @SuppressWarnings("unchecked") + public void createBindingOperations(Definition definition, Binding binding, PortType portType) { + try { + for (Iterator oi = portType.getOperations().iterator(); oi.hasNext();) { + Operation operation = (Operation)oi.next(); + BindingOperation bindingOperation = + createBindingOperation(definition, operation, "urn:" + operation.getName()); + binding.addBindingOperation(bindingOperation); + } + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + @SuppressWarnings("unchecked") + public BindingOperation createBindingOperation(Definition definition, Operation operation, String action) + throws WSDLException { + BindingOperation bindingOperation = definition.createBindingOperation(); + bindingOperation.setOperation(operation); + configureBindingOperation(bindingOperation, operation); + ExtensibilityElement operationExtension = + definition.getExtensionRegistry().createExtension(BindingOperation.class, soapOperation); + if (requiresSOAP12) { + ((SOAP12Operation)operationExtension).setSoapActionURI(action); + } else { + ((SOAPOperation)operationExtension).setSoapActionURI(action); + } + bindingOperation.addExtensibilityElement(operationExtension); + if (operation.getInput() != null) { + BindingInput bindingInput = definition.createBindingInput(); + configureBindingInput(bindingInput, operation.getInput()); + ExtensibilityElement inputExtension = + definition.getExtensionRegistry().createExtension(BindingInput.class, soapBody); + if (requiresSOAP12) { + ((SOAP12Body)inputExtension).setUse("literal"); + } else { + ((SOAPBody)inputExtension).setUse("literal"); + } + bindingInput.addExtensibilityElement(inputExtension); + bindingOperation.setBindingInput(bindingInput); + } + if (operation.getOutput() != null) { + BindingOutput bindingOutput = definition.createBindingOutput(); + configureBindingOutput(bindingOutput, operation.getOutput()); + ExtensibilityElement outputExtension = + definition.getExtensionRegistry().createExtension(BindingOutput.class, soapBody); + if (requiresSOAP12) { + ((SOAP12Body)outputExtension).setUse("literal"); + } else { + ((SOAPBody)outputExtension).setUse("literal"); + } + bindingOutput.addExtensibilityElement(outputExtension); + bindingOperation.setBindingOutput(bindingOutput); + } + for (Iterator fi = operation.getFaults().values().iterator(); fi.hasNext();) { + Fault fault = (Fault)fi.next(); + BindingFault bindingFault = definition.createBindingFault(); + ExtensibilityElement faultExtension = + definition.getExtensionRegistry().createExtension(BindingFault.class, soapFault); + configureBindingFault(bindingFault, faultExtension, fault); + bindingFault.addExtensibilityElement(faultExtension); + bindingOperation.addBindingFault(bindingFault); + } + return bindingOperation; + } + + protected void configureBindingOperation(BindingOperation bindingOperation, Operation operation) + throws WSDLException { + bindingOperation.setName(operation.getName()); + } + + protected void configureBindingInput(BindingInput bindingInput, Input input) throws WSDLException { + bindingInput.setName(input.getName()); + } + + protected void configureBindingOutput(BindingOutput bindingOutput, Output output) throws WSDLException { + bindingOutput.setName(output.getName()); + } + + protected void configureBindingFault(BindingFault bindingFault, + ExtensibilityElement faultExtension, + Fault fault) + throws WSDLException { + String faultName = fault.getName(); + bindingFault.setName(faultName); + if (requiresSOAP12) { + ((SOAP12Fault)faultExtension).setName(faultName); + ((SOAP12Fault)faultExtension).setUse("literal"); + } else { + ((SOAPFault)faultExtension).setName(faultName); + ((SOAPFault)faultExtension).setUse("literal"); + } + } + + public Service createService(Definition definition, PortType portType) { + try { + Service service = definition.createService(); + configureService(definition, service, portType); + // createPort(definition, binding, service); + definition.addService(service); + return service; + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + public Service createService(Definition definition, Binding binding) { + try { + Service service = definition.createService(); + configureService(definition, service, binding.getPortType()); + // createPort(definition, binding, service); + definition.addService(service); + return service; + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + protected void configureService(Definition definition, Service service, PortType portType) throws WSDLException { + QName portTypeName = portType.getQName(); + if (portTypeName != null) { + // Choose Service if available. If this name is in use, insert + // separating underscores until there is no clash. + for (String suffix = SERVICE_SUFFIX; ; suffix = "_" + suffix) { + QName name = new QName(definition.getTargetNamespace(), portTypeName.getLocalPart() + suffix); + if (definition.getService(name) == null) { + service.setQName(name); + break; + } + } + } + } + + public Port createPort(Definition definition, Binding binding, Service service, String uri) { + try { + Port port = definition.createPort(); + port.setBinding(binding); + configurePort(port, binding); + if (uri != null) { + ExtensibilityElement portExtension = + definition.getExtensionRegistry().createExtension(Port.class, soapAddress); + if (requiresSOAP12) { + ((SOAP12Address)portExtension).setLocationURI(uri); + } else { + ((SOAPAddress)portExtension).setLocationURI(uri); + } + port.addExtensibilityElement(portExtension); + } + service.addPort(port); + return port; + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + protected void configurePort(Port port, Binding binding) throws WSDLException { + if (binding.getPortType() != null && binding.getPortType().getQName() != null) { + port.setName(binding.getPortType().getQName().getLocalPart() + PORT_SUFFIX); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLGenerationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLGenerationException.java new file mode 100644 index 0000000000..bf9e22f645 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLGenerationException.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.sca.binding.ws.wsdlgen; + +import org.apache.tuscany.sca.monitor.Problem; +import org.osoa.sca.ServiceRuntimeException; + +public class WSDLGenerationException extends ServiceRuntimeException { + private static final long serialVersionUID = 1L; + private Problem problem; + + public WSDLGenerationException() { + super(); + } + + public WSDLGenerationException(String message, Throwable cause) { + super(message, cause); + } + + public WSDLGenerationException(String message) { + super(message); + } + + public WSDLGenerationException(Throwable cause) { + super(cause); + } + + public WSDLGenerationException(String message, Throwable cause, Problem problem) { + super(message, cause); + this.problem = problem; + } + + public Problem getProblem() { + return problem; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java new file mode 100644 index 0000000000..e57900f6cd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java @@ -0,0 +1,542 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.wsdlgen; + +//FIXME: trim the import list down to what's really needed + + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap12.SOAP12Address; +import javax.wsdl.extensions.soap12.SOAP12Binding; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * WSDLServiceGenerator generates a binding WSDL service document. + * + * @version $Rev$ $Date$ + */ +public class WSDLServiceGenerator { + // the following switch is temporary for debugging + public static boolean printWSDL; // external code sets this to print generated WSDL + + private static final Logger logger = Logger.getLogger(WSDLServiceGenerator.class.getName()); + private static final QName TRANSPORT_JMS_QUALIFIED_INTENT = + new QName("http://www.osoa.org/xmlns/sca/1.0", "transport.jms"); + private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; + private static final String ADDRESS = "Address"; + + private WSDLServiceGenerator() { + // this class has static methods only and cannot be instantiated + } + + /** + * Log a warning message. + * @param problem + */ + private static void logWarning(Problem problem) { + Logger problemLogger = Logger.getLogger(problem.getSourceClassName(), problem.getBundleName()); + if (problemLogger != null){ + problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null, problem.getMessageId(), problem.getMessageParams()); + } else { + logger.severe("Can't get logger " + problem.getSourceClassName()+ " with bundle " + problem.getBundleName()); + } + } + + /** + * Report a warning. + * @param message + * @param binding + * @param parameters + */ + private static void warning(Monitor monitor, String message, WebServiceBinding wsBinding, String... messageParameters) { + Problem problem = new ProblemImpl(WSDLServiceGenerator.class.getName(), "wsdlgen-validation-messages", Severity.WARNING, wsBinding, message, (Object[])messageParameters); + if (monitor != null) { + monitor.problem(problem); + } else { + logWarning(problem); + } + } + + /** + * Report an error. + * @param message + * @param binding + * @param parameters + */ + private static void error(Monitor monitor, String message, WebServiceBinding wsBinding, String... messageParameters) { + Problem problem = new ProblemImpl(WSDLServiceGenerator.class.getName(), "wsdlgen-validation-messages", Severity.ERROR, wsBinding, message, (Object[])messageParameters); + if (monitor != null) { + monitor.problem(problem); + } else { + throw new WSDLGenerationException(problem.toString(), null, problem); + } + } + + /** + * Generate a suitably configured WSDL definition + */ + protected static Definition configureWSDLDefinition(WebServiceBinding wsBinding, + Component component, + AbstractContract contract, + Monitor monitor) { + + //[nash] changes to the builder sequence avoid calling this for a CompositeService + assert !(contract instanceof CompositeService); + /* + // For every promoted composite service, the underlying component + // gets a copy of the service with the name prefixed by "$promoted$." + String contractName = (contract instanceof CompositeService ? "$promoted$." : "") + contract.getName(); + */ + String contractName = contract.getName(); + + List ports = new ArrayList(); + WSDLDefinition wsdlDefinition = wsBinding.getWSDLDefinition(); + if (wsdlDefinition == null) { + error(monitor, "NoWsdlInterface", wsBinding, component.getName(), contract.getName()); + return null; + } + Definition def = wsdlDefinition.getDefinition(); + + boolean wsdlProvidedByUser = (wsdlDefinition.getBinding() == null); + + if (wsdlProvidedByUser) { + // The WSDL document was provided by the user. Generate a new + // WSDL document with imports from the user-provided document. + WSDLFactory factory = null; + try { + factory = WSDLFactory.newInstance(); + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + Definition newDef = factory.newDefinition(); + + // Construct a target namespace from the base URI of the user's + // WSDL document (is this what we should be using?) and a path + // computed according to the SCA Web Service binding spec. + String nsName = component.getName() + "/" + contractName; + String namespaceURI = null; + try { + URI userTNS = new URI(def.getTargetNamespace()); + namespaceURI = userTNS.resolve("/" + nsName).toString(); + } catch (URISyntaxException e1) { + throw new WSDLGenerationException(e1); + } catch (IllegalArgumentException e2) { + throw new WSDLGenerationException(e2); + } + + // set name and targetNamespace attributes on the definition + String defsName = component.getName() + "." + contractName; + newDef.setQName(new QName(namespaceURI, defsName)); + newDef.setTargetNamespace(namespaceURI); + newDef.addNamespace("tns", namespaceURI); + + // set wsdl namespace prefix on the definition + newDef.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/"); + + // import the service or reference interface portType + List imports = new ArrayList(); + Interface interfaze = wsBinding.getBindingInterfaceContract().getInterface(); + if (interfaze instanceof WSDLInterface) { + PortType portType = ((WSDLInterface)interfaze).getPortType(); + boolean ok = importPortType(portType, wsdlDefinition, newDef, imports); + if (!ok) { + error(monitor, "PortTypeNotFound", wsBinding, portType.getQName().toString(), + component.getName(), contract.getName()); + } + } + + // import an existing binding if specified + Binding binding = wsBinding.getBinding(); + if (binding != null) { + boolean ok = importBinding(binding, wsdlDefinition, newDef, imports); + if (ok) { + boolean ok2 = importPortType(binding.getPortType(), wsdlDefinition, newDef, imports); + if (!ok2) { + error(monitor, "PortTypeNotFound", wsBinding, binding.getPortType().getQName().toString(), + component.getName(), contract.getName()); + } + } else { + error(monitor, "BindingNotFound", wsBinding, binding.getQName().toString(), + component.getName(), contract.getName()); + } + } + + // import bindings and portTypes needed by services and ports + QName serviceQName = wsBinding.getServiceName(); + String portName = wsBinding.getPortName(); + if (serviceQName != null) { + Service service = def.getService(serviceQName); + if (portName != null) { + Port port = service.getPort(portName); + Port newPort = copyPort(newDef, port, wsBinding); + if (newPort != null) { + importBinding(port.getBinding(), wsdlDefinition, newDef, imports); + ports.add(newPort); + } else { + error(monitor, "InvalidPort", wsBinding, serviceQName.toString(), portName, + component.getName(), contract.getName()); + } + } else { + for (Object port : service.getPorts().values()) { + Port newPort = copyPort(newDef, (Port)port, wsBinding); + if (newPort != null) { + importBinding(((Port)port).getBinding(), wsdlDefinition, newDef, imports); + ports.add(newPort); + } else { + // not an error, just ignore the port + warning(monitor, "IgnoringPort", wsBinding, serviceQName.toString(), ((Port)port).getName(), + component.getName(), contract.getName()); + } + } + if (ports.size() == 0) { + error(monitor, "NoValidPorts", wsBinding, serviceQName.toString(), + component.getName(), contract.getName()); + } + } + } + + // replace original WSDL definition by the generated definition + def = newDef; + + } else { + // The WSDL definition was generated by Interface2WSDLGenerator. + // Reuse it instead of creating a new definition here. + } + + // add a service and ports to the generated definition + WSDLDefinitionGenerator helper = + new WSDLDefinitionGenerator(BindingWSDLGenerator.requiresSOAP12(wsBinding),false); + WSDLInterface wi = (WSDLInterface)wsBinding.getBindingInterfaceContract().getInterface(); + PortType portType = wi.getPortType(); + Service service = helper.createService(def, portType); + if (wsBinding.getBinding() == null && ports.size() == 0) { + Binding binding = helper.createBinding(def, portType); + if (BindingWSDLGenerator.requiresSOAP12(wsBinding)) { + def.addNamespace("SOAP12", "http://schemas.xmlsoap.org/wsdl/soap12/"); + } else { + def.addNamespace("SOAP11", "http://schemas.xmlsoap.org/wsdl/soap/"); + } + helper.createBindingOperations(def, binding, portType); + binding.setUndefined(false); + def.addBinding(binding); + + String endpointURI = computeActualURI(wsBinding, null); + Port port = helper.createPort(def, binding, service, endpointURI); + wsBinding.setService(service); + wsBinding.setPort(port); + } else { + if (ports.size() > 0) { + // there are one or more user-specified valid ports + for (Port port : ports) { + service.addPort(port); + } + if (ports.size() == 1) { + // only one port, so use it + wsBinding.setPort(ports.get(0)); + } else { + // multiple ports, make them all available + wsBinding.setPort(null); + } + } else { + // no valid user-specified ports, so create a suitably configured port + String endpointURI = computeActualURI(wsBinding, null); + Port port = helper.createPort(def, wsBinding.getBinding(), service, endpointURI); + if (BindingWSDLGenerator.requiresSOAP12(wsBinding)) { + def.addNamespace("SOAP12", "http://schemas.xmlsoap.org/wsdl/soap12/"); + } else { + def.addNamespace("SOAP11", "http://schemas.xmlsoap.org/wsdl/soap/"); + } + wsBinding.setPort(port); + } + wsBinding.setService(service); + } + + // TUSCANY-2900 - add jms binding and service port if required + // TODO - remove service/ports from any imported WSDL + // - find away to allow users to retrieve WSDL with JMS bindings + // as a jms binding on it's own provides not target for ?wsdl + if ((!wsdlProvidedByUser) && + (wsBinding.getURI() != null) && + (wsBinding.getURI().startsWith("jms"))){ + + // need to work out how to check if user has already specified a binding + + // create jms binding + helper = new WSDLDefinitionGenerator(BindingWSDLGenerator.requiresSOAP12(wsBinding),true); + Binding binding = helper.createBinding(def, portType); + helper.createBindingOperations(def, binding, portType); + binding.setUndefined(false); + def.addBinding(binding); + + // create a jms port + String endpointURI = computeActualURI(wsBinding, null); + Port port = helper.createPort(def, binding, service, endpointURI); + wsBinding.setService(service); + wsBinding.setPort(port); + + //printWSDL = true; + } + + // for debugging + if (printWSDL) { + try { + System.out.println("Generated WSDL for " + component.getName() + "/" + contractName); + WSDLWriter writer = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter(); + writer.writeWSDL(def, System.out); + } catch (WSDLException e) { + throw new WSDLGenerationException(e); + } + } + + return def; + } + + private static boolean importPortType(PortType portType, + WSDLDefinition wsdlDef, + Definition newDef, + List imports) { + return addImport(portType.getQName(), PortType.class, wsdlDef, newDef, imports); + } + + private static boolean importBinding(Binding binding, + WSDLDefinition wsdlDef, + Definition newDef, + List imports) { + boolean ok = addImport(binding.getQName(), Binding.class, wsdlDef, newDef, imports); + if (ok) { + List bindingExtensions = binding.getExtensibilityElements(); + for (final Object extension : bindingExtensions) { + if (extension instanceof SOAPBinding) { + newDef.addNamespace("SOAP11", "http://schemas.xmlsoap.org/wsdl/soap/"); + } + if (extension instanceof SOAP12Binding) { + newDef.addNamespace("SOAP12", "http://schemas.xmlsoap.org/wsdl/soap12/"); + } + } + } + return ok; + } + + private static boolean addImport(QName name, + Class type, + WSDLDefinition wsdlDef, + Definition newDef, + List imports) { + String namespace = name.getNamespaceURI(); + if (newDef.getImports(namespace) == null) { + WSDLDefinition impDef = findDefinition(wsdlDef, name, type); + if (impDef != null) { + Import imp = newDef.createImport(); + imp.setNamespaceURI(namespace); + imp.setLocationURI(impDef.getURI().toString()); + imp.setDefinition(impDef.getDefinition()); + newDef.addNamespace("ns" + imports.size(), namespace); + newDef.addImport(imp); + imports.add(impDef); + return true; + } else { + // import was not added because element not found + return false; + } + } + return true; + } + + private static WSDLDefinition findDefinition(WSDLDefinition wsdlDef, QName name, Class type) { + if (wsdlDef == null || name == null) { + return wsdlDef; + } + if (wsdlDef.getURI() != null) { // not a facade + Definition def = wsdlDef.getDefinition(); + Map types = type == PortType.class ? def.getPortTypes() : def.getBindings(); + if (types.get(name) != null) { + return wsdlDef; + } + } + for (WSDLDefinition impDef : wsdlDef.getImportedDefinitions()) { + WSDLDefinition d = findDefinition(impDef, name, type); + if (d != null) { + return d; + } + } + return null; + } + + private static Port copyPort(Definition def, Port port, WebServiceBinding wsBinding) { + Port newPort = def.createPort(); + newPort.setName(port.getName()); + newPort.setBinding(port.getBinding()); + List portExtensions = port.getExtensibilityElements(); + for (final Object extension : portExtensions) { + ExtensibilityElement newExt = null; + if (extension instanceof SOAPAddress) { + def.addNamespace("SOAP11", "http://schemas.xmlsoap.org/wsdl/soap/"); + try { + newExt = def.getExtensionRegistry().createExtension( + Port.class, WSDLDefinitionGenerator.SOAP_ADDRESS); + } catch (WSDLException e) { + } + String uri = computeActualURI(wsBinding, port); + ((SOAPAddress)newExt).setLocationURI(uri); + newPort.addExtensibilityElement(newExt); + } else if (extension instanceof SOAP12Address) { + def.addNamespace("SOAP12", "http://schemas.xmlsoap.org/wsdl/soap12/"); + try { + newExt = def.getExtensionRegistry().createExtension( + Port.class, WSDLDefinitionGenerator.SOAP12_ADDRESS); + } catch (WSDLException e) { + } + String uri = computeActualURI(wsBinding, port); + ((SOAP12Address)newExt).setLocationURI(uri); + newPort.addExtensibilityElement(newExt); + } else { + // we don't support ports with other extensibility elements such as HTTPAddress + return null; + } + } + return newPort; + } + + /** + * Compute the endpoint URI based on section 2.1.1 of the WS binding Specification 1. + * The URIs in the endpoint(s) of the referenced WSDL, which may be relative + * 2. The URI specified by the wsa:Address element of the + * wsa:EndpointReference, which may be relative 3. The explicitly stated URI + * in the "uri" attribute of the binding.ws element, which may be relative, + * 4. The implicit URI as defined by in section 1.7 in the SCA Assembly Specification + * If the has no wsdlElement but does have a uri attribute then + * the uri takes precedence over any implicitly used WSDL. + * + */ + private static String computeActualURI(WebServiceBinding wsBinding, Port port) { + + URI eprURI = null; + if (wsBinding.getEndPointReference() != null) { + eprURI = getEPR(wsBinding); + } + + URI wsdlURI = null; + if (wsBinding.getServiceName() != null && wsBinding.getBindingName() == null) { + // explicitly points at a WSDL port, may be a relative URI + wsdlURI = getEndpoint(port); + } + + // if the WSDL port/endpoint has an absolute URI use that + if (wsdlURI != null && wsdlURI.isAbsolute()) { + return wsdlURI.toString(); + } + + // if the wsa:EndpointReference has an address element with an absolute URI use that + if (eprURI != null && eprURI.isAbsolute()) { + return eprURI.toString(); + } + + // either there is no WSDL port endpoint URI or that URI is relative + String actualURI = wsBinding.getURI(); + if (eprURI != null && eprURI.toString().length() != 0) { + // there is a relative URI in the binding EPR + actualURI = actualURI + "/" + eprURI; + } + + if (wsdlURI != null && wsdlURI.toString().length() != 0) { + // there is a relative URI in the WSDL port + actualURI = actualURI + "/" + wsdlURI; + } + + if (actualURI != null) { + actualURI = URI.create(actualURI).normalize().toString(); + } + + return actualURI; + } + + private static URI getEPR(WebServiceBinding wsBinding) { + NodeList nodeList = wsBinding.getEndPointReference().getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node childNode = nodeList.item(i); + if (childNode instanceof Element && ADDRESS.equals(childNode.getLocalName())) { + NodeList addrNodes = childNode.getChildNodes(); + for (int j = 0; j < addrNodes.getLength(); j++) { + Node addrNode = addrNodes.item(j); + if (addrNode instanceof Text) { + return URI.create(((Text)addrNode).getWholeText()); + } + } + } + } + return null; + } + + /** + * Returns the endpoint of a given port. + */ + private static URI getEndpoint(Port wsdlPort) { + if (wsdlPort != null) { + List wsdlPortExtensions = wsdlPort.getExtensibilityElements(); + for (Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + String uri = ((SOAPAddress)extension).getLocationURI(); + return (uri == null || "".equals(uri)) ? null : URI.create(uri); + } + if (extension instanceof SOAP12Address) { + SOAP12Address address = (SOAP12Address)extension; + String uri = address.getLocationURI(); + return (uri == null || "".equals(uri)) ? null : URI.create(uri); + } + } + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/resources/wsdlgen-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/resources/wsdlgen-validation-messages.properties new file mode 100644 index 0000000000..4bfbdd2901 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/main/resources/wsdlgen-validation-messages.properties @@ -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. +# +# +WsdlGenProblem = Unable to generate WSDL for {0}/{1} +WsdlGenException = Exception while generating WSDL for {0}/{1} +UnexpectedException = Exception thrown was: {0} +MissingInterfaceContract = No interface contract for {0}/{1} +InterfaceNotRemotable = Interface not remotable: {0} +IgnoringPort = Port {0}/{1} in {2}/{3} is not supported and was ignored +PortTypeNotFound = PortType {0} in {1}/{2} was not found +BindingNotFound = Binding {0} in {1}/{2} was not found +InvalidPort = Port {0}/{1} in {2}/{3} is not supported +NoValidPorts = No valid ports for service {0} in {1}/{2} +NoWsdlInterface = No WSDL interface definition for {1}/{2} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/Other.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/Other.java new file mode 100644 index 0000000000..7e6a1de546 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/Other.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.sca.binding.ws.other; + +/** + * + * @version $Rev$ $Date$ + */ +public class Other { + private String name; + + public String getName() { + return name; + } + public void setName(String name ) { + this.name = name; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/package-info.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/package-info.java new file mode 100644 index 0000000000..f10a2286e6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/other/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://other.ws.binding.sca.tuscany.apache.org/") +package org.apache.tuscany.sca.binding.ws.other; + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java new file mode 100644 index 0000000000..e474c7a318 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.wsdlgen; + +import java.util.List; +import java.util.Map; + +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.PortType; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor; +import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSFaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.xml.XSDModelResolver; +import org.osoa.sca.annotations.Remotable; + +/** + * + * @version $Rev$ $Date$ + */ +public class BindingWSDLGeneratorTestCase extends TestCase { + + public void testCreateWSDLInterfaceContract() throws InvalidInterfaceException { + DefaultModelFactoryExtensionPoint modelFactories = new DefaultModelFactoryExtensionPoint(); + WSDLFactory wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + XSDFactory xsdFactory = modelFactories.getFactory(XSDFactory.class); + DefaultJavaInterfaceFactory factory = new DefaultJavaInterfaceFactory(); + JavaInterfaceContract javaIC = factory.createJavaInterfaceContract(); + JavaInterface iface = factory.createJavaInterface(HelloWorld.class); + DefaultDataBindingExtensionPoint dataBindings = new DefaultDataBindingExtensionPoint(); + JAXWSFaultExceptionMapper faultExceptionMapper = new JAXWSFaultExceptionMapper(dataBindings, null); + new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper, null).visitInterface(iface); + new DataBindingJavaInterfaceProcessor(dataBindings).visitInterface(iface); + javaIC.setInterface(iface); + WSDLInterfaceContract wsdlIC = BindingWSDLGenerator.createWSDLInterfaceContract(javaIC, false, new XSDModelResolver(null, null), dataBindings, wsdlFactory, xsdFactory, null); + assertNotNull(wsdlIC); + WSDLInterface wsdlInterface = (WSDLInterface)wsdlIC.getInterface(); + assertNotNull(wsdlInterface); + assertEquals(1, wsdlInterface.getOperations().size()); + assertEquals("sayHello", wsdlInterface.getOperations().get(0).getName()); + assertNotNull(wsdlInterface.getPortType()); + + JavaInterfaceContract javaIC2 = factory.createJavaInterfaceContract(); + JavaInterface iface2 = factory.createJavaInterface(TestJavaInterface.class); + new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper, null).visitInterface(iface2); + new DataBindingJavaInterfaceProcessor(dataBindings).visitInterface(iface2); + javaIC2.setInterface(iface2); + WSDLInterfaceContract wsdlIC2 = BindingWSDLGenerator.createWSDLInterfaceContract(javaIC2, false, new XSDModelResolver(null, null), dataBindings, wsdlFactory, xsdFactory, null); + assertNotNull(wsdlIC2); + } + +} + +@Remotable +interface HelloWorld { + String sayHello(String s); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.java new file mode 100644 index 0000000000..f1e12f8ce0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.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.sca.binding.ws.wsdlgen; + +import java.io.StringWriter; + +import javax.wsdl.Definition; +import javax.wsdl.xml.WSDLWriter; + +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor; +import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSFaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor; +import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.xsd.DefaultXSDFactory; +import org.apache.tuscany.sca.xsd.xml.XSDModelResolver; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class Interface2WSDLGeneratorTestCase { + + @Test + public void testGenerate() throws Exception { + DefaultJavaInterfaceFactory iFactory = new DefaultJavaInterfaceFactory(); + JavaInterface iface = iFactory.createJavaInterface(TestJavaInterface.class); + DefaultDataBindingExtensionPoint dataBindings = new DefaultDataBindingExtensionPoint(); + JAXWSFaultExceptionMapper faultExceptionMapper = new JAXWSFaultExceptionMapper(dataBindings, null); + new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper, null).visitInterface(iface); + new DataBindingJavaInterfaceProcessor(dataBindings).visitInterface(iface); + DefaultModelFactoryExtensionPoint modelFactories = new DefaultModelFactoryExtensionPoint(); + WSDLDefinition wsdlDefinition = new DefaultWSDLFactory(modelFactories).createWSDLDefinition(); + DefaultXSDFactory factory = new DefaultXSDFactory(); + Interface2WSDLGenerator generator = new Interface2WSDLGenerator(false, new XSDModelResolver(null, null), dataBindings, factory, null); + Definition definition = generator.generate(iface, wsdlDefinition); + + // print the generated WSDL file and inline schemas + WSDLWriter writer = generator.getFactory().newWSDLWriter(); + StringWriter sw = new StringWriter(); + writer.writeWSDL(definition, sw); + System.out.println(sw.toString()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestException.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestException.java new file mode 100644 index 0000000000..1e4f802e01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestException.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.sca.binding.ws.wsdlgen; + +/** + * + * @version $Rev$ $Date$ + */ +public class TestException extends Exception { + + private String userdata; + + public TestException(String message) { + super(message); + } + + public TestException(String message, String userdata) { + super(message); + this.userdata = userdata; + } + + public String getUserdata() { + return userdata; + } + + public void setUserdata(String userdata) { + this.userdata = userdata; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFault.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFault.java new file mode 100644 index 0000000000..da2c285bac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFault.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.sca.binding.ws.wsdlgen; + +import javax.xml.ws.WebFault; + +/** + * + * @version $Rev$ $Date$ + */ +@WebFault(faultBean="org.apache.tuscany.sca.binding.ws.wsdlgen.TestFaultBean") +public class TestFault extends Exception { + + private TestFaultBean bean; + + public TestFault(TestFaultBean bean, String message) { + super(message); + this.bean = bean; + } + + public TestFault(TestFaultBean bean, String message, Throwable cause) { + super(message, cause); + this.bean = bean; + } + + public TestFaultBean getFaultInfo() { + return bean; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFaultBean.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFaultBean.java new file mode 100644 index 0000000000..64cce0e49d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestFaultBean.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.sca.binding.ws.wsdlgen; + +/** + * + * @version $Rev$ $Date$ + */ +public class TestFaultBean { + private String lastName; + private String firstName; + private float age; + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public float getAge() { + return age; + } + + public void setAge(float age) { + this.age = age; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaClass.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaClass.java new file mode 100644 index 0000000000..3fd7361ae1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaClass.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.sca.binding.ws.wsdlgen; +import org.apache.tuscany.sca.binding.ws.other.Other; + +/** + * + * @version $Rev$ $Date$ + */ +public class TestJavaClass { + public Other other; + public String name; + public int number; + public float balance; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaInterface.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaInterface.java new file mode 100644 index 0000000000..729ed9c146 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/TestJavaInterface.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.sca.binding.ws.wsdlgen; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; +import javax.jws.soap.SOAPBinding.ParameterStyle; + +import org.osoa.sca.annotations.OneWay; +import org.osoa.sca.annotations.Remotable; + +/** + * + * @version $Rev$ $Date$ + */ +@Remotable +@WebService +public interface TestJavaInterface { + String m1(String str); + + @OneWay + @WebMethod + void m2(int i); + + @WebMethod + String m3(); + + void m4(); + + @WebMethod + String m5(String str, int i); + + @WebMethod(exclude = true) + void dummy(); + + @WebMethod + void m6(TestJavaClass info) throws TestException; + + @WebMethod + void m7(TestJavaClass info) throws TestFault; + + @WebMethod + @SOAPBinding(parameterStyle=ParameterStyle.BARE) + void m8(String str); + + @WebMethod + @SOAPBinding(parameterStyle=ParameterStyle.BARE) + int m9(String str); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/pom.xml new file mode 100644 index 0000000000..1e3abd8ea7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/pom.xml @@ -0,0 +1,100 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-ws-xml + Apache Tuscany SCA WS Binding XML Model + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws-wsdlgen + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-sca + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-interface-wsdl-xml + 1.6-SNAPSHOT + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.ws.xml + ${pom.name} + org.apache.tuscany.sca.binding.ws.xml* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/BindingBuilderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/BindingBuilderImpl.java new file mode 100644 index 0000000000..f2376231ab --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/BindingBuilderImpl.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.sca.binding.ws.xml; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.builder.BindingBuilder; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A factory for the calculated WSDL document needed by Web Service bindings. + * + * @version $Rev$ $Date$ + */ +public class BindingBuilderImpl implements BindingBuilder { + + private ExtensionPointRegistry extensionPoints; + + public BindingBuilderImpl(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + } + + /** + * Create a calculated WSDL document and save it in the Web Service binding. + */ + public void build(Component component, AbstractContract contract, Binding binding, Monitor monitor) { + BindingWSDLGenerator.generateWSDL(component, contract, (WebServiceBinding)binding, extensionPoints, monitor); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.java new file mode 100644 index 0000000000..ad2540e5fe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.java @@ -0,0 +1,230 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.xml; + +import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; + +import java.io.StringWriter; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Helper methods to read and write a wsa:endpointReference + * TODO: almost direct copy of code for Assembly properties + * must be able to move to a common utility + * + * @version $Rev$ $Date$ + */ +public class EndPointReferenceHelper { + + /** + * Read a wsa:endpointReference into a DOM Element + */ + public static Element readEndPointReference(XMLStreamReader reader) { + try { + + return loadElement(reader); + + } catch (XMLStreamException e) { + throw new RuntimeException(e); + } catch (ParserConfigurationException e) { + throw new RuntimeException(e); + } + } + + /** + * Write a wsa:endpointReference from a DOM Element + */ + public static void writeEndPointReference(Element element, XMLStreamWriter writer) { + try { + + saveElement(element, writer); + + } catch (XMLStreamException e) { + throw new RuntimeException(e); + } + } + + private static Element loadElement(XMLStreamReader reader) throws XMLStreamException, ParserConfigurationException { + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + Node root = document; + Node current = root; + while (true) { + switch (reader.getEventType()) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + Element child = createElement(document, name); + + // push the new element and make it the current one + current.appendChild(child); + current = child; + + int count = reader.getNamespaceCount(); + for (int i = 0; i < count; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + declareNamespace(child, prefix, ns); + } + + if(!"".equals(name.getNamespaceURI())) + declareNamespace(child, name.getPrefix(), name.getNamespaceURI()); + + // add the attributes for this element + count = reader.getAttributeCount(); + for (int i = 0; i < count; i++) { + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String qname = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + if (prefix != null && prefix.length() != 0) { + qname = prefix + ":" + qname; + } + child.setAttributeNS(ns, qname, value); + if (ns != null) { + declareNamespace(child, prefix, ns); + } + } + + break; + case XMLStreamConstants.CDATA: + current.appendChild(document.createCDATASection(reader.getText())); + break; + case XMLStreamConstants.CHARACTERS: + current.appendChild(document.createTextNode(reader.getText())); + break; + case XMLStreamConstants.END_ELEMENT: + // if we are back at the root then we are done + if ("EndpointReference".equals(reader.getName().getLocalPart())) { + return document.getDocumentElement(); + } + + // pop the element off the stack + current = current.getParentNode(); + } + if ( reader.hasNext()) reader.next(); + } + } + + private 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); + } + + private static void declareNamespace(Element element, String prefix, String ns) { + if (ns == null) { + ns = ""; + } + if (prefix == null) { + prefix = ""; + } + String qname = null; + if ("".equals(prefix)) { + qname = "xmlns"; + } else { + qname = "xmlns:" + prefix; + } + Node node = element; + boolean declared = false; + while (node != null && node.getNodeType() == Node.ELEMENT_NODE) { + NamedNodeMap attrs = node.getAttributes(); + if (attrs == null) { + break; + } + Node attr = attrs.getNamedItem(qname); + if (attr != null) { + declared = ns.equals(attr.getNodeValue()); + break; + } + node = node.getParentNode(); + } + if (!declared) { + org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname); + attr.setValue(ns); + element.setAttributeNodeNS(attr); + } + } + + private static void saveElement(Element element, XMLStreamWriter writer) throws XMLStreamException{ + + XMLStreamReader reader = + XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(element)); + + while (reader.hasNext()) { + switch (reader.next()) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + writer.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); + + int namespaces = reader.getNamespaceCount(); + for (int i = 0; i < namespaces; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + writer.writeNamespace(prefix, ns); + } + + if (!"".equals(name.getNamespaceURI())) { + writer.writeNamespace(name.getPrefix(), name.getNamespaceURI()); + } + + // add the attributes for this element + namespaces = reader.getAttributeCount(); + for (int i = 0; i < namespaces; i++) { + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String qname = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + + writer.writeAttribute(prefix, ns, qname, value); + } + + break; + case XMLStreamConstants.CDATA: + writer.writeCData(reader.getText()); + break; + case XMLStreamConstants.CHARACTERS: + writer.writeCharacters(reader.getText()); + break; + case XMLStreamConstants.END_ELEMENT: + writer.writeEndElement(); + break; + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java new file mode 100644 index 0000000000..a3dfcc3c5b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java @@ -0,0 +1,484 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.List; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.xml.ConfiguredOperationProcessor; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; +import org.apache.tuscany.sca.binding.ws.DefaultWebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionRuntimeException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +import com.ibm.wsdl.OperationImpl; + +/** + * This is the StAXArtifactProcessor for the Web Services Binding. + * + * @version $Rev$ $Date$ + */ +public class WebServiceBindingProcessor implements StAXArtifactProcessor, WebServiceConstants { + + private ExtensionPointRegistry extensionPoints; + private WSDLFactory wsdlFactory; + private WebServiceBindingFactory wsFactory; + private PolicyFactory policyFactory; + private ExtensionFactory extensionFactory; + private PolicyAttachPointProcessor policyProcessor; + private IntentAttachPointTypeFactory intentAttachPointTypeFactory; + private ConfiguredOperationProcessor configuredOperationProcessor; + private StAXAttributeProcessor extensionAttributeProcessor; + private Monitor monitor; + + public WebServiceBindingProcessor(ExtensionPointRegistry extensionPoints, Monitor monitor) { + + this.extensionPoints = extensionPoints; + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.wsFactory = new DefaultWebServiceBindingFactory(); + this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.intentAttachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + this.monitor = monitor; + this.configuredOperationProcessor = new ConfiguredOperationProcessor(modelFactories, this.monitor); + + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + StAXAttributeProcessorExtensionPoint attributeExtensionPoint = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + this.extensionAttributeProcessor = new ExtensibleStAXAttributeProcessor(attributeExtensionPoint ,inputFactory, outputFactory, this.monitor); + } + + /** + * Report a warning. + * + * @param problem + * @param model + * @param message data + */ + private void warning(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "binding-wsxml-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report an error. + * + * @param problem + * @param model + * @param message data + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "binding-wsxml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report an exception. + * + * @param problem + * @param model + * @param exception + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "binding-wsxml-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public WebServiceBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + + // Read a + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + /*IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType(); + bindingType.setName(getArtifactType()); + bindingType.setUnresolved(true); + ((PolicySetAttachPoint)wsBinding).setType(bindingType);*/ + wsBinding.setUnresolved(true); + wsBinding.setBuilder(new BindingBuilderImpl(extensionPoints)); + + // Read policies + policyProcessor.readPolicies(wsBinding, reader); + + // Read the binding name + String name = reader.getAttributeValue(null, NAME); + if (name != null) { + wsBinding.setName(name); + } + + // Read URI + String uri = reader.getAttributeValue(null, URI); + if (uri != null) { + wsBinding.setURI(uri); + } + + // Read a qname in the form: + // namespace#wsdl.???(name) + Boolean wsdlElementIsBinding = null; + String wsdlElement = reader.getAttributeValue(null, WSDL_ELEMENT); + if (wsdlElement != null) { + int index = wsdlElement.indexOf('#'); + if (index == -1) { + error("InvalidWsdlElementAttr", reader, wsdlElement); + //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); + return wsBinding; + } + String namespace = wsdlElement.substring(0, index); + wsBinding.setNamespace(namespace); + String localName = wsdlElement.substring(index + 1); + if (localName.startsWith("wsdl.service")) { + + // Read a wsdl.service + localName = localName.substring("wsdl.service(".length(), localName.length() - 1); + wsBinding.setServiceName(new QName(namespace, localName)); + + } else if (localName.startsWith("wsdl.port")) { + + // Read a wsdl.port + localName = localName.substring("wsdl.port(".length(), localName.length() - 1); + int s = localName.indexOf('/'); + if (s == -1) { + error("InvalidWsdlElementAttr", reader, wsdlElement); + //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } else { + wsBinding.setServiceName(new QName(namespace, localName.substring(0, s))); + wsBinding.setPortName(localName.substring(s + 1)); + } + } else if (localName.startsWith("wsdl.endpoint")) { + + // Read a wsdl.endpoint + localName = localName.substring("wsdl.endpoint(".length(), localName.length() - 1); + int s = localName.indexOf('/'); + if (s == -1) { + error("InvalidWsdlElementAttr", reader, wsdlElement); + //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } else { + wsBinding.setServiceName(new QName(namespace, localName.substring(0, s))); + wsBinding.setEndpointName(localName.substring(s + 1)); + } + } else if (localName.startsWith("wsdl.binding")) { + + // Read a wsdl.binding + localName = localName.substring("wsdl.binding(".length(), localName.length() - 1); + wsBinding.setBindingName(new QName(namespace, localName)); + + wsdlElementIsBinding = true; + + } else { + error("InvalidWsdlElementAttr", reader, wsdlElement); + //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } + } + + // Read wsdlLocation + wsBinding.setLocation(reader.getAttributeValue(WSDLI_NS, WSDL_LOCATION)); + + // Handle extended attributes + for (int a = 0; a < reader.getAttributeCount(); a++) { + QName attributeName = reader.getAttributeName(a); + if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI() != WSDLI_NS && attributeName.getNamespaceURI().length() > 0) { + if( (! Constants.SCA10_NS.equals(attributeName.getNamespaceURI()) && + (! Constants.SCA10_TUSCANY_NS.equals(attributeName.getNamespaceURI()) ))) { + Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); + Extension attributeExtension; + if (attributeValue instanceof Extension) { + attributeExtension = (Extension) attributeValue; + } else { + attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true); + } + wsBinding.getAttributeExtensions().add(attributeExtension); + } + } + } + + + ConfiguredOperation confOp = null; + // Skip to end element + while (reader.hasNext()) { + int event = reader.next(); + switch (event) { + case START_ELEMENT: { + if (END_POINT_REFERENCE.equals(reader.getName().getLocalPart())) { + if (wsdlElement != null && (wsdlElementIsBinding == null || !wsdlElementIsBinding)) { + error("MustUseWsdlBinding", reader, wsdlElement); + throw new ContributionReadException(wsdlElement + " must use wsdl.binding when using wsa:EndpointReference"); + } + wsBinding.setEndPointReference(EndPointReferenceHelper.readEndPointReference(reader)); + } else if (Constants.OPERATION_QNAME.equals(reader.getName())) { + confOp = configuredOperationProcessor.read(reader); + if (confOp != null) { + ((OperationsConfigurator)wsBinding).getConfiguredOperations().add(confOp); + } + } + } + break; + + } + + if (event == END_ELEMENT && BINDING_WS_QNAME.equals(reader.getName())) { + break; + } + } + return wsBinding; + } + + protected void processEndPointReference(XMLStreamReader reader, WebServiceBinding wsBinding) { + } + + public void write(WebServiceBinding wsBinding, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + + // Write a + writer.writeStartElement(Constants.SCA10_NS, BINDING_WS); + policyProcessor.writePolicyAttributes(wsBinding, writer); + + // Write binding name + if (wsBinding.getName() != null) { + writer.writeAttribute(NAME, wsBinding.getName()); + } + + // Write binding URI + if (wsBinding.getURI() != null) { + writer.writeAttribute(URI, wsBinding.getURI()); + } + + // Write wsdlElement attribute + if (wsBinding.getPortName() != null) { + + // Write namespace#wsdl.port(service/port) + String wsdlElement = + wsBinding.getServiceName().getNamespaceURI() + "#wsdl.port(" + + wsBinding.getServiceName().getLocalPart() + + "/" + + wsBinding.getPortName() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + + } else if (wsBinding.getEndpointName() != null) { + + // Write namespace#wsdl.endpoint(service/endpoint) + String wsdlElement = + wsBinding.getServiceName().getNamespaceURI() + "#wsdl.endpoint(" + + wsBinding.getServiceName().getLocalPart() + + "/" + + wsBinding.getEndpointName() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + + } else if (wsBinding.getBindingName() != null) { + + // Write namespace#wsdl.binding(binding) + String wsdlElement = + wsBinding.getBindingName().getNamespaceURI() + "#wsdl.binding(" + + wsBinding.getBindingName().getLocalPart() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + + } else if (wsBinding.getServiceName() != null) { + + // Write namespace#wsdl.service(service) + String wsdlElement = + wsBinding.getServiceName().getNamespaceURI() + "#wsdl.service(" + + wsBinding.getServiceName().getLocalPart() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + } + + // Write location + if (wsBinding.getLocation() != null) { + writer.writeAttribute(WSDLI_NS, WSDL_LOCATION, wsBinding.getLocation()); + } + + // Write extended attributes + for(Extension extension : wsBinding.getAttributeExtensions()) { + if(extension.isAttribute()) { + extensionAttributeProcessor.write(extension, writer); + } + } + + if (wsBinding.getEndPointReference() != null) { + EndPointReferenceHelper.writeEndPointReference(wsBinding.getEndPointReference(), writer); + } + + writer.writeEndElement(); + } + + public void resolve(WebServiceBinding model, ModelResolver resolver) throws ContributionResolveException { + + if (model == null || !model.isUnresolved()) + return; + + WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); + wsdlDefinition.setUnresolved(true); + wsdlDefinition.setNamespace(model.getNamespace()); + WSDLDefinition resolved = null; + try { + resolved = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition); + } catch (ContributionRuntimeException e) { + ContributionResolveException ce = new ContributionResolveException(e.getCause()); + error("ContributionResolveException", wsdlDefinition, ce); + //throw ce; + } + + if (resolved != null && !resolved.isUnresolved()) { + wsdlDefinition.setDefinition(resolved.getDefinition()); + wsdlDefinition.setLocation(resolved.getLocation()); + wsdlDefinition.setURI(resolved.getURI()); + wsdlDefinition.getImportedDefinitions().addAll(resolved.getImportedDefinitions()); + wsdlDefinition.getXmlSchemas().addAll(resolved.getXmlSchemas()); + wsdlDefinition.setUnresolved(false); + model.setDefinition(wsdlDefinition); + if (model.getBindingName() != null) { + WSDLObject binding = wsdlDefinition.getWSDLObject(Binding.class, model.getBindingName()); + if (binding != null) { + wsdlDefinition.setDefinition(binding.getDefinition()); + model.setBinding(binding.getElement()); + } else { + warning("WsdlBindingDoesNotMatch", wsdlDefinition, model.getBindingName()); + } + } + if (model.getServiceName() != null) { + WSDLObject service = wsdlDefinition.getWSDLObject(Service.class, model.getServiceName()); + if (service != null) { + wsdlDefinition.setDefinition(service.getDefinition()); + model.setService(service.getElement()); + if (model.getPortName() != null) { + Port port = service.getElement().getPort(model.getPortName()); + if (port != null) { + model.setPort(port); + model.setBinding(port.getBinding()); + } else { + warning("WsdlPortTypeDoesNotMatch", wsdlDefinition, model.getPortName()); + } + } + } else { + warning("WsdlServiceDoesNotMatch", wsdlDefinition, model.getServiceName()); + } + } + + PortType portType = getPortType(model); + if (portType != null) { + // Introspect the WSDL portType and validate the input/output messages. + List operations = portType.getOperations(); + for (OperationImpl operation : operations) { + if (operation.getInput() != null && operation.getInput().getMessage() == null) { + ContributionResolveException ce = new ContributionResolveException("WSDL binding operation input name " + operation.getInput().getName() + " does not match with PortType Definition"); + error("ContributionResolveException", wsdlDefinition, ce); + } + if (operation.getOutput() != null && operation.getOutput().getMessage() == null) { + ContributionResolveException ce = new ContributionResolveException("WSDL binding operation output name " + operation.getOutput().getName() + " does not match with PortType Definition"); + error("ContributionResolveException", wsdlDefinition, ce); + } + } + + WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); + WSDLInterface wsdlInterface = null; + try { + wsdlInterface = wsdlFactory.createWSDLInterface(portType, wsdlDefinition, resolver); + interfaceContract.setInterface(wsdlInterface); + model.setBindingInterfaceContract(interfaceContract); + } catch (InvalidInterfaceException e) { + warning("InvalidInterfaceException", wsdlFactory, model.getName()); + } + } + } + policyProcessor.resolvePolicies(model, resolver); + OperationsConfigurator opCongigurator = (OperationsConfigurator)model; + for (ConfiguredOperation confOp : opCongigurator.getConfiguredOperations()) { + policyProcessor.resolvePolicies(confOp, resolver); + } + } + + private PortType getPortType(WebServiceBinding model) { + PortType portType = null; + if (model.getPort() != null) { + portType = model.getPort().getBinding().getPortType(); + } else if (model.getEndpoint() != null) { + portType = model.getPort().getBinding().getPortType(); + } else if (model.getBinding() != null) { + portType = model.getBinding().getPortType(); + } else if (model.getService() != null) { + // FIXME: How to find the compatible port? + Map ports = model.getService().getPorts(); + if (!ports.isEmpty()) { + Port port = (Port)ports.values().iterator().next(); + portType = port.getBinding().getPortType(); + } + } + return portType; + } + + public QName getArtifactType() { + return WebServiceConstants.BINDING_WS_QNAME; + } + + public Class getModelType() { + return WebServiceBinding.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java new file mode 100644 index 0000000000..03c84a6b41 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.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.sca.binding.ws.xml; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Constants for the Web Services Binding. + * + * @version $Rev$ $Date$ + */ +public interface WebServiceConstants { + + String BINDING_WS = "binding.ws"; + QName BINDING_WS_QNAME = new QName(Constants.SCA10_NS, BINDING_WS); + String WSDL_ELEMENT = "wsdlElement"; + QName WSDL_ELEMENT_QNAME = new QName(Constants.SCA10_NS, WSDL_ELEMENT); + String WSDL_LOCATION = "wsdlLocation"; + String WSDLI_NS = "http://www.w3.org/2004/08/wsdl-instance"; + QName WSDL_LOCATION_QNAME = new QName(WSDLI_NS, WSDL_LOCATION); + String NAME = "name"; + String URI = "uri"; + String END_POINT_REFERENCE = "EndpointReference"; + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..cb982e8647 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.ws.xml.WebServiceBindingProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#binding.ws,model=org.apache.tuscany.sca.binding.ws.WebServiceBinding diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/resources/binding-wsxml-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/resources/binding-wsxml-validation-messages.properties new file mode 100644 index 0000000000..9e2ff5830d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/main/resources/binding-wsxml-validation-messages.properties @@ -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. +# +# +InvalidWsdlElementAttr = Invalid WebService binding wsdlElement attribute: {0} +MustUseWsdlBinding = {0} must use wsdl.binding when using wsa:EndpointReference +InvalidInterfaceException = Exception creating interface from WSDL for binding: {0} +WsdlBindingDoesNotMatch = The #wsdl.binding({0}) does not match with the WSDL Definitions +WsdlServiceDoesNotMatch = The #wsdl.service({0}) does not match with the WSDL Definitions +WsdlPortTypeDoesNotMatch = The #wsdl.port({0}) does not match with the WSDL Definitions +ContributionResolveException = Error in contribution: {0} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java new file mode 100644 index 0000000000..ef955254c1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.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.sca.binding.ws.xml; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; + +/** + * Test reading WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class ReadTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private CompositeBuilder compositeBuilder; + + @Override + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null); + } + + @Override + public void tearDown() throws Exception { + } + + public void testReadComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ComponentType componentType = (ComponentType)staxProcessor.read(reader); + assertNotNull(componentType); + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + + compositeBuilder.build(composite); + } + + public void testReadPolicies() throws Exception { + InputStream is = getClass().getResourceAsStream("PoliciedCalculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + + compositeBuilder.build(composite); + + assertEquals(((OperationsConfigurator)composite.getServices().get(0).getBindings().get(0)) + .getConfiguredOperations().get(0).getRequiredIntents().size(), 2); + } + + /** + * This test makes sure that an exception is thrown when a bad wsdlElement is present along with EndpointReference. + * + * Ref: Web Service Binding Specification v1.0 - Sec 2.1 - Lines 61 to 65. + * When an EndpointReference is present along with the wsdlElement attribute on the parent element, the wsdlElement attribute value MUST + * be of the 'Binding' form. + */ + public void testReadBadWsdlElement() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator-bad-wsdlElement.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + try { + staxProcessor.read(reader); + fail("ContributionReadException expected."); + } catch(ContributionReadException e) { + // Expected + assertNotSame(-1, e.getMessage().indexOf("must use wsdl.binding when using wsa:EndpointReference")); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadWriteAnyAttributeTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadWriteAnyAttributeTestCase.java new file mode 100644 index 0000000000..742c6783a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadWriteAnyAttributeTestCase.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.xml.AnyAttributeProcessor; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadWriteAnyAttributeTestCase { + + private static final QName EXTENDED_ATTRIBUTE = new QName("http://test", "customAttribute"); + + private static final String XML = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + + /** + * Initialize the test environment + * This takes care to register attribute processors when provided + * + * @param attributeProcessor + * @throws Exception + */ + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + + inputFactory = XMLInputFactory.newInstance(); + + StAXAttributeProcessor attributeProcessor = new AnyAttributeProcessor(modelFactories,null); + + StAXAttributeProcessorExtensionPoint staxAttributeProcessors = new DefaultStAXAttributeProcessorExtensionPoint(extensionPoints); + staxAttributeProcessors.addArtifactProcessor(attributeProcessor); + extensionPoints.addExtensionPoint(staxAttributeProcessors); + + WebServiceBindingProcessor wsbp = new WebServiceBindingProcessor(extensionPoints,null); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessors.addArtifactProcessor(wsbp); + + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + @After + public void tearDown() throws Exception { + + } + + + @Test + //@Ignore() + public void testReadWriteCompositeWithBindings() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML); + // System.out.println(bos.toString()); + + assertEquals(XML, bos.toString()); + bos.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java new file mode 100644 index 0000000000..7ab9b19a56 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.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.sca.binding.ws.xml; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; + +/** + * Test reading/write WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class WriteTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private StAXArtifactProcessor staxProcessor; + + @Override + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + StAXAttributeProcessorExtensionPoint staxAttributeProcessors = new DefaultStAXAttributeProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + } +/* + public void testReadWriteComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + assertNotNull(componentType); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos)); + } +*/ + + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + assertNotNull(composite); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + System.out.println(bos.toString()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator-bad-wsdlElement.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator-bad-wsdlElement.composite new file mode 100644 index 0000000000..d8d1b3401e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator-bad-wsdlElement.composite @@ -0,0 +1,59 @@ + + + + + + + + + http://localhost:8085/Calculator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite new file mode 100644 index 0000000000..f7460813cd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite @@ -0,0 +1,63 @@ + + + + + + + + + + + + + http://localhost:8085/services/HelloWorldWebService + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType new file mode 100644 index 0000000000..959802af43 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + myURI + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/PoliciedCalculator.composite b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/PoliciedCalculator.composite new file mode 100644 index 0000000000..37c80aa910 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/PoliciedCalculator.composite @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl new file mode 100644 index 0000000000..5e8e5dad0d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl @@ -0,0 +1,26 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl new file mode 100644 index 0000000000..ad81fc7867 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd new file mode 100644 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl new file mode 100644 index 0000000000..39cd5547d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl new file mode 100644 index 0000000000..8e26f7b4b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd new file mode 100644 index 0000000000..c2210f4a94 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl new file mode 100644 index 0000000000..529b395fd5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl new file mode 100644 index 0000000000..666a7e4069 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/pom.xml new file mode 100644 index 0000000000..f973665cde --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-binding-ws + Apache Tuscany SCA WS Binding Model + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 1.6-SNAPSHOT + + + + wsdl4j + wsdl4j + 1.6.2 + + + + + + + apache.ws.zone + Apache WS Zone Repository + http://ws.zones.apache.org/repository2 + + true + + + false + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.ws + ${pom.name} + org.apache.tuscany.sca.binding.ws* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.java new file mode 100644 index 0000000000..2ccaa5dc58 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.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.sca.binding.ws; + +import org.apache.tuscany.sca.binding.ws.impl.WebServiceBindingFactoryImpl; + +/** + * A factory for the Web Service binding model. + * + * @version $Rev$ $Date$ + */ +@Deprecated +public class DefaultWebServiceBindingFactory extends WebServiceBindingFactoryImpl implements WebServiceBindingFactory { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java new file mode 100644 index 0000000000..9e1a261dcf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java @@ -0,0 +1,215 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.w3c.dom.Element; + + +/** + * Represents a WebService binding. + * + * @version $Rev$ $Date$ + */ +public interface WebServiceBinding extends Binding, BindingBuilderExtension, Extensible { + + /** + * Sets the WSDL location. + * @param location the WSDL location + */ + void setLocation(String location); + + /** + * Returns the WSDL location + * @return the WSDL location + */ + String getLocation(); + + /** + * Returns the name of the WSDL service. + * + * @return the name of the WSDL service + */ + QName getServiceName(); + + /** + * Sets the name of the WSDL service. + * + * @param serviceName the name of the WSDL service + */ + void setServiceName(QName serviceName); + + /** + * Returns the name of the WSDL port. + * + * @return the name of the WSDL port + */ + String getPortName(); + + /** + * Sets the name of the WSDL port. + * + * @param portName the name of the WSDL port + */ + void setPortName(String portName); + + /** + * Returns the name of the WSDL binding. + * + * @return the name of the WSDL binding + */ + QName getBindingName(); + + /** + * Sets the name of the WSDL binding. + * + * @param bindingName the name of the WSDL binding + */ + void setBindingName(QName bindingName); + + /** + * Returns the name of the WSDL endpoint. + * + * @return the name of the WSDL endpoint + */ + String getEndpointName(); + + /** + * Sets the name of the WSDL endpoint. + * + * @param endpointName the name of the WSDL endpoint + */ + void setEndpointName(String endpointName); + + /** + * Returns the WSDL service + * @return the WSDL service + */ + Service getService(); + + /** + * Sets the WSDL service. + * @param service the WSDL service + */ + void setService(Service service); + + /** + * Returns the WSDL port + * @return the WSDL port + */ + Port getPort(); + + /** + * Sets the WSDL endpoint + * @param endpoint the WSDL endpoint + */ + void setEndpoint(Port endpoint); + + /** + * Returns the WSDL endpoint + * @return the WSDL endpoint + */ + Port getEndpoint(); + + /** + * Sets the WSDL port + * @param port the WSDL port + */ + void setPort(Port port); + + /** + * Returns the WSDL binding. + * @return the WSDL binding + */ + javax.wsdl.Binding getBinding(); + + /** + * Sets the WSDL binding + * @param binding the WSDL binding + */ + void setBinding(javax.wsdl.Binding binding); + + /** + * Returns the WSDL definition. + * @return the WSDL definition + */ + WSDLDefinition getWSDLDefinition(); + + /** + * Sets the WSDL definition. + * @param wsdlDefinition the WSDL definition + */ + void setDefinition(WSDLDefinition wsdlDefinition); + + /** + * Returns the WSDL namespace. + * @return the WSDL namespace + */ + String getNamespace(); + + /** + * Sets the WSDL namespace + * @param namespace the WSDL namespace + */ + void setNamespace(String namespace); + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + + InterfaceContract getBindingInterfaceContract(); + + void setBindingInterfaceContract(InterfaceContract bindingInterfaceContract); + + Element getEndPointReference(); + + void setEndPointReference(Element element); + + /** + * Returns the generated WSDL definitions document. + * @return the generated WSDL definitions document + */ + Definition getWSDLDocument(); + + /** + * Sets the generated WSDL definitions document. + * @param definition the generated WSDL definitions document + */ + void setWSDLDocument(Definition definition); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java new file mode 100644 index 0000000000..1ad38c69e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.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.sca.binding.ws; + +/** + * Factory for the Web Service binding model. + * + * @version $Rev$ $Date$ + */ +public interface WebServiceBindingFactory { + + /** + * Creates a new WebService binding. + * + * @return a new WebService binding + */ + WebServiceBinding createWebServiceBinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/addressing/EndPointReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/addressing/EndPointReference.java new file mode 100644 index 0000000000..a13584a3c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/addressing/EndPointReference.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.sca.binding.ws.addressing; + +import java.net.URI; +import java.util.List; + +import javax.xml.namespace.QName; + +/** + * Defines a model for WS-Addressing + * <wsa:EndpointReference> + * <wsa:Address>xs:anyURI</wsa:Address> + * <wsa:ReferenceProperties>... </wsa:ReferenceProperties> ? + * <wsa:ReferenceParameters>... </wsa:ReferenceParameters> ? + * <wsa:PortType>xs:QName</wsa:PortType> ? + * <wsa:ServiceName PortName="xs:NCName"?>xs:QName</wsa:ServiceName> ? + * <wsp:Policy> ... </wsp:Policy>* + * </wsa:EndpointReference> + * @version $Rev$ $Date$ + */ +public interface EndPointReference { + URI getAddress(); + + void setAddress(URI address); + + QName getPortType(); + + void setPortType(QName portType); + + QName getServiceName(); + + void setServiceName(QName serviceName); + + QName getPortName(); + + void setPortName(QName portName); + + List getReferenceProperties(); + + List getReferenceParameters(); + + List getPolicies(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java new file mode 100644 index 0000000000..055e2012dc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.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.sca.binding.ws.impl; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; + +/** + * A factory for the WSDL model. + * + * @version $Rev$ $Date$ + */ +public class WebServiceBindingFactoryImpl implements WebServiceBindingFactory { + + public WebServiceBinding createWebServiceBinding() { + return new WebServiceBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java new file mode 100644 index 0000000000..245031f3cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java @@ -0,0 +1,321 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.builder.BindingBuilder; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.w3c.dom.Element; + +/** + * Represents a WebService binding. + * + * @version $Rev$ $Date$ + */ +class WebServiceBindingImpl implements WebServiceBinding, PolicySetAttachPoint, OperationsConfigurator { + private String name; + private String uri; + private boolean unresolved; + private List extensions = new ArrayList(); + private List attributeExtensions = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List configuredOperations = new ArrayList(); + private List applicablePolicySets = new ArrayList(); + private String location; + private Binding binding; + private Service service; + private Port port; + private Port endpoint; + private QName bindingName; + private String portName; + private QName serviceName; + private String endpointName; + private WSDLDefinition wsdlDefinition; + private String wsdlNamespace; + private InterfaceContract bindingInterfaceContract; + private Element endPointReference; + private Definition generatedWSDLDocument; + private BindingBuilder builder; + + protected WebServiceBindingImpl() { + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public List getExtensions() { + return extensions; + } + + public List getAttributeExtensions() { + return attributeExtensions; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public Binding getBinding() { + if (binding == null) { + if (getWSDLDefinition() != null && wsdlDefinition.getBinding() != null) { + binding = wsdlDefinition.getBinding(); + } + } + return binding; + } + + public QName getBindingName() { + if (isUnresolved()) { + return bindingName; + } else if (binding != null) { + return binding.getQName(); + } else { + return null; + } + } + + public String getEndpointName() { + if (isUnresolved()) { + return endpointName; + } else if (endpoint != null) { + //TODO support WSDL 2.0 + return endpoint.getName(); + } else { + return null; + } + } + + public Port getEndpoint() { + return endpoint; + } + + public Port getPort() { + return port; + } + + public String getPortName() { + if (isUnresolved()) { + return portName; + } else if (port != null) { + return port.getName(); + } else { + return null; + } + } + + public Service getService() { + return service; + } + + public QName getServiceName() { + if (isUnresolved()) { + return serviceName; + } else if (service != null) { + return service.getQName(); + } else { + return null; + } + } + + public void setBinding(Binding binding) { + this.binding = binding; + } + + public void setBindingName(QName bindingName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.bindingName = bindingName; + } + + public void setEndpoint(Port endpoint) { + this.endpoint = endpoint; + } + + public void setEndpointName(String endpointName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.endpointName = endpointName; + } + + public void setPort(Port port) { + this.port = port; + } + + public void setPortName(String portName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.portName = portName; + } + + public void setService(Service service) { + this.service = service; + } + + public void setServiceName(QName serviceName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.serviceName = serviceName; + } + + public WSDLDefinition getWSDLDefinition() { + if (wsdlDefinition == null) { + Interface iface = bindingInterfaceContract.getInterface(); + if (iface instanceof WSDLInterface) { + wsdlDefinition = ((WSDLInterface) iface).getWsdlDefinition(); + } + } + return wsdlDefinition; + } + + public void setDefinition(WSDLDefinition wsdlDefinition) { + this.wsdlDefinition = wsdlDefinition; + } + + public String getNamespace() { + return wsdlNamespace; + } + + public void setNamespace(String namespace) { + this.wsdlNamespace = namespace; + } + + public InterfaceContract getBindingInterfaceContract() { + return bindingInterfaceContract; + } + + public void setBindingInterfaceContract(InterfaceContract bindingInterfaceContract) { + this.bindingInterfaceContract = bindingInterfaceContract; + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + public Element getEndPointReference() { + return endPointReference; + } + + public void setEndPointReference(Element epr) { + this.endPointReference = epr; + } + + public Definition getWSDLDocument() { + return generatedWSDLDocument; + } + + public void setWSDLDocument(Definition definition) { + this.generatedWSDLDocument = definition; + } + + public BindingBuilder getBuilder() { + return builder; + } + + public void setBuilder(BindingBuilder builder) { + this.builder = builder; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public List getConfiguredOperations() { + return configuredOperations; + } + + public void setConfiguredOperations(List configuredOperations) { + this.configuredOperations = configuredOperations; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory new file mode 100644 index 0000000000..6d50a24b93 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/binding-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the model factory +org.apache.tuscany.sca.binding.ws.impl.WebServiceBindingFactoryImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/NOTICE new file mode 100644 index 0000000000..917b66ba7f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/NOTICE @@ -0,0 +1,8 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + +This product uses Relax WS (http://code.google.com/p/relax-ws/) with the following copyright: + * Copyright 2008 Jason Sando diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/pom.xml new file mode 100644 index 0000000000..7e17734bfe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/pom.xml @@ -0,0 +1,84 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + + tuscany-contribution-groovy + Apache Tuscany SCA Groovy contributions + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + org.codehaus.groovy + groovy-all-minimal + 1.5.4 + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.6-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.6-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.contribution.groovy + ${pom.name} + org.apache.tuscany.sca.contribution.groovy* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyArtifact.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyArtifact.java new file mode 100644 index 0000000000..77dab193b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyArtifact.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.sca.contribution.groovy; + +import java.net.URL; + +/** + * GroovyArtifact holds the URL to the Groovy script. + * + * @version $Rev$ $Date$ + */ +public class GroovyArtifact { + + private URL artifactURL; + + public GroovyArtifact(URL artifactURL) { + this.artifactURL = artifactURL; + } + + public URL getArtifactURL() { + return artifactURL; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyArtifactProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyArtifactProcessor.java new file mode 100644 index 0000000000..4b7df4d9f8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyArtifactProcessor.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.sca.contribution.groovy; + +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A URLArtifactProcessor for Groovy scripts + * + * @version $Rev$ $Date$ + */ +public class GroovyArtifactProcessor implements URLArtifactProcessor { + + public GroovyArtifactProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + public GroovyArtifact read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { + return new GroovyArtifact(artifactURL); + } + + public String getArtifactType() { + return ".groovy"; + } + + public Class getModelType() { + return GroovyArtifact.class; + } + + public void resolve(GroovyArtifact groovyModel, ModelResolver arg1) throws ContributionResolveException { + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyModelResolver.java new file mode 100644 index 0000000000..82fe0326df --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/java/org/apache/tuscany/sca/contribution/groovy/GroovyModelResolver.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.sca.contribution.groovy; + +import groovy.lang.GroovyClassLoader; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A ModelResolver that compiles Groovy scripts into the contribution + * class loader so they can be used just like a regular java class. + * + * @version $Rev$ $Date$ + */ +public class GroovyModelResolver implements ModelResolver { + + protected ModelResolver modelresolver; + protected Contribution contribution; + + public GroovyModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + modelresolver = contribution.getModelResolver(); + this.contribution = contribution; + } + + public void addModel(Object model) { + ClassLoader cl = contribution.getClassLoader(); + if (!(cl instanceof GroovyClassLoader)) { + // replace the contribution class loader with a Groovy one + // If the contribution does not have a ClassLoader, use this ClassLoader as parent + if (cl == null) cl = this.getClass().getClassLoader(); + cl = new GroovyClassLoader(cl); + contribution.setClassLoader(cl); + } + try { + + ((GroovyClassLoader)cl).parseClass(((GroovyArtifact)model).getArtifactURL().openStream()); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public Object removeModel(Object arg0) { + return null; + } + + public T resolveModel(Class arg0, T arg1) { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor new file mode 100644 index 0000000000..f9dbee53bb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.contribution.groovy.GroovyArtifactProcessor;type=.groovy,model=org.apache.tuscany.sca.contribution.groovy.GroovyArtifact + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..86434ac4bf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.groovy.GroovyModelResolver;model=org.apache.tuscany.sca.contribution.groovy.GroovyArtifact diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/java/org/apache/tuscany/sca/contribution/groovy/HelloWorld.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/java/org/apache/tuscany/sca/contribution/groovy/HelloWorld.java new file mode 100644 index 0000000000..788c42f07d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/java/org/apache/tuscany/sca/contribution/groovy/HelloWorld.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.sca.contribution.groovy; + +/** + * HelloWorld Service interface used for testing. + * + * @version $Rev$ $Date$ + */ +public interface HelloWorld { + + String sayHello(String s); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/java/org/apache/tuscany/sca/contribution/groovy/HelloWorldTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/java/org/apache/tuscany/sca/contribution/groovy/HelloWorldTestCase.java new file mode 100644 index 0000000000..02be3acd23 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/java/org/apache/tuscany/sca/contribution/groovy/HelloWorldTestCase.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.sca.contribution.groovy; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Runs a distributed domain in a single VM by using and in memory implementation of the distributed domain + * + * @version $Rev$ $Date$ + */ +public class HelloWorldTestCase { + + private static HelloWorld helloWorld; + private static SCADomain scaDomain; + + @BeforeClass + public static void init() throws Exception { + scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/contribution/groovy/helloworld.composite"); + helloWorld = scaDomain.getService(HelloWorld.class, "HelloWolrdComponent"); + } + + @AfterClass + public static void destroy() throws Exception { + if (scaDomain != null) { + scaDomain.close(); + } + } + + @Test + public void testCalculator() throws Exception { + Assert.assertEquals("Hello Petra", helloWorld.sayHello("Petra")); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/resources/org/apache/tuscany/sca/contribution/groovy/HelloWorld.groovy b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/resources/org/apache/tuscany/sca/contribution/groovy/HelloWorld.groovy new file mode 100644 index 0000000000..c172528538 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/resources/org/apache/tuscany/sca/contribution/groovy/HelloWorld.groovy @@ -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.sca.contribution.groovy + +class HelloWorldImpl implements org.apache.tuscany.sca.contribution.groovy.HelloWorld { + + String sayHello(String you) { + return "Hello $you" + } + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/resources/org/apache/tuscany/sca/contribution/groovy/helloworld.composite b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/resources/org/apache/tuscany/sca/contribution/groovy/helloworld.composite new file mode 100644 index 0000000000..0d4c17a15b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-groovy/src/test/resources/org/apache/tuscany/sca/contribution/groovy/helloworld.composite @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/pom.xml new file mode 100644 index 0000000000..3d9dfbe314 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-contribution-impl + Apache Tuscany SCA Contribution Model Implementation + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution-xml + 1.6-SNAPSHOT + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.contribution.impl + ${pom.name} + org.apache.tuscany.sca.contribution* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java new file mode 100644 index 0000000000..9bd4d23680 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor.impl; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.contribution.PackageType; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * Folder contribution package processor. + * + * @version $Rev$ $Date$ + */ +public class FolderContributionProcessor implements PackageProcessor { + + public FolderContributionProcessor() { + } + + public String getPackageType() { + return PackageType.FOLDER; + } + + /** + * Recursively traverse a root directory + * + * @param fileList + * @param file + * @param root + * @throws IOException + */ + private static void traverse(List fileList, final File file, final File root) throws IOException { + // Allow privileged access to test file. Requires FilePermissions in security policy file. + Boolean isFile = AccessController.doPrivileged(new PrivilegedAction() { + public Boolean run() { + return file.isFile(); + } + }); + if (isFile) { + fileList.add(AccessController.doPrivileged(new PrivilegedAction() { + public URI run() { + return root.toURI().relativize(file.toURI()); + } + })); + } else { + // Allow privileged access to test file. Requires FilePermissions in security policy + // file. + Boolean isDirectory = AccessController.doPrivileged(new PrivilegedAction() { + public Boolean run() { + return file.isDirectory(); + } + }); + if (isDirectory) { + String uri = AccessController.doPrivileged(new PrivilegedAction() { + public URI run() { + return root.toURI().relativize(file.toURI()); + } + }).toString(); + + if (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + try { + fileList.add(new URI(null, uri, null)); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Invalid artifact uri:" + uri); + } + + // Allow privileged access to list files. Requires FilePermission in security + // policy. + File[] files = AccessController.doPrivileged(new PrivilegedAction() { + public File[] run() { + return file.listFiles(); + } + }); + for (File f : files) { + if (!f.getName().startsWith(".")) { + traverse(fileList, f, root); + } + } + } + } + } + + public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException { + return new URL(sourceURL, artifact.toString()); + } + + public List getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, + IOException { + if (packageSourceURL == null) { + throw new IllegalArgumentException("Invalid null package source URL."); + } + + List artifacts = new ArrayList(); + + try { + // Assume the root is a jar file + final File rootFolder = new File(packageSourceURL.toURI()); + // Allow privileged access to test file. Requires FilePermissions in security policy + // file. + Boolean isDirectory = AccessController.doPrivileged(new PrivilegedAction() { + public Boolean run() { + return rootFolder.isDirectory(); + } + }); + if (isDirectory) { + // Allow privileged access to test file. Requires FilePermissions in security policy + // file. + Boolean folderExists = AccessController.doPrivileged(new PrivilegedAction() { + public Boolean run() { + return rootFolder.exists(); + } + }); + if (!folderExists) { + throw new ContributionReadException(rootFolder.getAbsolutePath()); + } + + // Security consideration. This method gathers URIs of enclosed + // artifacts. The URIs are protected by the policy when a user + // yries to open those URLs. + traverse(artifacts, rootFolder, rootFolder); + } + + } catch (URISyntaxException e) { + throw new ContributionReadException(packageSourceURL.toExternalForm(), e); + } + + return artifacts; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java new file mode 100644 index 0000000000..47a0f95687 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; + +import org.apache.tuscany.sca.contribution.PackageType; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Jar Contribution package processor. + * + * @version $Rev$ $Date$ + */ +public class JarContributionProcessor implements PackageProcessor { + + public JarContributionProcessor() { + } + + public String getPackageType() { + return PackageType.JAR; + } + + public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException { + if (sourceURL.toString().startsWith("jar:")) { + return new URL(sourceURL, artifact.toString()); + } else if(!artifact.toString().equals("")) { + return new URL("jar:" + sourceURL.toExternalForm() + "!/" + artifact); + } else { + return sourceURL; + } + } + + public List getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, + IOException { + if (packageSourceURL == null) { + throw new IllegalArgumentException("Invalid null package source URL."); + } + + if (inputStream == null) { + throw new IllegalArgumentException("Invalid null source inputstream."); + } + + // Assume the root is a jar file + JarInputStream jar = new JarInputStream(inputStream); + try { + Set names = new HashSet(); + while (true) { + JarEntry entry = jar.getNextJarEntry(); + if (entry == null) { + // EOF + break; + } + + // FIXME: Maybe we should externalize the filter as a property + String name = entry.getName(); + if (!name.startsWith(".")) { + + // Trim trailing / + if (name.endsWith("/")) { + name = name.substring(0, name.length() - 1); + } + + // Add the entry name + if (!names.contains(name)) { + names.add(name); + + // Add parent folder names to the list too + for (;;) { + int s = name.lastIndexOf('/'); + if (s == -1) { + name = ""; + } else { + name = name.substring(0, s); + } + if (!names.contains(name)) { + names.add(name); + } else { + break; + } + } + } + } + } + + // Return list of URIs + List artifacts = new ArrayList(); + for (String name: names) { + try { + artifacts.add(new URI(null, name, null)); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Invalid artifact uri:" + name); + } + } + return artifacts; + + } finally { + jar.close(); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java new file mode 100644 index 0000000000..e658054381 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java @@ -0,0 +1,469 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service.impl; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; +import org.apache.tuscany.sca.contribution.service.util.FileHelper; +import org.apache.tuscany.sca.contribution.service.util.IOHelper; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * The default implementation of ContributionRepository + * + * @version $Rev$ $Date$ + */ +public class ContributionRepositoryImpl implements ContributionRepository { + private static final String NS = "http://tuscany.apache.org/xmlns/1.0-SNAPSHOT"; + private static final String DOMAIN_INDEX_FILENAME = "sca-domain.xml"; + private boolean initialized = false; + private String repository = null; + private File rootFile = null; + private Map contributionLocations = new HashMap(); + + private Map contributionMap = new HashMap(); + private List contributions = new ArrayList(); + + private URI domain; + private XMLInputFactory factory; + private Monitor monitor; + + /** + * Marshals warnings into the monitor + * + * @param message + * @param model + * @param messageParameters + */ + protected void warning(String message, Object model, String... messageParameters) { + if (monitor != null){ + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-impl-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Marshals errors into the monitor + * + * @param problems + * @param message + * @param model + */ + protected void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-impl-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Marshals exceptions into the monitor + * + * @param problems + * @param message + * @param model + */ + protected void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-impl-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + /** + * Constructor with repository root + * + * @param repository + * @param factory + */ + public ContributionRepositoryImpl(final String repository, XMLInputFactory factory, Monitor monitor) throws IOException { + this.monitor = monitor; + this.repository = repository; + this.factory = factory; + } + + + public URI getDomain() { + return domain; + } + + public URL store(final String contribution, URL sourceURL, InputStream contributionStream) throws IOException { + if(! initialized) { + try { + initializeRepository(); + } catch(Exception e) { + //ignore + } + } + + + // where the file should be stored in the repository + final File location = mapToFile(sourceURL); + FileHelper.forceMkdir(location.getParentFile()); + + copy(contributionStream, location); + + // add contribution to repositoryContent + // Allow ability to read user.dir property. Requires PropertyPermission in security policy. + URL contributionURL; + try { + contributionURL= AccessController.doPrivileged(new PrivilegedExceptionAction() { + public URL run() throws IOException { + URL contributionURL = location.toURL(); + URI relative = rootFile.toURI().relativize(location.toURI()); + contributionLocations.put(contribution, relative.toString()); + return contributionURL; + } + }); + } catch (PrivilegedActionException e) { + error("PrivilegedActionException", location, (IOException)e.getException()); + throw (IOException)e.getException(); + } + saveMap(); + + return contributionURL; + } + + public URL store(String contribution, URL sourceURL) throws IOException { + if(! initialized) { + try { + initializeRepository(); + } catch(Exception e) { + //ignore + } + } + + // where the file should be stored in the repository + File location = mapToFile(sourceURL); + File source = FileHelper.toFile(sourceURL); + if (source == null || source.isFile()) { + URLConnection connection = sourceURL.openConnection(); + connection.setUseCaches(false); + InputStream is = connection.getInputStream(); + try { + return store(contribution, sourceURL, is); + } finally { + IOHelper.closeQuietly(is); + } + } + + FileHelper.forceMkdir(location); + FileHelper.copyDirectory(source, location); + + // add contribution to repositoryContent + URI relative = rootFile.toURI().relativize(location.toURI()); + contributionLocations.put(contribution, relative.toString()); + saveMap(); + + return location.toURL(); + } + + public URL find(String contribution) { + if(! initialized) { + try { + initializeRepository(); + } catch(Exception e) { + //ignore + } + } + + + if (contribution == null) { + return null; + } + String location = contributionLocations.get(contribution); + if (location == null) { + return null; + } + try { + return new File(rootFile, location).toURL(); + } catch (MalformedURLException e) { + // Should not happen + error("MalformedURLException", location, new AssertionError(e)); + throw new AssertionError(e); + } + } + + public void remove(String contribution) { + if(! initialized) { + try { + initializeRepository(); + } catch(Exception e) { + //ignore + } + } + + + URL contributionURL = this.find(contribution); + if (contributionURL != null) { + // remove + try { + FileHelper.forceDelete(FileHelper.toFile(contributionURL)); + this.contributionLocations.remove(contribution); + saveMap(); + } catch (IOException ioe) { + // handle file could not be removed + } + } + } + + public List list() { + return new ArrayList(contributionLocations.keySet()); + } + + /** + * Contribution Registry methods + */ + + + public void addContribution(Contribution contribution) { + contributionMap.put(contribution.getURI(), contribution); + contributions.add(contribution); + } + + public void removeContribution(Contribution contribution) { + contributionMap.remove(contribution.getURI()); + contributions.remove(contribution); + } + + public void updateContribution(Contribution contribution) { + Contribution oldContribution = contributionMap.remove(contribution.getURI()); + contributions.remove(oldContribution); + contributionMap.put(contribution.getURI(), contribution); + contributions.add(contribution); + } + + public Contribution getContribution(String uri) { + return contributionMap.get(uri); + } + + public List getContributions() { + return Collections.unmodifiableList(contributions); + } + + + /** + * Resolve contribution location in the repository -> root repository / + * contribution file -> contribution group id / artifact id / version + * + * @param contribution + * @return + */ + private File mapToFile(URL sourceURL) { + String fileName = FileHelper.toFile(sourceURL).getName(); + return new File(rootFile, "contributions" + File.separator + fileName); + } + + + /** + * Persist contribution state to xml file in the repository + */ + private void saveMap() { + File domainFile = new File(rootFile, DOMAIN_INDEX_FILENAME); + FileOutputStream os = null; + try { + os = new FileOutputStream(domainFile); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(os, "UTF-8")); + writer.println(""); + writer.println(""); + for (Map.Entry e : contributionLocations.entrySet()) { + writer.println(" "); + } + writer.println(""); + writer.flush(); + } catch (IOException e) { + IllegalArgumentException ae = new IllegalArgumentException(e); + error("IllegalArgumentException", os, ae); + throw ae; + } finally { + IOHelper.closeQuietly(os); + } + } + + /** + * Initialize contribution repository + * @throws IOException + */ + private void initializeRepository() throws IOException { + String root = this.repository; + if (root == null) { + root = AccessController.doPrivileged(new PrivilegedAction() { + public String run() { + // Default to /.tuscany/domains/local/ + String userHome = System.getProperty("user.home"); + String slash = File.separator; + return userHome + slash + ".tuscany" + slash + "domains" + slash + "local" + slash; + } + }); + } + + // Allow privileged access to File. Requires FilePermission in security policy file. + final String finalRoot = root; + this.rootFile = AccessController.doPrivileged(new PrivilegedAction() { + public File run() { + return new File(finalRoot); + } + }); + + // Allow privileged access to File. Requires FilePermission in security policy file. + this.domain = AccessController.doPrivileged(new PrivilegedAction() { + public URI run() { + return rootFile.toURI(); + } + }); + + // Allow privileged access to mkdir. Requires FilePermission in security policy file. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws IOException { + FileHelper.forceMkdir(rootFile); + return null; + } + }); + } catch (PrivilegedActionException e) { + error("PrivilegedActionException", rootFile, (IOException)e.getException()); + throw (IOException)e.getException(); + } + + // Allow privileged access to test file. Requires FilePermissions in security policy file. + Boolean notDirectory = AccessController.doPrivileged(new PrivilegedAction() { + public Boolean run() { + return (!rootFile.exists() || !rootFile.isDirectory() || !rootFile.canRead()); + } + }); + if (notDirectory) { + error("RootNotDirectory", rootFile, repository); + throw new IOException("The root is not a directory: " + repository); + } + + } + + + /** + * + */ + void init() { + if(! initialized) { + try { + initializeRepository(); + } catch(Exception e) { + //ignore + } + } + + File domainFile = new File(rootFile, "sca-domain.xml"); + if (!domainFile.isFile()) { + return; + } + FileInputStream is; + try { + is = new FileInputStream(domainFile); + } catch (FileNotFoundException e) { + warning("DomainFileNotFound", domainFile, domainFile.getAbsolutePath()); + return; + } + try { + XMLStreamReader reader = factory.createXMLStreamReader(new InputStreamReader(is, "UTF-8")); + while (reader.hasNext()) { + switch (reader.getEventType()) { + case XMLStreamConstants.START_ELEMENT: + String name = reader.getName().getLocalPart(); + if ("domain".equals(name)) { + String uri = reader.getAttributeValue(null, "uri"); + if (uri != null) { + domain = URI.create(uri); + } + } + if ("contribution".equals(name)) { + String uri = reader.getAttributeValue(null, "uri"); + String location = reader.getAttributeValue(null, "location"); + contributionLocations.put(uri, location); + } + break; + default: + break; + } + reader.next(); + } + } catch (Exception e) { + // Ignore + } finally { + IOHelper.closeQuietly(is); + } + } + + /** + * Utility functions + */ + + /** + * Write a specific source InputStream to a file on disk + * + * @param source contents of the file to be written to disk + * @param target file to be written + * @throws IOException + */ + private static void copy(InputStream source, File target) throws IOException { + BufferedOutputStream out = null; + BufferedInputStream in = null; + + try { + out = new BufferedOutputStream(new FileOutputStream(target)); + in = new BufferedInputStream(source); + IOHelper.copy(in, out); + } finally { + IOHelper.closeQuietly(out); + IOHelper.closeQuietly(in); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java new file mode 100644 index 0000000000..64f61fc6c8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java @@ -0,0 +1,640 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service.impl; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.ContributionMetadata; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; +import org.apache.tuscany.sca.contribution.service.ContributionService; +import org.apache.tuscany.sca.contribution.service.ExtensibleContributionListener; +import org.apache.tuscany.sca.contribution.service.TypeDescriber; +import org.apache.tuscany.sca.contribution.service.util.IOHelper; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Service interface that manages artifacts contributed to a Tuscany runtime. + * + * @version $Rev$ $Date$ + */ +public class ContributionServiceImpl implements ContributionService { + private ExtensionPointRegistry extensionPoints; + + /** + * Repository where contributions are stored. Usually set by injection. + */ + private ContributionRepository contributionRepository; + + /** + * Registry of available package processors. + */ + private PackageProcessor packageProcessor; + + /** + * Registry of available artifact processors + */ + + private URLArtifactProcessor artifactProcessor; + + /** + * Registry of available StAX processors, + * used for loading contribution metadata in a extensible way + */ + private StAXArtifactProcessor staxProcessor; + + /** + * Event listener for contribution operations + */ + private ExtensibleContributionListener contributionListener; + + /** + * Registry of available model resolvers + */ + + private ModelResolverExtensionPoint modelResolvers; + + /** + * Model factory extension point + */ + + private ModelFactoryExtensionPoint modelFactories; + + /** + * XML factory used to create reader instance to load contribution metadata + */ + private XMLInputFactory xmlFactory; + + /** + * Assembly factory + */ + private AssemblyFactory assemblyFactory; + + /** + * Contribution model factory + */ + private ContributionFactory contributionFactory; + + + private ModelResolver policyDefinitionsResolver; + + private List policyDefinitions; + + private Monitor monitor; + + private String COMPOSITE_FILE_EXTN = ".composite"; + + private TypeDescriber packageTypeDescriber; + + public ContributionServiceImpl(ContributionRepository repository, + PackageProcessor packageProcessor, + URLArtifactProcessor documentProcessor, + StAXArtifactProcessor staxProcessor, + ExtensibleContributionListener contributionListener, + ModelResolver policyDefinitionsResolver, + ModelResolverExtensionPoint modelResolvers, + ModelFactoryExtensionPoint modelFactories, + AssemblyFactory assemblyFactory, + ContributionFactory contributionFactory, + XMLInputFactory xmlFactory, + List policyDefinitions, + ExtensionPointRegistry extensionPoints, + Monitor monitor) { + super(); + this.extensionPoints = extensionPoints; + this.contributionRepository = repository; + this.packageProcessor = packageProcessor; + this.artifactProcessor = documentProcessor; + this.staxProcessor = staxProcessor; + this.contributionListener = contributionListener; + this.modelResolvers = modelResolvers; + this.modelFactories = modelFactories; + this.xmlFactory = xmlFactory; + this.assemblyFactory = assemblyFactory; + this.contributionFactory = contributionFactory; + this.policyDefinitionsResolver = policyDefinitionsResolver; + this.policyDefinitions = policyDefinitions; + this.monitor = monitor; + + this.packageTypeDescriber = new PackageTypeDescriberImpl(); + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-impl-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + public Contribution contribute(String contributionURI, URL sourceURL, boolean storeInRepository) + throws ContributionException, IOException { + if (contributionURI == null) { + error("ContributionURINull", contributionURI); + throw new IllegalArgumentException("URI for the contribution is null"); + } + if (sourceURL == null) { + error("SourceURLNull", sourceURL); + throw new IllegalArgumentException("Source URL for the contribution is null"); + } + return addContribution(contributionURI, sourceURL, null, null, storeInRepository); + } + + public Contribution contribute(String contributionURI, + URL sourceURL, + ModelResolver modelResolver, + boolean storeInRepository) throws ContributionException, IOException { + if (contributionURI == null) { + error("ContributionURINull", contributionURI); + throw new IllegalArgumentException("URI for the contribution is null"); + } + if (sourceURL == null) { + error("SourceURLNull", sourceURL); + throw new IllegalArgumentException("Source URL for the contribution is null"); + } + + return addContribution(contributionURI, sourceURL, null, modelResolver, storeInRepository); + } + + public Contribution contribute(String contributionURI, URL sourceURL, InputStream input) + throws ContributionException, IOException { + + return addContribution(contributionURI, sourceURL, input, null, true); + } + + public Contribution contribute(String contributionURI, URL sourceURL, InputStream input, ModelResolver modelResolver) + throws ContributionException, IOException { + + return addContribution(contributionURI, sourceURL, input, modelResolver, true); + } + + public Contribution getContribution(String uri) { + return this.contributionRepository.getContribution(uri); + } + + /** + * Remove a contribution and notify listener that contribution was removed + */ + public void remove(String uri) throws ContributionException { + Contribution contribution = contributionRepository.getContribution(uri); + this.contributionRepository.removeContribution(contribution); + this.contributionListener.contributionRemoved(this.contributionRepository, contribution); + } + + /** + * Add a composite model to the contribution + */ + public void addDeploymentComposite(Contribution contribution, Composite composite) throws ContributionException { + Artifact artifact = this.contributionFactory.createArtifact(); + artifact.setURI(composite.getURI()); + artifact.setModel(composite); + + contribution.getArtifacts().add(artifact); + + contribution.getDeployables().add(composite); + } + + /** + * Utility/Helper methods for contribution service + */ + + /** + * Perform read of the contribution metadata loader (sca-contribution.xml and sca-contribution-generated.xml) + * When the two metadata files are available, the information provided are merged, and the sca-contribution has priorities + * + * @param sourceURL + * @return Contribution + * @throws ContributionException + */ + /* + private Contribution readContributionMetadata(URL sourceURL) throws ContributionException { + Contribution contributionMetadata = contributionFactory.createContribution(); + + ContributionMetadataDocumentProcessor metadataDocumentProcessor = + new ContributionMetadataDocumentProcessor(modelFactories, staxProcessor, monitor); + + final URL[] urls = {sourceURL}; + // Allow access to create classloader. Requires RuntimePermission in security policy. + URLClassLoader cl = AccessController.doPrivileged(new PrivilegedAction() { + public URLClassLoader run() { + return new URLClassLoader(urls, null); + } + }); + for (String path: new String[]{ + Contribution.SCA_CONTRIBUTION_GENERATED_META, + Contribution.SCA_CONTRIBUTION_META}) { + URL url = cl.getResource(path); + if (url != null) { + ContributionMetadata contribution = metadataDocumentProcessor.read(sourceURL, URI.create(path), url); + contributionMetadata.getImports().addAll(contribution.getImports()); + contributionMetadata.getExports().addAll(contribution.getExports()); + contributionMetadata.getDeployables().addAll(contribution.getDeployables()); + } + } + + // For debugging purposes, write it back to XML + // if (contributionMetadata != null) { + // try { + // ByteArrayOutputStream bos = new ByteArrayOutputStream(); + // XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + // outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); + // staxProcessor.write(contributionMetadata, outputFactory.createXMLStreamWriter(bos)); + // Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray())); + // OutputFormat format = new OutputFormat(); + // format.setIndenting(true); + // format.setIndent(2); + // XMLSerializer serializer = new XMLSerializer(System.out, format); + // serializer.serialize(document); + // } catch (Exception e) { + // e.printStackTrace(); + // } + // } + + return contributionMetadata; + } + */ + + private static boolean isDirectory(URL url) { + if ("file".equals(url.getProtocol())) { + try { + final URI uri = url.toURI(); + return AccessController.doPrivileged(new PrivilegedAction() { + public Boolean run() { + return new File(uri).isDirectory(); + } + }); + } catch (URISyntaxException e) { + // Ignore + } + } + return false; + } + + /** + * Note: + * + * @param contributionURI ContributionID + * @param sourceURL contribution location + * @param contributionStream contribution content + * @param storeInRepository flag if we store the contribution into the + * repository or not + * @return the contribution model representing the contribution + * @throws IOException + * @throws DeploymentException + */ + private Contribution addContribution(String contributionURI, + URL sourceURL, + InputStream contributionStream, + ModelResolver modelResolver, + boolean storeInRepository) throws IOException, ContributionException { + + if (contributionStream == null && sourceURL == null) { + error("ContributionContentNull", contributionStream); + throw new IllegalArgumentException("The content of the contribution is null."); + } + + // store the contribution in the contribution repository + URL locationURL = sourceURL; + if (contributionRepository != null && storeInRepository) { + if (contributionStream == null) { + locationURL = contributionRepository.store(contributionURI, sourceURL); + } else { + locationURL = contributionRepository.store(contributionURI, sourceURL, contributionStream); + } + } + + Contribution contribution = contributionFactory.createContribution(); + + // Create contribution model resolver + if (modelResolver == null) { + //FIXME Remove this domain resolver, visibility of policy declarations should be handled by + // the contribution import/export mechanism instead of this domainResolver hack. + modelResolver = new ExtensibleModelResolver(contribution, extensionPoints, modelResolvers, modelFactories, policyDefinitionsResolver); + } + + //set contribution initial information + contribution.setURI(contributionURI); + contribution.setLocation(locationURL.toString()); + contribution.setModelResolver(modelResolver); + contribution.setType(packageTypeDescriber.getType(locationURL, null)); + + List contributionArtifacts = null; + + //NOTE: if a contribution is stored on the repository + //the stream would be consumed at this point + if (storeInRepository || contributionStream == null) { + if (isDirectory(sourceURL)) { + // TUSCANY-2702: This is a directory + contributionStream = null; + } else { + URLConnection connection = sourceURL.openConnection(); + connection.setUseCaches(false); + // Allow access to open URL stream. Add FilePermission to added to security policy file. + final URLConnection finalConnection = connection; + try { + contributionStream = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public InputStream run() throws IOException { + return finalConnection.getInputStream(); + } + }); + } catch (PrivilegedActionException e) { + throw (IOException)e.getException(); + } + } + + try { + // process the contribution + contributionArtifacts = this.packageProcessor.getArtifacts(locationURL, contributionStream); + } finally { + IOHelper.closeQuietly(contributionStream); + contributionStream = null; + } + } else { + // process the contribution + contributionArtifacts = this.packageProcessor.getArtifacts(locationURL, contributionStream); + } + + // Read all artifacts in the contribution + try { + // Allow access to read system properties. Requires PropertyPermission in security policy. + // Any security exceptions are caught and wrapped as ContributionException. + processReadPhase(contribution, contributionArtifacts); + } catch ( Exception e ) { + throw new ContributionException(e); + } + + readContributionMetadata(contribution); + + // + this.contributionListener.contributionAdded(this.contributionRepository, contribution); + + // Resolve them + processResolvePhase(contribution); + + // Add all composites under META-INF/sca-deployables to the + // list of deployables + String prefix = Contribution.SCA_CONTRIBUTION_DEPLOYABLES; + for (Artifact artifact : contribution.getArtifacts()) { + if (artifact.getModel() instanceof Composite) { + if (artifact.getURI().startsWith(prefix)) { + Composite composite = (Composite)artifact.getModel(); + if (!contribution.getDeployables().contains(composite)) { + contribution.getDeployables().add(composite); + } + } + } + } + + processApplicationComposite(contribution); + + // store the contribution on the registry + this.contributionRepository.addContribution(contribution); + + return contribution; + } + + private void readContributionMetadata(Contribution contribution) { + ContributionMetadata m1 = null, m2 = null; + for(Artifact a: contribution.getArtifacts()) { + if(Contribution.SCA_CONTRIBUTION_GENERATED_META.equals(a.getURI())) { + m1 = (ContributionMetadata) a.getModel(); + } + if(Contribution.SCA_CONTRIBUTION_META.equals(a.getURI())) { + m2 = (ContributionMetadata) a.getModel(); + } + } + if (m1 != null) { + contribution.getImports().addAll(m1.getImports()); + contribution.getExports().addAll(m1.getExports()); + contribution.getDeployables().addAll(m1.getDeployables()); + } + if (m2 != null) { + contribution.getImports().addAll(m2.getImports()); + contribution.getExports().addAll(m2.getExports()); + contribution.getDeployables().addAll(m2.getDeployables()); + } + } + + /** + * Process any application composite (eg see 5.1.3 of SCA JEE spec) + * TODO: see TUSCANY-2581 + */ + private void processApplicationComposite(Contribution contribution) { + + Composite composite = findComposite("web-inf/web.composite", contribution); + if (composite != null) { + if (!contribution.getDeployables().contains(composite)) { + contribution.getDeployables().add(createDeploymentComposite(composite)); + } + } + } + + /** + * Create a deployment composite for the composite + * See line 247 section 5.1.3 of SCA JEE spec + */ + private Composite createDeploymentComposite(Composite composite) { + // TODO: for now just use as-is + return composite; + } + + private Composite findComposite(String name, Contribution contribution) { + for (Artifact artifact : contribution.getArtifacts()) { + if (artifact.getModel() instanceof Composite) { + if (name.equalsIgnoreCase(artifact.getURI())) { + return (Composite)artifact.getModel(); + } + } + } + return null; + } + + /** + * This utility method process each artifact and delegates to proper + * artifactProcessor to read the model and generate the in-memory representation + * + * @param contribution + * @param artifacts + * @throws ContributionException + * @throws MalformedURLException + */ + private void processReadPhase(Contribution contribution, List artifacts) throws ContributionException, + MalformedURLException, XMLStreamException { + + ModelResolver modelResolver = contribution.getModelResolver(); + URL contributionURL = new URL(contribution.getLocation()); + + List compositeUris = new ArrayList(); + + Object model = null; + for (URI anArtifactUri : artifacts) { + if ( anArtifactUri.toString().endsWith(COMPOSITE_FILE_EXTN)) { + compositeUris.add(anArtifactUri); + } else { + URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), anArtifactUri); + + // Add the deployed artifact model to the resolver + Artifact artifact = this.contributionFactory.createArtifact(); + artifact.setURI(anArtifactUri.toString()); + artifact.setLocation(artifactURL.toString()); + contribution.getArtifacts().add(artifact); + modelResolver.addModel(artifact); + + model = this.artifactProcessor.read(contributionURL, anArtifactUri, artifactURL); + + if (model != null) { + artifact.setModel(model); + + // Add the loaded model to the model resolver + modelResolver.addModel(model); + + // Add policy definitions to the list of policy definitions + if (model instanceof SCADefinitions) { + policyDefinitions.add(model); + + SCADefinitions definitions = (SCADefinitions)model; + for (Intent intent : definitions.getPolicyIntents() ) { + policyDefinitionsResolver.addModel(intent); + } + + for (PolicySet policySet : definitions.getPolicySets() ) { + policyDefinitionsResolver.addModel(policySet); + } + + for (IntentAttachPointType attachPointType : definitions.getBindingTypes() ) { + policyDefinitionsResolver.addModel(attachPointType); + } + + for (IntentAttachPointType attachPointType : definitions.getImplementationTypes() ) { + policyDefinitionsResolver.addModel(attachPointType); + } + for (Object binding : definitions.getBindings() ) { + policyDefinitionsResolver.addModel(binding); + } + } + } + } + } + + for (URI anArtifactUri : compositeUris) { + URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), anArtifactUri); + + // Add the deployed artifact model to the resolver + Artifact artifact = this.contributionFactory.createArtifact(); + artifact.setURI(anArtifactUri.toString()); + artifact.setLocation(artifactURL.toString()); + contribution.getArtifacts().add(artifact); + modelResolver.addModel(artifact); + + model = this.artifactProcessor.read(contributionURL, anArtifactUri, artifactURL); + if (model != null) { + artifact.setModel(model); + // Add the loaded model to the model resolver + modelResolver.addModel(model); + } + } + } + + /** + * This utility method process each artifact and delegates to proper + * artifactProcessor to resolve the model references + * + * @param contribution + * @throws ContributionException + */ + @SuppressWarnings("unchecked") + private void processResolvePhase(Contribution contribution) throws ContributionException { + List composites = new ArrayList(); + + // for each artifact that was processed on the contribution + for (Artifact artifact : contribution.getArtifacts()) { + //leave the composites to be resolved at the end + if (artifact.getURI().endsWith(".composite")) { + composites.add(artifact); + } else { + // resolve the model object + if (artifact.getModel() != null) { + // System.out.println("Processing Resolve Phase : " + artifact.getURI()); + this.artifactProcessor.resolve(artifact.getModel(), contribution.getModelResolver()); + } + } + } + + //process each composite file + for (Artifact artifact : composites) { + // resolve the model object + if (artifact.getModel() != null) { + this.artifactProcessor.resolve(artifact.getModel(), contribution.getModelResolver()); + } + } + + //resolve deployables from contribution metadata + List resolvedDeployables = new ArrayList(); + for (Composite deployableComposite : contribution.getDeployables()) { + Composite resolvedDeployable = + contribution.getModelResolver().resolveModel(Composite.class, deployableComposite); + + resolvedDeployables.add(resolvedDeployable); + } + contribution.getDeployables().clear(); + contribution.getDeployables().addAll(resolvedDeployables); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java new file mode 100644 index 0000000000..a052e43356 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.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.sca.contribution.service.impl; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.PackageType; +import org.apache.tuscany.sca.contribution.service.TypeDescriber; +import org.apache.tuscany.sca.contribution.service.util.FileHelper; + +/** + * Implementation of the content describer for contribution packages + * + * @version $Rev$ $Date$ + */ +public class PackageTypeDescriberImpl implements TypeDescriber { + private final Map contentTypeRegistry = new HashMap(); + + public PackageTypeDescriberImpl() { + super(); + init(); + } + + /** + * Initialize contentType registry with know types based on known file extensions + */ + private void init() { + contentTypeRegistry.put("EAR", PackageType.EAR); + contentTypeRegistry.put("JAR", PackageType.JAR); + contentTypeRegistry.put("WAR", PackageType.WAR); + contentTypeRegistry.put("ZIP", PackageType.ZIP); + } + + protected String resolveContentyTypeByExtension(URL resourceURL) { + String artifactExtension = FileHelper.getExtension(resourceURL.getPath()); + if (artifactExtension == null) { + return null; + } + return contentTypeRegistry.get(artifactExtension.toUpperCase()); + } + + /** + * Build contentType for a specific resource. We first check if the file is a supported one + * (looking into our registry based on resource extension) If not found, we try to check file + * contentType Or we return defaultContentType provided + * + * @param resourceURL The artifact URL + * @param defaultContentType The default content type if we can't find the correct one + * @return The content type + */ + public String getType(URL resourceURL, String defaultContentType) { + URLConnection connection = null; + String contentType = defaultContentType; + final String urlProtocol = resourceURL.getProtocol(); + + if (urlProtocol.equals("file")) { + final File fileOrDir = FileHelper.toFile(resourceURL); + // Allow privileged access to test file. Requires FilePermissions in security policy. + Boolean isDirectory = AccessController.doPrivileged(new PrivilegedAction() { + public Boolean run() { + return fileOrDir.isDirectory(); + } + }); + if (isDirectory) { + // Special case : contribution is a folder + contentType = PackageType.FOLDER; + } + + String type = resolveContentyTypeByExtension(resourceURL); + if (type != null) { + return type; + } + } else if (urlProtocol.equals("bundle") || urlProtocol.equals("bundleresource")) { + contentType = PackageType.BUNDLE; + } else { + contentType = resolveContentyTypeByExtension(resourceURL); + if (contentType == null) { + try { + connection = resourceURL.openConnection(); + connection.setUseCaches(false); + contentType = connection.getContentType(); + + if (contentType == null || contentType.equals("content/unknown")) { + // here we couldn't figure out from our registry or from URL and it's not a + // special file + // return defaultContentType if provided + contentType = defaultContentType; + } + } catch (IOException io) { + // could not access artifact, just ignore and we will return + // null contentType + } + } + } + return contentType == null ? defaultContentType : contentType; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java new file mode 100644 index 0000000000..cd5e87ca42 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java @@ -0,0 +1,701 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service.util; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.util.regex.Pattern; + +public class FileHelper { + /** + * The extension separator character. + */ + private static final char EXTENSION_SEPARATOR = '.'; + + /** + * The Unix separator character. + */ + private static final char UNIX_SEPARATOR = '/'; + + /** + * The Windows separator character. + */ + private static final char WINDOWS_SEPARATOR = '\\'; + + /** + * Returns the index of the last directory separator character. + *

+ * This method will handle a file in either Unix or Windows format. The + * position of the last forward or backslash is returned. + *

+ * The output will be the same irrespective of the machine that the code is + * running on. + * + * @param filename the filename to find the last path separator in, null + * returns -1 + * @return the index of the last separator character, or -1 if there is no + * such character + */ + public static int indexOfLastSeparator(String filename) { + if (filename == null) { + return -1; + } + int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR); + int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR); + return Math.max(lastUnixPos, lastWindowsPos); + } + + /** + * Returns the index of the last extension separator character, which is a + * dot. + *

+ * This method also checks that there is no directory separator after the + * last dot. To do this it uses {@link #indexOfLastSeparator(String)} which + * will handle a file in either Unix or Windows format. + *

+ * The output will be the same irrespective of the machine that the code is + * running on. + * + * @param filename the filename to find the last path separator in, null + * returns -1 + * @return the index of the last separator character, or -1 if there is no + * such character + */ + public static int indexOfExtension(String filename) { + if (filename == null) { + return -1; + } + int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR); + int lastSeparator = indexOfLastSeparator(filename); + return lastSeparator > extensionPos ? -1 : extensionPos; + } + + /** + * Gets the name minus the path from a full filename. + *

+ * This method will handle a file in either Unix or Windows format. The text + * after the last forward or backslash is returned. + * + *

+     * a/b/c.txt --> c.txt
+     * a.txt     --> a.txt
+     * a/b/c     --> c
+     * a/b/c/    --> ""
+     * 
+ * + *

+ * The output will be the same irrespective of the machine that the code is + * running on. + * + * @param fileName the filename to query, null returns null + * @return the name of the file without the path, or an empty string if none + * exists + */ + public static String getName(String fileName) { + if (fileName == null) { + return null; + } + int index = indexOfLastSeparator(fileName); + return fileName.substring(index + 1); + } + + /** + * Gets the extension of a filename. + *

+ * This method returns the textual part of the filename after the last dot. + * There must be no directory separator after the dot. + * + *

+     * foo.txt      --> "txt"
+     * a/b/c.jpg    --> "jpg"
+     * a/b.txt/c    --> ""
+     * a/b/c        --> ""
+     * 
+ * + *

+ * The output will be the same irrespective of the machine that the code is + * running on. + * + * @param filename the filename to retrieve the extension of. + * @return the extension of the file or an empty string if none exists. + */ + public static String getExtension(String filename) { + if (filename == null) { + return null; + } + int index = indexOfExtension(filename); + if (index == -1) { + return ""; + } else { + return filename.substring(index + 1); + } + } + + /** + * Make a directory, including any necessary but nonexistent parent + * directories. If there already exists a file with specified name or the + * directory cannot be created then an exception is thrown. + * + * @param directory directory to create, not null + * @throws NullPointerException if the directory is null + * @throws IOException if the directory cannot be created + */ + public static void forceMkdir(File directory) throws IOException { + if (directory.exists()) { + if (directory.isFile()) { + String message = + "File " + directory + " exists and is " + "not a directory. Unable to create directory."; + throw new IOException(message); + } + } else { + if (!directory.mkdirs()) { + String message = "Unable to create directory " + directory; + throw new IOException(message); + } + } + } + + /** + * Delete a file. If file is a directory, delete it and all sub-directories. + *

+ * The difference between File.delete() and this method are: + *

    + *
  • A directory to be deleted does not have to be empty.
  • + *
  • You get exceptions when a file or directory cannot be deleted. + * (java.io.File methods returns a boolean)
  • + *
+ * + * @param file file or directory to delete, not null + * @throws NullPointerException if the directory is null + * @throws IOException in case deletion is unsuccessful + */ + public static void forceDelete(File file) throws IOException { + if (file.isDirectory()) { + deleteDirectory(file); + } else { + if (!file.exists()) { + throw new FileNotFoundException("File does not exist: " + file); + } + if (!file.delete()) { + String message = "Unable to delete file: " + file; + throw new IOException(message); + } + } + } + + /** + * Convert from a URL to a File. + *

+ * From version 1.1 this method will decode the URL. Syntax such as + * file:///my%20docs/file.txt will be correctly decoded to + * /my docs/file.txt. + * + * @param url the file URL to convert, null returns null + * @return the equivalent File object, or null + * if the URL's protocol is not file + * @throws IllegalArgumentException if the file is incorrectly encoded + */ + public static File toFile(URL url) { + if (url == null || !url.getProtocol().equals("file")) { + return null; + } else { + String filename = url.getFile().replace('/', File.separatorChar); + int pos = 0; + while ((pos = filename.indexOf('%', pos)) >= 0) { // NOPMD + if (pos + 2 < filename.length()) { + String hexStr = filename.substring(pos + 1, pos + 3); + char ch = (char)Integer.parseInt(hexStr, 16); + filename = filename.substring(0, pos) + ch + filename.substring(pos + 3); + } + } + return new File(filename); + } + } + + public static FileFilter getFileFilter(String regExp, boolean ignoreCase) { + return new RegExpFilter(regExp, ignoreCase); + } + + /** + * A regular-expression based resource filter + */ + public static class RegExpFilter implements FileFilter { + private Pattern pattern; + + public RegExpFilter(Pattern pattern) { + this.pattern = pattern; + } + + public RegExpFilter(String patternStr, boolean ignoreCase) { + this.pattern = Pattern.compile(patternStr, ignoreCase ? Pattern.CASE_INSENSITIVE : 0); + } + + public boolean accept(File file) { + return pattern.matcher(file.getName()).matches(); + } + + /** + * Convert wildcard into a regex pattern + * + * @param str + * @return + */ + public static RegExpFilter getWildcardFilter(String str, boolean ignoreCase) { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < str.length(); i++) { + char ch = str.charAt(i); + if (ch == '?') { + buffer.append('.'); + } else if (ch == '*') { + buffer.append(".*"); + } else { + buffer.append(ch); + } + } + return new RegExpFilter(buffer.toString(), ignoreCase); + } + + } + + /** + * Clean a directory without deleting it. + * + * @param directory directory to clean + * @throws IOException in case cleaning is unsuccessful + */ + public static void cleanDirectory(File directory) throws IOException { + if (!directory.exists()) { + String message = directory + " does not exist"; + throw new IllegalArgumentException(message); + } + + if (!directory.isDirectory()) { + String message = directory + " is not a directory"; + throw new IllegalArgumentException(message); + } + + File[] files = directory.listFiles(); + if (files == null) { // null if security restricted + throw new IOException("Failed to list contents of " + directory); + } + + IOException exception = null; + for (int i = 0; i < files.length; i++) { + File file = files[i]; + try { + forceDelete(file); + } catch (IOException ioe) { + exception = ioe; + } + } + + if (null != exception) { + throw exception; + } + } + + /** + * Clean a directory without deleting it. + * + * @param directory directory to clean, must not be null + * @throws NullPointerException if the directory is null + * @throws IOException in case cleaning is unsuccessful + */ + private static void cleanDirectoryOnExit(File directory) throws IOException { + if (!directory.exists()) { + String message = directory + " does not exist"; + throw new IllegalArgumentException(message); + } + + if (!directory.isDirectory()) { + String message = directory + " is not a directory"; + throw new IllegalArgumentException(message); + } + + File[] files = directory.listFiles(); + if (files == null) { // null if security restricted + throw new IOException("Failed to list contents of " + directory); + } + + IOException exception = null; + for (int i = 0; i < files.length; i++) { + File file = files[i]; + try { + forceDeleteOnExit(file); + } catch (IOException ioe) { + exception = ioe; + } + } + + if (null != exception) { + throw exception; + } + } + + /** + * Copies a whole directory to a new location preserving the file dates. + *

+ * This method copies the specified directory and all its child directories + * and files to the specified destination. The destination is the new + * location and name of the directory. + *

+ * The destination directory is created if it does not exist. If the + * destination directory did exist, then this method merges the source with + * the destination, with the source taking precedence. + * + * @param srcDir an existing directory to copy, must not be + * null + * @param destDir the new directory, must not be null + * @throws NullPointerException if source or destination is + * null + * @throws IOException if source or destination is invalid + * @throws IOException if an IO error occurs during copying + * @since Commons IO 1.1 + */ + public static void copyDirectory(File srcDir, File destDir) throws IOException { + copyDirectory(srcDir, destDir, true); + } + + /** + * Copies a whole directory to a new location. + *

+ * This method copies the contents of the specified source directory to + * within the specified destination directory. + *

+ * The destination directory is created if it does not exist. If the + * destination directory did exist, then this method merges the source with + * the destination, with the source taking precedence. + * + * @param srcDir an existing directory to copy, must not be + * null + * @param destDir the new directory, must not be null + * @param preserveFileDate true if the file date of the copy should be the + * same as the original + * @throws NullPointerException if source or destination is + * null + * @throws IOException if source or destination is invalid + * @throws IOException if an IO error occurs during copying + * @since Commons IO 1.1 + */ + public static void copyDirectory(File srcDir, File destDir, boolean preserveFileDate) throws IOException { + if (srcDir == null) { + throw new NullPointerException("Source must not be null"); + } + if (destDir == null) { + throw new NullPointerException("Destination must not be null"); + } + if (!srcDir.exists()) { + throw new FileNotFoundException("Source '" + srcDir + "' does not exist"); + } + if (!srcDir.isDirectory()) { + throw new IOException("Source '" + srcDir + "' exists but is not a directory"); + } + if (srcDir.getCanonicalPath().equals(destDir.getCanonicalPath())) { + throw new IOException("Source '" + srcDir + "' and destination '" + destDir + "' are the same"); + } + doCopyDirectory(srcDir, destDir, preserveFileDate); + } + + // ----------------------------------------------------------------------- + /** + * Copies a directory to within another directory preserving the file dates. + *

+ * This method copies the source directory and all its contents to a + * directory of the same name in the specified destination directory. + *

+ * The destination directory is created if it does not exist. If the + * destination directory did exist, then this method merges the source with + * the destination, with the source taking precedence. + * + * @param srcDir an existing directory to copy, must not be + * null + * @param destDir the directory to place the copy in, must not be + * null + * @throws NullPointerException if source or destination is + * null + * @throws IOException if source or destination is invalid + * @throws IOException if an IO error occurs during copying + * @since Commons IO 1.2 + */ + public static void copyDirectoryToDirectory(File srcDir, File destDir) throws IOException { + if (srcDir == null) { + throw new NullPointerException("Source must not be null"); + } + if (!(srcDir.exists() && srcDir.isDirectory())) { + throw new IllegalArgumentException("Source '" + destDir + "' is not a directory"); + } + if (destDir == null) { + throw new NullPointerException("Destination must not be null"); + } + if (!(destDir.exists() && destDir.isDirectory())) { + throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory"); + } + copyDirectory(srcDir, new File(destDir, srcDir.getName()), true); + } + + /** + * Copies a file to a new location preserving the file date. + *

+ * This method copies the contents of the specified source file to the + * specified destination file. The directory holding the destination file is + * created if it does not exist. If the destination file exists, then this + * method will overwrite it. + * + * @param srcFile an existing file to copy, must not be null + * @param destFile the new file, must not be null + * @throws NullPointerException if source or destination is + * null + * @throws IOException if source or destination is invalid + * @throws IOException if an IO error occurs during copying + * @see #copyFileToDirectory(File, File) + */ + public static void copyFile(File srcFile, File destFile) throws IOException { + copyFile(srcFile, destFile, true); + } + + /** + * Copies a file to a new location. + *

+ * This method copies the contents of the specified source file to the + * specified destination file. The directory holding the destination file is + * created if it does not exist. If the destination file exists, then this + * method will overwrite it. + * + * @param srcFile an existing file to copy, must not be null + * @param destFile the new file, must not be null + * @param preserveFileDate true if the file date of the copy should be the + * same as the original + * @throws NullPointerException if source or destination is + * null + * @throws IOException if source or destination is invalid + * @throws IOException if an IO error occurs during copying + * @see #copyFileToDirectory(File, File, boolean) + */ + public static void copyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException { + if (srcFile == null) { + throw new NullPointerException("Source must not be null"); + } + if (destFile == null) { + throw new NullPointerException("Destination must not be null"); + } + if (!srcFile.exists()) { + throw new FileNotFoundException("Source '" + srcFile + "' does not exist"); + } + if (srcFile.isDirectory()) { + throw new IOException("Source '" + srcFile + "' exists but is a directory"); + } + if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) { + throw new IOException("Source '" + srcFile + "' and destination '" + destFile + "' are the same"); + } + if (!(destFile.getParentFile() != null && destFile.getParentFile().exists())) { + if (!destFile.getParentFile().mkdirs()) { //NOPMD + throw new IOException("Destination '" + destFile + "' directory cannot be created"); + } + } + if (!(destFile.exists() && destFile.canWrite())) { + throw new IOException("Destination '" + destFile + "' exists but is read-only"); + } + doCopyFile(srcFile, destFile, preserveFileDate); + } + + // ----------------------------------------------------------------------- + /** + * Copies a file to a directory preserving the file date. + *

+ * This method copies the contents of the specified source file to a file of + * the same name in the specified destination directory. The destination + * directory is created if it does not exist. If the destination file + * exists, then this method will overwrite it. + * + * @param srcFile an existing file to copy, must not be null + * @param destDir the directory to place the copy in, must not be + * null + * @throws NullPointerException if source or destination is null + * @throws IOException if source or destination is invalid + * @throws IOException if an IO error occurs during copying + * @see #copyFile(File, File, boolean) + */ + public static void copyFileToDirectory(File srcFile, File destDir) throws IOException { + copyFileToDirectory(srcFile, destDir, true); + } + + /** + * Copies a file to a directory optionally preserving the file date. + *

+ * This method copies the contents of the specified source file to a file of + * the same name in the specified destination directory. The destination + * directory is created if it does not exist. If the destination file + * exists, then this method will overwrite it. + * + * @param srcFile an existing file to copy, must not be null + * @param destDir the directory to place the copy in, must not be + * null + * @param preserveFileDate true if the file date of the copy should be the + * same as the original + * @throws NullPointerException if source or destination is + * null + * @throws IOException if source or destination is invalid + * @throws IOException if an IO error occurs during copying + * @see #copyFile(File, File, boolean) + * @since Commons IO 1.3 + */ + public static void copyFileToDirectory(File srcFile, File destDir, boolean preserveFileDate) throws IOException { + if (destDir == null) { + throw new NullPointerException("Destination must not be null"); + } + if (!(destDir.exists() && destDir.isDirectory())) { + throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory"); + } + copyFile(srcFile, new File(destDir, srcFile.getName()), preserveFileDate); + } + + // ----------------------------------------------------------------------- + /** + * Recursively delete a directory. + * + * @param directory directory to delete + * @throws IOException in case deletion is unsuccessful + */ + public static void deleteDirectory(File directory) throws IOException { + if (!directory.exists()) { + return; + } + + cleanDirectory(directory); + if (!directory.delete()) { + String message = "Unable to delete directory " + directory + "."; + throw new IOException(message); + } + } + + /** + * Recursively schedule directory for deletion on JVM exit. + * + * @param directory directory to delete, must not be null + * @throws NullPointerException if the directory is null + * @throws IOException in case deletion is unsuccessful + */ + private static void deleteDirectoryOnExit(File directory) throws IOException { + if (!directory.exists()) { + return; + } + + cleanDirectoryOnExit(directory); + directory.deleteOnExit(); + } + + /** + * Internal copy directory method. + * + * @param srcDir the validated source directory, must not be + * null + * @param destDir the validated destination directory, must not be + * null + * @param preserveFileDate whether to preserve the file date + * @throws IOException if an error occurs + * @since Commons IO 1.1 + */ + private static void doCopyDirectory(File srcDir, File destDir, boolean preserveFileDate) throws IOException { + if (destDir.exists()) { + if (!destDir.isDirectory()) { + throw new IOException("Destination '" + destDir + "' exists but is not a directory"); + } + } else { + if (!destDir.mkdirs()) { + throw new IOException("Destination '" + destDir + "' directory cannot be created"); + } + if (preserveFileDate) { + destDir.setLastModified(srcDir.lastModified()); + } + } + if (!destDir.canWrite()) { + throw new IOException("Destination '" + destDir + "' cannot be written to"); + } + // recurse + File[] files = srcDir.listFiles(); + if (files == null) { // null if security restricted + throw new IOException("Failed to list contents of " + srcDir); + } + for (int i = 0; i < files.length; i++) { + File copiedFile = new File(destDir, files[i].getName()); + if (files[i].isDirectory()) { + doCopyDirectory(files[i], copiedFile, preserveFileDate); + } else { + doCopyFile(files[i], copiedFile, preserveFileDate); + } + } + } + + /** + * Internal copy file method. + * + * @param srcFile the validated source file, must not be null + * @param destFile the validated destination file, must not be + * null + * @param preserveFileDate whether to preserve the file date + * @throws IOException if an error occurs + */ + private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException { + if (destFile.exists() && destFile.isDirectory()) { + throw new IOException("Destination '" + destFile + "' exists but is a directory"); + } + + FileInputStream input = new FileInputStream(srcFile); + try { + FileOutputStream output = new FileOutputStream(destFile); + try { + IOHelper.copy(input, output); + } finally { + IOHelper.closeQuietly(output); + } + } finally { + IOHelper.closeQuietly(input); + } + + if (srcFile.length() != destFile.length()) { + throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'"); + } + if (preserveFileDate) { + destFile.setLastModified(srcFile.lastModified()); + } + } + + /** + * Schedule a file to be deleted when JVM exits. If file is directory delete + * it and all sub-directories. + * + * @param file file or directory to delete, must not be null + * @throws NullPointerException if the file is null + * @throws IOException in case deletion is unsuccessful + */ + public static void forceDeleteOnExit(File file) throws IOException { + if (file.isDirectory()) { + deleteDirectoryOnExit(file); + } else { + file.deleteOnExit(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java new file mode 100644 index 0000000000..630d1f6bf4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service.util; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.JarURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.util.jar.JarFile; + +public class IOHelper { + /** + * The default buffer size to use. + */ + private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + + /** + * Unconditionally close an InputStream. + *

+ * Equivalent to {@link InputStream#close()}, except any exceptions will be ignored. + * This is typically used in finally blocks. + * + * @param input the InputStream to close, may be null or already closed + */ + public static void closeQuietly(InputStream input) { + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + + /** + * Unconditionally close an OutputStream. + *

+ * Equivalent to {@link OutputStream#close()}, except any exceptions will be ignored. + * This is typically used in finally blocks. + * + * @param output the OutputStream to close, may be null or already closed + */ + public static void closeQuietly(OutputStream output) { + try { + if (output != null) { + output.close(); + } + } catch (IOException ioe) { + // ignore + } + } + + /** + * Copy bytes from an InputStream to an + * OutputStream. + *

+ * This method buffers the input internally, so there is no need to use a + * BufferedInputStream. + * + * @param input the InputStream to read from + * @param output the OutputStream to write to + * @return the number of bytes copied + * @throws NullPointerException if the input or output is null + * @throws IOException if an I/O error occurs + * @since Commons IO 1.1 + */ + public static int copy(InputStream input, OutputStream output) throws IOException { + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + int count = 0; + int n = 0; + while (-1 != (n = input.read(buffer))) { // NOPMD + output.write(buffer, 0, n); + count += n; + } + return count; + } + + public static InputStream getInputStream(URL url) throws IOException { + return new SafeURLInputStream(url); + } + + /** + * This class is a workaround for URL stream issue as illustrated below. + * InputStream is=url.getInputStream(); is.close(); // This line doesn't close + * the JAR file if the URL is a jar entry like "jar:file:/a.jar!/my.composite" We + * also need to turn off the JarFile cache. + * + * @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4950148 + * + * @version $Rev$ $Date$ + */ + public static class SafeURLInputStream extends InputStream { + private JarFile jarFile; + private InputStream is; + + public SafeURLInputStream(URL url) throws IOException { + String protocol = url.getProtocol(); + if (protocol != null && (protocol.equals("jar"))) { + JarURLConnection connection = (JarURLConnection)url.openConnection(); + // We cannot use cache + connection.setUseCaches(false); + try { + is = connection.getInputStream(); + } catch (IOException e) { + throw e; + } + jarFile = connection.getJarFile(); + } else { + URLConnection connection = url.openConnection(); + connection.setUseCaches(false); + is = connection.getInputStream(); + } + } + + public SafeURLInputStream(JarURLConnection connection) throws IOException { + // We cannot use cache + connection.setUseCaches(false); + is = connection.getInputStream(); + jarFile = connection.getJarFile(); + } + + @Override + public int available() throws IOException { + return is.available(); + } + + @Override + public void close() throws IOException { + is.close(); + // We need to close the JAR file + if (jarFile != null) { + jarFile.close(); + } + } + + @Override + public synchronized void mark(int readlimit) { + is.mark(readlimit); + } + + @Override + public boolean markSupported() { + return is.markSupported(); + } + + @Override + public int read() throws IOException { + return is.read(); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + return is.read(b, off, len); + } + + @Override + public int read(byte[] b) throws IOException { + return is.read(b); + } + + @Override + public synchronized void reset() throws IOException { + is.reset(); + } + + @Override + public long skip(long n) throws IOException { + return is.skip(n); + } + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor new file mode 100644 index 0000000000..b644709266 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.processor.impl.FolderContributionProcessor;type=application/vnd.tuscany.folder +org.apache.tuscany.sca.contribution.processor.impl.JarContributionProcessor;type=application/x-compressed diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/resources/contribution-impl-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/resources/contribution-impl-validation-messages.properties new file mode 100644 index 0000000000..158ee2102d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/main/resources/contribution-impl-validation-messages.properties @@ -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. +# +# +ContributionURINull =URI for the contribution is null +SourceURLNull = Source URL for the contribution is null +ContributionContentNull = The content of the contribution is null +PrivilegedActionException = Exception occured due to FilePermissions in security policy file +RootNotDirectory = The root is not a directory {0} +IllegalArgumentException = IllegalArgumentException occured due to : +DomainFileNotFound = Domain file "sca-domain.xml" not found ({0}) +MalformedURLException = MalformedURLException occured due to : \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java new file mode 100644 index 0000000000..c33b31b550 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.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.sca.contribution.processor; + +import java.io.File; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.processor.impl.FolderContributionProcessor; + +/** + * Folder Package Processor test case + * Verifies proper handle of File System structured contributions + * + * @version $Rev$ $Date$ + */ +public class FolderContributionPackageProcessorTestCase extends TestCase { + private static final String FOLDER_CONTRIBUTION = "."; + + public final void testProcessPackageArtifacts() throws Exception { + FolderContributionProcessor folderProcessor = new FolderContributionProcessor(); + URL contributionURL = new File(FOLDER_CONTRIBUTION).toURL().toURI().toURL(); + + List artifacts = folderProcessor.getArtifacts(contributionURL, null); + assertNotNull(artifacts); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java new file mode 100644 index 0000000000..9b3dce7029 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.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.sca.contribution.processor; + +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.processor.impl.JarContributionProcessor; +import org.apache.tuscany.sca.contribution.service.util.IOHelper; + +/** + * JAR Package Processor test case + * Verifies proper handle of JAR Archives contributions + * + * @version $Rev$ $Date$ + */ + +public class JarContributionPackageProcessorTestCase extends TestCase { + private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar"; + + public final void testProcessPackageArtifacts() throws Exception { + JarContributionProcessor jarProcessor = new JarContributionProcessor(); + + URL jarURL = getClass().getResource(JAR_CONTRIBUTION); + InputStream jarStream = jarURL.openStream(); + List artifacts = null; + try { + artifacts = jarProcessor.getArtifacts(jarURL, jarStream); + } finally { + IOHelper.closeQuietly(jarStream); + } + + assertNotNull(artifacts); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java new file mode 100644 index 0000000000..46b4183380 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import java.net.URI; +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + + +/** + * URL Artifact Processor Extension Point test case + * Verifies the right registration and lookup for processors that handle filename and file types + * + * @version $Rev$ $Date$ + */ +public class URLartifactProcessorExtensionPointTestCase extends TestCase { + + private URLArtifactProcessorExtensionPoint artifactProcessors; + + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + artifactProcessors = new DefaultURLArtifactProcessorExtensionPoint(extensionPoints); + artifactProcessors.addArtifactProcessor(new FileTypeArtifactProcessor()); + artifactProcessors.addArtifactProcessor(new FileNameArtifactProcessor()); + } + + + public final void testFileTypeProcessor() { + assertNotNull(artifactProcessors.getProcessor(".m1")); + } + + + public final void testFileNameProcessor() { + assertNotNull(artifactProcessors.getProcessor("file.m2")); + + } + + /** + * Internal mock classes + * + */ + + private class M1 { + } + + private class M2 { + } + + private class FileTypeArtifactProcessor implements URLArtifactProcessor { + public FileTypeArtifactProcessor() { + } + + public M1 read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + return null; + } + + public void resolve(M1 m1, ModelResolver resolver) throws ContributionResolveException { + } + + public String getArtifactType() { + return ".m1"; + } + + public Class getModelType() { + return M1.class; + } + } + + private class FileNameArtifactProcessor implements URLArtifactProcessor { + public FileNameArtifactProcessor() { + } + + public M2 read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + return null; + } + + public void resolve(M2 m2, ModelResolver resolver) throws ContributionResolveException { + } + + public String getArtifactType() { + return "file.m2"; + } + + public Class getModelType() { + return M2.class; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java new file mode 100644 index 0000000000..98852e951c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resolver; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DefaultContributionFactory; + +/** + * Test the default model resolver implementation. + * + * @version $Rev$ $Date$ + */ +public class DefaultModelResolverTestCase extends TestCase { + + private ModelResolver resolver; + private ContributionFactory factory; + + @Override + protected void setUp() throws Exception { + resolver = new DefaultModelResolver(); + factory = new DefaultContributionFactory(); + } + + public void testResolved() { + Model a = new Model("a"); + resolver.addModel(a); + Model x = new Model("a"); + x = resolver.resolveModel(Model.class, x); + assertTrue(x == a); + } + + public void testUnresolved() { + Model x = new Model("a"); + Model y = resolver.resolveModel(Model.class, x); + assertTrue(x == y); + } + + public void testResolvedArtifact() { + Artifact artifact = factory.createArtifact(); + artifact.setURI("foo/bar"); + resolver.addModel(artifact); + Artifact x = factory.createArtifact(); + x.setURI("foo/bar"); + x = resolver.resolveModel(Artifact.class, x); + assertTrue(x == artifact); + } + + class Model { + private String name; + + Model(String name) { + this.name = name; + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return name.equals(((Model)obj).name); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java new file mode 100644 index 0000000000..f66b429d65 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java @@ -0,0 +1,126 @@ + /* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resolver; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DefaultContributionFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; + +/** + * Test DefaultArtifactResolver. + * + * @version $Rev$ $Date$ + */ +public class ExtensibleModelResolverTestCase extends TestCase { + private ExtensibleModelResolver resolver; + + private ContributionFactory factory; + + @Override + protected void setUp() throws Exception { + + ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint(null); + resolvers.addResolver(Model.class, TestModelResolver.class); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + + resolver = new ExtensibleModelResolver(null, null, resolvers, factories, null); + + factory = new DefaultContributionFactory(); + } + + public void testResolvedDefault() { + OtherModel a = new OtherModel("a"); + resolver.addModel(a); + OtherModel x = new OtherModel("a"); + x = resolver.resolveModel(OtherModel.class, x); + assertTrue(x == a); + } + + public void testResolvedRegisteredClass() { + Model a = new Model("a"); + resolver.addModel(a); + Model x = new Model("a"); + x = resolver.resolveModel(Model.class, x); + assertTrue(x == a); + } + + public void testUnresolvedDefault() { + OtherModel x = new OtherModel("a"); + OtherModel y = resolver.resolveModel(OtherModel.class, x); + assertTrue(x == y); + } + + public void testUnresolved() { + Model x = new Model("a"); + Model y = resolver.resolveModel(Model.class, x); + assertTrue(x == y); + } + + public void testResolvedArtifact() { + Artifact artifact = factory.createArtifact(); + artifact.setURI("foo/bar"); + resolver.addModel(artifact); + Artifact x = factory.createArtifact(); + x.setURI("foo/bar"); + x = resolver.resolveModel(Artifact.class, x); + assertTrue(x == artifact); + } + + private class Model { + private String name; + + Model(String name) { + this.name = name; + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return name.equals(((Model)obj).name); + } + } + + private class OtherModel { + private String name; + + OtherModel(String name) { + this.name = name; + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return name.equals(((OtherModel)obj).name); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java new file mode 100644 index 0000000000..66ecd33da6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.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.sca.contribution.resolver; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; + +/** + * A test implementation of a model resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class TestModelResolver implements ModelResolver { + + private Map map = new HashMap(); + + public TestModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + } + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + if (resolved != null) { + // Return the resolved object + return modelClass.cast(resolved); + } + // Return the unresolved object + return unresolved; + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(resolved); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryTestCase.java new file mode 100644 index 0000000000..a90f5b36ad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryTestCase.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service.impl; + +import java.io.File; +import java.io.InputStream; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.service.impl.ContributionRepositoryImpl; +import org.apache.tuscany.sca.contribution.service.util.FileHelper; + +public class ContributionRepositoryTestCase extends TestCase { + private ContributionRepositoryImpl repository; + + @Override + protected void setUp() throws Exception { + // create repository (this should re-create the root directory) + this.repository = new ContributionRepositoryImpl("target/repository/", XMLInputFactory.newInstance(), null); + repository.init(); + } + + public void testStore() throws Exception { + String resourceLocation = "/repository/sample-calculator.jar"; + String contribution = "sample-calculator.jar"; + URL contributionLocation = getClass().getResource(resourceLocation); + InputStream contributionStream = getClass().getResourceAsStream(resourceLocation); + repository.store(contribution, contributionLocation, contributionStream); + + URL contributionURL = repository.find(contribution); + assertNotNull(contributionURL); + } + + public void testRemove() throws Exception { + String resourceLocation = "/repository/sample-calculator.jar"; + String contribution = "sample-calculator.jar"; + URL contributionLocation = getClass().getResource(resourceLocation); + InputStream contributionStream = getClass().getResourceAsStream(resourceLocation); + repository.store(contribution, contributionLocation, contributionStream); + + repository.remove(contribution); + URL contributionURL = repository.find(contribution); + assertNull(contributionURL); + } + + public void testList() throws Exception { + String resourceLocation = "/repository/sample-calculator.jar"; + String contribution = "sample-calculator.jar"; + URL contributionLocation = getClass().getResource(resourceLocation); + InputStream contributionStream = getClass().getResourceAsStream(resourceLocation); + repository.store(contribution, contributionLocation, contributionStream); + + assertEquals(1, repository.list().size()); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + FileHelper.deleteDirectory(new File("target/repository")); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImplTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImplTestCase.java new file mode 100644 index 0000000000..49e9cc166b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImplTestCase.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.sca.contribution.service.impl; + +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.PackageType; +import org.apache.tuscany.sca.contribution.service.impl.PackageTypeDescriberImpl; + +public class PackageTypeDescriberImplTestCase extends TestCase { + private PackageTypeDescriberImpl packageTypeDescriber; + + public void testResolveArchivePackageType() throws Exception { + URL artifactURL = getClass().getResource("/deployables/sample-calculator.jar"); + assertEquals(PackageType.JAR, this.packageTypeDescriber.getType(artifactURL, null)); + } + + public void testResolveFolderPackageType() throws Exception { + URL artifactURL = getClass().getResource("/deployables/"); + assertEquals(PackageType.FOLDER, this.packageTypeDescriber.getType(artifactURL, null)); + } + + public void testResolveFolder2PackageType() throws Exception { + URL artifactURL = getClass().getResource("/deployables"); + assertEquals(PackageType.FOLDER, this.packageTypeDescriber.getType(artifactURL, null)); + } + + + public void testResolveUnknownPackageType() throws Exception { + URL artifactURL = getClass().getResource("/test.ext"); + assertNull(this.packageTypeDescriber.getType(artifactURL, null)); + } + + public void testDefaultPackageType() throws Exception { + URL artifactURL = getClass().getResource("/test.ext"); + assertEquals("application/vnd.tuscany.ext", + packageTypeDescriber.getType(artifactURL, "application/vnd.tuscany.ext")); + } + + @Override + protected void setUp() throws Exception { + packageTypeDescriber = new PackageTypeDescriberImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar new file mode 100644 index 0000000000..0ca3a1b781 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar new file mode 100644 index 0000000000..7c042e64f1 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/repository3/contribution.zip b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/repository3/contribution.zip new file mode 100644 index 0000000000..b293aa4bcc Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/repository3/contribution.zip differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/test.composite b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/test.composite new file mode 100644 index 0000000000..1e09549194 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/test.composite @@ -0,0 +1,22 @@ + + + + This file just needs to exist + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/test.ext b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-impl/src/test/resources/test.ext new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/pom.xml new file mode 100644 index 0000000000..da2318ec71 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/pom.xml @@ -0,0 +1,77 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-contribution-java + Apache Tuscany SCA Java Import/Export Model + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.contribution.java + ${pom.name} + org.apache.tuscany.sca.contribution.java* + org.apache.tuscany.sca.contribution.osgi.impl + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassLoaderProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassLoaderProvider.java new file mode 100644 index 0000000000..aa314dd13f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassLoaderProvider.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.sca.contribution.java; + +import org.apache.tuscany.sca.contribution.Contribution; + +/** + * A pluggable utility to provide a classloader for a given contribution + */ +public interface ContributionClassLoaderProvider { + + /** + * Get the contribution type that this object will provide + * classloaders for. Takes values from o.a.t.s.contribution.PackageType + * + * @return + */ + String getContributionType(); + + /** + * Get the classloader for the given contribution + * @param contribution + * @param parent + * @return + */ + ClassLoader getClassLoader(Contribution contribution, ClassLoader parent); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassloaderProviderExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassloaderProviderExtensionPoint.java new file mode 100644 index 0000000000..b714090ff2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassloaderProviderExtensionPoint.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.sca.contribution.java; + +/** + * An extension point for contribution classloaders. Contribution + * classloaders respect the classloading strategy for the contribution + * in question. For example, a JAR contribution loads classes from its + * root directory while an EAR contribution follows the JEE classloading + * strategy. The choice of classloader is driven by the type of + * contribution being loaded. + * + * @version $Rev$ $Date$ + */ +public interface ContributionClassloaderProviderExtensionPoint { + + /** + * Add a contribution classloader provider extension. + * + * @param provider The provider to add + */ + void addProvider(ContributionClassLoaderProvider provider); + + /** + * Remove a contribution classloader provider extension. + * + * @param provider The provider to remove + */ + void removeProvider(ContributionClassLoaderProvider provider); + + /** + * Get a contribution classloader provider for the given contribution type. + * @param contributionType the lookup key + * @return The provider + */ + ContributionClassLoaderProvider getProvider(String contributionType); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassLoaderProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassLoaderProvider.java new file mode 100644 index 0000000000..8fd1898ad6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassLoaderProvider.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.sca.contribution.java; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.java.impl.ContributionClassLoader; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * The default implementation of the ContributionClassLoaderProvider + */ +public class DefaultContributionClassLoaderProvider implements ContributionClassLoaderProvider { + + public DefaultContributionClassLoaderProvider() { + super(); + } + + /** + * returns null as it is the default provider and applies when no specific + * provider has been specified + */ + public String getContributionType() { + return null; + } + + public ClassLoader getClassLoader(Contribution contribution, ClassLoader parent) { + return new ContributionClassLoader(contribution, parent); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassloaderProviderExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassloaderProviderExtensionPoint.java new file mode 100644 index 0000000000..7ffecdf312 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassloaderProviderExtensionPoint.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.java; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + + +/** + * Default implementation of a contribution classloader provider extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultContributionClassloaderProviderExtensionPoint implements ContributionClassloaderProviderExtensionPoint { + + private HashMap providers = new HashMap(); + private boolean loaded; + + /** + * Constructs a new DefaultModelFactoryExtensionPoint. + */ + public DefaultContributionClassloaderProviderExtensionPoint() { + } + + /** + * Add a contribution classloader provider extension. + * + * @param provider The provider to add + */ + public void addProvider(ContributionClassLoaderProvider provider){ + providers.put(provider.getContributionType(), provider); + } + + /** + * Remove a contribution classloader provider extension. + * + * @param provider The provider to remove + */ + public void removeProvider(ContributionClassLoaderProvider provider){ + providers.remove(provider.getContributionType()); + } + + /** + * Get a contribution classloader provider for the given contribution type. + * @param contributionType the lookup key + * @return The provider + */ + public ContributionClassLoaderProvider getProvider(String contributionType){ + loadProviders(); + return providers.get(contributionType); + } + + private synchronized void loadProviders() { + if (loaded) + return; + + // Get the processor service declarations + Set processorDeclarations; + try { + processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ContributionClassLoaderProvider.class); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + for (ServiceDeclaration processorDeclaration: processorDeclarations) { + Map attributes = processorDeclaration.getAttributes(); + + // Load a URL artifact processor + String contributionType = attributes.get("type"); + + // Create a processor wrapper and register it + ContributionClassLoaderProvider provider = new LazyContributionClassLoaderProvider(contributionType, processorDeclaration); + addProvider(provider); + } + + loaded = true; + } + + /** + * A facade for package processors. + */ + private static class LazyContributionClassLoaderProvider implements ContributionClassLoaderProvider { + + private ServiceDeclaration processorDeclaration; + private String contributionType; + private ContributionClassLoaderProvider provider; + + private LazyContributionClassLoaderProvider(String contributionType, ServiceDeclaration processorDeclaration) { + this.processorDeclaration = processorDeclaration; + this.contributionType = contributionType; + } + + public String getContributionType() { + return contributionType; + } + + @SuppressWarnings("unchecked") + public ClassLoader getClassLoader(Contribution contribution, ClassLoader parent){ + if (provider == null) { + try { + Class providerClass = (Class)processorDeclaration.loadClass(); + Constructor constructor = providerClass.getConstructor(); + provider = constructor.newInstance(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return provider.getClassLoader(contribution, parent); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java new file mode 100644 index 0000000000..886c61c00a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.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.sca.contribution.java; + +import org.apache.tuscany.sca.contribution.java.impl.JavaImportExportFactoryImpl; + +/** + * Default Java Import/Export Factory implementation + * + * @version $Rev$ $Date$ + */ +public class DefaultJavaImportExportFactory extends JavaImportExportFactoryImpl implements JavaImportExportFactory { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java new file mode 100644 index 0000000000..41e93ec148 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.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.sca.contribution.java; + +import org.apache.tuscany.sca.contribution.Export; + +/** + * Base Java Export model interface + * + * @version $Rev$ $Date$ + */ +public interface JavaExport extends Export { + /** + * Get java package that identifies the import + * + * @return The package name + */ + String getPackage(); + + /** + * Set java package that identifies the import + * + * @param packageName The package name + */ + void setPackage(String packageName); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java new file mode 100644 index 0000000000..d3568f6283 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.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.sca.contribution.java; + +import org.apache.tuscany.sca.contribution.Import; + +/** + * Base Java Import model interface + * + * @version $Rev$ $Date$ + */ +public interface JavaImport extends Import { + + /** + * Get the location used to resolve the definitions for this import + * + * @return The import location + */ + String getLocation(); + + /** + * Set the location used to resolve the definitions for this import + * + * @param location The import location + */ + void setLocation(String location); + + /** + * Get java package that identifies the import + * + * @return The package name + */ + String getPackage(); + + /** + * Set java package that identifies the import + * + * @param packageName The package name + */ + void setPackage(String packageName); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java new file mode 100644 index 0000000000..af2ca9cd57 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.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.sca.contribution.java; + +/** + * Base Java Import/Export model factory + * + * @version $Rev$ $Date$ + */ +public interface JavaImportExportFactory { + + /** + * Create a java import model object + * + * @return The new JavaImport model object + */ + JavaImport createJavaImport(); + + /** + * Create a java export model object + * + * @return The new JavaExport model object + */ + JavaExport createJavaExport(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java new file mode 100644 index 0000000000..c44a08c67b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.java.impl; + +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.DefaultDelegatingModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + +/** + * A Model Resolver for ClassReferences. + * + * @version $Rev$ $Date$ + */ +public class ClassLoaderModelResolver extends URLClassLoader implements ModelResolver { + private Contribution contribution; + private Map importResolvers = new HashMap(); + + private static ClassLoader parentClassLoader() { + ClassLoader parentClassLoader = ServiceDiscovery.class.getClassLoader(); + return parentClassLoader; + } + + private static URL[] getContributionURLs(final Contribution contribution) throws IOException { + List urls = new ArrayList(); + urls.add(new URL(contribution.getLocation())); + urls.addAll(ContributionHelper.getNestedJarUrls(contribution)); + return urls.toArray(new URL[urls.size()]); + } + + public ClassLoaderModelResolver(final Contribution contribution, ModelFactoryExtensionPoint modelFactories) throws IOException { + super(getContributionURLs(contribution), parentClassLoader()); + this.contribution = contribution; + + // Index Java import resolvers by package name + Map> resolverMap = new HashMap>(); + for (Import import_: this.contribution.getImports()) { + if (import_ instanceof JavaImport) { + JavaImport javaImport = (JavaImport)import_; + List resolvers = resolverMap.get(javaImport.getPackage()); + if (resolvers == null) { + resolvers = new ArrayList(); + resolverMap.put(javaImport.getPackage(), resolvers); + } + resolvers.add(javaImport.getModelResolver()); + } + } + + // Create a delegating model resolver for each imported package + for (Map.Entry> entry: resolverMap.entrySet()) { + importResolvers.put(entry.getKey(), new DefaultDelegatingModelResolver(entry.getValue())); + } + } + + public void addModel(Object resolved) { + throw new IllegalStateException(); + } + + public Object removeModel(Object resolved) { + throw new IllegalStateException(); + } + + public T resolveModel(Class modelClass, T unresolved) { + if (!(unresolved instanceof ClassReference)) { + return unresolved; + } + + try { + + // Load the class and return a class reference for it + String className = ((ClassReference)unresolved).getClassName(); + Class clazz = Class.forName(className, true, this); + return modelClass.cast(new ClassReference(clazz)); + + } catch (ClassNotFoundException e) { + return unresolved; + } catch (NoClassDefFoundError e) { + return unresolved; + } + } + + @Override + public URL findResource(String name) { + + //TODO delegate to the Java import resolvers + + URL url = super.findResource(name); + return url; + } + + @Override + public Enumeration findResources(String name) throws IOException { + + //TODO delegate to the Java import resolvers + //Enumeration importedResources; + + Enumeration resources = super.findResources(name); + List allResources = new ArrayList(); + //for (; importedResources.hasMoreElements(); ) { + // allResources.add(importedResources.nextElement()); + //} + for (; resources.hasMoreElements(); ) { + allResources.add(resources.nextElement()); + } + return Collections.enumeration(allResources); + } + + @Override + protected Class findClass(String name) throws ClassNotFoundException { + + // Extract the package name + int d = name.lastIndexOf('.'); + String packageName; + if (d != -1) { + packageName = name.substring(0, d); + } else { + packageName = null; + } + + // First try to load the class using the Java import resolvers + ModelResolver importResolver = importResolvers.get(packageName); + if (importResolver != null) { + ClassReference classReference = importResolver.resolveModel(ClassReference.class, new ClassReference(name)); + if (!classReference.isUnresolved()) { + return classReference.getJavaClass(); + } + } + + // Next, try to load the class from the current contribution + Class clazz = super.findClass(name); + return clazz; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java new file mode 100644 index 0000000000..0b1c035ff4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java @@ -0,0 +1,177 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.java.impl; + +import java.lang.ref.WeakReference; +import java.lang.reflect.Constructor; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider; +import org.apache.tuscany.sca.contribution.java.ContributionClassloaderProviderExtensionPoint; +import org.apache.tuscany.sca.contribution.java.DefaultContributionClassLoaderProvider; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + +/** + * A Model Resolver for ClassReferences. + * + * @version $Rev: 557916 $ $Date: 2007-07-20 01:04:40 -0700 (Fri, 20 Jul 2007) $ + */ +public class ClassReferenceModelResolver implements ModelResolver { + private final ExtensionPointRegistry registry; + private final Contribution contribution; + private WeakReference classLoader; + private Map map = new HashMap(); + + private ModelResolver osgiResolver; + + public ClassReferenceModelResolver(final Contribution contribution, ExtensionPointRegistry registry) { + this.contribution = contribution; + this.registry = registry; + if (this.contribution != null) { + // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy. + // ClassLoader cl = contribution.getClassLoader(); + ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction() { + public ClassLoader run() { + return contribution.getClassLoader(); + } + }); + + if (cl == null) { + // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy. + //ClassLoader contextClassLoader = AccessController.doPrivileged(new PrivilegedAction() { + // public ClassLoader run() { + // return Thread.currentThread().getContextClassLoader(); + // } + //}); + ClassLoader contextClassLoader = ServiceDiscovery.getInstance().getServiceDiscoverer().getClass().getClassLoader(); + ContributionClassLoaderProvider provider = null; + try { + ContributionClassloaderProviderExtensionPoint providers = + registry.getExtensionPoint(ContributionClassloaderProviderExtensionPoint.class); + + provider = providers.getProvider(contribution.getType()); + + } catch (Throwable e) { + // Ignore errors + } + if (provider == null) { + provider = new DefaultContributionClassLoaderProvider(); + } + cl = provider.getClassLoader(contribution, contextClassLoader); + contribution.setClassLoader(cl); + } + this.classLoader = new WeakReference(cl); + } else { + // This path should be used only for unit testing. + // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy. + // this.classLoader = new WeakReference(this.getClass().getClassLoader()); + ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction() { + public ClassLoader run() { + return this.getClass().getClassLoader(); + } + }); + this.classLoader = new WeakReference( cl ); + } + + try { + Class osgiResolverClass = + Class.forName("org.apache.tuscany.sca.contribution.osgi.impl.OSGiClassReferenceModelResolver"); + if (osgiResolverClass != null) { + Constructor constructor = + osgiResolverClass.getConstructor(Contribution.class, ExtensionPointRegistry.class); + this.osgiResolver = (ModelResolver)constructor.newInstance(contribution, registry); + } + } catch (Throwable e) { + // Ignore error, non-OSGi classloading is used in this case + } + } + + public void addModel(Object resolved) { + ClassReference clazz = (ClassReference)resolved; + map.put(clazz.getClassName(), clazz); + } + + public Object removeModel(Object resolved) { + return map.remove(((ClassReference)resolved).getClassName()); + } + + + + public T resolveModel(Class modelClass, T unresolved) { + if (!(unresolved instanceof ClassReference)) { + return unresolved; + } + Object resolved = map.get(((ClassReference)unresolved).getClassName()); + + if (resolved != null) { + return modelClass.cast(resolved); + } + + //Load a class on demand + Class clazz = null; + + if (osgiResolver != null) { + resolved = osgiResolver.resolveModel(modelClass, unresolved); + clazz = ((ClassReference)resolved).getJavaClass(); + } + + if (clazz == null) { + try { + // Search contribution ClassLoader (which has visibility of classes in the contribution + // as well as explicitly imported packages from other contributions) + clazz = Class.forName(((ClassReference)unresolved).getClassName(), true, classLoader.get()); + } catch (ClassNotFoundException e) { + } catch (NoClassDefFoundError e) { + } + } + + if (clazz != null) { + //if we load the class + // Store a new ClassReference wrapping the loaded class + ClassReference classReference = new ClassReference(clazz); + map.put(clazz.getName(), classReference); + + // Return the resolved ClassReference + return modelClass.cast(classReference); + } else { + return unresolved; + } + + } + + + /*************** + * Helper methods + ***************/ + + private String getPackageName(ClassReference clazz) { + int pos = clazz.getClassName().lastIndexOf("."); + return clazz.getClassName().substring(0, pos); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java new file mode 100644 index 0000000000..b167d9af4e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java @@ -0,0 +1,390 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.java.impl; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.java.JavaImport; + + +public class ContributionClassLoader extends URLClassLoader { +// public class ContributionClassLoader { + + private Contribution contribution; + // private b urlClassLoader; + + /** + * Constructor for contribution ClassLoader + * + * @param contribution + * @param parent + * @throws MalformedURLException + */ + public ContributionClassLoader(Contribution contribution, final ClassLoader parent) { + super(new URL[0], parent); + // Note that privileged use of getContextClassLoader have been promoted to callers. + // super(new URL[0], parent == null?Thread.currentThread().getContextClassLoader(): null); + this.contribution = contribution; + if (contribution.getLocation() != null) { + try { + this.addURL(new URL(contribution.getLocation())); + for (URL url : ContributionHelper.getNestedJarUrls(contribution)) { + this.addURL(url); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + /* + * Return the ClassLoader corresponding to a contribution providing an export + * Create a new ClassLoader for the contribution if one does not exist + */ + private ClassLoader getExportClassLoader(Contribution exportingContribution) { + ClassLoader cl = exportingContribution.getClassLoader(); + if (!(cl instanceof ContributionClassLoader)) { + if (cl == null) { + cl = getParent(); + } + + cl = new ContributionClassLoader(exportingContribution, cl); + exportingContribution.setClassLoader(cl); + } + return cl; + } + + /* (non-Javadoc) + * @see java.net.URLClassLoader#findClass(java.lang.String) + * + * Search path for class: + * This contribution + * Imported contributions + */ + @Override + protected Class findClass(String className) throws ClassNotFoundException { + + Class clazz = null; + try { + clazz = findClassFromContribution(className); + } catch (ClassNotFoundException e) { + + for (Import import_ : this.contribution.getImports()) { + if (classNameMatchesImport(className, import_)) { + // Delegate the resolution to the imported contribution + for (Contribution exportingContribution : ((JavaImportModelResolver)import_.getModelResolver()).getExportContributions()) { + + ClassLoader exportClassLoader = getExportClassLoader(exportingContribution); + if (exportClassLoader instanceof ContributionClassLoader) { + + for (Export export : exportingContribution.getExports()) { + try { + if (import_.match(export)) { + clazz = ((ContributionClassLoader)exportClassLoader).findClassFromContribution(className); + break; + } + } catch (ClassNotFoundException e1) { + continue; + } + + } + if (clazz != null) break; + } + } + if (clazz != null) break; + } + } + + if (clazz == null) throw e; + } + return clazz; + } + + + /* (non-Javadoc) + * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean) + * + * Search path for class: + * Parent ClassLoader + * This contribution + * Imported contributions + * + */ + @Override + protected synchronized Class loadClass(String className, boolean resolveClass) + throws ClassNotFoundException { + + Class clazz = null; + try { + + if (this.getParent() != null) + clazz = this.getParent().loadClass(className); + + } catch (ClassNotFoundException e) { + } + + if (clazz == null) + clazz = findClass(className); + + + if (resolveClass) + this.resolveClass(clazz); + return clazz; + + } + + + + /* + * (non-Javadoc) + * + * @see java.net.URLClassLoader#findResource(java.lang.String) + */ + @Override + public URL findResource(String name) { + + URL url = findResourceFromContribution(name); + + if (url == null) { + for (Import import_ : this.contribution.getImports()) { + if (resourceNameMatchesImport(name, import_)) { + // Delegate the resolution to the imported contribution + for (Contribution exportingContribution : ((JavaImportModelResolver)import_.getModelResolver()).getExportContributions()) { + + ClassLoader exportClassLoader = getExportClassLoader(exportingContribution); + if (exportClassLoader instanceof ContributionClassLoader) { + + for (Export export : exportingContribution.getExports()) { + if (import_.match(export)) { + url = ((ContributionClassLoader)exportClassLoader).findResourceFromContribution(name); + if (url != null) break; + } + } + if (url != null) break; + } + } + if (url != null) break; + } + } + + } + return url; + } + + + /* (non-Javadoc) + * @see java.net.URLClassLoader#findResources(java.lang.String) + */ + @Override + public Enumeration findResources(String name) throws IOException { + + return Collections.enumeration(findResourceSet(name)); + } + + + + + /* (non-Javadoc) + * @see java.lang.ClassLoader#getResource(java.lang.String) + * + * Find a resource. + * Search path for resource: + * Parent ClassLoader + * This contribution + * Imported contributions + */ + @Override + public URL getResource(String resName) { + + URL resource = null; + + if (this.getParent() != null) { + resource = this.getParent().getResource(resName); + } + if (resource == null) + resource = findResource(resName); + + return resource; + } + + + + /* (non-Javadoc) + * @see java.lang.ClassLoader#getResources(java.lang.String) + * + * Return list of resources from this contribution, resources + * imported through imported contributions and resources from parent + * ClassLoader. + */ + @Override + public Enumeration getResources(String resName) throws IOException { + + HashSet resourceSet = findResourceSet(resName); + addEnumerationToCollection(resourceSet, super.getResources(resName)); + + return Collections.enumeration(resourceSet); + } + + + /* + * Find set of resources + */ + private HashSet findResourceSet(String name) throws IOException { + + HashSet resources = new HashSet(); + + addEnumerationToCollection(resources, super.findResources(name)); + + for (Import import_ : this.contribution.getImports()) { + if (!(import_ instanceof JavaImport)) { + continue; + } + if (resourceNameMatchesImport(name, import_)) { + // Delegate the resolution to the imported contribution + for (Contribution exportingContribution : ((JavaImportModelResolver)import_.getModelResolver()).getExportContributions()) { + + ClassLoader exportClassLoader = getExportClassLoader(exportingContribution); + if (exportClassLoader instanceof ContributionClassLoader) { + + for (Export export : exportingContribution.getExports()) { + if (import_.match(export)) { + addEnumerationToCollection(resources, + ((ContributionClassLoader)exportClassLoader).findResources(name)); + } + } + } + } + } + } + + return resources; + } + + + /* + * Find class from contribution. If class has already been loaded, return loaded class. + */ + private Class findClassFromContribution(String className) throws ClassNotFoundException { + + Class clazz = findLoadedClass(className); + if (clazz == null) + clazz = super.findClass(className); + return clazz; + + } + + /* + * Find resource from contribution. + */ + private URL findResourceFromContribution(String name) { + + return super.findResource(name); + } + + /** + * Check if a class name matches an import statement. + * Class matches if the package name used in matches + * + * @param name Name of class + * @param import_ SCA contribution import + * @return true if this is a matching import + */ + private boolean classNameMatchesImport(String name, Import import_) { + + if (import_ instanceof JavaImport && name != null && name.lastIndexOf('.') > 0) { + JavaImport javaImport = (JavaImport) import_; + + String packageName = name.substring(0, name.lastIndexOf('.')); + if (javaImport.getPackage().endsWith(".*")) { + String prefix = javaImport.getPackage().substring(0, javaImport.getPackage().length() -1); + if (packageName.startsWith(prefix)) { + return true; + } + } else { + return packageName.equals(javaImport.getPackage()); + } + } + + return false; + } + + /** + * Check if a resource name matches an import statement. + * Resource matches if package/namespace match the directory of resource. + * + * @param name Name of resource + * @param import_ SCA contribution import + * @return true if this is a matching import + */ + private boolean resourceNameMatchesImport(String name, Import import_) { + + + if (name == null || name.lastIndexOf('/') <= 0) + return false; + else if (import_ instanceof JavaImport) { + JavaImport javaImport = (JavaImport) import_; + + if (javaImport.getPackage().endsWith(".*")) { + String packageName = name.substring(0, name.lastIndexOf('/')).replace('/', '.'); + String prefix = javaImport.getPackage().substring(0, javaImport.getPackage().length() -1); + if (packageName.startsWith(prefix)) { + return true; + } + } else { + // 'name' is a resource : contains "/" as separators + // Get package name from resource name + String packageName = name.substring(0, name.lastIndexOf('/')); + return packageName.equals(javaImport.getPackage().replaceAll("\\.", "/")); + } + } + return false; + } + + /* + * Add an enumeration to a Collection + */ + private void addEnumerationToCollection(Collection collection, Enumeration enumeration) { + + while (enumeration.hasMoreElements()) + collection.add(enumeration.nextElement()); + } + + + @Override + public String toString() { + return "SCA Contribution ClassLoader location: " + contribution.getLocation() + " parent ClassLoader: " + getParent(); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionHelper.java new file mode 100644 index 0000000000..e913495789 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionHelper.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.sca.contribution.java.impl; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; + +public class ContributionHelper { + + public static List getNestedJarUrls(final Contribution contribution) throws IOException { + List urls = new ArrayList(); + boolean isZipContribution = contribution.getLocation().endsWith(".zip"); + URI uri = URI.create(contribution.getLocation()); + boolean isFolderContribution = !isZipContribution && uri.getScheme().equals("file") && new File(uri).isDirectory(); + if (isZipContribution || isFolderContribution) { + for (Artifact a : contribution.getArtifacts()) { + if (a.getLocation().endsWith(".jar")) { + if (isZipContribution) { + urls.add(createTempJar(a, contribution)); + } else { + urls.add(new URL(a.getLocation())); + } + } + } + } + return urls; + } + + /** + * URLClassLoader doesn't seem to work with URLs to jars within an archive so as a work around + * copy the jar to a temp file and use the url to that. + */ + private static URL createTempJar(Artifact artifact, Contribution contribution) throws IOException { + FileOutputStream fileOutputStream = null; + ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(new File(URI.create(contribution.getLocation())))); + try { + ZipEntry zipEntry = zipInputStream.getNextEntry(); + while (zipEntry != null) { + if (artifact.getLocation().endsWith(zipEntry.getName())) { + + String tempName = ("tmp." + artifact.getURI().substring(0, artifact.getURI().length() - 3)).replace('/', '.'); + File tempFile = File.createTempFile(tempName, ".jar"); + tempFile.deleteOnExit(); + fileOutputStream = new FileOutputStream(tempFile); + + byte[] buf = new byte[2048]; + int n; + while ((n = zipInputStream.read(buf, 0, buf.length)) > -1) { + fileOutputStream.write(buf, 0, n); + } + + fileOutputStream.close(); + zipInputStream.closeEntry(); + + return tempFile.toURI().toURL(); + + } + zipEntry = zipInputStream.getNextEntry(); + } + } finally { + zipInputStream.close(); + if (fileOutputStream != null) { + fileOutputStream.close(); + } + } + + throw new IllegalStateException(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java new file mode 100644 index 0000000000..c0bd9465e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.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.sca.contribution.java.impl; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * Implementation of a Java Import model + * + * @version $Rev$ $Date$ + */ +public class JavaExportImpl extends ExtensibleImpl implements JavaExport { + private ModelResolver modelResolver; + + /** + * Java package being exported + */ + private String packageName; + + public JavaExportImpl() { + super(); + } + + public String getPackage() { + return this.packageName; + } + + public void setPackage(String packageName) { + this.packageName = packageName; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java new file mode 100644 index 0000000000..8d5412f6d7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.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.sca.contribution.java.impl; + +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A model resolver for Java exports. + * + * @version $Rev$ $Date$ + */ +public class JavaExportModelResolver implements ModelResolver { + + private JavaExport export; + private ModelResolver resolver; + + public JavaExportModelResolver(JavaExport export, ModelResolver resolver) { + this.export = export; + this.resolver = resolver; + } + + public void addModel(Object resolved) { + throw new IllegalStateException(); + } + + public Object removeModel(Object resolved) { + throw new IllegalStateException(); + } + + public T resolveModel(Class modelClass, T unresolved) { + if (!(unresolved instanceof ClassReference)) { + return unresolved; + } + + // Filter package name + ClassReference classReference = (ClassReference)unresolved; + String className = classReference.getClassName(); + int d = className.lastIndexOf('.'); + String packageName; + if (d != -1) { + packageName = className.substring(0, d); + } else { + packageName = ""; + } + if (export.getPackage().equals(packageName)) { + + // Package matches the exported package, delegate to the + // contribution's resolver + return resolver.resolveModel(modelClass, unresolved); + } else { + + // Package is not exported, return the unresolved object + return unresolved; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java new file mode 100644 index 0000000000..b79aa32dc3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.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.sca.contribution.java.impl; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Artifact processor for Java Export + * + * @version $Rev$ $Date$ + */ +public class JavaExportProcessor implements StAXArtifactProcessor { + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + + private static final QName EXPORT_JAVA = new QName(SCA10_NS, "export.java"); + + private static final String PACKAGE = "package"; + + private final JavaImportExportFactory factory; + private final Monitor monitor; + + public JavaExportProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + super(); + this.factory = modelFactories.getFactory(JavaImportExportFactory.class); + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return EXPORT_JAVA; + } + + public Class getModelType() { + return JavaExport.class; + } + + /** + * Process + */ + public JavaExport read(XMLStreamReader reader) throws ContributionReadException { + JavaExport javaExport = this.factory.createJavaExport(); + QName element = null; + + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read + if (EXPORT_JAVA.equals(element)) { + String packageName = reader.getAttributeValue(null, PACKAGE); + if (packageName == null) { + error("AttributePackageMissing", reader); + //throw new ContributionReadException("Attribute 'package' is missing"); + } else + javaExport.setPackage(packageName); + } + break; + case XMLStreamConstants.END_ELEMENT: + if (EXPORT_JAVA.equals(reader.getName())) { + return javaExport; + } + break; + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return javaExport; + } + + public void write(JavaExport javaExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + writer.writeStartElement(EXPORT_JAVA.getNamespaceURI(), EXPORT_JAVA.getLocalPart()); + + if (javaExport.getPackage() != null) { + writer.writeAttribute(PACKAGE, javaExport.getPackage()); + } + + writer.writeEndElement(); + } + + public void resolve(JavaExport javaExport, ModelResolver resolver) throws ContributionResolveException { + + if (javaExport.getPackage() != null) + // Initialize the export resolver + javaExport.setModelResolver(new JavaExportModelResolver(javaExport, resolver)); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java new file mode 100644 index 0000000000..e5dc397f4e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.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.sca.contribution.java.impl; + +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory; + +/** + * Java Import/Export Factory implementation + * + * @version $Rev$ $Date$ + */ +public class JavaImportExportFactoryImpl implements JavaImportExportFactory { + + public JavaImport createJavaImport() { + return new JavaImportImpl(); + } + + public JavaExport createJavaExport() { + return new JavaExportImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java new file mode 100644 index 0000000000..47cdc9767b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.java.impl; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.resolver.DefaultImportAllModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionListener; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; + +/** + * Java Import/Export contribution listener + * The listener would process all import/export from a given contribution + * and initialize the model resolvers properly + * + * @version $Rev$ $Date$ + */ +public class JavaImportExportListener implements ContributionListener { + + private ContributionFactory contributionFactory; + + /** + * Constructs a new JavaImportExportListener + */ + public JavaImportExportListener(ModelFactoryExtensionPoint modelFactories) { + contributionFactory = modelFactories.getFactory(ContributionFactory.class); + } + + /** + * Initialize the import/export model resolvers + * Export model resolvers are same as Contribution model resolver + * Import model resolvers are matched to a specific contribution if a location URI is specified, + * otherwise it try to resolve against all the other contributions + * Also set the exporting contributions used by contribution ClassLoaders to + * match import/export for class loading. + */ + public void contributionAdded(ContributionRepository repository, Contribution contribution) { + + // If the contribution does not contain sca-contribution.xml metadata + // (for example it's an existing JAR developed before SCA existed) + // export all its Java packages + ModelResolver modelResolver = contribution.getModelResolver(); + + // Look for META-INF/sca-contribution.xml + Artifact artifact = contributionFactory.createArtifact(); + artifact.setURI(Contribution.SCA_CONTRIBUTION_META); + artifact = modelResolver.resolveModel(Artifact.class, artifact); + if (artifact.getLocation() == null) { + + // Look for META-INF/sca-contribution-generated.xml + artifact.setURI(Contribution.SCA_CONTRIBUTION_GENERATED_META); + artifact = modelResolver.resolveModel(Artifact.class, artifact); + if (artifact.getLocation() == null) { + + // No contribution metadata file was found, default to export all the + // Java packages found in the contribution + Set packages = new HashSet(); + for (Artifact a: contribution.getArtifacts()) { + String uri = a.getURI(); + if (uri.endsWith(".class")) { + uri = uri.substring(0, uri.length() - 6); + int d = uri.lastIndexOf('/'); + if (d != -1) { + packages.add(uri.substring(0, d).replace('/', '.')); + } + } + } + + // Add Java export model objects for all the packages we found + for (String pkg: packages) { + JavaExport export = new JavaExportImpl(); + export.setPackage(pkg); + contribution.getExports().add(export); + } + } + } + + // Initialize the contribution exports + for (Export export: contribution.getExports()) { + export.setModelResolver(contribution.getModelResolver()); + } + + // Initialize the contribution imports + for (Import import_: contribution.getImports()) { + boolean initialized = false; + + if(import_ instanceof JavaImport) { + JavaImport javaImport = (JavaImport) import_; + + //Find a matching contribution + if(javaImport.getLocation() != null) { + Contribution targetContribution = repository.getContribution(javaImport.getLocation()); + if (targetContribution != null) { + + // Find a matching contribution export + for (Export export: targetContribution.getExports()) { + if (export instanceof JavaExport) { + JavaExport javaExport = (JavaExport)export; + if (javaImport.getPackage().equals(javaExport.getPackage())) { + List exportingContributions = new ArrayList(); + exportingContributions.add(targetContribution); + javaImport.setModelResolver(new JavaImportModelResolver(exportingContributions, javaExport.getModelResolver())); + initialized = true; + break; + } + } + } + } + } + + //if no location was specified, try to resolve with any contribution + if (!initialized) { + //Use a resolver that will consider all contributions + import_.setModelResolver(new JavaImportModelResolver(repository.getContributions(), new DefaultImportAllModelResolver(import_, repository.getContributions()))); + } + } + } + } + + public void contributionRemoved(ContributionRepository repository, Contribution contribution) { + + } + + public void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution) { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java new file mode 100644 index 0000000000..f2fdb3278e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.java.impl; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * Implementation of a Java Import model + * + * @version $Rev$ $Date$ + */ +public class JavaImportImpl extends ExtensibleImpl implements JavaImport { + private ModelResolver modelResolver; + private List contributions; + /** + * Java package name being imported + */ + private String packageName; + /** + * Contribution URI where the artifact is imported from + */ + private String location; + + public JavaImportImpl() { + super(); + } + + public String getLocation() { + return this.location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getPackage() { + return this.packageName; + } + + public void setPackage(String packageName) { + this.packageName = packageName; + } + + public ModelResolver getModelResolver() { + return this.modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + public List getExportContributions() { + return contributions; + } + + public void setExportContributions(List contributions) { + this.contributions = contributions; + } + + /** + * Match a JavaImport to a given JavaExport based on : + * location is not provided + * import and export packages match + */ + public boolean match(Export export) { + if(export instanceof JavaExport) { + JavaExport javaExport = (JavaExport)export; + String exportedPackage = javaExport.getPackage(); + if (packageName.equals(exportedPackage)) { + return true; + } else { + if (packageName.endsWith(".*")) { + String prefix = packageName.substring(0, packageName.length() - 1); + if (exportedPackage.startsWith(prefix)) { + return true; + } + } + } + } + + return false; + } + + @Override + public String toString() { + return String.valueOf(packageName); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java new file mode 100644 index 0000000000..484eddd222 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.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.sca.contribution.java.impl; + +import java.util.List; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A JavaImport specific model resolver. This model resolver is temporary + * and provides the ContributionClassLoader with the list of exporting + * contributions that it currently needs. + * + * FIXME Remove this class after the ContributionClassLoader is simplified + * and cleaned up. + * + * @version $Rev$ $Date$ + */ +public class JavaImportModelResolver implements ModelResolver { + + private ModelResolver modelResolver; + private List contributions; + + public JavaImportModelResolver(List contributions, ModelResolver modelResolver) { + this.modelResolver = modelResolver; + this.contributions = contributions; + } + + public List getExportContributions() { + return contributions; + } + + public void addModel(Object resolved) { + modelResolver.addModel(resolved); + } + + public Object removeModel(Object resolved) { + return modelResolver.removeModel(resolved); + } + + public T resolveModel(Class modelClass, T unresolved) { + return modelResolver.resolveModel(modelClass, unresolved); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java new file mode 100644 index 0000000000..d18977714c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.java.impl; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Artifact Processor for Java Imports + * + * @version $Rev$ $Date$ + */ +public class JavaImportProcessor implements StAXArtifactProcessor { + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + + private static final QName IMPORT_JAVA = new QName(SCA10_NS, "import.java"); + + private static final String PACKAGE = "package"; + private static final String LOCATION = "location"; + + private final JavaImportExportFactory factory; + private final Monitor monitor; + + public JavaImportProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + super(); + this.factory = modelFactories.getFactory(JavaImportExportFactory.class); + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return IMPORT_JAVA; + } + + public Class getModelType() { + return JavaImport.class; + } + + /** + * Process + */ + public JavaImport read(XMLStreamReader reader) throws ContributionReadException { + JavaImport javaImport = this.factory.createJavaImport(); + QName element = null; + + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read + if (IMPORT_JAVA.equals(element)) { + String packageName = reader.getAttributeValue(null, PACKAGE); + if (packageName == null) { + error("AttributePackageMissing", reader); + //throw new ContributionReadException("Attribute 'package' is missing"); + } else + javaImport.setPackage(packageName); + + String location = reader.getAttributeValue(null, LOCATION); + javaImport.setLocation(location); + } + break; + case XMLStreamConstants.END_ELEMENT: + if (IMPORT_JAVA.equals(reader.getName())) { + return javaImport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return javaImport; + } + + public void write(JavaImport javaImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + writer.writeStartElement(IMPORT_JAVA.getNamespaceURI(), IMPORT_JAVA.getLocalPart()); + + if (javaImport.getPackage() != null) { + writer.writeAttribute(PACKAGE, javaImport.getPackage()); + } + if (javaImport.getLocation() != null) { + writer.writeAttribute(LOCATION, javaImport.getLocation()); + } + + writer.writeEndElement(); + } + + + public void resolve(JavaImport model, ModelResolver resolver) throws ContributionResolveException { + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider new file mode 100644 index 0000000000..caf247750d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +org.apache.tuscany.sca.contribution.java.DefaultContributionClassLoaderProvider;type=application/x-compressed +org.apache.tuscany.sca.contribution.java.DefaultContributionClassLoaderProvider;type=application/vnd.tuscany.folder +org.apache.tuscany.sca.contribution.java.DefaultContributionClassLoaderProvider;type=application/osgi.bundle + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassloaderProviderExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassloaderProviderExtensionPoint new file mode 100644 index 0000000000..e6cf964e81 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassloaderProviderExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.java.DefaultContributionClassloaderProviderExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory new file mode 100644 index 0000000000..a293330a57 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.java.impl.JavaImportExportFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..ac1fa9aade --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.java.impl.JavaImportProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#import.java,model=org.apache.tuscany.sca.contribution.java.JavaImport +org.apache.tuscany.sca.contribution.java.impl.JavaExportProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#export.java,model=org.apache.tuscany.sca.contribution.java.JavaExport diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..c69eb40636 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.java.impl.ClassReferenceModelResolver;model=org.apache.tuscany.sca.contribution.resolver.ClassReference diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener new file mode 100644 index 0000000000..7debb3d3c6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.java.impl.JavaImportExportListener diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties new file mode 100644 index 0000000000..09fc3e9fff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties @@ -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. +# +# +AttributePackageMissing = Attribute 'package' is missing +XMLStreamException = XMLStreamException occured due to : {0} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java new file mode 100644 index 0000000000..52c8567f3f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.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.sca.contribution.java.impl; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * Test ClassReferenceArtifactResolver. + * + * @version $Rev: 560435 $ $Date: 2007-07-27 18:26:55 -0700 (Fri, 27 Jul 2007) $ + */ +public class ClassReferenceArtifactResolverTestCase extends TestCase { + private ExtensibleModelResolver resolver; + + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + + ModelResolverExtensionPoint resolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); + resolvers.addResolver(ClassReference.class, ClassReferenceModelResolver.class); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + resolver = new ExtensibleModelResolver(null, extensionPoints); + } + + /** + * Test ClassReference resolution + * + */ + public void testResolveClass() { + ClassReference ref = new ClassReference(getClass().getName()); + ClassReference clazz = resolver.resolveModel(ClassReference.class, ref); + assertFalse(clazz.isUnresolved()); + assertTrue(clazz.getJavaClass() == getClass()); + } + + /** + * Test ClassReference resolution of inexistent class + * + */ + public void testUnresolvedClass() { + ClassReference ref = new ClassReference("NonExistentClass"); + ClassReference clazz = resolver.resolveModel(ClassReference.class, ref); + assertTrue(clazz.isUnresolved()); + assertTrue(clazz.getJavaClass() == null); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoaderTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoaderTestCase.java new file mode 100644 index 0000000000..3ae161642d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoaderTestCase.java @@ -0,0 +1,262 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.java.impl; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +/** + * Test ContributionClassLoader. + * + */ +public class ContributionClassLoaderTestCase { + + private ContributionFactory contributionFactory; + private JavaImportExportFactory javaImportExportFactory; + + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + contributionFactory = modelFactories.getFactory(ContributionFactory.class); + javaImportExportFactory = modelFactories.getFactory(JavaImportExportFactory.class); + } + + private Contribution createContribution(String fileName) throws MalformedURLException { + Contribution contrib = contributionFactory.createContribution(); + File contribDir = new File(fileName); + contrib.setLocation(contribDir.toURI().toURL().toString()); + ClassLoader contextClassLoader = AccessController.doPrivileged(new PrivilegedAction() { + public ClassLoader run() { + return Thread.currentThread().getContextClassLoader(); + } + }); + contrib.setClassLoader(new ContributionClassLoader(contrib, contextClassLoader)); + return contrib; + } + + + @Test + public void testClassLoadingFromContribution() throws ClassNotFoundException, MalformedURLException { + + Contribution contribA = createContribution("target/test-classes"); + Contribution contribB = createContribution("target"); + Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar"); + + // Class present in contribution, also in parent. Class is loaded from parent + Class testClassA = contribA.getClassLoader().loadClass(this.getClass().getName()); + Assert.assertNotNull(testClassA); + Assert.assertSame(this.getClass(), testClassA); + + // Class not present in contribution, but present in parent ClassLoader + Class testClassB = contribB.getClassLoader().loadClass(this.getClass().getName()); + Assert.assertNotNull(testClassB); + Assert.assertSame(this.getClass(), testClassB); + + // Class present in contribution, but not in parent + Class testClassC = contribC.getClassLoader().loadClass("calculator.AddService"); + Assert.assertNotNull(testClassC); + + // Class not present in contribution or in parent + try { + contribA.getClassLoader().loadClass("NonExistent"); + + Assert.assertTrue("ClassNotFoundException not thrown as expected", false); + + } catch (ClassNotFoundException e) { + } + + + + } + + @Test + public void testResourceLoadingFromContribution() throws ClassNotFoundException, MalformedURLException { + + Contribution contribA = createContribution("target/test-classes"); + Contribution contribB = createContribution("target"); + Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar"); + + // Resource present in contribution, and in parent + URL resA = contribA.getClassLoader().getResource("deployables/sample-calculator.jar"); + Assert.assertNotNull(resA); + + // Resource not present in contribution, but present in parent ClassLoader + URL resB = contribB.getClassLoader().getResource("deployables/sample-calculator.jar"); + Assert.assertNotNull(resB); + + // Resource present in contribution, but not in parent + URL resC = contribC.getClassLoader().getResource("calculator/AddService.class"); + Assert.assertNotNull(resC); + + // Load Java class as resource from parent + String classResName = this.getClass().getName().replaceAll("\\.", "/") + ".class"; + URL classResA = contribA.getClassLoader().getResource(classResName); + Assert.assertNotNull(classResA); + + // Non-existent resource + URL res = contribA.getClassLoader().getResource("deployables/NonExistent"); + Assert.assertNull(res); + + } + + private static String getPackageName(Class cls) { + String name = cls.getName(); + int index = name.lastIndexOf('.'); + return index == -1 ? "" : name.substring(0, index); + } + + @Test + public void testClassLoadingFromImportedContribution() throws ClassNotFoundException, MalformedURLException { + + Contribution contribA = createContribution("target/test-classes"); + Contribution contribB = createContribution("target"); + Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar"); + ArrayList exportContribList = new ArrayList(); + exportContribList.add(contribA); + exportContribList.add(contribC); + + JavaImport import_ = javaImportExportFactory.createJavaImport(); + import_.setPackage(getPackageName(getClass())); + import_.setModelResolver(new JavaImportModelResolver(exportContribList, null)); + contribB.getImports().add(import_); + import_ = javaImportExportFactory.createJavaImport(); + import_.setPackage("calculator"); + import_.setModelResolver(new JavaImportModelResolver(exportContribList, null)); + contribB.getImports().add(import_); + + JavaExport export = javaImportExportFactory.createJavaExport(); + export.setPackage(getPackageName(getClass())); + contribA.getExports().add(export); + export = javaImportExportFactory.createJavaExport(); + export.setPackage("calculator"); + contribC.getExports().add(export); + + // Load class from parent, class is also present in imported contribution. Class should + // be loaded from parent + Class testClassB = contribB.getClassLoader().loadClass(this.getClass().getName()); + Assert.assertNotNull(testClassB); + Assert.assertSame(this.getClass(), testClassB); + + // Load class from parent, class is also present in parent. Class should be loaded + // from parent. + Class testClassA = contribA.getClassLoader().loadClass(this.getClass().getName()); + Assert.assertNotNull(testClassA); + Assert.assertSame(this.getClass(), testClassA); + + // Imported class should be the same as the one loaded by the exporting contribution + Assert.assertSame(testClassA, testClassB); + + // Load class from imported contribution, class is not present in parent + Class testClassB1 = contribB.getClassLoader().loadClass("calculator.AddService"); + Assert.assertNotNull(testClassB1); + + // Imported class should be the same as the one loaded by the exporting contribution + Class testClassC = contribC.getClassLoader().loadClass("calculator.AddService"); + Assert.assertNotNull(testClassC); + Assert.assertSame(testClassC, testClassB1); + + + // Try to load class from package which is not explicitly imported - should throw ClassNotFoundException + try { + contribA.getClassLoader().loadClass("calculator.AddService"); + + Assert.assertTrue("ClassNotFoundException not thrown as expected", false); + + } catch (ClassNotFoundException e) { + } + + // Try to load non-existent class from imported package - should throw ClassNotFoundException + try { + contribB.getClassLoader().loadClass(getPackageName(getClass()) + ".NonExistentClass"); + + Assert.assertTrue("ClassNotFoundException not thrown as expected", false); + + } catch (ClassNotFoundException e) { + } + + } + + @Test + public void testResourceLoadingFromImportedContribution() throws ClassNotFoundException, MalformedURLException { + + Contribution contribA = createContribution("target/test-classes"); + Contribution contribB = createContribution("target"); + Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar"); + + ArrayList exportContribList = new ArrayList(); + exportContribList.add(contribA); + exportContribList.add(contribC); + + JavaImport import_ = javaImportExportFactory.createJavaImport(); + import_.setPackage(getPackageName(getClass())); + import_.setModelResolver(new JavaImportModelResolver(exportContribList, null)); + contribB.getImports().add(import_); + JavaImport import1_ = javaImportExportFactory.createJavaImport(); + import1_.setPackage("calculator"); + import1_.setModelResolver(new JavaImportModelResolver(exportContribList, null)); + contribB.getImports().add(import1_); + + JavaExport export = javaImportExportFactory.createJavaExport(); + export.setPackage(getPackageName(getClass())); + contribA.getExports().add(export); + JavaExport export1 = javaImportExportFactory.createJavaExport(); + export1.setPackage("calculator"); + contribC.getExports().add(export1); + + + // Load resource from parent + URL resB = contribB.getClassLoader().getResource("deployables/sample-calculator.jar"); + Assert.assertNotNull(resB); + + // Load Java class as resource from imported contribution with JavaImport + String classResName = this.getClass().getName().replaceAll("\\.", "/") + ".class"; + URL classResB = contribB.getClassLoader().getResource(classResName); + Assert.assertNotNull(classResB); + + // Load Java class as resource from imported contribution with JavaImport + URL classResB1 = contribB.getClassLoader().getResource("calculator/AddService.class"); + Assert.assertNotNull(classResB1); + + // Try to load resource not explicitly imported by contribution + URL classResA1 = contribA.getClassLoader().getResource("calculator/AddService.class"); + Assert.assertNull(classResA1); + + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java new file mode 100644 index 0000000000..0ec5bfba39 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.java.impl; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; + +/** + * Test JavaExportProcessorTestCase + * + * @version $Rev$ $Date$ + */ +public class JavaExportProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + ""; + + private static final String INVALID_XML = + "" + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + } + + /** + * Test loading a valid export element from a contribution metadata stream + * @throws Exception + */ + public void testLoad() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); + JavaExport javaExport = (JavaExport)staxProcessor.read(reader); + assertEquals("org.apache.tuscany.sca.contribution.java", javaExport.getPackage()); + } + + /** + * Test loading an INVALID export element from a contribution metadata stream + * @throws Exception + */ + public void testLoadInvalid() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + /*try { + staxProcessor.read(reader); + fail("readerException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + }*/ + staxProcessor.read(reader); + Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + assertNotNull(problem); + assertEquals("AttributePackageMissing", problem.getMessageId()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java new file mode 100644 index 0000000000..9e43b744cf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.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.sca.contribution.java.impl; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; + +/** + * Test JavaImportProcessorTestCase + * + * @version $Rev$ $Date$ + */ +public class JavaImportProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + ""; + + private static final String INVALID_XML = + "" + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + } + + /** + * Test loading a valid import element from a contribution metadata stream + * @throws Exception + */ + public void testLoad() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); + JavaImport javaImport = (JavaImport)staxProcessor.read(reader); + + assertEquals("org.apache.tuscany.sca.contribution.java", javaImport.getPackage()); + assertEquals("sca://contributions/001", javaImport.getLocation()); + } + + /** + * Test loading a INVALID import element from a contribution metadata stream + * @throws Exception + */ + public void testLoadInvalid() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + /*try { + staxProcessor.read(reader); + fail("readerException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + }*/ + staxProcessor.read(reader); + Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + assertNotNull(problem); + assertEquals("AttributePackageMissing", problem.getMessageId()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/resources/deployables/sample-calculator.jar b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/resources/deployables/sample-calculator.jar new file mode 100644 index 0000000000..0ca3a1b781 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-java/src/test/resources/deployables/sample-calculator.jar differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/pom.xml new file mode 100644 index 0000000000..3442beb923 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/pom.xml @@ -0,0 +1,127 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-contribution-jee-impl + Apache Tuscany SCA Java EE Impl + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-contribution-jee + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 1.6-SNAPSHOT + + + + + + org.apache.openejb + openejb-core + 3.0.1 + + + + org.apache.openejb + openejb-jee + 3.0.1 + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.contribution.jee + ${pom.name} + org.apache.tuscany.sca.contribution.jee* + org.apache.tuscany.sca.contribution.osgi.impl + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/JEEDefinitionsProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/JEEDefinitionsProvider.java new file mode 100644 index 0000000000..262875c49a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/JEEDefinitionsProvider.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.sca.contribution.jee; + +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.definitions.util.SCADefinitionsUtil; +import org.apache.tuscany.sca.provider.SCADefinitionsProvider; +import org.apache.tuscany.sca.provider.SCADefinitionsProviderException; + +/** + * Provider for Policy Intents and PolicySet definitions related to security + * + * @version $Rev$ $Date$ + */ +public class JEEDefinitionsProvider implements SCADefinitionsProvider { + private static final String definitionsFile = "org/apache/tuscany/sca/contribution/jee/definitions.xml"; + + URLArtifactProcessor urlArtifactProcessor = null; + + public JEEDefinitionsProvider(ExtensionPointRegistry registry) { + URLArtifactProcessorExtensionPoint documentProcessors = + registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + urlArtifactProcessor = (URLArtifactProcessor)documentProcessors.getProcessor(SCADefinitions.class); + } + + public SCADefinitions getSCADefinition() throws SCADefinitionsProviderException { + SCADefinitions scaDefns = null; + try { + // Allow privileged access to load resource. Requires + // RuntimePermssion in security policy. + URL definitionsFileUrl = AccessController.doPrivileged(new PrivilegedAction() { + public URL run() { + return getClass().getClassLoader().getResource(definitionsFile); + } + }); + + URI uri = new URI(definitionsFile); + + scaDefns = (SCADefinitions)urlArtifactProcessor.read(null, uri, definitionsFileUrl); + + return scaDefns; + + } catch (Exception e) { + throw new SCADefinitionsProviderException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEModuleHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEModuleHelper.java new file mode 100644 index 0000000000..a903f6dbc0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEModuleHelper.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.jee; + +import java.io.File; + +import org.apache.openejb.OpenEJBException; +import org.apache.openejb.config.AnnotationDeployer; +import org.apache.openejb.config.AppModule; +import org.apache.openejb.config.DeploymentLoader; +import org.apache.openejb.config.EjbModule; +import org.apache.openejb.config.ReadDescriptors; +import org.apache.openejb.config.WebModule; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * @version $Rev$ $Date$ + */ +public class JavaEEModuleHelper { + + public AppModule getMetadataCompleteModules(String jarFilePath) throws ContributionReadException { + DeploymentLoader loader = new DeploymentLoader(); + AppModule appModule = null; + try { + appModule = loader.load(new File(jarFilePath)); + } catch (OpenEJBException e) { + throw new ContributionReadException(e); + } + + // Set the Thread context class loader as the module's class loader and all the Web and EJB modules + // inside. Otherwise, SCA annotations could not be processed + // TODO: Eliminate the use of reflection for setting the class loader + java.lang.reflect.Field field = null; + try { + field = appModule.getClass().getDeclaredField("classLoader"); + } catch (SecurityException e) { + throw new ContributionReadException(e); + } catch (NoSuchFieldException e) { + throw new ContributionReadException(e); + } + field.setAccessible(true); + try{ + field.set(appModule, Thread.currentThread().getContextClassLoader()); + } catch (IllegalArgumentException e) { + throw new ContributionReadException(e); + } catch (IllegalAccessException e) { + throw new ContributionReadException(e); + } + + for(EjbModule ejbModule:appModule.getEjbModules()) { + java.lang.reflect.Field field1 = null; + try { + field1 = ejbModule.getClass().getDeclaredField("classLoader"); + } catch (SecurityException e) { + throw new ContributionReadException(e); + } catch (NoSuchFieldException e) { + throw new ContributionReadException(e); + } + field1.setAccessible(true); + try { + field1.set(ejbModule, Thread.currentThread().getContextClassLoader()); + } catch (IllegalArgumentException e) { + throw new ContributionReadException(e); + } catch (IllegalAccessException e) { + throw new ContributionReadException(e); + } + } + + for(WebModule webModule:appModule.getWebModules()) { + java.lang.reflect.Field field1 = null; + try { + field1 = webModule.getClass().getDeclaredField("classLoader"); + } catch (SecurityException e) { + throw new ContributionReadException(e); + } catch (NoSuchFieldException e) { + throw new ContributionReadException(e); + } + field1.setAccessible(true); + try { + field1.set(webModule, Thread.currentThread().getContextClassLoader()); + } catch (IllegalArgumentException e) { + throw new ContributionReadException(e); + } catch (IllegalAccessException e) { + throw new ContributionReadException(e); + } + } + + // Process deployment descriptor files + ReadDescriptors readDescriptors = new ReadDescriptors(); + try { + readDescriptors.deploy(appModule); + } catch (OpenEJBException e) { + throw new ContributionReadException(e); + } + + // Process annotations + AnnotationDeployer annDeployer = new AnnotationDeployer(); + try { + annDeployer.deploy(appModule); + } catch (OpenEJBException e) { + throw new ContributionReadException(e); + } + + return appModule; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EARContributionClassLoader.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EARContributionClassLoader.java new file mode 100644 index 0000000000..87cdaa2cf3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EARContributionClassLoader.java @@ -0,0 +1,201 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.jee.impl; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; +import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo; +import org.apache.tuscany.sca.contribution.jee.WebModuleInfo; + + +public class EARContributionClassLoader extends URLClassLoader { + + private Contribution contribution; + private List ejbModules = new ArrayList(); + + /** + * Constructor for contribution ClassLoader + * + * @param contribution + * @param parent + * @throws MalformedURLException + */ + public EARContributionClassLoader(Contribution contribution, final ClassLoader parent) { + super(new URL[0], parent); + + this.contribution = contribution; + + // get the classloaders for any EAR archive that is a contribution + for (Artifact artifact : contribution.getArtifacts()){ + if (artifact.getModel() instanceof JavaEEApplicationInfo){ + JavaEEApplicationInfo jeeAppInfo = (JavaEEApplicationInfo)artifact.getModel(); + // TODO - won't these all have the same classloader? + ejbModules.addAll(jeeAppInfo.getEjbModuleInfos().values()); + } + } + + } + + /* (non-Javadoc) + * @see java.net.URLClassLoader#findClass(java.lang.String) + * + * Search path for class: + * This contribution + * Imported contributions + */ + @Override + protected Class findClass(String className) throws ClassNotFoundException { + + Class clazz = null; + ClassNotFoundException cne = null; + + // TODO - Won't these classloaders all be the same? + for (EjbModuleInfo ejbModuleInfo : ejbModules){ + try { + clazz = ejbModuleInfo.getModuleClassloader().loadClass(className); + } catch (ClassNotFoundException e) { + cne = e; + } + + if (clazz != null){ + break; + } + } + + if (clazz == null){ + throw cne; + } + + return clazz; + } + + + /* (non-Javadoc) + * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean) + * + * Search path for class: + * Parent ClassLoader + * This contribution + * Imported contributions + * + */ + @Override + protected synchronized Class loadClass(String className, boolean resolveClass) + throws ClassNotFoundException { + + Class clazz = null; + try { + + if (this.getParent() != null) + clazz = this.getParent().loadClass(className); + + } catch (ClassNotFoundException e) { + } + + if (clazz == null) + clazz = findClass(className); + + + if (resolveClass) + this.resolveClass(clazz); + return clazz; + + } + + + + /* (non-Javadoc) + * @see java.lang.ClassLoader#getResource(java.lang.String) + * + * Find a resource. + * Search path for resource: + * Parent ClassLoader + * This contribution + */ + @Override + public URL getResource(String resName) { + + URL resource = null; + + if (this.getParent() != null) { + resource = this.getParent().getResource(resName); + } + if (resource == null) { +// TODO Which classloader? +// resource = webModuleInfo.getModuleClassloader().getResource(resName); + } + + return resource; + } + + + /* (non-Javadoc) + * @see java.lang.ClassLoader#getResources(java.lang.String) + * + * Return list of resources from this contribution, resources + * imported through imported contributions and resources from parent + * ClassLoader. + */ + @Override + public Enumeration getResources(String resName) throws IOException { + + HashSet resourceSet = new HashSet(); + +// TODO - which classloader +// addEnumerationToCollection(resourceSet, webModuleInfo.getModuleClassloader().getResources(resName)); + addEnumerationToCollection(resourceSet, super.getResources(resName)); + + return Collections.enumeration(resourceSet); + } + + /* + * Add an enumeration to a Collection + */ + private void addEnumerationToCollection(Collection collection, Enumeration enumeration) { + + while (enumeration.hasMoreElements()) + collection.add(enumeration.nextElement()); + } + + + @Override + public String toString() { + return "SCA JEE ClassLoader, parent ClassLoader: " + getParent(); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EARContributionClassLoaderProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EARContributionClassLoaderProvider.java new file mode 100644 index 0000000000..5ea7dc55f7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EARContributionClassLoaderProvider.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.sca.contribution.jee.impl; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.PackageType; +import org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider; +import org.apache.tuscany.sca.contribution.java.impl.ContributionClassLoader; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * The default implementation of the ContributionClassLoaderProvider + */ +public class EARContributionClassLoaderProvider implements ContributionClassLoaderProvider { + + public EARContributionClassLoaderProvider() { + super(); + } + + public String getContributionType() { + return PackageType.EAR; + } + + public ClassLoader getClassLoader(Contribution contribution, ClassLoader parent) { + // TODO - This is not quite right at the CCL will load up the nested jars + // also. However we do need to pick up the import processing so + // need a bit of a refactor + ContributionClassLoader ccl = new ContributionClassLoader(contribution, parent); + return new EARContributionClassLoader(contribution, ccl); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEIntrospectorImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEIntrospectorImpl.java new file mode 100644 index 0000000000..c0830cbb2c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEIntrospectorImpl.java @@ -0,0 +1,427 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.jee.impl; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.util.Map; + +import org.apache.openejb.config.AppModule; +import org.apache.openejb.config.EjbModule; +import org.apache.openejb.config.UnknownModuleTypeException; +import org.apache.openejb.config.UnsupportedModuleTypeException; +import org.apache.openejb.config.WebModule; +import org.apache.openejb.jee.EjbJar; +import org.apache.openejb.jee.EjbRef; +import org.apache.openejb.jee.EjbRefType; +import org.apache.openejb.jee.EjbReference; +import org.apache.openejb.jee.EnterpriseBean; +import org.apache.openejb.jee.EnvEntry; +import org.apache.openejb.jee.Filter; +import org.apache.openejb.jee.InjectionTarget; +import org.apache.openejb.jee.Listener; +import org.apache.openejb.jee.MessageDrivenBean; +import org.apache.openejb.jee.Servlet; +import org.apache.openejb.jee.SessionBean; +import org.apache.openejb.jee.SessionType; +import org.apache.openejb.jee.WebApp; +import org.apache.tuscany.sca.contribution.jee.EjbInfo; +import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; +import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo; +import org.apache.tuscany.sca.contribution.jee.JavaEEIntrospector; +import org.apache.tuscany.sca.contribution.jee.JavaEEModuleHelper; +import org.apache.tuscany.sca.contribution.jee.WebModuleInfo; +import org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo.EjbType; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.util.IOHelper; + +/** + * @version $Rev$ $Date$ + */ +public class JavaEEIntrospectorImpl implements JavaEEIntrospector { + + public WebModuleInfo introspectWebArchive(URL artifactURL) throws ContributionReadException { + // Create a temporary file since openejb extracts the archive to process + InputStream inp = null; + File tempFile = null; + try { + URLConnection connection = artifactURL.openConnection(); + connection.setUseCaches(false); + inp = connection.getInputStream(); + tempFile = File.createTempFile("temp", ".war"); + FileOutputStream fout = new FileOutputStream(tempFile); + IOHelper.copy(inp, fout); + fout.close(); + inp.close(); + } catch (IOException e) { + throw new ContributionReadException(e); + } + + JavaEEModuleHelper jmh = new JavaEEModuleHelper(); + WebModule wm = jmh.getMetadataCompleteModules(tempFile.getAbsolutePath()).getWebModules().get(0); + if(!tempFile.delete()) { + tempFile.deleteOnExit(); + } + return createWebModuleInfo(wm); + } + + private WebModuleInfo createWebModuleInfo(WebModule webModule) { + WebModuleInfo wmInfo = new WebModuleInfoImpl(); + + WebApp webApp = webModule.getWebApp(); + ClassLoader classLoader = webModule.getClassLoader(); + wmInfo.setmoduleClassloader(classLoader); + + // Process Remote EJB References + for (Map.Entry entry : webApp.getEjbRefMap().entrySet()) { + EjbRef ejbRef = entry.getValue(); + if(ejbRef.getHome() != null) { + // References to only EJB3 beans need to be considered. + // Skip the current on as it is not a reference to an EJB3 bean. + continue; + } + if (ejbRef.getRefType().compareTo(EjbReference.Type.REMOTE) != 0) { + // Only Remote EJB references need to be considered. + // Skip the current one as it is not a remote reference. + continue; + } + //FIXME: ejbRef.getEjbRefType() is null sometimes. Need a different way to figure the type. + if(ejbRef.getEjbRefType() != null && ejbRef.getEjbRefType().compareTo(EjbRefType.SESSION) != 0) { + // Only references to Session beans need to be considered. + // Skip the current one as it is not a Session bean. + continue; + } + + try { + wmInfo.getEjbReferences().put(ejbRef.getEjbRefName(), createEjbReferenceInfo(ejbRef, classLoader)); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // Process env-entries to compute properties + for (Map.Entry entry : webApp.getEnvEntryMap().entrySet()) { + EnvEntry envEntry = entry.getValue(); + wmInfo.getEnvEntries().put(envEntry.getEnvEntryName(), createEnvEntryInfo(envEntry)); + } + + // Process Servlets + for(Servlet servlet: webApp.getServlet()) { + try { + wmInfo.getServletClasses().add(classLoader.loadClass(servlet.getServletClass())); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // Process Filters + for(Filter filter: webApp.getFilter()) { + try { + wmInfo.getFilterClasses().add(classLoader.loadClass(filter.getFilterClass())); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // Process Listeners + for(Listener listener: webApp.getListener()) { + try { + wmInfo.getListenerClasses().add(classLoader.loadClass(listener.getListenerClass())); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // TODO: Process JSF Managed beans + + // TODO: Process JSP pages + + return wmInfo; + } + + private org.apache.tuscany.sca.contribution.jee.EnvEntryInfo createEnvEntryInfo(EnvEntry envEntry) { + org.apache.tuscany.sca.contribution.jee.EnvEntryInfo envEntryInfo = new org.apache.tuscany.sca.contribution.jee.EnvEntryInfo(); + envEntryInfo.name = envEntry.getEnvEntryName(); + envEntryInfo.type = envEntry.getEnvEntryType(); + envEntryInfo.value = envEntry.getEnvEntryValue(); + + return envEntryInfo; + } + + private org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo createEjbReferenceInfo(EjbRef ejbRef, ClassLoader classLoader) throws ClassNotFoundException { + org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo ejbReferenceInfo = new org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo(); + + ejbReferenceInfo.referenceName = ejbRef.getEjbRefName(); + ejbReferenceInfo.referenceType = ejbRef.getRefType().compareTo(EjbReference.Type.REMOTE) == 0 ? org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo.RefType.REMOTE : ejbRef.getRefType().compareTo(EjbReference.Type.LOCAL) == 0 ? org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo.RefType.LOCAL : org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo.RefType.UNKNOWN; + ejbReferenceInfo.businessInterface = classLoader.loadClass(ejbRef.getInterface()); + + ejbReferenceInfo.ejbType = EjbType.UNKNOWN; + if(ejbRef.getEjbRefType() != null) { + if(ejbRef.getEjbRefType().compareTo(EjbRefType.SESSION) == 0) { + ejbReferenceInfo.ejbType = EjbType.SESSION_UNKNOWN; + } + } + + ejbReferenceInfo.ejbLink = ejbRef.getEjbLink(); + ejbReferenceInfo.mappedName = ejbRef.getMappedName(); + if(ejbRef.getInjectionTarget().size() > 0) { + InjectionTarget it = ejbRef.getInjectionTarget().iterator().next(); + ejbReferenceInfo.injectionTarget.targetClass = it.getInjectionTargetClass(); + ejbReferenceInfo.injectionTarget.targetName = it.getInjectionTargetName(); + } + + return ejbReferenceInfo; + } + + public EjbModuleInfo introspectEjbArchive(URL artifactURL) throws ContributionReadException { + // Create a temporary file since openejb extracts the archive to process + InputStream inp = null; + File tempFile = null; + try { + URLConnection connection = artifactURL.openConnection(); + connection.setUseCaches(false); + inp = connection.getInputStream(); + tempFile = File.createTempFile("temp", ".jar"); + FileOutputStream fout = new FileOutputStream(tempFile); + IOHelper.copy(inp, fout); + fout.close(); + inp.close(); + } catch (IOException e) { + throw new ContributionReadException(e); + } + + JavaEEModuleHelper jmh = new JavaEEModuleHelper(); + EjbModule em; + try { + em = jmh.getMetadataCompleteModules(tempFile.getAbsolutePath()).getEjbModules().get(0); + } catch(ContributionReadException e) { + if((e.getCause() instanceof UnknownModuleTypeException) || + (e.getCause() instanceof UnsupportedModuleTypeException)) { + // Not an EJB jar + return null; + } else { + throw e; + } + } finally { + if(!tempFile.delete()) { + tempFile.deleteOnExit(); + } + } + return createEjbModuleInfo(em); + } + + private EjbModuleInfo createEjbModuleInfo(EjbModule ejbModule) { + EjbModuleInfo ejbModuleInfo = new EjbModuleInfoImpl(); + + EjbJar ejbJar = ejbModule.getEjbJar(); + if (!ejbJar.getVersion().startsWith("3")) { + // Not an EJB3 module + // TODO: should throw an exception + return null; + } + + ClassLoader classLoader = ejbModule.getClassLoader(); + ejbModuleInfo.setmoduleClassloader(classLoader); + Map beansMap = ejbJar.getEnterpriseBeansByEjbName(); + for (Map.Entry entry : beansMap.entrySet()) { + EnterpriseBean bean = entry.getValue(); + EjbInfo ejbInfo = null; + if (bean instanceof SessionBean) { + SessionBean sbean = (SessionBean)bean; + ejbInfo = createEjbInfo(sbean, classLoader); + } else if (bean instanceof MessageDrivenBean) { + MessageDrivenBean mdbean = (MessageDrivenBean)bean; + ejbInfo = createEjbInfo(mdbean, classLoader); + } else { + continue; + } + if (ejbInfo != null) { + // Bean is an EJB3 bean + ejbModuleInfo.getEjbInfos().put(bean.getEjbName(), ejbInfo); + } + } + + return ejbModuleInfo; + } + + private EjbInfo createEjbInfo(MessageDrivenBean bean, ClassLoader classLoader) { + try { + if(javax.ejb.MessageDrivenBean.class.isAssignableFrom(classLoader.loadClass(bean.getEjbClass()))) { + // Not an EJB3 bean + return null; + } + } catch (ClassNotFoundException ignored) { + // Should not happen + } + EjbInfo ejbInfo = new EjbInfo(); + + ejbInfo.beanName = bean.getEjbName(); + + try { + ejbInfo.beanClass = classLoader.loadClass(bean.getEjbClass()); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ejbInfo.ejbType = org.apache.tuscany.sca.contribution.jee.EjbInfo.EjbType.MESSAGE_DRIVEN; + + ejbInfo.mappedName = bean.getMappedName(); + + processReferencesEnvEntries(bean, classLoader, ejbInfo); + + return ejbInfo; + } + + private EjbInfo createEjbInfo(SessionBean bean, ClassLoader classLoader) { + if(bean.getBusinessRemote().size() == 0 && bean.getBusinessLocal().size() == 0) { + // Not an EJB3 Session bean + return null; + } + EjbInfo ejbInfo = new EjbInfo(); + + ejbInfo.beanName = bean.getEjbName(); + + try { + ejbInfo.beanClass = classLoader.loadClass(bean.getEjbClass()); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ejbInfo.ejbType = bean.getSessionType().equals(SessionType.STATEFUL) ? org.apache.tuscany.sca.contribution.jee.EjbInfo.EjbType.SESSION_STATEFUL : bean.getSessionType().equals(SessionType.STATELESS) ? org.apache.tuscany.sca.contribution.jee.EjbInfo.EjbType.SESSION_STATELESS : org.apache.tuscany.sca.contribution.jee.EjbInfo.EjbType.SESSION_UNKNOWN; + + ejbInfo.mappedName = bean.getMappedName(); + //FIXME: Is it ok to use beanName when mapped name is null? + if(ejbInfo.mappedName == null) { + ejbInfo.mappedName = ejbInfo.beanName; + } + + // Process Remote Business interfaces of the SessionBean + for (String intfName : bean.getBusinessRemote()) { + try { + ejbInfo.businessRemote.add(classLoader.loadClass(intfName)); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // Process Local Business interfaces of the SessionBean + for (String intfName : bean.getBusinessLocal()) { + try { + ejbInfo.businessLocal.add(classLoader.loadClass(intfName)); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + processReferencesEnvEntries(bean, classLoader, ejbInfo); + + return ejbInfo; + } + + private void processReferencesEnvEntries(EnterpriseBean bean, ClassLoader classLoader, EjbInfo ejbInfo) { + // Process Remote EJB References + for (Map.Entry entry : bean.getEjbRefMap().entrySet()) { + EjbRef ejbRef = entry.getValue(); + if(ejbRef.getHome() != null) { + // References to only EJB3 beans need to be considered. + // Skip the current on as it is not a reference to an EJB3 bean. + continue; + } + if (ejbRef.getRefType().compareTo(EjbReference.Type.REMOTE) != 0) { + // Only Remote EJB references need to be considered. + // Skip the current one as it is not a remote reference. + continue; + } + //FIXME: ejbRef.getEjbRefType() is null sometimes. Need a different way to figure the type. + if(ejbRef.getEjbRefType() != null && ejbRef.getEjbRefType().compareTo(EjbRefType.SESSION) != 0) { + // Only references to Session beans need to be considered. + // Skip the current one as it is not a Session bean. + continue; + } + + try { + ejbInfo.ejbReferences.put(ejbRef.getEjbRefName(), createEjbReferenceInfo(ejbRef, classLoader)); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // Process env-entries + for (Map.Entry entry : bean.getEnvEntryMap().entrySet()) { + EnvEntry envEntry = entry.getValue(); + + ejbInfo.envEntries.put(envEntry.getEnvEntryName(), createEnvEntryInfo(envEntry)); + } + } + + public JavaEEApplicationInfo introspectJeeArchive(URL artifactURL) throws ContributionReadException { + // Create a temporary file since openejb extracts the archive to process + InputStream inp = null; + File tempFile = null; + try { + URLConnection connection = artifactURL.openConnection(); + connection.setUseCaches(false); + inp = connection.getInputStream(); + tempFile = File.createTempFile("temp", ".ear"); + FileOutputStream fout = new FileOutputStream(tempFile); + IOHelper.copy(inp, fout); + fout.close(); + inp.close(); + } catch (IOException e) { + throw new ContributionReadException(e); + } + + JavaEEModuleHelper jmh = new JavaEEModuleHelper(); + AppModule appModule = jmh.getMetadataCompleteModules(tempFile.getAbsolutePath()); + if(!tempFile.delete()) { + tempFile.deleteOnExit(); + } + return createJavaEEApplicationInfo(appModule); + } + + private org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo createJavaEEApplicationInfo(AppModule appModule) { + JavaEEApplicationInfo appInfo = new JavaEEApplicationInfoImpl(); + for(EjbModule em : appModule.getEjbModules()){ + EjbModuleInfo ejbModuleInfo = createEjbModuleInfo(em); + ejbModuleInfo.setModuleName(em.getModuleId()); + appInfo.getEjbModuleInfos().put(em.getModuleId(), ejbModuleInfo); + } + + for(WebModule wm : appModule.getWebModules()) { + WebModuleInfo webModuleInfo = createWebModuleInfo(wm); + webModuleInfo.setModuleName(wm.getModuleId()); + appInfo.getWebModuleInfos().put(wm.getModuleId(), webModuleInfo); + } + + return appInfo; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WARContributionClassLoader.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WARContributionClassLoader.java new file mode 100644 index 0000000000..4047371583 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WARContributionClassLoader.java @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.jee.impl; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; +import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo; +import org.apache.tuscany.sca.contribution.jee.WebModuleInfo; + + +public class WARContributionClassLoader extends URLClassLoader { + + private Contribution contribution; + private WebModuleInfo webModuleInfo = null; + + /** + * Constructor for contribution ClassLoader + * + * @param contribution + * @param parent + * @throws MalformedURLException + */ + public WARContributionClassLoader(Contribution contribution, final ClassLoader parent) { + super(new URL[0], parent); + + this.contribution = contribution; + + // get the classloaders for any WAR archive that is a contribution + // TODO extend to case where JEE archive is outside the contribution + for (Artifact artifact : contribution.getArtifacts()){ + if (artifact.getModel() instanceof WebModuleInfo){ + webModuleInfo = (WebModuleInfo)artifact.getModel(); + break; + } + } + + } + + /* (non-Javadoc) + * @see java.net.URLClassLoader#findClass(java.lang.String) + * + * Search path for class: + * This contribution + * Imported contributions + */ + @Override + protected Class findClass(String className) throws ClassNotFoundException { + + Class clazz = null; + ClassNotFoundException cne = null; + + try { + clazz = webModuleInfo.getModuleClassloader().loadClass(className); + } catch (ClassNotFoundException e) { + cne = e; + } + + if (clazz == null){ + throw cne; + } + + return clazz; + } + + + /* (non-Javadoc) + * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean) + * + * Search path for class: + * Parent ClassLoader + * This contribution + * Imported contributions + * + */ + @Override + protected synchronized Class loadClass(String className, boolean resolveClass) + throws ClassNotFoundException { + + Class clazz = null; + try { + + if (this.getParent() != null) + clazz = this.getParent().loadClass(className); + + } catch (ClassNotFoundException e) { + } + + if (clazz == null) + clazz = findClass(className); + + + if (resolveClass) + this.resolveClass(clazz); + return clazz; + + } + + + /* (non-Javadoc) + * @see java.lang.ClassLoader#getResource(java.lang.String) + * + * Find a resource. + * Search path for resource: + * Parent ClassLoader + * This contribution + */ + @Override + public URL getResource(String resName) { + + URL resource = null; + + if (this.getParent() != null) { + resource = this.getParent().getResource(resName); + } + if (resource == null) + resource = webModuleInfo.getModuleClassloader().getResource(resName); + + return resource; + } + + + /* (non-Javadoc) + * @see java.lang.ClassLoader#getResources(java.lang.String) + * + * Return list of resources from this contribution, resources + * imported through imported contributions and resources from parent + * ClassLoader. + */ + @Override + public Enumeration getResources(String resName) throws IOException { + + HashSet resourceSet = new HashSet(); + + addEnumerationToCollection(resourceSet, webModuleInfo.getModuleClassloader().getResources(resName)); + addEnumerationToCollection(resourceSet, super.getResources(resName)); + + return Collections.enumeration(resourceSet); + } + + + /* + * Add an enumeration to a Collection + */ + private void addEnumerationToCollection(Collection collection, Enumeration enumeration) { + + while (enumeration.hasMoreElements()) + collection.add(enumeration.nextElement()); + } + + + @Override + public String toString() { + return "SCA WAR ClassLoader, parent ClassLoader: " + getParent(); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WARContributionClassLoaderProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WARContributionClassLoaderProvider.java new file mode 100644 index 0000000000..d2af85a7d5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WARContributionClassLoaderProvider.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.sca.contribution.jee.impl; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.PackageType; +import org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider; +import org.apache.tuscany.sca.contribution.java.impl.ContributionClassLoader; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * The default implementation of the ContributionClassLoaderProvider + */ +public class WARContributionClassLoaderProvider implements ContributionClassLoaderProvider { + + public WARContributionClassLoaderProvider() { + super(); + } + + public String getContributionType() { + return PackageType.WAR; + } + + public ClassLoader getClassLoader(Contribution contribution, ClassLoader parent) { + // TODO - This is not quite right at the CCL will load up the nested jars + // also. However we do need to pick up the import processing so + // need a bit of a refactor + ContributionClassLoader ccl = new ContributionClassLoader(contribution, parent); + return new WARContributionClassLoader(contribution, ccl); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider new file mode 100644 index 0000000000..460bf3206c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +org.apache.tuscany.sca.contribution.jee.impl.EARContributionClassLoaderProvider;type=application/ear +org.apache.tuscany.sca.contribution.jee.impl.WARContributionClassLoaderProvider;type=application/war \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEIntrospector b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEIntrospector new file mode 100644 index 0000000000..35c1b709a5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEIntrospector @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.jee.impl.JavaEEIntrospectorImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider new file mode 100644 index 0000000000..cd81aab7a0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for SCA Definitions Providers +org.apache.tuscany.sca.contribution.jee.JEEDefinitionsProvider \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/org/apache/tuscany/sca/contribution/jee/definitions.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/org/apache/tuscany/sca/contribution/jee/definitions.xml new file mode 100644 index 0000000000..bfc7f9097c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee-impl/src/main/resources/org/apache/tuscany/sca/contribution/jee/definitions.xml @@ -0,0 +1,35 @@ + + + + + + + + + This intent is used to indicate that a message passing + through a service or reference observers the same rules + as if it had been received/sent by a vanilla Java EE EJB. + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/pom.xml new file mode 100644 index 0000000000..f43b95a3b6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/pom.xml @@ -0,0 +1,106 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-contribution-jee + Apache Tuscany SCA Java EE + + + + org.apache.geronimo.specs + geronimo-ejb_3.0_spec + 1.0.1 + provided + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 1.6-SNAPSHOT + + + + org.eclipse.emf + common + 2.2.3 + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.contribution.jee + ${pom.name} + org.apache.tuscany.sca.contribution.jee* + org.apache.tuscany.sca.contribution.osgi.impl + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBImplementationGenerated.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBImplementationGenerated.java new file mode 100644 index 0000000000..770fb08279 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBImplementationGenerated.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.sca.contribution.jee; + +import org.apache.tuscany.sca.assembly.Implementation; + + + +/** + * The model representing an EJB implementation in an SCA assembly model when the + * EJB implementation has been generated by introspecting a non-enhanced EAR + */ +public interface EJBImplementationGenerated extends Implementation { + + /** + * Return the EjbInfo which generated this EJB component implementation + * @return + */ + EjbInfo getEJBInfo(); + + /** + * Set the EjbInfo which generated this EJB component implementation + * @param ejbInfo + */ + void setEJBInfo(EjbInfo ejbInfo); + + /** + * return the EjbModuleInfo which contains the EJB Info used to generate this object + * + * @return + */ + EjbModuleInfo getEjbModuleInfo(); + + /** + * Set the EjbModuleInfo which contains the EJB Info used to generate this object + * + * @param ejbModuleInfo + */ + void setEjbModuleInfo(EjbModuleInfo ejbModuleInfo); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbInfo.java new file mode 100644 index 0000000000..c3cb4e7b90 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbInfo.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.sca.contribution.jee; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * @version $Rev$ $Date$ + */ +public class EjbInfo { + public enum EjbType {SESSION_STATELESS, SESSION_STATEFUL, SESSION_UNKNOWN, MESSAGE_DRIVEN}; + public String beanName; + public Class beanClass; + public String mappedName; + public EjbType ejbType; + public Collection> businessRemote = new ArrayList>(); + public Collection> businessLocal = new ArrayList>(); + public Map ejbReferences = new HashMap(); + public Map envEntries = new HashMap(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbModuleInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbModuleInfo.java new file mode 100644 index 0000000000..00f7011111 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbModuleInfo.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.sca.contribution.jee; + +import java.net.URI; +import java.util.Map; + +/** + * @version $Rev$ $Date$ + */ +public interface EjbModuleInfo { + URI getUri(); + void setUri(URI uri); + + String getModuleName(); + void setModuleName(String moduleName); + + ClassLoader getModuleClassloader(); + void setmoduleClassloader(ClassLoader classLoader); + + Map getEjbInfos(); + EjbInfo getEjbInfo(String beanName); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbModuleModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbModuleModelResolver.java new file mode 100644 index 0000000000..72d594c4d0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbModuleModelResolver.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.sca.contribution.jee; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Model Resolver for EjbModule models. + * + * @version $Rev$ $Date$ + */ +public class EjbModuleModelResolver implements ModelResolver { + + private Map map = new HashMap(); + private Contribution contribution; + + public EjbModuleModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + } + + public void addModel(Object resolved) { + EjbModuleInfo ejbModule = (EjbModuleInfo)resolved; + map.put(ejbModule.getUri(), ejbModule); + } + + public Object removeModel(Object resolved) { + return map.remove(((EjbModuleInfo)resolved).getUri()); + } + + public T resolveModel(Class modelClass, T unresolved) { + // Lookup a EjbModuleInfo for the given URI + URI uri = ((EjbModuleInfo)unresolved).getUri(); + if (uri != null) { + EjbModuleInfo resolved = (EjbModuleInfo) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } else { + uri = URI.create(""); + resolved = (EjbModuleInfo) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } + } + } + return unresolved; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbReferenceInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbReferenceInfo.java new file mode 100644 index 0000000000..70470f1133 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EjbReferenceInfo.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.sca.contribution.jee; + +/** + * @version $Rev$ $Date$ + */ +public class EjbReferenceInfo { + public enum EjbType {STATELESS, STATEFUL, SESSION_UNKNOWN, UNKNOWN}; + public enum RefType {LOCAL, REMOTE, UNKNOWN}; + public String referenceName; + public EjbType ejbType; + public RefType referenceType; + public Class businessInterface; + public String ejbLink; + public String mappedName; + public InjectionTarget injectionTarget = new InjectionTarget(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EnvEntryInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EnvEntryInfo.java new file mode 100644 index 0000000000..26ce44c07e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EnvEntryInfo.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.sca.contribution.jee; + + +/** + * @version $Rev$ $Date$ + */ +public class EnvEntryInfo { + public String type; + public String name; + public String value; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java new file mode 100644 index 0000000000..c0b54156ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.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.sca.contribution.jee; + +import org.apache.tuscany.sca.assembly.Composite; + + +/** + * @version $Rev: 755722 $ $Date: 2009-03-18 20:23:02 +0000 (Wed, 18 Mar 2009) $ + */ +public interface ExternalEarInfo { + + JavaEEApplicationInfo getAppInfo(); + Composite getAppComposite(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/InjectionTarget.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/InjectionTarget.java new file mode 100644 index 0000000000..4ea2b6b072 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/InjectionTarget.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.sca.contribution.jee; + + +/** + * @version $Rev$ $Date$ + */ +public class InjectionTarget { + public String targetClass; + public String targetName; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationInfo.java new file mode 100644 index 0000000000..107c251ea7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationInfo.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.sca.contribution.jee; + +import java.net.URI; +import java.util.Map; + +/** + * @version $Rev$ $Date$ + */ +public interface JavaEEApplicationInfo { + URI getUri(); + void setUri(URI uri); + + String getApplicationName(); + void setApplicationName(String applicationName); + + Map getWebModuleInfos(); + WebModuleInfo getWebModuleInfo(String moduleName); + Map getEjbModuleInfos(); + EjbModuleInfo getEjbModuleInfo(String moduleName); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationModelResolver.java new file mode 100644 index 0000000000..e27fa5ae44 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationModelResolver.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.sca.contribution.jee; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Model Resolver for JavaEEApplicationInfo models. + * + * @version $Rev$ $Date$ + */ +public class JavaEEApplicationModelResolver implements ModelResolver { + + private Map map = new HashMap(); + private Contribution contribution; + + public JavaEEApplicationModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + } + + public void addModel(Object resolved) { + JavaEEApplicationInfo jeeApp = (JavaEEApplicationInfo)resolved; + map.put(jeeApp.getUri(), jeeApp); + } + + public Object removeModel(Object resolved) { + return map.remove(((JavaEEApplicationInfo)resolved).getUri()); + } + + public T resolveModel(Class modelClass, T unresolved) { + // Lookup a JavaEEApplicationInfo for the given URI + URI uri = ((JavaEEApplicationInfo)unresolved).getUri(); + if (uri != null) { + JavaEEApplicationInfo resolved = (JavaEEApplicationInfo) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } else { + uri = URI.create(""); + resolved = (JavaEEApplicationInfo) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } + } + } + return unresolved; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEExtension.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEExtension.java new file mode 100644 index 0000000000..7b7d1f161f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEExtension.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.sca.contribution.jee; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; + +/** + * Compute componentType with EJB3 business interfaces translating into SCA services. + * + * @version $Rev$ $Date$ + */ +public interface JavaEEExtension { + // The EJBImplementation model is a straight implementation so we deal in + // component types + ComponentType createImplementationEjbComponentType(EjbModuleInfo ejbModule, String ejbName); + + // The JEEImplemenation model is a composite and so we have to fluff + // up the composite contents to match the JEE artifact + void createImplementationJeeComposite(EjbModuleInfo ejbModule, Composite composite); + void createImplementationJeeComposite(JavaEEApplicationInfo appInfo, Composite composite); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEIntrospector.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEIntrospector.java new file mode 100644 index 0000000000..ab89ce2bf7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEIntrospector.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.sca.contribution.jee; + +import java.net.URL; + +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * Introspect JavaEE modules and applications. + * + * @version $Rev$ $Date$ + */ +public interface JavaEEIntrospector { + WebModuleInfo introspectWebArchive(URL artifactURL) throws ContributionReadException; + EjbModuleInfo introspectEjbArchive(URL artifactURL) throws ContributionReadException; + JavaEEApplicationInfo introspectJeeArchive(URL artifactURL) throws ContributionReadException; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEOptionalExtension.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEOptionalExtension.java new file mode 100644 index 0000000000..50a449ce78 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEOptionalExtension.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.sca.contribution.jee; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; + +/** + * Compute componentType with Remote EJB references translating into SCA references and env-entries translating into + * SCA properties. + * + * @version $Rev$ $Date$ + */ +public interface JavaEEOptionalExtension { + // The EJBImplementation and WEBImplemenation models are straight implementations so + // we deals in component types + ComponentType createImplementationWebComponentType(WebModuleInfo webModule); + ComponentType createImplementationEjbComponentType(EjbModuleInfo ejbModule, String ejbName); + + // The JEEImplemenation model is a composite and so we have to fluff + // up the composite contents to match the JEE artifact + void createImplementationJeeComposite(WebModuleInfo webModule, Composite composite); + void createImplementationJeeComposite(EjbModuleInfo ejbModule, Composite composite); + void createImplementationJeeComposite(JavaEEApplicationInfo appInfo, Composite composite); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JspReferenceTagInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JspReferenceTagInfo.java new file mode 100644 index 0000000000..e36aea2790 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JspReferenceTagInfo.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.sca.contribution.jee; + + +/** + * @version $Rev$ $Date$ + * + * Information on SCA reference tags in JSP pages. + */ +public class JspReferenceTagInfo { + public String name; + public Class type; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObject.java new file mode 100644 index 0000000000..e981339733 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObject.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.sca.contribution.jee; + +import java.net.URI; + +/** + * @version $Rev$ $Date$ + */ +public interface ModelObject { + URI getUri(); + void setUri(URI uri); + + Object getObject(); + void setObject(Object obj); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObjectModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObjectModelResolver.java new file mode 100644 index 0000000000..aa24dcac2c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObjectModelResolver.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.sca.contribution.jee; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.jee.impl.ModelObjectImpl; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Model Resolver for obtaining any model object using URI. + * + * @version $Rev$ $Date$ + */ +public class ModelObjectModelResolver implements ModelResolver { + + private Map map = new HashMap(); + private Contribution contribution; + + public ModelObjectModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + } + + public void addModel(Object resolved) { + map.put(((ModelObject)resolved).getUri(), (ModelObject)resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(((ModelObject)resolved).getUri()); + } + + public T resolveModel(Class modelClass, T unresolved) { + URI uri = ((ModelObject)unresolved).getUri(); + if (uri != null) { + ModelObject resolved = (ModelObject) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } else { + for(Artifact artifact : contribution.getArtifacts()) { + if(artifact.getURI().equals(uri.toString())) { + resolved = new ModelObjectImpl(); + resolved.setUri(uri); + resolved.setObject(artifact.getModel()); + return modelClass.cast(resolved); + } + } + } + } + return unresolved; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebImplementationGenerated.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebImplementationGenerated.java new file mode 100644 index 0000000000..ee3b057ee6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebImplementationGenerated.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.sca.contribution.jee; + +import org.apache.tuscany.sca.assembly.Implementation; + + + +/** + * The model representing a WEB implementation in an SCA assembly model when the + * WEB implementation has been generated by introspecting a non-enhanced EAR + */ +public interface WebImplementationGenerated extends Implementation { + + /** + * Return the WebModuleInfo which generated this Web component implementation + * @return + */ + WebModuleInfo getWebInfo(); + + /** + * Set the WebModuleInfo which generated this Web component implementation + * @param webInfo + */ + void setWebInfo(WebModuleInfo webInfo); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleInfo.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleInfo.java new file mode 100644 index 0000000000..79e9019b11 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleInfo.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.sca.contribution.jee; + +import java.net.URI; +import java.util.Collection; +import java.util.Map; + +/** + * @version $Rev$ $Date$ + */ +public interface WebModuleInfo { + URI getUri(); + void setUri(URI uri); + + String getModuleName(); + void setModuleName(String moduleName); + + ClassLoader getModuleClassloader(); + void setmoduleClassloader(ClassLoader classLoader); + + Map getEjbReferences(); + Map getEnvEntries(); + + EjbReferenceInfo getEjbReference(String ejbRefName); + EnvEntryInfo getEnvEntry(String envEntryName); + + Collection> getServletClasses(); + Collection> getListenerClasses(); + Collection> getFilterClasses(); + Collection> getJSFClasses(); + + Collection getJspReferenceTags(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleModelResolver.java new file mode 100644 index 0000000000..74117a13f0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleModelResolver.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.sca.contribution.jee; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Model Resolver for WebModuleInfo models. + * + * @version $Rev$ $Date$ + */ +public class WebModuleModelResolver implements ModelResolver { + + private Map map = new HashMap(); + private Contribution contribution; + + public WebModuleModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + } + + public void addModel(Object resolved) { + WebModuleInfo webModule = (WebModuleInfo)resolved; + map.put(webModule.getUri(), webModule); + } + + public Object removeModel(Object resolved) { + return map.remove(((WebModuleInfo)resolved).getUri()); + } + + public T resolveModel(Class modelClass, T unresolved) { + // Lookup a WebModuleInfo for the given URI + URI uri = ((WebModuleInfo)unresolved).getUri(); + if (uri != null) { + WebModuleInfo resolved = (WebModuleInfo) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } else { + uri = URI.create(""); + resolved = (WebModuleInfo) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } + } + } + return unresolved; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedImpl.java new file mode 100644 index 0000000000..eb5b8d8463 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedImpl.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.sca.contribution.jee.impl; + +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; +import org.apache.tuscany.sca.contribution.jee.EJBImplementationGenerated; +import org.apache.tuscany.sca.contribution.jee.EjbInfo; +import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; + +/** + * The model representing an EJB implementation in an SCA assembly model when the + * EJB implementation has been generated by introspecting a non-enhanced EAR $ + */ +class EJBImplementationGeneratedImpl extends ImplementationImpl implements EJBImplementationGenerated { + + private EjbInfo ejbInfo; + private EjbModuleInfo ejbModuleInfo; + + /** + * Constructs a new EJB implementation. + */ + EJBImplementationGeneratedImpl() { + super(); + } + + @Override + public ConstrainingType getConstrainingType() { + // The EJB implementation does not support constrainingTypes + return null; + } + + @Override + public void setConstrainingType(ConstrainingType constrainingType) { + // The EJB implementation does not support constrainingTypes + } + + public EjbInfo getEJBInfo() { + return ejbInfo; + } + + public void setEJBInfo(EjbInfo ejbInfo) { + this.ejbInfo = ejbInfo; + } + + public EjbModuleInfo getEjbModuleInfo() { + return ejbModuleInfo; + } + + public void setEjbModuleInfo(EjbModuleInfo ejbModuleInfo) { + this.ejbModuleInfo = ejbModuleInfo; + } + + // make sure the generated implementation can be distinguished + // based on the ejb info that is referenced + @Override + public int hashCode() { + return getEJBInfo().hashCode(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedProcessor.java new file mode 100644 index 0000000000..bc8bc99770 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedProcessor.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.sca.contribution.jee.impl; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.monitor.Monitor; + + +/** + * Dummy processor that's used to mark EJBImplementationGeneratedImpl instance + * as resolved at the appropriate point in the resolution processing + * + * @version $Rev$ $Date$ + */ +public class EJBImplementationGeneratedProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public EJBImplementationGeneratedProcessor(ExtensionPointRegistry registry, + Monitor monitor) { + } + + public QName getArtifactType() { + return null; + } + + public Class getModelType() { + // Returns the type of model processed by this processor + return EJBImplementationGeneratedImpl.class; + } + + public EJBImplementationGeneratedImpl read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + return null; + } + + public void resolve(EJBImplementationGeneratedImpl implementation, ModelResolver resolver) throws ContributionResolveException { + implementation.setUnresolved(false); + } + + public void write(EJBImplementationGeneratedImpl implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EarContributionProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EarContributionProcessor.java new file mode 100644 index 0000000000..b0eb155636 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EarContributionProcessor.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.sca.contribution.jee.impl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; + +import org.apache.tuscany.sca.contribution.PackageType; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.processor.impl.JarContributionProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.eclipse.emf.common.archive.ArchiveURLConnection; + +/** + * Ear Contribution package processor. + * + * @version $Rev$ $Date$ + */ +public class EarContributionProcessor implements PackageProcessor { + + /* URL stream handler for "archive" */ + private static URLStreamHandler archiveUrlStreamHandler = new URLStreamHandler() { + @Override + protected URLConnection openConnection(URL u) throws IOException { + return new ArchiveURLConnection(u); + } + }; + + public URL getArtifactURL(URL packageSourceURL, URI artifact) + throws MalformedURLException { + if(artifact.toString().equals("")) { + return packageSourceURL; + } + if (packageSourceURL.toString().startsWith("archive:")) { + return new URL(packageSourceURL, artifact.toString(), archiveUrlStreamHandler); + } else { + return new URL("archive", "", -1, packageSourceURL.toExternalForm() + "!/" + artifact, archiveUrlStreamHandler); + } + } + + public List getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, IOException { + if (packageSourceURL == null) { + throw new IllegalArgumentException("Invalid null package source URL."); + } + + if (inputStream == null) { + throw new IllegalArgumentException("Invalid null source inputstream."); + } + + // The root is a jar file + JarInputStream jar = new JarInputStream(inputStream); + try { + Set names = new HashSet(); + while (true) { + JarEntry entry = jar.getNextJarEntry(); + if (entry == null) { + // EOF + break; + } + + String name = entry.getName(); + if (!name.startsWith(".")) { + + // Trim trailing / + if (name.endsWith("/")) { + name = name.substring(0, name.length() - 1); + } + + // Add the entry name + if (!names.contains(name)) { + names.add(name); + + // Add parent folder names to the list too + for (;;) { + int s = name.lastIndexOf('/'); + if (s == -1) { + name = ""; + } else { + name = name.substring(0, s); + } + if (!names.contains(name)) { + names.add(name); + } else { + break; + } + } + } + } + if(entry.getName().indexOf("/") == -1 && (entry.getName().toLowerCase().endsWith(".war") || entry.getName().toLowerCase().endsWith(".jar"))) { + // A WAR or an EJB JAR file in the root of the archive. + // Get entries from the nested archive. + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + int b; + while((b = jar.read()) != -1) { + bout.write(b); + } + bout.close(); + ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); + + PackageProcessor archiveProcessor = entry.getName().toLowerCase().endsWith(".war") ? new WarContributionProcessor() : new JarContributionProcessor(); + List artifacts = archiveProcessor.getArtifacts(packageSourceURL, bin); + bin.close(); + for(URI artifact : artifacts) { + // don't add in nested application composites + if ((artifact.toString().endsWith("ejb-jar.composite") == false) && + (artifact.toString().endsWith("web.composite") == false)) { + names.add(entry.getName()+"!/"+artifact); + } + } + } + } + + // Return list of URIs + List artifacts = new ArrayList(); + for (String name: names) { + artifacts.add(URI.create(name)); + } + return artifacts; + + } finally { + jar.close(); + } + } + + public String getPackageType() { + return PackageType.EAR; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EjbArchiveProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EjbArchiveProcessor.java new file mode 100644 index 0000000000..36aabefa99 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EjbArchiveProcessor.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.sca.contribution.jee.impl; + +import java.io.File; +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; +import org.apache.tuscany.sca.contribution.jee.JavaEEIntrospector; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * URLArtifactProcessor for EJB jars. + * + * @version $Rev$ $Date$ + */ +public class EjbArchiveProcessor implements URLArtifactProcessor { + private JavaEEIntrospector jeeIntrospector; + + public EjbArchiveProcessor(ExtensionPointRegistry registry, Monitor monitor) { + jeeIntrospector = registry.getExtensionPoint(JavaEEIntrospector.class); + } + + public String getArtifactType() { + return ".jar"; + } + + public EjbModuleInfo read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { + if (jeeIntrospector != null) { + EjbModuleInfo ejbModuleInfo = jeeIntrospector.introspectEjbArchive(artifactURL); + if(ejbModuleInfo != null) { + ejbModuleInfo.setUri(artifactURI); + ejbModuleInfo.setModuleName(new File(artifactURL.getFile()).getName()); + } + return ejbModuleInfo; + } + return null; + } + + public Class getModelType() { + return EjbModuleInfo.class; + } + + public void resolve(EjbModuleInfo arg0, ModelResolver arg1) + throws ContributionResolveException { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EjbModuleInfoImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EjbModuleInfoImpl.java new file mode 100644 index 0000000000..830aa81b19 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EjbModuleInfoImpl.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.sca.contribution.jee.impl; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.jee.EjbInfo; +import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; + +public class EjbModuleInfoImpl implements EjbModuleInfo { + + private URI uri; + private String moduleName; + private ClassLoader moduleClassLoader; + private Map ejbInfos = new HashMap(); + + public EjbInfo getEjbInfo(String beanName) { + return ejbInfos.get(beanName); + } + + public Map getEjbInfos() { + return ejbInfos; + } + + public String getModuleName() { + return moduleName; + } + + public void setModuleName(String moduleName) { + this.moduleName = moduleName; + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + public ClassLoader getModuleClassloader() { + return moduleClassLoader; + } + + public void setmoduleClassloader(ClassLoader classLoader) { + this.moduleClassLoader = classLoader; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEApplicationInfoImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEApplicationInfoImpl.java new file mode 100644 index 0000000000..993605ebe5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEApplicationInfoImpl.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.jee.impl; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; +import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo; +import org.apache.tuscany.sca.contribution.jee.WebModuleInfo; + +public class JavaEEApplicationInfoImpl implements JavaEEApplicationInfo { + + private URI uri; + private String applicationName; + private Map ejbModuleInfos = new HashMap(); + private Map webModuleInfos = new HashMap(); + + + public String getApplicationName() { + return applicationName; + } + + public void setApplicationName(String applicationName) { + this.applicationName = applicationName; + } + + public EjbModuleInfo getEjbModuleInfo(String moduleName) { + return ejbModuleInfos.get(moduleName); + } + + public Map getEjbModuleInfos() { + return ejbModuleInfos; + } + + public WebModuleInfo getWebModuleInfo(String moduleName) { + return webModuleInfos.get(moduleName); + } + + public Map getWebModuleInfos() { + return webModuleInfos; + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEArchiveProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEArchiveProcessor.java new file mode 100644 index 0000000000..53201b5e2b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEArchiveProcessor.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.sca.contribution.jee.impl; + +import java.io.File; +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo; +import org.apache.tuscany.sca.contribution.jee.JavaEEIntrospector; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.monitor.Monitor; + +public class JavaEEArchiveProcessor implements URLArtifactProcessor { + private JavaEEIntrospector jeeIntrospector; + + public JavaEEArchiveProcessor(ExtensionPointRegistry registry, Monitor monitor) { + jeeIntrospector = registry.getExtensionPoint(JavaEEIntrospector.class); + } + + public String getArtifactType() { + return ".ear"; + } + + public JavaEEApplicationInfo read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { + JavaEEApplicationInfo jeeAppInfo = jeeIntrospector.introspectJeeArchive(artifactURL); + jeeAppInfo.setUri(artifactURI); + jeeAppInfo.setApplicationName(new File(artifactURL.getFile()).getName()); + return jeeAppInfo; + } + + public Class getModelType() { + return JavaEEApplicationInfo.class; + } + + public void resolve(JavaEEApplicationInfo arg0, ModelResolver arg1) + throws ContributionResolveException { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEExtensionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEExtensionImpl.java new file mode 100644 index 0000000000..4271a93399 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEExtensionImpl.java @@ -0,0 +1,262 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.jee.impl; + +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.jee.EJBImplementationGenerated; +import org.apache.tuscany.sca.contribution.jee.EjbInfo; +import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; +import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo; +import org.apache.tuscany.sca.contribution.jee.JavaEEExtension; +import org.apache.tuscany.sca.contribution.jee.EjbInfo.EjbType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyFactory; + +public class JavaEEExtensionImpl implements JavaEEExtension { + + private AssemblyFactory assemblyFactory; + private JavaInterfaceFactory javaInterfaceFactory; + private PolicyFactory policyFactory; + private Intent EJB_INTENT; + + public JavaEEExtensionImpl(ModelFactoryExtensionPoint modelFactories) { + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + + EJB_INTENT = policyFactory.createIntent(); + EJB_INTENT.setName(new QName("http://www.osoa.org/xmlns/sca/1.0", "ejb")); + } + + public ComponentType createImplementationEjbComponentType(EjbModuleInfo ejbModule, String ejbName) { + ComponentType componentType = assemblyFactory.createComponentType(); + EjbInfo ejbInfo = ejbModule.getEjbInfo(ejbName); + if(ejbInfo == null) { + return null; + } + if(ejbInfo.ejbType.compareTo(EjbType.MESSAGE_DRIVEN) != 0) { + for(Class intf : ejbInfo.businessRemote) { + Service service = assemblyFactory.createComponentService(); + String intfName = intf.getName(); + String serviceName = intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName; + service.setName(serviceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(intf)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + service.setInterfaceContract(ic); + service.getRequiredIntents().add(EJB_INTENT); + + componentType.getServices().add(service); + } + + for(Class intf : ejbInfo.businessLocal) { + Service service = assemblyFactory.createComponentService(); + String intfName = intf.getName(); + String serviceName = intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName; + service.setName(serviceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(intf)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + service.setInterfaceContract(ic); + service.getRequiredIntents().add(EJB_INTENT); + + componentType.getServices().add(service); + } + } + return componentType; + } + + public void createImplementationJeeComposite(EjbModuleInfo ejbModule, Composite composite) { + + for(Map.Entry entry : ejbModule.getEjbInfos().entrySet()) { + EjbInfo ejbInfo = entry.getValue(); + + Component component = findComponent(composite, ejbInfo, ejbModule); + + if(ejbInfo.ejbType.compareTo(EjbType.MESSAGE_DRIVEN) != 0) { + for(Class intf : ejbInfo.businessRemote) { + ComponentService service = assemblyFactory.createComponentService(); + String intfName = intf.getName(); + String serviceName = intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName; + serviceName = ejbInfo.beanName+"_"+serviceName; + service.setName(serviceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(intf)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + service.setInterfaceContract(ic); + service.getRequiredIntents().add(EJB_INTENT); + + addComponentService(composite, component, service); + } + + for(Class intf : ejbInfo.businessLocal) { + ComponentService service = assemblyFactory.createComponentService(); + String intfName = intf.getName(); + String serviceName = intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName; + serviceName = ejbInfo.beanName+"_"+serviceName; + service.setName(serviceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(intf)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + service.setInterfaceContract(ic); + service.getRequiredIntents().add(EJB_INTENT); + + addComponentService(composite, component, service); + } + } + } + } + + public void createImplementationJeeComposite(JavaEEApplicationInfo appInfo, Composite composite) { + + for(Map.Entry entry0 : appInfo.getEjbModuleInfos().entrySet()) { + EjbModuleInfo ejbModule = entry0.getValue(); + + for(Map.Entry entry : ejbModule.getEjbInfos().entrySet()) { + EjbInfo ejbInfo = entry.getValue(); + + Component component = findComponent(composite, ejbInfo, ejbModule); + + if(ejbInfo.ejbType.compareTo(EjbType.MESSAGE_DRIVEN) != 0) { + for(Class intf : ejbInfo.businessRemote) { + ComponentService service = assemblyFactory.createComponentService(); + String intfName = intf.getName(); + String serviceName = intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName; + serviceName = ejbInfo.mappedName+"_"+serviceName; + service.setName(serviceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(intf)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + service.setInterfaceContract(ic); + service.getRequiredIntents().add(EJB_INTENT); + + addComponentService(composite, component, service); + } + + for(Class intf : ejbInfo.businessLocal) { + ComponentService service = assemblyFactory.createComponentService(); + String intfName = intf.getName(); + String serviceName = intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName; + serviceName = ejbInfo.mappedName+"_"+serviceName; + service.setName(serviceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(intf)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + service.setInterfaceContract(ic); + service.getRequiredIntents().add(EJB_INTENT); + + addComponentService(composite, component, service); + } + } + } + } + } + + /** + * We are fluffing up the JEEImplemention composite to represented the components + * in the JEE archive. Given the JEEimplemenation composite find a named component + * it if already exists or create it if it doesn't. + * + * @param ejbInfo + * @param componentName + * @return + */ + private Component findComponent(Composite composite, EjbInfo ejbInfo, EjbModuleInfo ejbmoduleInfo){ + String componentName = ejbInfo.beanName; + Component component = null; + + for (Component tmpComponent : composite.getComponents()){ + if (tmpComponent.getName().equals(componentName)){ + component = tmpComponent; + break; + } + } + + if (component == null){ + component = assemblyFactory.createComponent(); + component.setName(componentName); + component.setUnresolved(true); + composite.getComponents().add(component); + + EJBImplementationGenerated implementation = new EJBImplementationGeneratedImpl(); + implementation.setUnresolved(true); + implementation.setEJBInfo(ejbInfo); + implementation.setEjbModuleInfo(ejbmoduleInfo); + component.setImplementation(implementation); + } + + return component; + } + + /** + * Add a component service and fluff up a composite service to match + * + * @param composite + * @param component + * @param service + */ + private void addComponentService(Composite composite, Component component, ComponentService service){ + component.getImplementation().getServices().add(service); + + CompositeService compositeService = assemblyFactory.createCompositeService(); + composite.getServices().add(compositeService); + + compositeService.setName(service.getName()); + compositeService.setPromotedComponent(component); + compositeService.setPromotedService(service); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java new file mode 100644 index 0000000000..505578d6f1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java @@ -0,0 +1,398 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.jee.impl; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.jee.EJBImplementationGenerated; +import org.apache.tuscany.sca.contribution.jee.EjbInfo; +import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; +import org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo; +import org.apache.tuscany.sca.contribution.jee.EnvEntryInfo; +import org.apache.tuscany.sca.contribution.jee.InjectionTarget; +import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo; +import org.apache.tuscany.sca.contribution.jee.JavaEEOptionalExtension; +import org.apache.tuscany.sca.contribution.jee.WebImplementationGenerated; +import org.apache.tuscany.sca.contribution.jee.WebModuleInfo; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyFactory; + +public class JavaEEOptionalExtensionImpl implements JavaEEOptionalExtension { + + private AssemblyFactory assemblyFactory; + private JavaInterfaceFactory javaInterfaceFactory; + private PolicyFactory policyFactory; + private Intent EJB_INTENT; + + public static final Map ALLOWED_ENV_ENTRY_TYPES; + static { + ALLOWED_ENV_ENTRY_TYPES = new HashMap(); + ALLOWED_ENV_ENTRY_TYPES.put(String.class.getName(), new QName("http://www.w3.org/2001/XMLSchema", "string", + "xsd")); + ALLOWED_ENV_ENTRY_TYPES.put(Character.class.getName(), new QName("http://www.w3.org/2001/XMLSchema", "string", + "xsd")); + ALLOWED_ENV_ENTRY_TYPES.put(Byte.class.getName(), new QName("http://www.w3.org/2001/XMLSchema", "byte", "xsd")); + ALLOWED_ENV_ENTRY_TYPES.put(Short.class.getName(), + new QName("http://www.w3.org/2001/XMLSchema", "short", "xsd")); + ALLOWED_ENV_ENTRY_TYPES.put(Integer.class.getName(), + new QName("http://www.w3.org/2001/XMLSchema", "int", "xsd")); + ALLOWED_ENV_ENTRY_TYPES.put(Long.class.getName(), new QName("http://www.w3.org/2001/XMLSchema", "long", "xsd")); + ALLOWED_ENV_ENTRY_TYPES.put(Boolean.class.getName(), new QName("http://www.w3.org/2001/XMLSchema", "boolean", + "xsd")); + ALLOWED_ENV_ENTRY_TYPES.put(Double.class.getName(), new QName("http://www.w3.org/2001/XMLSchema", "double", + "xsd")); + ALLOWED_ENV_ENTRY_TYPES.put(Float.class.getName(), + new QName("http://www.w3.org/2001/XMLSchema", "float", "xsd")); + } + + public JavaEEOptionalExtensionImpl(ModelFactoryExtensionPoint modelFactories) { + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + + EJB_INTENT = policyFactory.createIntent(); + EJB_INTENT.setName(new QName("http://www.osoa.org/xmlns/sca/1.0", "ejb")); + } + + public ComponentType createImplementationWebComponentType(WebModuleInfo webModule) { + ComponentType componentType = assemblyFactory.createComponentType(); + + // Process Remote EJB References + for(Map.Entry entry : webModule.getEjbReferences().entrySet()) { + EjbReferenceInfo ejbRef = entry.getValue(); + // If the EJB reference has @Reference SCA annotation, then skip that reference + if(!hasReferenceAnnotation(ejbRef.injectionTarget)) { + continue; + } + String referenceName = entry.getKey(); + referenceName = referenceName.replace("/", "_"); + Reference reference = assemblyFactory.createComponentReference(); + reference.setName(referenceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(ejbRef.businessInterface)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + reference.setInterfaceContract(ic); + reference.getRequiredIntents().add(EJB_INTENT); + reference.setMultiplicity(Multiplicity.ZERO_ONE); + componentType.getReferences().add(reference); + } + + // Process env-entries to compute properties + for (Map.Entry entry : webModule.getEnvEntries().entrySet()) { + EnvEntryInfo envEntry = entry.getValue(); + String type = envEntry.type; + if (!ALLOWED_ENV_ENTRY_TYPES.containsKey(type)) { + continue; + } + String propertyName = envEntry.name; + propertyName = propertyName.replace("/", "_"); + String value = envEntry.value; + Property property = assemblyFactory.createComponentProperty(); + property.setName(propertyName); + property.setXSDType(ALLOWED_ENV_ENTRY_TYPES.get(type)); + property.setValue(value); + componentType.getProperties().add(property); + } + + return componentType; + } + + public ComponentType createImplementationEjbComponentType(EjbModuleInfo ejbModule, String ejbName) { + ComponentType componentType = assemblyFactory.createComponentType(); + EjbInfo ejbInfo = ejbModule.getEjbInfo(ejbName); + if(ejbInfo == null) { + return null; + } + + // Process Remote EJB References + for(Map.Entry entry : ejbInfo.ejbReferences.entrySet()) { + EjbReferenceInfo ejbRef = entry.getValue(); + // If the EJB reference has @Reference SCA annotation, then skip that reference + if(!hasReferenceAnnotation(ejbRef.injectionTarget)) { + continue; + } + String referenceName = entry.getKey(); + referenceName = referenceName.replace("/", "_"); + Reference reference = assemblyFactory.createComponentReference(); + reference.setName(referenceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(ejbRef.businessInterface)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + reference.setInterfaceContract(ic); + reference.getRequiredIntents().add(EJB_INTENT); + reference.setMultiplicity(Multiplicity.ZERO_ONE); + componentType.getReferences().add(reference); + } + + // Process env-entries to compute properties + for (Map.Entry entry : ejbInfo.envEntries.entrySet()) { + EnvEntryInfo envEntry = entry.getValue(); + String type = envEntry.type; + if (!ALLOWED_ENV_ENTRY_TYPES.containsKey(type)) { + continue; + } + String propertyName = envEntry.name; + propertyName = propertyName.replace("/", "_"); + String value = envEntry.value; + Property property = assemblyFactory.createComponentProperty(); + property.setName(propertyName); + property.setXSDType(ALLOWED_ENV_ENTRY_TYPES.get(type)); + property.setValue(value); + componentType.getProperties().add(property); + } + return componentType; + } + + public void createImplementationJeeComposite(WebModuleInfo webModule, Composite composite) { + + Component component = findComponent(composite, webModule); + + // Process Remote EJB References + for(Map.Entry entry : webModule.getEjbReferences().entrySet()) { + EjbReferenceInfo ejbRef = entry.getValue(); + String referenceName = entry.getKey(); + referenceName = referenceName.replace("/", "_"); + ComponentReference reference = assemblyFactory.createComponentReference(); + reference.setName(referenceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(ejbRef.businessInterface)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + reference.setInterfaceContract(ic); + reference.getRequiredIntents().add(EJB_INTENT); + reference.setMultiplicity(Multiplicity.ZERO_ONE); + + addComponentReference(composite, component, reference); + } + } + + public void createImplementationJeeComposite(EjbModuleInfo ejbModule, Composite composite) { + + for(Map.Entry entry : ejbModule.getEjbInfos().entrySet()) { + EjbInfo ejbInfo = entry.getValue(); + + Component component = findComponent(composite, ejbInfo, ejbModule); + + // Process Remote EJB References + for(Map.Entry entry1 : ejbInfo.ejbReferences.entrySet()) { + EjbReferenceInfo ejbRef = entry1.getValue(); + String referenceName = ejbRef.referenceName; + referenceName = referenceName.replace("/", "_"); + referenceName = ejbInfo.beanName + "_" + referenceName; + ComponentReference reference = assemblyFactory.createComponentReference(); + reference.setName(referenceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(ejbRef.businessInterface)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + reference.setInterfaceContract(ic); + reference.getRequiredIntents().add(EJB_INTENT); + reference.setMultiplicity(Multiplicity.ZERO_ONE); + + addComponentReference(composite, component, reference); + } + } + } + + + public void createImplementationJeeComposite(JavaEEApplicationInfo appInfo, Composite composite) { + + for(Map.Entry entry0 : appInfo.getEjbModuleInfos().entrySet()) { + EjbModuleInfo ejbModule = entry0.getValue(); + + for(Map.Entry entry : ejbModule.getEjbInfos().entrySet()) { + EjbInfo ejbInfo = entry.getValue(); + + Component component = findComponent(composite, ejbInfo, ejbModule); + + // Process Remote EJB References + for(Map.Entry entry1 : ejbInfo.ejbReferences.entrySet()) { + EjbReferenceInfo ejbRef = entry1.getValue(); + String referenceName = ejbRef.referenceName; + referenceName = referenceName.replace("/", "_"); + referenceName = ejbInfo.beanName + "_" + referenceName; + ComponentReference reference = assemblyFactory.createComponentReference(); + reference.setName(referenceName); + InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); + try { + ic.setInterface(javaInterfaceFactory.createJavaInterface(ejbRef.businessInterface)); + } catch (InvalidInterfaceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + reference.setInterfaceContract(ic); + reference.getRequiredIntents().add(EJB_INTENT); + reference.setMultiplicity(Multiplicity.ZERO_ONE); + + addComponentReference(composite, component, reference); + } + } + } + } + + /** + * We are fluffing up the JEEImplemention composite to represent the components + * in the JEE archive. Given the JEEimplemenation composite find a named component + * it if already exists or create it if it doesn't. + * + * @param composite + * @param ejbInfo + * @return + */ + private Component findComponent(Composite composite, EjbInfo ejbInfo, EjbModuleInfo ejbmoduleInfo){ + String componentName = ejbInfo.beanName; + Component component = null; + + for (Component tmpComponent : composite.getComponents()){ + if (tmpComponent.getName().equals(componentName)){ + component = tmpComponent; + break; + } + } + + if (component == null){ + component = assemblyFactory.createComponent(); + component.setName(componentName); + component.setUnresolved(true); + composite.getComponents().add(component); + + EJBImplementationGenerated implementation = new EJBImplementationGeneratedImpl(); + implementation.setUnresolved(true); + implementation.setEJBInfo(ejbInfo); + implementation.setEjbModuleInfo(ejbmoduleInfo); + component.setImplementation(implementation); + } + + return component; + } + + /** + * We are fluffing up the JEEImplemention composite to represent the components + * in the JEE archive. Given the JEEimplemenation composite find a named component + * it if already exists or create it if it doesn't. + * + * @param composite + * @param ejbInfo + * @return + */ + private Component findComponent(Composite composite, WebModuleInfo webInfo){ + String componentName = webInfo.getModuleName(); + Component component = null; + + for (Component tmpComponent : composite.getComponents()){ + if (tmpComponent.getName().equals(componentName)){ + component = tmpComponent; + break; + } + } + + if (component == null){ + component = assemblyFactory.createComponent(); + component.setName(componentName); + component.setUnresolved(true); + composite.getComponents().add(component); + + WebImplementationGenerated implementation = new WebImplementationGeneratedImpl(); + implementation.setUnresolved(true); + // need generated impl to represent web modules + implementation.setWebInfo(webInfo); + component.setImplementation(implementation); + } + + return component; + } + + /** + * Add a component reference and fluff up a composite reference to match + * + * @param composite + * @param component + * @param service + */ + private void addComponentReference(Composite composite, Component component, ComponentReference reference){ + component.getImplementation().getReferences().add(reference); + + CompositeReference compositeReference = assemblyFactory.createCompositeReference(); + composite.getReferences().add(compositeReference); + + compositeReference.setName(reference.getName()); + compositeReference.getPromotedReferences().add(reference); + } + + private boolean hasReferenceAnnotation(InjectionTarget injectionTarget) { + if(injectionTarget.targetClass == null || injectionTarget.targetClass.equals("")) { + return false; + } + try { + Class clazz = Class.forName(injectionTarget.targetClass); + try { + Method method = clazz.getDeclaredMethod("set"+injectionTarget.targetName); + if(method.isAnnotationPresent(javax.ejb.EJB.class)) { + return method.isAnnotationPresent(org.osoa.sca.annotations.Reference.class); + } else { + // The method does not have @EJB annotation. So, the method is not good for us. + throw new NoSuchMethodException("set"+injectionTarget.targetName); + } + } catch(NoSuchMethodException nsme) { + try { + Field field = clazz.getDeclaredField(injectionTarget.targetName); + return field.isAnnotationPresent(org.osoa.sca.annotations.Reference.class); + } catch(NoSuchFieldException nsfe) { + return false; + } + } + } catch(ClassNotFoundException cnfe) { + return false; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/ModelObjectImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/ModelObjectImpl.java new file mode 100644 index 0000000000..95050dfd88 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/ModelObjectImpl.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.sca.contribution.jee.impl; + +import java.net.URI; + +import org.apache.tuscany.sca.contribution.jee.ModelObject; + +/** + * @version $Rev$ $Date$ + */ +public class ModelObjectImpl implements ModelObject { + + private URI uri; + private Object obj; + + public ModelObjectImpl() { + } + + public Object getObject() { + return obj; + } + + public void setObject(Object obj) { + this.obj = obj; + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WarContributionProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WarContributionProcessor.java new file mode 100644 index 0000000000..17974e831f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WarContributionProcessor.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.sca.contribution.jee.impl; + +import org.apache.tuscany.sca.contribution.PackageType; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.processor.impl.JarContributionProcessor; + +/** + * War Contribution package processor. + * + * @version $Rev$ $Date$ + */ +public class WarContributionProcessor extends JarContributionProcessor implements PackageProcessor { + @Override + public String getPackageType() { + return PackageType.WAR; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebArchiveProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebArchiveProcessor.java new file mode 100644 index 0000000000..9e9bfb8bc1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebArchiveProcessor.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.sca.contribution.jee.impl; + +import java.io.File; +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.contribution.jee.JavaEEIntrospector; +import org.apache.tuscany.sca.contribution.jee.WebModuleInfo; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.monitor.Monitor; + +public class WebArchiveProcessor implements URLArtifactProcessor { + private JavaEEIntrospector jeeIntrospector; + + public WebArchiveProcessor(ExtensionPointRegistry registry, Monitor monitor) { + jeeIntrospector = registry.getExtensionPoint(JavaEEIntrospector.class); + } + + public String getArtifactType() { + return ".war"; + } + + public WebModuleInfo read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { + WebModuleInfo webModuleInfo = jeeIntrospector.introspectWebArchive(artifactURL); + webModuleInfo.setUri(artifactURI); + webModuleInfo.setModuleName(new File(artifactURL.getFile()).getName()); + return webModuleInfo; + } + + public Class getModelType() { + return WebModuleInfo.class; + } + + public void resolve(WebModuleInfo arg0, ModelResolver arg1) + throws ContributionResolveException { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebImplementationGeneratedImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebImplementationGeneratedImpl.java new file mode 100644 index 0000000000..d898bd4ea0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebImplementationGeneratedImpl.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.sca.contribution.jee.impl; + +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; +import org.apache.tuscany.sca.contribution.jee.WebImplementationGenerated; +import org.apache.tuscany.sca.contribution.jee.WebModuleInfo; + + +/** + * The model representing a WEB implementation in an SCA assembly model when the + * WEB implementation has been generated by introspecting a non-enhanced EAR + */ +class WebImplementationGeneratedImpl extends ImplementationImpl implements WebImplementationGenerated { + + private WebModuleInfo webInfo; + + /** + * Constructs a new EJB implementation. + */ + WebImplementationGeneratedImpl() { + super(); + } + + @Override + public ConstrainingType getConstrainingType() { + // The Web implementation does not support constrainingTypes + return null; + } + + @Override + public void setConstrainingType(ConstrainingType constrainingType) { + // The Web implementation does not support constrainingTypes + } + + public WebModuleInfo getWebInfo() { + return webInfo; + } + + public void setWebInfo(WebModuleInfo webInfo) { + this.webInfo = webInfo; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebImplementationGeneratedProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebImplementationGeneratedProcessor.java new file mode 100644 index 0000000000..4e50b15960 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebImplementationGeneratedProcessor.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.sca.contribution.jee.impl; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.monitor.Monitor; + + +/** + * Dummy processor that's used to mark WebImplementationGeneratedImpl instance + * as resolved at the appropriate point in the resolution processing + * + */ +public class WebImplementationGeneratedProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public WebImplementationGeneratedProcessor(ExtensionPointRegistry registry, + Monitor monitor) { + } + + public QName getArtifactType() { + return null; + } + + public Class getModelType() { + // Returns the type of model processed by this processor + return WebImplementationGeneratedImpl.class; + } + + public WebImplementationGeneratedImpl read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + return null; + } + + public void resolve(WebImplementationGeneratedImpl implementation, ModelResolver resolver) throws ContributionResolveException { + implementation.setUnresolved(false); + } + + public void write(WebImplementationGeneratedImpl implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebModuleInfoImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebModuleInfoImpl.java new file mode 100644 index 0000000000..ceca698356 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/WebModuleInfoImpl.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.jee.impl; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo; +import org.apache.tuscany.sca.contribution.jee.EnvEntryInfo; +import org.apache.tuscany.sca.contribution.jee.JspReferenceTagInfo; +import org.apache.tuscany.sca.contribution.jee.WebModuleInfo; + +public class WebModuleInfoImpl implements WebModuleInfo { + + private URI uri; + private String moduleName; + private ClassLoader moduleClassLoader; + + private Collection> servletClasses = new ArrayList>(); + private Collection> listenerClasses = new ArrayList>(); + private Collection> filterClasses = new ArrayList>(); + private Collection> jsfClasses = new ArrayList>(); + + private Collection jspReferenceTags = new ArrayList(); + + private Map ejbReferences = new HashMap(); + private Map envEntries = new HashMap(); + + public WebModuleInfoImpl() { + } + public Collection> getServletClasses() { + return servletClasses; + } + + public Collection> getListenerClasses() { + return listenerClasses; + } + + public Collection> getFilterClasses() { + return filterClasses; + } + + public Collection> getJSFClasses() { + return jsfClasses; + } + + public Collection getJspReferenceTags() { + return jspReferenceTags; + } + + public EjbReferenceInfo getEjbReference(String ejbRefName) { + return ejbReferences.get(ejbRefName); + } + + public Map getEjbReferences() { + return ejbReferences; + } + + public Map getEnvEntries() { + return envEntries; + } + + public EnvEntryInfo getEnvEntry(String envEntryName) { + return envEntries.get(envEntryName); + } + + public String getModuleName() { + return moduleName; + } + + public void setModuleName(String moduleName) { + this.moduleName = moduleName; + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + public ClassLoader getModuleClassloader() { + return moduleClassLoader; + } + + public void setmoduleClassloader(ClassLoader classLoader) { + this.moduleClassLoader = classLoader; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEExtension b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEExtension new file mode 100644 index 0000000000..c79600bca6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEExtension @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.jee.impl.JavaEEExtensionImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEOptionalExtension b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEOptionalExtension new file mode 100644 index 0000000000..5ce036e6b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.jee.JavaEEOptionalExtension @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.jee.impl.JavaEEOptionalExtensionImpl \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor new file mode 100644 index 0000000000..88c69658f6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.jee.impl.EarContributionProcessor;type=application/ear +org.apache.tuscany.sca.contribution.jee.impl.WarContributionProcessor;type=application/war diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..b0bb63225a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# $Rev: 685124 $ $Date: 2008-08-12 12:46:19 +0100 (Tue, 12 Aug 2008) $ + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.contribution.jee.impl.EJBImplementationGeneratedProcessor;qname=http://dummy_namespace/#dummy.name,model=org.apache.tuscany.sca.contribution.jee.impl.EJBImplementationGeneratedImpl,factory=dummy +org.apache.tuscany.sca.contribution.jee.impl.WebImplementationGeneratedProcessor;qname=http://dummy_namespace/#dummy.name,model=org.apache.tuscany.sca.contribution.jee.impl.WebImplementationGeneratedImpl,factory=dummy diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor new file mode 100644 index 0000000000..71575b5ddd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.contribution.jee.impl.WebArchiveProcessor;type=.war,model=org.apache.tuscany.sca.contribution.jee.WebModuleInfo +org.apache.tuscany.sca.contribution.jee.impl.EjbArchiveProcessor;type=.jar,model=org.apache.tuscany.sca.contribution.jee.EjbModuleInfo +org.apache.tuscany.sca.contribution.jee.impl.JavaEEArchiveProcessor;type=.ear,model=org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..90ff87e0b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.jee.WebModuleModelResolver;model=org.apache.tuscany.sca.contribution.jee.WebModuleInfo +org.apache.tuscany.sca.contribution.jee.EjbModuleModelResolver;model=org.apache.tuscany.sca.contribution.jee.EjbModuleInfo +org.apache.tuscany.sca.contribution.jee.JavaEEApplicationModelResolver;model=org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo +org.apache.tuscany.sca.contribution.jee.ModelObjectModelResolver;model=org.apache.tuscany.sca.contribution.jee.ModelObject diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/EarContributionProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/EarContributionProcessorTestCase.java new file mode 100644 index 0000000000..9495df70b7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/EarContributionProcessorTestCase.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.sca.contribution.jee; + +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.contribution.jee.impl.EarContributionProcessor; +import org.apache.tuscany.sca.contribution.service.util.IOHelper; +import org.junit.Test; + +/** + * Ear Contribution package processor test case. + * Verifies proper handling of EAR contributions. + * + * @version $Rev$ $Date$ + */ +public class EarContributionProcessorTestCase { + private static final String EAR_CONTRIBUTION = "/ejb-injection-sample.ear"; + + @Test + public void testProcessPackageArtifacts() throws Exception { + EarContributionProcessor earProcessor = new EarContributionProcessor(); + + URL earURL = getClass().getResource(EAR_CONTRIBUTION); + InputStream earStream = earURL.openStream(); + List artifacts = null; + try { + artifacts = earProcessor.getArtifacts(earURL, earStream); + } finally { + IOHelper.closeQuietly(earStream); + } + + Assert.assertNotNull(artifacts); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/WarContributionProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/WarContributionProcessorTestCase.java new file mode 100644 index 0000000000..e315c417b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/WarContributionProcessorTestCase.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.sca.contribution.jee; + +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.contribution.jee.impl.WarContributionProcessor; +import org.apache.tuscany.sca.contribution.service.util.IOHelper; +import org.junit.Test; + +/** + * War Contribution package processor test case. + * Verifies proper handling of WAR contributions. + * + * @version $Rev$ $Date$ + */ +public class WarContributionProcessorTestCase { + private static final String WAR_CONTRIBUTION = "/sample-web-app.war"; + + @Test + public void testProcessPackageArtifacts() throws Exception { + WarContributionProcessor warProcessor = new WarContributionProcessor(); + + URL warURL = getClass().getResource(WAR_CONTRIBUTION); + InputStream warStream = warURL.openStream(); + List artifacts = null; + try { + artifacts = warProcessor.getArtifacts(warURL, warStream); + } finally { + IOHelper.closeQuietly(warStream); + } + + Assert.assertNotNull(artifacts); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/ejb-injection-sample.ear b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/ejb-injection-sample.ear new file mode 100644 index 0000000000..3efdd206c7 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/ejb-injection-sample.ear differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/ejb-injection-sample.jar b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/ejb-injection-sample.jar new file mode 100644 index 0000000000..4b9e3b79f4 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/ejb-injection-sample.jar differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/sample-web-app.war b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/sample-web-app.war new file mode 100644 index 0000000000..681b203fab Binary files /dev/null and b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-jee/src/test/resources/sample-web-app.war differ diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/pom.xml new file mode 100644 index 0000000000..ed0275a947 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-contribution-namespace + Apache Tuscany SCA Namespace Import/Export Model + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.contribution.namespace + ${pom.name} + org.apache.tuscany.sca.contribution.namespace* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/DefaultNamespaceImportExportFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/DefaultNamespaceImportExportFactory.java new file mode 100644 index 0000000000..a71fa61a54 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/DefaultNamespaceImportExportFactory.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.sca.contribution.namespace; + +import org.apache.tuscany.sca.contribution.namespace.impl.NamespaceImportExportFactoryImpl; + +/** + * Default Namespace Import/Export model factory implementation + * + * @version $Rev$ $Date$ + */ +public class DefaultNamespaceImportExportFactory extends NamespaceImportExportFactoryImpl implements NamespaceImportExportFactory { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.java new file mode 100644 index 0000000000..c68aee8521 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.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.sca.contribution.namespace; + +import org.apache.tuscany.sca.contribution.Export; + + +/** + * The representation of an XML namespace export. + * + * @version $Rev$ $Date$ + */ +public interface NamespaceExport extends Export { + + /** + * Get Namespace that identifies the export + * + * @return The exported namespace + */ + String getNamespace(); + + /** + * Set Namespace that identifies the export + * + * @param namespace The exported namespace + */ + void setNamespace(String namespace); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.java new file mode 100644 index 0000000000..8af36d7da0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.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.sca.contribution.namespace; + +import org.apache.tuscany.sca.contribution.Import; + +/** + * The representation of an XML namespace import. + * + * @version $Rev$ $Date$ + */ +public interface NamespaceImport extends Import { + + /** + * Get the location used to resolve the definitions for this import + * + * @return The import location + */ + String getLocation(); + + /** + * Set the location used to resolve the definitions for this import + * + * @param location The import location + */ + void setLocation(String location); + + /** + * Get Namespace that identifies the import + * + * @return The namespace + */ + String getNamespace(); + + /** + * Set Namespace that identifies the import + * + * @param namespace The namespace + */ + void setNamespace(String namespace); + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.java new file mode 100644 index 0000000000..cfbac8bb1f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.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.sca.contribution.namespace; + +/** + * Base Namespace import/export model factory + * + * @version $Rev$ $Date$ + */ +public interface NamespaceImportExportFactory { + + /** + * Create a namespace import model object + * + * @return The new NamespaceImport model object + */ + NamespaceImport createNamespaceImport(); + + /** + * Create a namespace export model object + * + * @return The new NamespaceExport model object + */ + NamespaceExport createNamespaceExport(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java new file mode 100644 index 0000000000..99af328964 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.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.sca.contribution.namespace.impl; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an export for the contribution + * + * @version $Rev$ $Date$ + */ +public class NamespaceExportImpl extends ExtensibleImpl implements NamespaceExport { + private String namespace; + private ModelResolver modelResolver; + + protected NamespaceExportImpl() { + super(); + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java new file mode 100644 index 0000000000..5c5ae22f77 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.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.sca.contribution.namespace.impl; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A model resolver for namespace exports. + * + * @version $Rev$ $Date$ + */ +public class NamespaceExportModelResolver implements ModelResolver { + + private ModelResolver resolver; + + public NamespaceExportModelResolver(ModelResolver resolver) { + this.resolver = resolver; + } + + public void addModel(Object resolved) { + throw new IllegalStateException(); + } + + public Object removeModel(Object resolved) { + throw new IllegalStateException(); + } + + public T resolveModel(Class modelClass, T unresolved) { + + // Just delegate to the contribution's model resolver, namespace + // based filtering is implemented in the model specific model + // resolver, which know how to get the namespace of the particular + // type of model that they handle + return resolver.resolveModel(modelClass, unresolved); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java new file mode 100644 index 0000000000..25ddb7573b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.namespace.impl; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Artifact processor for Namespace export + * + * @version $Rev$ $Date$ + */ +public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + private static final QName EXPORT = new QName(SCA10_NS, "export"); + private static final String NAMESPACE = "namespace"; + + private final NamespaceImportExportFactory factory; + private final Monitor monitor; + private final ExtensionFactory extensionFactory; + private final StAXArtifactProcessor extensionProcessor; + private final StAXAttributeProcessor attributeProcessor; + + public NamespaceExportProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor attributeProcessor, + Monitor monitor) { + this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class); + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.extensionProcessor = extensionProcessor; + this.attributeProcessor = attributeProcessor; + this.monitor = monitor; + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return EXPORT; + } + + public Class getModelType() { + return NamespaceExport.class; + } + + /** + * Process + */ + public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException { + NamespaceExport namespaceExport = this.factory.createNamespaceExport(); + QName element = null; + + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read + if (EXPORT.equals(element)) { + String ns = reader.getAttributeValue(null, NAMESPACE); + if (ns == null) { + error("AttributeNameSpaceMissing", reader); + //throw new ContributionReadException("Attribute 'namespace' is missing"); + } else { + namespaceExport.setNamespace(ns); + } + readExtendedAttributes(reader, namespaceExport, attributeProcessor, extensionFactory); + } else { + readExtendedElement(reader, namespaceExport, extensionProcessor); + } + + break; + case XMLStreamConstants.END_ELEMENT: + if (EXPORT.equals(reader.getName())) { + return namespaceExport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return namespaceExport; + } + + public void write(NamespaceExport namespaceExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + writer.writeStartElement(EXPORT.getNamespaceURI(), EXPORT.getLocalPart()); + + if (namespaceExport.getNamespace() != null) { + writer.writeAttribute(NAMESPACE, namespaceExport.getNamespace()); + } + + writeExtendedAttributes(writer, namespaceExport, attributeProcessor); + + writeExtendedElements(writer, namespaceExport, extensionProcessor); + + writer.writeEndElement(); + } + + public void resolve(NamespaceExport namespaceExport, ModelResolver resolver) throws ContributionResolveException { + + if (namespaceExport.getNamespace() != null) + // Initialize the export's resolver + namespaceExport.setModelResolver(new NamespaceExportModelResolver(resolver)); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportFactoryImpl.java new file mode 100644 index 0000000000..1146e593a9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportFactoryImpl.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.sca.contribution.namespace.impl; + +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory; + +/** + * Namespace Import/Export model factory implementation + * + * @version $Rev$ $Date$ + */ +public class NamespaceImportExportFactoryImpl implements NamespaceImportExportFactory { + + public NamespaceImport createNamespaceImport() { + return new NamespaceImportImpl(); + } + + public NamespaceExport createNamespaceExport() { + return new NamespaceExportImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportListener.java new file mode 100644 index 0000000000..7ea09a47c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportListener.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.namespace.impl; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.resolver.DefaultImportAllModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionListener; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; + +/** + * Namespace Import/Export contribution listener + * The listener would process all import/export from a given contribution + * and initialize the model resolvers properly + * + * @version $Rev$ $Date$ + */ +public class NamespaceImportExportListener implements ContributionListener { + + /** + * Initialize the import/export model resolvers + * Export model resolvers are same as Contribution model resolver + * Import model resolvers are matched to a specific contribution if a location URI is specified, + * otherwise it try to resolve against all the other contributions + * Also set the exporting contributions used by contribution ClassLoaders to + * match import/export for class loading. + */ + public void contributionAdded(ContributionRepository repository, Contribution contribution) { + // Initialize the contribution exports + for (Export export: contribution.getExports()) { + export.setModelResolver(contribution.getModelResolver()); + } + + // Initialize the contribution imports + for (Import import_: contribution.getImports()) { + boolean initialized = false; + + if (import_ instanceof NamespaceImport) { + NamespaceImport namespaceImport = (NamespaceImport)import_; + + // Find a matching contribution + if (namespaceImport.getLocation() != null) { + Contribution targetContribution = repository.getContribution(namespaceImport.getLocation()); + if (targetContribution != null) { + + // Find a matching contribution export + for (Export export: targetContribution.getExports()) { + if (export instanceof NamespaceExport) { + NamespaceExport namespaceExport = (NamespaceExport)export; + if (namespaceImport.getNamespace().equals(namespaceExport.getNamespace())) { + namespaceImport.setModelResolver(namespaceExport.getModelResolver()); + initialized = true; + break; + } + } + } + } + } + + //if no location was specified, try to resolve with any contribution + if( !initialized ) { + // Use a resolver that will consider all contributions + import_.setModelResolver(new DefaultImportAllModelResolver(import_, repository.getContributions())); + } + } + } + + } + + public void contributionRemoved(ContributionRepository repository, Contribution contribution) { + + } + + public void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution) { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java new file mode 100644 index 0000000000..35e2d539d4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.namespace.impl; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an import for the contribution + * + * @version $Rev$ $Date$ + */ +public class NamespaceImportImpl extends ExtensibleImpl implements NamespaceImport { + private ModelResolver modelResolver; + + /** + * The namespace to be imported + */ + private String namespace; + /** + * Optional location URI pointing to a Contribution that exports the namespace + */ + private String location; + + + protected NamespaceImportImpl() { + super(); + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + + + /** + * Match a NamespaceImport to a given NamespaceExport based on : + * location is not provided + * import and export namespaces match + */ + public boolean match(Export export) { + if (export instanceof NamespaceExport) { + if (this.getNamespace().equals(((NamespaceExport)export).getNamespace())) { + return true; + } + } + return false; + } + + @Override + public String toString() { + return String.valueOf(namespace); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java new file mode 100644 index 0000000000..ab7c76114a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.namespace.impl; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Artifact processor for Namespace import + * + * @version $Rev$ $Date$ + */ +public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + + private static final QName IMPORT = new QName(SCA10_NS, "import"); + + private static final String NAMESPACE = "namespace"; + private static final String LOCATION = "location"; + + private final NamespaceImportExportFactory factory; + private final ExtensionFactory extensionFactory; + private final StAXArtifactProcessor extensionProcessor; + private final StAXAttributeProcessor attributeProcessor; + private final Monitor monitor; + + public NamespaceImportProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor attributeProcessor, + Monitor monitor) { + this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class); + this.monitor = monitor; + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.extensionProcessor = extensionProcessor; + this.attributeProcessor = attributeProcessor; + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return IMPORT; + } + + public Class getModelType() { + return NamespaceImport.class; + } + + /** + * Process + */ + public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException { + NamespaceImport namespaceImport = this.factory.createNamespaceImport(); + QName element; + + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read + if (IMPORT.equals(element)) { + String ns = reader.getAttributeValue(null, NAMESPACE); + if (ns == null) { + error("AttributeNameSpaceMissing", reader); + //throw new ContributionReadException("Attribute 'namespace' is missing"); + } else { + namespaceImport.setNamespace(ns); + } + + String location = reader.getAttributeValue(null, LOCATION); + if (location != null) { + namespaceImport.setLocation(location); + } + readExtendedAttributes(reader, namespaceImport, attributeProcessor, extensionFactory); + } else { + readExtendedElement(reader, namespaceImport, extensionProcessor); + } + break; + case XMLStreamConstants.END_ELEMENT: + if (IMPORT.equals(reader.getName())) { + return namespaceImport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return namespaceImport; + } + + public void write(NamespaceImport namespaceImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + writer.writeStartElement(IMPORT.getNamespaceURI(), IMPORT.getLocalPart()); + + if (namespaceImport.getNamespace() != null) { + writer.writeAttribute(NAMESPACE, namespaceImport.getNamespace()); + } + if (namespaceImport.getLocation() != null) { + writer.writeAttribute(LOCATION, namespaceImport.getLocation()); + } + + writeExtendedAttributes(writer, namespaceImport, attributeProcessor); + writeExtendedElements(writer, namespaceImport, extensionProcessor); + writer.writeEndElement(); + } + + + public void resolve(NamespaceImport model, ModelResolver resolver) throws ContributionResolveException { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory new file mode 100644 index 0000000000..095866fb6f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.namespace.impl.NamespaceImportExportFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..86f199368b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.namespace.impl.NamespaceImportProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#import,model=org.apache.tuscany.sca.contribution.namespace.NamespaceImport +org.apache.tuscany.sca.contribution.namespace.impl.NamespaceExportProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#export,model=org.apache.tuscany.sca.contribution.namespace.NamespaceExport diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener new file mode 100644 index 0000000000..cdf16a383f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.namespace.impl.NamespaceImportExportListener diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties new file mode 100644 index 0000000000..c1cbd06e7f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/main/resources/contribution-namespace-validation-messages.properties @@ -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. +# +# +AttributeNameSpaceMissing = Attribute 'namespace' is missing +XMLStreamException = XMLStreamException occured due to : {0} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java new file mode 100644 index 0000000000..5e213e3729 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.namespace.impl; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; + +/** + * Test NamespaceExportProcessorTestCase + * + * @version $Rev$ $Date$ + */ +public class NamespaceExportProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); + } + + /** + * Test loading a valid export element from a contribution metadata stream + * @throws Exception + */ + public void testLoad() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); + NamespaceExport namespaceExport = (NamespaceExport)staxProcessor.read(reader); + assertEquals("http://foo", namespaceExport.getNamespace()); + assertEquals(1, namespaceExport.getAttributeExtensions().size()); + assertEquals(1, namespaceExport.getExtensions().size()); + } + + /** + * Test loading an INVALID export element from a contribution metadata stream + * @throws Exception + */ + public void testLoadInvalid() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + /*try { + staxProcessor.read(reader); + fail("readerException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + }*/ + staxProcessor.read(reader); + Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + assertNotNull(problem); + assertEquals("AttributeNameSpaceMissing", problem.getMessageId()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java new file mode 100644 index 0000000000..7e889ec3ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.namespace.impl; + + + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; + +/** + * Test NamespaceImportProcessorTestCase + * + * @version $Rev$ $Date$ + */ +public class NamespaceImportProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); + } + + /** + * Test loading a valid import element from a contribution metadata stream + * @throws Exception + */ + public void testLoad() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); + NamespaceImport namespaceImport = (NamespaceImport)staxProcessor.read(reader); + + assertEquals("http://foo", namespaceImport.getNamespace()); + assertEquals("sca://contributions/001", namespaceImport.getLocation()); + assertEquals(1, namespaceImport.getAttributeExtensions().size()); + assertEquals(1, namespaceImport.getExtensions().size()); + } + + /** + * Test loading a INVALID import element from a contribution metadata stream + * @throws Exception + */ + public void testLoadInvalid() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + /*try { + staxProcessor.read(reader); + fail("readerException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + }*/ + staxProcessor.read(reader); + Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + assertNotNull(problem); + assertEquals("AttributeNameSpaceMissing", problem.getMessageId()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/pom.xml new file mode 100644 index 0000000000..244f5fdf9b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/pom.xml @@ -0,0 +1,96 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-contribution-osgi + Apache Tuscany SCA Contribution Service OSGi + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-osgi-runtime + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.felix + org.apache.felix.main + 1.0.4 + + + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.contribution.osgi + ${pom.name} + org.apache.tuscany.sca.contribution.osgi* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/BundleReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/BundleReference.java new file mode 100644 index 0000000000..0bbb8b707a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/BundleReference.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.osgi; + + +/** + * A weak reference to a class, which should be used to register classes + * with an ArtifactResolver and resolve these classes later. + * + * @version $Rev$ $Date$ + */ +public class BundleReference { + + /** + * The bundle. + */ + private Object bundle; + + /** + * The bundle name. + */ + private String bundleName; + + /** + * The bundle version. + */ + private String bundleVersion; + + /** + * The bundle name and version. + */ + private String bundleUniqueName; + + /** + * The bundle relative path. + */ + private String bundleRelativePath; + + /** + * Constructs a new BundleReference. + * + * @param bundle The bundle reference + * @param bundleName The bundle name + * @param bundleVersion The bundle version + * @param bundleRelativePath The relative path for the bundle + */ + public BundleReference(Object bundle, String bundleName, String bundleVersion, String bundleRelativePath) { + this.bundle = bundle; + this.bundleName = bundleName; + this.bundleVersion = bundleVersion; + this.bundleRelativePath = bundleRelativePath; + this.bundleUniqueName = bundleName + "(" + (bundleVersion == null?"0.0.0":bundleVersion) + ")"; + } + + /** + * Constructs a new BundleReference. + * + * @param bundleName The bundle name + * @param bundleVersion The bundle version + */ + public BundleReference(String bundleName, String bundleVersion) { + this.bundleName = bundleName; + this.bundleVersion = bundleVersion; + this.bundleUniqueName = bundleName + "(" + (bundleVersion == null?"0.0.0":bundleVersion) + ")"; + } + + /** + * Get the referenced bundle. + * + * @return The referenced bundle + */ + public Object getBundle() { + return bundle; + } + + /** + * Get the referenced bundle name. + * + * @return The bundle name + */ + public String getBundleName() { + return bundleName; + } + + /** + * Get the referenced bundle version. + * + * @return The bundle version + */ + public String getBundleVersion() { + return bundleVersion; + } + + /** + * Get the referenced bundle name and version. + * + * @return The bundle name + */ + public String getBundleUniqueName() { + return bundleUniqueName; + } + + /** + * Get the relative location of the bundle inside its contribution. + * + * @return The bundle path + */ + public String getBundleRelativePath() { + return bundleRelativePath; + } + + + + /** + * Returns true if the bundle reference is unresolved. + * + * @return Whether or not the bundle has been resolved + */ + public boolean isUnresolved() { + return bundle == null; + } + + @Override + public int hashCode() { + return bundleUniqueName.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else { + if (obj instanceof BundleReference) { + BundleReference ref = (BundleReference)obj; + return bundleName.equals(ref.bundleName) && + (bundleVersion == null || ref.bundleVersion == null || + bundleVersion.equals(ref.bundleVersion)); + } else { + return false; + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleContributionProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleContributionProcessor.java new file mode 100644 index 0000000000..5033d7eefc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleContributionProcessor.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.osgi.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; + +import org.apache.tuscany.sca.contribution.PackageType; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; +import org.osgi.framework.Bundle; + +/** + * Bundle Contribution package processor. + * + * @version $Rev$ $Date$ + */ +public class OSGiBundleContributionProcessor implements PackageProcessor { + + public OSGiBundleContributionProcessor() { + } + + public String getPackageType() { + return PackageType.BUNDLE; + } + + public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException { + Bundle bundle = null; + try { + bundle = OSGiRuntime.findInstalledBundle(sourceURL); + if (bundle != null) { + URL url = bundle.getResource(artifact.getPath()); + if (url == null) + System.out.println("Could not load resource " + artifact); + return url; + } + } catch (Exception e) { + } + return null; + } + + public List getJarArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, + IOException { + if (packageSourceURL == null) { + throw new IllegalArgumentException("Invalid null package source URL."); + } + + if (inputStream == null) { + throw new IllegalArgumentException("Invalid null source inputstream."); + } + + // Assume the root is a jar file + JarInputStream jar = new JarInputStream(inputStream); + try { + Set names = new HashSet(); + while (true) { + JarEntry entry = jar.getNextJarEntry(); + if (entry == null) { + // EOF + break; + } + + // FIXME: Maybe we should externalize the filter as a property + String name = entry.getName(); + if (!name.startsWith(".") && !entry.isDirectory()) { + + // Trim trailing / + if (name.endsWith("/")) { + name = name.substring(0, name.length() - 1); + } + + // Add the entry name + if (!names.contains(name) && name.length() > 0) { + names.add(name); + + } + } + } + + // Return list of URIs + List artifacts = new ArrayList(); + for (String name: names) { + artifacts.add(URI.create(name)); + } + return artifacts; + + } finally { + jar.close(); + } +} + + public List getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, + IOException { + + Bundle bundle = null; + try { + bundle = OSGiRuntime.findInstalledBundle(packageSourceURL); + } catch (Exception e) { + } + + if (bundle == null) { + throw new IllegalArgumentException("Could not find OSGi bundle " + packageSourceURL); + } + + if (packageSourceURL == null) { + throw new IllegalArgumentException("Invalid null package source URL."); + } + + List artifacts = new ArrayList(); + + try { + Enumeration entries = bundle.findEntries("/", "*", true); + while (entries.hasMoreElements()) { + URL entry = (URL)entries.nextElement(); + String entryName = entry.getPath(); + if (entryName.startsWith("/")) + entryName = entryName.substring(1); + artifacts.add(new URI(entryName)); + + if (entryName.endsWith(".jar")) { + + URL jarResource = bundle.getResource(entryName); + artifacts.addAll(getJarArtifacts(jarResource, jarResource.openStream())); + } + + } + } catch (Exception e) { + throw new RuntimeException(e); + } + + return artifacts; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleProcessor.java new file mode 100644 index 0000000000..b3c2302f60 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleProcessor.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.sca.contribution.osgi.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.List; +import java.util.jar.Attributes; +import java.util.jar.JarInputStream; +import java.util.jar.Manifest; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.osgi.BundleReference; +import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; + +/** + * OSGi bundle processor + * + * @version $Rev$ $Date$ + */ +public class OSGiBundleProcessor { + + private boolean initializedOSGi; + private OSGiRuntime osgiRuntime; + + public OSGiBundleProcessor() { + } + + public Object installContributionBundle(Contribution contribution) { + + JarInputStream jar = null; + Object bundle = null; + + try { + + URL contribURL = new URL(contribution.getLocation()); + jar = new JarInputStream(contribURL.openStream()); + + Manifest manifest = jar.getManifest(); + if (manifest != null && manifest.getMainAttributes() + .containsKey(new Attributes.Name("Bundle-SymbolicName"))) { + + initialize(); + if (osgiRuntime != null) + bundle = osgiRuntime.installBundle(contribURL.toString(), null); + } + } catch (Exception e) { + // If OSGi cannot process the jar, treat the bundle as a plain jar file. + } finally { + + try { + if (jar != null) + jar.close(); + } catch (IOException e) { + } + } + + return bundle; + } + + public BundleReference installNestedBundle(Contribution contribution, + String bundleSymbolicName, + String bundleVersion) { + + BundleReference bundleReference = null; + + initialize(); + if (osgiRuntime == null) + return null; + + List artifacts = contribution.getArtifacts(); + for (Artifact a : artifacts) { + if (a.getURI().endsWith(".jar")) { + + InputStream stream; + JarInputStream jar = null; + Object name; + Object version; + try { + + URL artifactURL = new URL(a.getLocation()); + stream = artifactURL.openStream(); + jar = new JarInputStream(artifactURL.openStream()); + Manifest manifest = jar.getManifest(); + name = manifest.getMainAttributes().get(new Attributes.Name("Bundle-SymbolicName")); + version = manifest.getMainAttributes().get(new Attributes.Name("Bundle-Version")); + + if (bundleSymbolicName.equals(name) && (bundleVersion == null || version == null || bundleVersion + .equals(version))) { + + Object bundle = osgiRuntime.installBundle(a.getLocation(), stream); + + bundleReference = new BundleReference(bundle, bundleSymbolicName, bundleVersion, a.getURI()); + + break; + } + + } catch (Exception e) { + + // If OSGi cannot process the jar, treat the bundle as a plain jar file. + } finally { + try { + if (jar != null) + jar.close(); + } catch (IOException e) { + } + } + } + } + return bundleReference; + } + + private void initialize() { + try { + if (!initializedOSGi) { + initializedOSGi = true; + osgiRuntime = OSGiRuntime.getRuntime(); + } + } catch (Exception e) { + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java new file mode 100644 index 0000000000..07e80f66f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.osgi.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.osgi.BundleReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; +import org.osgi.framework.Bundle; + +/** + * A Model Resolver for BundleReferences. + * + * @version $Rev$ $Date$ + */ +public class OSGiBundleReferenceModelResolver implements ModelResolver { + private Contribution contribution; + private Map map = new HashMap(); + + OSGiRuntime osgiRuntime; + private OSGiBundleProcessor bundleProcessor; + + public OSGiBundleReferenceModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + this.bundleProcessor = new OSGiBundleProcessor(); + } + + public void addModel(Object resolved) { + BundleReference bundleRef = (BundleReference)resolved; + map.put(bundleRef.getBundleUniqueName(), bundleRef); + } + + public Object removeModel(Object resolved) { + return map.remove(((BundleReference)resolved).getBundleUniqueName()); + } + + /** + * Handle artifact resolution when the specific class reference is imported from another contribution + * @param unresolved + * @return + */ + private BundleReference resolveImportedModel(BundleReference unresolved) { + BundleReference resolved = unresolved; + + if( this.contribution != null) { + for (Import import_ : this.contribution.getImports()) { + + resolved = import_.getModelResolver().resolveModel(BundleReference.class, unresolved); + if (resolved != unresolved) + break; + } + + } + return resolved; + } + + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + + if (resolved != null ){ + return modelClass.cast(resolved); + } + + try { + if (osgiRuntime == null) + osgiRuntime = OSGiRuntime.getRuntime(); + } catch (Exception e) { + } + if (osgiRuntime == null) + return unresolved; + + //Load a class on demand + Object bundle = null; + String bundleName = ((BundleReference)unresolved).getBundleName(); + String bundleVersion = ((BundleReference)unresolved).getBundleVersion(); + + bundle = osgiRuntime.findBundle(bundleName, bundleVersion); + BundleReference bundleReference; + + if (bundle == null) + bundleReference = bundleProcessor.installNestedBundle(contribution, bundleName, bundleVersion); + else { + bundleReference = new BundleReference(bundle, + ((BundleReference)unresolved).getBundleName(), + bundleVersion, + getBundleFileName(bundle) + ); + } + + + if (bundleReference != null) { + //if we load the class + + map.put(((BundleReference)unresolved).getBundleUniqueName(), bundleReference); + + // Return the resolved BundleReference + return modelClass.cast(bundleReference); + } else { + //delegate resolution of the class + resolved = this.resolveImportedModel((BundleReference)unresolved); + return modelClass.cast(resolved); + } + + + } + + + private String getBundleFileName(Object bundle) { + if (bundle instanceof Bundle) { + String path = ((Bundle)bundle).getLocation(); + if (path.endsWith("/")) + path = path.substring(0, path.length()-1); + if (path.startsWith(contribution.getLocation())) { + if (path.equals(contribution.getLocation())) { + int index = path.lastIndexOf('/'); + if (index > 0 && index < path.length()-1) + path = path.substring(index+1); + } else { + path = path.substring(contribution.getLocation().length()); + if (path.startsWith("/")) + path = path.substring(1); + } + } else if (path.lastIndexOf('/') >= 0) + path = path.substring(path.lastIndexOf('/')+1); + return path; + } + return null; + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java new file mode 100644 index 0000000000..39cdd6fcd3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.osgi.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; +import org.osgi.framework.Bundle; + +/** + * A Model Resolver for ClassReferences. + * + * @version $Rev$ $Date$ + */ +public class OSGiClassReferenceModelResolver implements ModelResolver { + private Contribution contribution; + private Map map = new HashMap(); + private Bundle bundle; + private boolean initialized; + private boolean useOSGi; + + public OSGiClassReferenceModelResolver(Contribution contribution, ExtensionPointRegistry registry) { + this.contribution = contribution; + } + + public void addModel(Object resolved) { + ClassReference clazz = (ClassReference)resolved; + map.put(clazz.getClassName(), clazz); + } + + public Object removeModel(Object resolved) { + return map.remove(((ClassReference)resolved).getClassName()); + } + + /** + * Handle artifact resolution when the specific class reference is imported from another contribution + * @param unresolved + * @return + */ + private ClassReference resolveImportedModel(ClassReference unresolved) { + ClassReference resolved = unresolved; + + if (this.contribution != null) { + for (Import import_ : this.contribution.getImports()) { + + if (resolved == unresolved && bundle != null) { + resolved = import_.getModelResolver().resolveModel(ClassReference.class, unresolved); + if (resolved != unresolved) + break; + } + } + + } + return resolved; + } + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + + if (resolved != null) { + return modelClass.cast(resolved); + } + initialize(); + if (!useOSGi) + return unresolved; + + //Load a class on demand + Class clazz = null; + if (bundle != null) { + try { + clazz = bundle.loadClass(((ClassReference)unresolved).getClassName()); + } catch (Exception e) { + // we will later try to delegate to imported model resolvers + } + } + + if (clazz != null) { + //if we load the class + // Store a new ClassReference wrapping the loaded class + ClassReference classReference = new ClassReference(clazz); + map.put(getPackageName(classReference), classReference); + + // Return the resolved ClassReference + return modelClass.cast(classReference); + } else { + //delegate resolution of the class + resolved = this.resolveImportedModel((ClassReference)unresolved); + return modelClass.cast(resolved); + } + + } + + /*************** + * Helper methods + ***************/ + + private String getPackageName(ClassReference clazz) { + int pos = clazz.getClassName().lastIndexOf("."); + return clazz.getClassName().substring(0, pos - 1); + } + + private void initialize() { + if (initialized) + return; + + initialized = true; + try { + bundle = OSGiRuntime.findInstalledBundle(contribution.getLocation()); + useOSGi = bundle != null; + } catch (Throwable e) { + // Ignore errors, default to ClassReferenceModelResolver + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiImportExportListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiImportExportListener.java new file mode 100644 index 0000000000..15ad0bd948 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiImportExportListener.java @@ -0,0 +1,215 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.osgi.impl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.URL; +import java.util.HashSet; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.service.ContributionListener; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; +import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; + +/** + * Namespace Import/Export contribution listener + * The listener would process all import/export from a given contribution + * and initialize the model resolvers properly + * + * @version $Rev$ $Date$ + */ +public class OSGiImportExportListener implements ContributionListener { + + private OSGiBundleProcessor bundleProcessor; + + public OSGiImportExportListener() { + bundleProcessor = new OSGiBundleProcessor(); + } + + /** + * Initialize the import/export model resolvers + * Export model resolvers are same as Contribution model resolver + * Import model resolvers are matched to a specific contribution if a location URI is specified, + * otherwise it try to resolve against all the other contributions + */ + public void contributionAdded(ContributionRepository repository, Contribution contribution) { + + OSGiRuntime osgiRuntime = null; + try { + if (bundleProcessor.installContributionBundle(contribution) == null) { + return; + } else { + osgiRuntime = OSGiRuntime.getRuntime(); + } + } catch (Exception e) { + return; + } + + HashSet bundlesToInstall = new HashSet(); + // Initialize the contribution imports + for (Import import_ : contribution.getImports()) { + boolean initialized = false; + + if (import_ instanceof JavaImport) { + JavaImport javaImport = (JavaImport)import_; + String packageName = javaImport.getPackage(); + + //Find a matching contribution + if (javaImport.getLocation() != null) { + Contribution targetContribution = repository.getContribution(javaImport.getLocation()); + if (targetContribution != null) { + + // Find a matching contribution export + for (Export export : targetContribution.getExports()) { + if (export instanceof JavaExport) { + JavaExport javaExport = (JavaExport)export; + if (packageName.equals(javaExport.getPackage())) { + + if (osgiRuntime.findBundle(targetContribution.getLocation()) == null) + bundlesToInstall.add(targetContribution); + + initialized = true; + + } + } + if (initialized) + break; + } + } + } + } + if (!initialized) { + for (Contribution c : repository.getContributions()) { + + // Go over all exports in the contribution + for (Export export : c.getExports()) { + // If the export matches our namespace, try to the resolve the model object + if (import_.match(export) && osgiRuntime.findBundle(c.getLocation()) == null) { + bundlesToInstall.add(c); + } + } + } + } + } + for (Contribution c : bundlesToInstall) { + try { + installDummyBundle(osgiRuntime, c); + } catch (Exception e) { + } + } + + } + + public void contributionRemoved(ContributionRepository repository, Contribution contribution) { + + } + + public void contributionUpdated(ContributionRepository repository, + Contribution oldContribution, + Contribution contribution) { + + } + + private void installDummyBundle(OSGiRuntime osgiRuntime, Contribution contribution) throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + String EOL = System.getProperty("line.separator"); + + String bundleName = contribution.getURI(); + URL contribURL = new URL(contribution.getLocation()); + String contribName = contribURL.getPath(); + if (contribName.endsWith("/")) + contribName = contribName.substring(0, contribName.length()-1); + if (contribName.lastIndexOf("/") >= 0) + contribName = contribName.substring(contribName.lastIndexOf("/")+1); + + StringBuffer exportPackageNames = new StringBuffer(); + for (Export export : contribution.getExports()) { + if (export instanceof JavaExport) { + if (exportPackageNames.length() > 0) + exportPackageNames.append(","); + exportPackageNames.append(((JavaExport)export).getPackage()); + } + } + StringBuffer importPackageNames = new StringBuffer(); + for (Import import_ : contribution.getImports()) { + if (import_ instanceof JavaImport) { + if (importPackageNames.length() > 0) + importPackageNames.append(","); + importPackageNames.append(((JavaImport)import_).getPackage()); + } + } + + String manifestStr = + "Manifest-Version: 1.0" + EOL + + "Bundle-ManifestVersion: 2" + + EOL + + "Bundle-Name: " + + bundleName + + EOL + + "Bundle-SymbolicName: " + + bundleName + + EOL + + "Bundle-Version: " + + "1.0.0" + + EOL + + "Bundle-Localization: plugin" + + EOL; + + StringBuilder manifestBuf = new StringBuilder(); + manifestBuf.append(manifestStr); + manifestBuf.append("Export-Package: " + exportPackageNames + EOL); + manifestBuf.append("Import-Package: " + importPackageNames + EOL); + manifestBuf.append("Bundle-ClassPath: .," + contribName + EOL); + + ByteArrayInputStream manifestStream = new ByteArrayInputStream(manifestBuf.toString().getBytes()); + Manifest manifest = new Manifest(); + manifest.read(manifestStream); + + JarOutputStream jarOut = new JarOutputStream(out, manifest); + + ZipEntry ze = new ZipEntry(contribName); + jarOut.putNextEntry(ze); + InputStream stream = contribURL.openStream(); + + byte[] bytes = new byte[stream.available()]; + stream.read(bytes); + jarOut.write(bytes); + stream.close(); + + jarOut.close(); + out.close(); + + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + + osgiRuntime.installBundle("file://" + bundleName + ".jar", in); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiModelResolverImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiModelResolverImpl.java new file mode 100644 index 0000000000..e624b1d3b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiModelResolverImpl.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.sca.contribution.osgi.impl; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.osgi.BundleReference; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.osgi.framework.Bundle; + +/** + * An implementation of an artifact resolver for OSGi bundles. + * + * @version $Rev$ $Date$ + */ +public class OSGiModelResolverImpl implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map map = new HashMap(); + + private Hashtable bundles; + public OSGiModelResolverImpl(Hashtable bundles) { + this.bundles = bundles; + } + + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + if (resolved != null) { + + // Return the resolved object + return modelClass.cast(resolved); + + } else if (unresolved instanceof ClassReference) { + + // Load a class on demand + ClassReference classReference = (ClassReference)unresolved; + Class clazz = null; + for (Bundle bundle : bundles.values()) { + try { + clazz = bundle.loadClass(classReference.getClassName()); + } catch (ClassNotFoundException e) { + continue; + } + break; + } + if (clazz == null) { + + // Return the unresolved object + return unresolved; + } + + // Store a new ClassReference wrapping the loaded class + resolved = new ClassReference(clazz); + map.put(resolved, resolved); + + // Return the resolved ClassReference + return modelClass.cast(resolved); + + } else if (unresolved instanceof BundleReference) { + for (String bundlePath: bundles.keySet()) { + Bundle bundle = bundles.get(bundlePath); + BundleReference bundleRef = (BundleReference)unresolved; + String bundleVersion = (String)bundle.getHeaders().get("Bundle-Version"); + if (bundle.getSymbolicName().equals(bundleRef.getBundleName())&& + (bundleVersion == null || bundleRef.getBundleVersion() == null || + bundleVersion.equals(bundleRef.getBundleVersion()))) { + + resolved = new BundleReference(bundle, + bundle.getSymbolicName(), + bundleVersion, + bundlePath); + map.put(resolved, resolved); + + // Return the resolved BundleReference + return modelClass.cast(resolved); + + } + } + } + + // Return the unresolved object + return unresolved; + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(resolved); + } + + public Collection getModels() { + return map.values(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor new file mode 100644 index 0000000000..632d135cb5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.osgi.impl.OSGiBundleContributionProcessor;type=application/osgi.bundle diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..02e8b411eb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.osgi.impl.OSGiBundleReferenceModelResolver;model=org.apache.tuscany.sca.contribution.osgi.BundleReference diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener new file mode 100644 index 0000000000..8dec190930 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.osgi.impl.OSGiImportExportListener diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/pom.xml new file mode 100644 index 0000000000..19fa153548 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-contribution-resource + Apache Tuscany SCA Resource Import/Export Model + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.contribution.resource + ${pom.name} + org.apache.tuscany.sca.contribution.resource* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceExport.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceExport.java new file mode 100644 index 0000000000..0bd30c19dd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceExport.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.sca.contribution.resource; + +import org.apache.tuscany.sca.contribution.Export; + + +/** + * The representation of an resource export. + * + * @version $Rev$ $Date$ + */ +public interface ResourceExport extends Export { + + /** + * Get Resource URI that identifies the export. + * + * @return The exported resource URI + */ + String getURI(); + + /** + * Set Resource URI that identifies the export. + * + * @param uri The exported resource URI + */ + void setURI(String uri); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceImport.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceImport.java new file mode 100644 index 0000000000..07eac9d843 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceImport.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.sca.contribution.resource; + +import org.apache.tuscany.sca.contribution.Import; + +/** + * The representation of an resource import. + * + * @version $Rev$ $Date$ + */ +public interface ResourceImport extends Import { + + /** + * Get the location used to resolve the definitions for this import + * + * @return The import location + */ + String getLocation(); + + /** + * Set the location used to resolve the definitions for this import + * + * @param location The import location + */ + void setLocation(String location); + + /** + * Get URI that identifies the resource import + * + * @return The URI + */ + String getURI(); + + /** + * Set URI that identifies the resource import + * + * @param uri The resource URI + */ + void setURI(String uri); + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceImportExportFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceImportExportFactory.java new file mode 100644 index 0000000000..4119c344ce --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/ResourceImportExportFactory.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.sca.contribution.resource; + +/** + * Base Resource import/export model factory + * + * @version $Rev$ $Date$ + */ +public interface ResourceImportExportFactory { + + /** + * Create a resource import model object + * + * @return The new ResourceImport model object + */ + ResourceImport createResourceImport(); + + /** + * Create a resource export model object + * + * @return The new ResourceExport model object + */ + ResourceExport createResourceExport(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ArtifactModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ArtifactModelResolver.java new file mode 100644 index 0000000000..67836748fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ArtifactModelResolver.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.sca.contribution.resource.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resource.ResourceImport; + +/** + * A Model Resolver for contribution artifacts. + * + * @version $Rev$ $Date$ + */ +public class ArtifactModelResolver implements ModelResolver { + private Contribution contribution; + private Map map = new HashMap(); + + public ArtifactModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + } + + public void addModel(Object resolved) { + Artifact artifact = (Artifact)resolved; + map.put(artifact.getURI(), artifact); + } + + public Object removeModel(Object resolved) { + return map.remove(((Artifact)resolved).getURI()); + } + + public T resolveModel(Class modelClass, T unresolved) { + + // Get the artifact URI + String uri = ((Artifact)unresolved).getURI(); + if (uri == null) { + return (T)unresolved; + } + + // Lookup the artifact + Artifact resolved = (Artifact) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } + + // If not found, delegate the resolution to the imports (in this case based on the resource imports) + for (Import import_ : this.contribution.getImports()) { + if (import_ instanceof ResourceImport) { + ResourceImport resourceImport = (ResourceImport)import_; + //check the import location against the computed package name from the componentType URI + if ((resourceImport.getURI().equals(uri)) && + (resourceImport.getModelResolver() != null)){ + // Delegate the resolution to the import resolver + resolved = resourceImport.getModelResolver().resolveModel(Artifact.class, (Artifact)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } + } + } + + return (T)unresolved; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportImpl.java new file mode 100644 index 0000000000..50ba5bcd6f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportImpl.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.sca.contribution.resource.impl; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resource.ResourceExport; + +/** + * The representation of an export for the contribution + * + * @version $Rev$ $Date$ + */ +public class ResourceExportImpl extends ExtensibleImpl implements ResourceExport { + /** + * The resource URI to be exported + */ + private String uri; + + private ModelResolver modelResolver; + + protected ResourceExportImpl() { + super(); + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportModelResolver.java new file mode 100644 index 0000000000..fd568e533d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportModelResolver.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.sca.contribution.resource.impl; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resource.ResourceExport; + +/** + * A model resolver for resource exports. + * + * @version $Rev$ $Date$ + */ +public class ResourceExportModelResolver implements ModelResolver { + + private ResourceExport export; + private ModelResolver resolver; + + public ResourceExportModelResolver(ResourceExport export, ModelResolver resolver) { + this.export = export; + this.resolver = resolver; + } + + public void addModel(Object resolved) { + throw new IllegalStateException(); + } + + public Object removeModel(Object resolved) { + throw new IllegalStateException(); + } + + public T resolveModel(Class modelClass, T unresolved) { + + // Filter based on the artifact URI + Artifact artifact = (Artifact)unresolved; + if (export.getURI().equals(artifact.getURI())) { + + // The artifact URI matches the exported URI, delegate to the + // contribution's resolver + return resolver.resolveModel(modelClass, unresolved); + } else { + + // The artifact URI is not exported, return the unresolved object + return unresolved; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java new file mode 100644 index 0000000000..dcd806776f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessor.java @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resource.impl; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resource.ResourceExport; +import org.apache.tuscany.sca.contribution.resource.ResourceImportExportFactory; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Artifact processor for Resource export + * + * @version $Rev$ $Date$ + */ +public class ResourceExportProcessor implements StAXArtifactProcessor { + + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + private static final QName EXPORT_RESOURCE = new QName(SCA10_NS, "export.resource"); + private static final String URI = "uri"; + + private final ResourceImportExportFactory factory; + private final Monitor monitor; + + public ResourceExportProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + this.factory = modelFactories.getFactory(ResourceImportExportFactory.class); + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return EXPORT_RESOURCE; + } + + public Class getModelType() { + return ResourceExport.class; + } + + /** + * Process + */ + public ResourceExport read(XMLStreamReader reader) throws ContributionReadException { + ResourceExport resourceExport = this.factory.createResourceExport(); + QName element = null; + + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read + if (EXPORT_RESOURCE.equals(element)) { + String uri = reader.getAttributeValue(null, URI); + if (uri == null) { + error("AttributeURIMissing", reader); + //throw new ContributionReadException("Attribute 'uri' is missing"); + } else + resourceExport.setURI(uri); + } + + break; + case XMLStreamConstants.END_ELEMENT: + if (EXPORT_RESOURCE.equals(reader.getName())) { + return resourceExport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return resourceExport; + } + + public void write(ResourceExport resourceExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + writer.writeStartElement(EXPORT_RESOURCE.getNamespaceURI(), EXPORT_RESOURCE.getLocalPart()); + + if (resourceExport.getURI() != null) { + writer.writeAttribute(URI, resourceExport.getURI()); + } + + writer.writeEndElement(); + } + + public void resolve(ResourceExport resourceExport, ModelResolver resolver) throws ContributionResolveException { + + if (resourceExport.getURI() != null) + // Initialize the export's model resolver + resourceExport.setModelResolver(new ResourceExportModelResolver(resourceExport, resolver)); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportExportFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportExportFactoryImpl.java new file mode 100644 index 0000000000..880f5f5786 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportExportFactoryImpl.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.sca.contribution.resource.impl; + +import org.apache.tuscany.sca.contribution.resource.ResourceExport; +import org.apache.tuscany.sca.contribution.resource.ResourceImport; +import org.apache.tuscany.sca.contribution.resource.ResourceImportExportFactory; + +/** + * Resource Import/Export model factory implementation + * + * @version $Rev$ $Date$ + */ +public class ResourceImportExportFactoryImpl implements ResourceImportExportFactory { + + public ResourceImport createResourceImport() { + return new ResourceImportImpl(); + } + + public ResourceExport createResourceExport() { + return new ResourceExportImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportExportListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportExportListener.java new file mode 100644 index 0000000000..e7aecad786 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportExportListener.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resource.impl; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.resolver.DefaultImportAllModelResolver; +import org.apache.tuscany.sca.contribution.resource.ResourceExport; +import org.apache.tuscany.sca.contribution.resource.ResourceImport; +import org.apache.tuscany.sca.contribution.service.ContributionListener; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; + +/** + * Resource Import/Export contribution listener + * The listener would process all import/export from a given contribution + * and initialize the model resolvers properly + * + * @version $Rev$ $Date$ + */ +public class ResourceImportExportListener implements ContributionListener { + + /** + * Initialize the import/export model resolvers + * Export model resolvers are same as Contribution model resolver + * Import model resolvers are matched to a specific contribution if a location URI is specified, + * otherwise it try to resolve against all the other contributions + * Also set the exporting contributions used by contribution ClassLoaders to + * match import/export for class loading. + */ + public void contributionAdded(ContributionRepository repository, Contribution contribution) { + // Initialize the contribution exports + for (Export export: contribution.getExports()) { + export.setModelResolver(contribution.getModelResolver()); + } + + // Initialize the contribution imports + for (Import import_: contribution.getImports()) { + boolean initialized = false; + + if (import_ instanceof ResourceImport) { + ResourceImport resourceImport = (ResourceImport)import_; + + // Find a matching contribution + if (resourceImport.getLocation() != null) { + Contribution targetContribution = repository.getContribution(resourceImport.getLocation()); + if (targetContribution != null) { + + // Find a matching contribution export + for (Export export: targetContribution.getExports()) { + if (export instanceof ResourceExport) { + ResourceExport resourceExport = (ResourceExport)export; + if (resourceImport.getURI().equals(resourceExport.getURI())) { + resourceImport.setModelResolver(resourceExport.getModelResolver()); + initialized = true; + break; + } + } + } + } + } + + //if no location was specified, try to resolve with any contribution + if( !initialized ) { + // Use a resolver that will consider all contributions + import_.setModelResolver(new DefaultImportAllModelResolver(import_, repository.getContributions())); + } + } + } + } + + public void contributionRemoved(ContributionRepository repository, Contribution contribution) { + + } + + public void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution) { + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportImpl.java new file mode 100644 index 0000000000..6a862a2f04 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportImpl.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resource.impl; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resource.ResourceExport; +import org.apache.tuscany.sca.contribution.resource.ResourceImport; + +/** + * The representation of an import for the contribution + * + * @version $Rev$ $Date$ + */ +public class ResourceImportImpl extends ExtensibleImpl implements ResourceImport { + /** + * The resource URI to be imported + */ + private String uri; + + private ModelResolver modelResolver; + private List exportContributions; + + /** + * Optional location URI pointing to a Contribution that exports the resource + */ + private String location; + + protected ResourceImportImpl() { + super(); + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + + public List getExportContributions() { + return exportContributions; + } + + public void setExportContributions(List contributions) { + this.exportContributions = contributions; + } + + /** + * Match a ResourceImport to a given ResourceExport based on : + * location is not provided + * import and export resource URI match + */ + public boolean match(Export export) { + if (export instanceof ResourceExport) { + if (this.getLocation() == null || this.getLocation().length() == 0) { + if (this.getURI().equals(((ResourceExport)export).getURI())) { + return true; + } + } + + } + return false; + } + + @Override + public String toString() { + return String.valueOf(uri); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java new file mode 100644 index 0000000000..e5d30b389a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessor.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resource.impl; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resource.ResourceImport; +import org.apache.tuscany.sca.contribution.resource.ResourceImportExportFactory; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Artifact processor for Namespace import + * + * @version $Rev$ $Date$ + */ +public class ResourceImportProcessor implements StAXArtifactProcessor { + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + + private static final QName IMPORT_RESOURCE = new QName(SCA10_NS, "import.resource"); + + private static final String URI = "uri"; + private static final String LOCATION = "location"; + + private final ResourceImportExportFactory factory; + private final Monitor monitor; + + public ResourceImportProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + this.factory = modelFactories.getFactory(ResourceImportExportFactory.class); + this.monitor = monitor; + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-resource-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return IMPORT_RESOURCE; + } + + public Class getModelType() { + return ResourceImport.class; + } + + /** + * Process + */ + public ResourceImport read(XMLStreamReader reader) throws ContributionReadException { + ResourceImport resourceImport = this.factory.createResourceImport(); + QName element; + + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read + if (IMPORT_RESOURCE.equals(element)) { + String uri = reader.getAttributeValue(null, URI); + if (uri == null) { + error("AttributeURIMissing", reader); + //throw new ContributionReadException("Attribute 'uri' is missing"); + } else + resourceImport.setURI(uri); + + String location = reader.getAttributeValue(null, LOCATION); + if (location != null) { + resourceImport.setLocation(location); + } + } + break; + case XMLStreamConstants.END_ELEMENT: + if (IMPORT_RESOURCE.equals(reader.getName())) { + return resourceImport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return resourceImport; + } + + public void write(ResourceImport resourceImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + writer.writeStartElement(IMPORT_RESOURCE.getNamespaceURI(), IMPORT_RESOURCE.getLocalPart()); + + if (resourceImport.getURI() != null) { + writer.writeAttribute(URI, resourceImport.getURI()); + } + if (resourceImport.getLocation() != null) { + writer.writeAttribute(LOCATION, resourceImport.getLocation()); + } + + writer.writeEndElement(); + } + + + public void resolve(ResourceImport model, ModelResolver resolver) throws ContributionResolveException { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..14eb81546d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.resource.impl.ResourceImportProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#import.resource,model=org.apache.tuscany.sca.contribution.resource.ResourceImport +org.apache.tuscany.sca.contribution.resource.impl.ResourceExportProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#export.resource,model=org.apache.tuscany.sca.contribution.resource.ResourceExport diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..08d2b1c338 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.resource.impl.ArtifactModelResolver;model=org.apache.tuscany.sca.contribution.Artifact \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resource.ResourceImportExportFactory b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resource.ResourceImportExportFactory new file mode 100644 index 0000000000..d39a5065c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resource.ResourceImportExportFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.resource.impl.ResourceImportExportFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener new file mode 100644 index 0000000000..f4751db9aa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.resource.impl.ResourceImportExportListener diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties new file mode 100644 index 0000000000..9df66cce52 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/main/resources/contribution-resource-validation-messages.properties @@ -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. +# +# +AttributeURIMissing = Attribute 'uri' is missing +XMLStreamException = XMLStreamException occured due to : {0} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.java new file mode 100644 index 0000000000..ea44cb506b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.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.sca.contribution.resource.impl; + + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resource.ResourceExport; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; + +/** + * Test NamespaceExportProcessorTestCase + * + * @version $Rev$ $Date$ + */ +public class ResourceExportProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + ""; + + private static final String INVALID_XML = + "" + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + } + + /** + * Test loading a valid export element from a contribution metadata stream + * @throws Exception + */ + public void testLoad() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); + ResourceExport resourceExport = (ResourceExport)staxProcessor.read(reader); + assertEquals("helloworld/HelloWorldService.componentType", resourceExport.getURI()); + } + + /** + * Test loading an INVALID export element from a contribution metadata stream + * @throws Exception + */ + public void testLoadInvalid() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + /*try { + staxProcessor.read(reader); + fail("readerException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + }*/ + staxProcessor.read(reader); + Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + assertNotNull(problem); + assertEquals("AttributeURIMissing", problem.getMessageId()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessorTestCase.java new file mode 100644 index 0000000000..1ff931c162 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceImportProcessorTestCase.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.sca.contribution.resource.impl; + + + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resource.ResourceImport; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; + +/** + * Test NamespaceImportProcessorTestCase + * + * @version $Rev$ $Date$ + */ +public class ResourceImportProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + ""; + + private static final String INVALID_XML = + "" + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + } + + /** + * Test loading a valid import element from a contribution metadata stream + * @throws Exception + */ + public void testLoad() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); + ResourceImport namespaceImport = (ResourceImport)staxProcessor.read(reader); + assertEquals("helloworld/HelloWorldService.componentType", namespaceImport.getURI()); + assertEquals("sca://contributions/001", namespaceImport.getLocation()); + } + + /** + * Test loading a INVALID import element from a contribution metadata stream + * @throws Exception + */ + public void testLoadInvalid() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + /*try { + staxProcessor.read(reader); + fail("readerException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + }*/ + staxProcessor.read(reader); + Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + assertNotNull(problem); + assertEquals("AttributeURIMissing", problem.getMessageId()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/pom.xml new file mode 100644 index 0000000000..c0614b8687 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/pom.xml @@ -0,0 +1,70 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-contribution-xml + Apache Tuscany SCA XML Contribution Model + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.contribution.xml + ${pom.name} + org.apache.tuscany.sca.contribution.xml* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java new file mode 100644 index 0000000000..0031063c79 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.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.sca.contribution.processor.xml; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.contribution.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A Policy Processor used for testing. + * + * @version $Rev$ $Date$ + */ +public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements StAXAttributeProcessor { + private static final QName ANY_ATTRIBUTE = new QName(Constants.XMLSCHEMA_NS, "anyAttribute"); + + private ExtensionFactory extensionFactory; + + public AnyAttributeProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + } + + public QName getArtifactType() { + return ANY_ATTRIBUTE; + } + + public Class getModelType() { + return Extension.class; + } + + public Extension read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + String attributeValue = reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart()); + return extensionFactory.createExtension(attributeName, attributeValue, true); + } + + public void write(Extension attributeExtension, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + writer.writeAttribute(attributeExtension.getQName().getPrefix(), + attributeExtension.getQName().getNamespaceURI(), + attributeExtension.getQName().getLocalPart(), + attributeExtension.getValue().toString()); //for extended attributes, we can assume values + // are just the string representation fo the attribute + } + + public void resolve(Extension arg0, ModelResolver arg1) throws ContributionResolveException { + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java new file mode 100644 index 0000000000..6e6803a806 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor.xml; + +import static javax.xml.stream.XMLStreamConstants.CDATA; +import static javax.xml.stream.XMLStreamConstants.CHARACTERS; +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.stream.events.XMLEvent; + +import org.apache.tuscany.sca.contribution.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.monitor.Monitor; + +public class AnyElementProcessor implements StAXArtifactProcessor { + private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS, "anyElement"); + + private XMLInputFactory xmlInputFactory; + @SuppressWarnings("unused") + private Monitor monitor; + + // Map map = new HashMap(); + + public AnyElementProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + xmlInputFactory = modelFactories.getFactory(XMLInputFactory.class); + this.monitor = monitor; + } + + public QName getArtifactType() { + return ANY_ELEMENT; + } + + public Class getModelType() { + return Object.class; + } + + /** + * Reads the contetns of the unknown elements and generates a custom + * implementation of XMLStreamReader i.e. XMLEventsStreamReader + * + * @param reader + * @return + * @throws XMLStreamException + */ + @SuppressWarnings("unchecked") + public Object read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + + // Custom variables + String currentElement = null; + List eventsList = new ArrayList(); + + Map eventContext = new HashMap(); + + try { + // Cast the block of unknown elements into document + XMLDocumentStreamReader docReader = new XMLDocumentStreamReader(reader); + + XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(docReader); + + while (xmlEventReader.hasNext()) { + XMLEvent event = xmlEventReader.nextEvent(); + + // Populate the eventContext map with the current element's name + // and corresponding NamesapceContext + if (currentElement != null && !(eventContext.containsKey(currentElement))) { + eventContext.put(currentElement, reader.getNamespaceContext()); + } + + // Populate the list with the XMLEvents + eventsList.add(event); + if (event.isStartElement()) { + currentElement = reader.getName().getLocalPart(); + } + if (event.isEndDocument()) { + return new XMLEventsStreamReader(eventsList, eventContext); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * Writes unknown portions back to the writer + * + * @param model + * @param writer + */ + public void write(Object model, XMLStreamWriter writer) throws XMLStreamException { + if (!(model instanceof XMLStreamReader)) { + return; + } + XMLStreamReader reader = (XMLStreamReader)model; + + int event = reader.getEventType(); + while (reader.hasNext()) { + switch (event) { + case START_ELEMENT: + + writer.writeStartElement(reader.getPrefix(), reader.getLocalName(), reader.getNamespaceURI()); + for (int i = 1; i <= reader.getAttributeCount(); i++) { + writer.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader + .getAttributeLocalName(i), reader.getAttributeValue(i)); + } + break; + + case CHARACTERS: + writer.writeCharacters(reader.getText()); + break; + + case CDATA: + writer.writeCData(reader.getText()); + break; + + case END_ELEMENT: + writer.writeEndElement(); + break; + } + if (reader.hasNext()) { + event = reader.next(); + } + } + } + + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + // TODO Auto-generated method stub + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java new file mode 100644 index 0000000000..d326324a5d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java @@ -0,0 +1,486 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor.xml; + +import java.util.NoSuchElementException; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +/** + * This class is derived from Apache Axis2 class + * org.apache.axis2.util.StreamWrapper. It's used wrap a XMLStreamReader to + * create a XMLStreamReader representing a document and it will produce + * START_DOCUMENT, END_DOCUMENT events. + * + * @version $Rev: 659153 $ $Date: 2008-05-22 09:43:58 -0700 (Thu, 22 May 2008) $ + */ +public class XMLDocumentStreamReader implements XMLStreamReader { + private static final int STATE_COMPLETE_AT_NEXT = 2; // The wrapper + // will produce + // END_DOCUMENT + + private static final int STATE_COMPLETED = 3; // Done + + private static final int STATE_INIT = 0; // The wrapper will produce + // START_DOCUMENT + + private static final int STATE_SWITCHED = 1; // The real reader will + // produce events + + private XMLStreamReader realReader; + private boolean fragment; + private int level = 0; + + private int state = STATE_INIT; + + public XMLDocumentStreamReader(XMLStreamReader realReader) { + if (realReader == null) { + throw new UnsupportedOperationException("Reader cannot be null"); + } + + this.realReader = realReader; + + if (realReader instanceof XMLFragmentStreamReader) { + ((XMLFragmentStreamReader)realReader).init(); + } + + // If the real reader is positioned at START_DOCUMENT, always use + // the real reader + if (realReader.getEventType() == START_DOCUMENT) { + fragment = false; + state = STATE_SWITCHED; + } + } + + public void close() throws XMLStreamException { + realReader.close(); + } + + public int getAttributeCount() { + if (isDelegating()) { + return realReader.getAttributeCount(); + } else { + throw new IllegalStateException(); + } + } + + public String getAttributeLocalName(int i) { + if (isDelegating()) { + return realReader.getAttributeLocalName(i); + } else { + throw new IllegalStateException(); + } + } + + public QName getAttributeName(int i) { + if (isDelegating()) { + return realReader.getAttributeName(i); + } else { + throw new IllegalStateException(); + } + } + + public String getAttributeNamespace(int i) { + if (isDelegating()) { + return realReader.getAttributeNamespace(i); + } else { + throw new IllegalStateException(); + } + } + + public String getAttributePrefix(int i) { + if (isDelegating()) { + return realReader.getAttributePrefix(i); + } else { + throw new IllegalStateException(); + } + } + + public String getAttributeType(int i) { + if (isDelegating()) { + return realReader.getAttributeType(i); + } else { + throw new IllegalStateException(); + } + } + + public String getAttributeValue(int i) { + if (isDelegating()) { + return realReader.getAttributeValue(i); + } else { + throw new IllegalStateException(); + } + } + + public String getAttributeValue(String s, String s1) { + if (isDelegating()) { + return realReader.getAttributeValue(s, s1); + } else { + throw new IllegalStateException(); + } + } + + public String getCharacterEncodingScheme() { + if (isDelegating()) { + return realReader.getCharacterEncodingScheme(); + } else { + return "UTF-8"; + } + } + + public String getElementText() throws XMLStreamException { + if (isDelegating()) { + return realReader.getElementText(); + } else { + throw new XMLStreamException(); + } + } + + public String getEncoding() { + return realReader.getEncoding(); + } + + public int getEventType() { + int event = -1; + switch (state) { + case STATE_SWITCHED: + case STATE_COMPLETE_AT_NEXT: + event = realReader.getEventType(); + break; + case STATE_INIT: + event = START_DOCUMENT; + break; + case STATE_COMPLETED: + event = END_DOCUMENT; + break; + } + return event; + } + + public String getLocalName() { + if (isDelegating()) { + return realReader.getLocalName(); + } else { + throw new IllegalStateException(); + } + } + + public Location getLocation() { + if (isDelegating()) { + return realReader.getLocation(); + } else { + return null; + } + } + + public QName getName() { + if (isDelegating()) { + return realReader.getName(); + } else { + throw new IllegalStateException(); + } + } + + public NamespaceContext getNamespaceContext() { + return realReader.getNamespaceContext(); + } + + public int getNamespaceCount() { + if (isDelegating()) { + return realReader.getNamespaceCount(); + } else { + throw new IllegalStateException(); + } + } + + public String getNamespacePrefix(int i) { + if (isDelegating()) { + return realReader.getNamespacePrefix(i); + } else { + throw new IllegalStateException(); + } + } + + public String getNamespaceURI() { + if (isDelegating()) { + return realReader.getNamespaceURI(); + } else { + throw new IllegalStateException(); + } + } + + public String getNamespaceURI(int i) { + if (isDelegating()) { + return realReader.getNamespaceURI(i); + } else { + throw new IllegalStateException(); + } + } + + public String getNamespaceURI(String s) { + if (isDelegating()) { + return realReader.getNamespaceURI(s); + } else { + throw new IllegalStateException(); + } + } + + public String getPIData() { + if (isDelegating()) { + return realReader.getPIData(); + } else { + throw new IllegalStateException(); + } + } + + public String getPITarget() { + if (isDelegating()) { + return realReader.getPITarget(); + } else { + throw new IllegalStateException(); + } + } + + public String getPrefix() { + if (isDelegating()) { + return realReader.getPrefix(); + } else { + throw new IllegalStateException(); + } + } + + public Object getProperty(String s) throws IllegalArgumentException { + if (isDelegating()) { + return realReader.getProperty(s); + } else { + throw new IllegalArgumentException(); + } + } + + public String getText() { + if (isDelegating()) { + return realReader.getText(); + } else { + throw new IllegalStateException(); + } + } + + public char[] getTextCharacters() { + if (isDelegating()) { + return realReader.getTextCharacters(); + } else { + throw new IllegalStateException(); + } + } + + public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException { + if (isDelegating()) { + return realReader.getTextCharacters(i, chars, i1, i2); + } else { + throw new IllegalStateException(); + } + } + + public int getTextLength() { + if (isDelegating()) { + return realReader.getTextLength(); + } else { + throw new IllegalStateException(); + } + } + + public int getTextStart() { + if (isDelegating()) { + return realReader.getTextStart(); + } else { + throw new IllegalStateException(); + } + } + + public String getVersion() { + if (isDelegating()) { + return realReader.getVersion(); + } else { + return null; + } + } + + public boolean hasName() { + if (isDelegating()) { + return realReader.hasName(); + } else { + return false; + } + } + + public boolean hasNext() throws XMLStreamException { + if (state == STATE_COMPLETE_AT_NEXT) { + return true; + } else if (state == STATE_COMPLETED) { + return false; + } else if (state == STATE_SWITCHED) { + return realReader.hasNext(); + } else { + return true; + } + } + + public boolean hasText() { + if (isDelegating()) { + return realReader.hasText(); + } else { + return false; + } + } + + public boolean isAttributeSpecified(int i) { + if (isDelegating()) { + return realReader.isAttributeSpecified(i); + } else { + return false; + } + } + + public boolean isCharacters() { + if (isDelegating()) { + return realReader.isCharacters(); + } else { + return false; + } + } + + private boolean isDelegating() { + return state == STATE_SWITCHED || state == STATE_COMPLETE_AT_NEXT; + } + + public boolean isEndElement() { + if (isDelegating()) { + return realReader.isEndElement(); + } else { + return false; + } + } + + public boolean isStandalone() { + if (isDelegating()) { + return realReader.isStandalone(); + } else { + return false; + } + } + + public boolean isStartElement() { + if (isDelegating()) { + return realReader.isStartElement(); + } else { + return false; + } + } + + public boolean isWhiteSpace() { + if (isDelegating()) { + return realReader.isWhiteSpace(); + } else { + return false; + } + } + + public int next() throws XMLStreamException { + int returnEvent; + + switch (state) { + case STATE_SWITCHED: + returnEvent = realReader.next(); + if (returnEvent == END_DOCUMENT) { + state = STATE_COMPLETED; + } else if (!realReader.hasNext()) { + state = STATE_COMPLETE_AT_NEXT; + } + if (fragment && returnEvent == END_ELEMENT) { + level--; + if (level == -1) { + // We are now at the end of the top-level element in the fragment + state = STATE_COMPLETE_AT_NEXT; + } + } + if (fragment && returnEvent == START_ELEMENT) { + level++; + } + break; + case STATE_INIT: + state = STATE_SWITCHED; + returnEvent = realReader.getEventType(); + if (returnEvent == START_ELEMENT) { + // The real reader is positioned at the top-level element in the fragment + level = 0; + fragment = true; + } + break; + case STATE_COMPLETE_AT_NEXT: + state = STATE_COMPLETED; + returnEvent = END_DOCUMENT; + break; + case STATE_COMPLETED: + // oops - no way we can go beyond this + throw new NoSuchElementException("End of stream has reached."); + default: + throw new UnsupportedOperationException(); + } + + return returnEvent; + } + + public int nextTag() throws XMLStreamException { + if (isDelegating()) { + int returnEvent = realReader.nextTag(); + if (fragment && returnEvent == END_ELEMENT) { + level--; + if (level == 0) { + // We are now at the end of the top-level element in the fragment + state = STATE_COMPLETE_AT_NEXT; + } + } + if (fragment && returnEvent == START_ELEMENT) { + level++; + } + return returnEvent; + } else { + throw new XMLStreamException(); + } + } + + public void require(int i, String s, String s1) throws XMLStreamException { + if (isDelegating()) { + realReader.require(i, s, s1); + } + } + + public boolean standaloneSet() { + if (isDelegating()) { + return realReader.standaloneSet(); + } else { + return false; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java new file mode 100644 index 0000000000..351929d8a1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java @@ -0,0 +1,448 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor.xml; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import java.util.Iterator; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.events.Attribute; +import javax.xml.stream.events.Namespace; +import javax.xml.stream.events.ProcessingInstruction; +import javax.xml.stream.events.XMLEvent; + + +public class XMLEventsStreamReader implements XMLStreamReader { + + @SuppressWarnings("unused") + private ArrayList events = null; + @SuppressWarnings("unchecked") + private HashMap eventContext = null; + + private int state; + private java.util.Iterator iterator; + private XMLEvent current; + + @SuppressWarnings("unchecked") + public XMLEventsStreamReader(List events,Map map) { + this.events = (ArrayList) events; + this.eventContext = (HashMap) map; + this.iterator = events.iterator(); + this.current = iterator.next(); + this.state = current.getEventType(); + } + + public void close() throws XMLStreamException { + this.events = null; + this.eventContext = null; + this.iterator = null; + this.current = null; + } + + private void checkElementState() { + if (getEventType() != START_ELEMENT && getEventType() != END_ELEMENT) { + throw new IllegalStateException(); + } + } + + @SuppressWarnings("unchecked") + public int getAttributeCount() { + checkElementState(); + int count = 0; + Iterator iterator = current.asStartElement().getAttributes(); + while (iterator.hasNext()) { + count++; + iterator.next(); + } + return count; + } + + /* + * Custom method to get attribute from the specified index + */ + @SuppressWarnings("unchecked") + private Attribute getAttribute(int index) { + checkElementState(); + int count = 0; + Attribute attribute = null; + Iterator iterator = current.asStartElement().getAttributes(); + while (iterator.hasNext()) { + count++; + if (count == index) { + attribute = iterator.next(); + } else { + iterator.next(); + } + } + return attribute; + } + + + public String getAttributeLocalName(int index) { + checkElementState(); + return getAttribute(index).getName().getLocalPart(); + } + + public QName getAttributeName(int index) { + checkElementState(); + return getAttribute(index).getName(); + } + + public String getAttributeNamespace(int index) { + checkElementState(); + return getAttributeName(index).getNamespaceURI(); + } + + public String getAttributePrefix(int index) { + checkElementState(); + return getAttributeName(index).getPrefix(); + } + + public String getAttributeType(int index) { + checkElementState(); + return getAttribute(index).getDTDType(); + } + + public String getAttributeValue(int index) { + checkElementState(); + return getAttribute(index).getValue(); + } + + @SuppressWarnings("unchecked") + public String getAttributeValue(String namespaceURI, String localName) { + checkElementState(); + Iterator iterator = current.asStartElement().getAttributes(); + Attribute attribute; + while (iterator.hasNext()) { + attribute = iterator.next(); + if (attribute.getName().getNamespaceURI().equalsIgnoreCase( + namespaceURI) + && attribute.getName().getLocalPart().equalsIgnoreCase( + localName)) { + return attribute.getValue(); + } + } + return null; + + } + + public String getCharacterEncodingScheme() { + return "UTF-8"; + } + + public String getElementText() throws XMLStreamException { + checkElementState(); + int eventType = getEventType(); + String elementText = null; + + if (eventType == START_ELEMENT) { + elementText = current.asStartElement().getName().getLocalPart(); + } else if (eventType == END_ELEMENT) { + elementText = current.asEndElement().getName().getLocalPart(); + } + return elementText; + } + + public String getEncoding() { + return "UTF-8"; + } + + public int getEventType() { + return state; + } + + public String getLocalName() { + checkElementState(); + switch (current.getEventType()) { + case START_ELEMENT: + return current.asStartElement().getName().getLocalPart(); + case END_ELEMENT: + return current.asEndElement().getName().getLocalPart(); + } + return null; + } + + public Location getLocation() { + return current.getLocation(); + } + + public QName getName() { + checkElementState(); + switch (current.getEventType()) { + case START_ELEMENT: + return current.asStartElement().getName(); + case END_ELEMENT: + return current.asEndElement().getName(); + } + return null; + } + + public NamespaceContext getNamespaceContext() { + checkElementState(); + //return new TuscanyNamespaceContext(eventContext.get(getLocalName())); + return eventContext.get(getLocalName()); + } + + @SuppressWarnings("unchecked") + public int getNamespaceCount() { + int count = 0; + Iterator itr = current.asStartElement().getNamespaces(); + while (itr.hasNext()) { + count++; + itr.next(); + } + return count; + } + + @SuppressWarnings("unchecked") + public String getNamespacePrefix(int index) { + Iterator itr = current.asStartElement().getNamespaces(); + int level = 0; + Namespace ns = null; + while (itr.hasNext()) { + ns = itr.next(); + if (level == index) { + return ns.getPrefix(); + } + level++; + } + return null; + } + + public String getNamespaceURI() { + checkElementState(); + switch (current.getEventType()) { + case START_ELEMENT: + return current.asStartElement().getName().getNamespaceURI(); + case END_ELEMENT: + return current.asEndElement().getName().getNamespaceURI(); + } + return null; + } + + public String getNamespaceURI(String prefix) { + return getNamespaceContext().getNamespaceURI(prefix); + } + + @SuppressWarnings("unchecked") + public String getNamespaceURI(int index) { + Iterator itr = current.asStartElement().getNamespaces(); + int level = 0; + Namespace ns = null; + while (itr.hasNext()) { + ns = itr.next(); + if (level == index) { + return ns.getNamespaceURI(); + } + level++; + } + return null; + } + + public String getPIData() { + if (current.isProcessingInstruction()) { + ProcessingInstruction pi = (ProcessingInstruction) current; + return pi.getData(); + } else { + throw new IllegalStateException(current.toString()); + } + } + + public String getPITarget() { + if (current.isProcessingInstruction()) { + ProcessingInstruction pi = (ProcessingInstruction) current; + return pi.getTarget(); + } else { + throw new IllegalStateException(current.toString()); + } + } + + public String getPrefix() { + checkElementState(); + if (current.isStartElement()) { + return current.asStartElement().getName().getPrefix(); + } + return null; + } + + /* + * FIXME: Implementation pending... + * + * @see (non-Javadoc) + * javax.xml.stream.util.StreamReaderDelegate#getProperty(java.lang.String) + */ + public Object getProperty(String name) throws IllegalArgumentException { + // TODO Auto-generated method stub + + return null; + } + + public String getText() { + if (current.isCharacters()) { + return current.asCharacters().getData(); + } else { + throw new IllegalStateException(current.toString()); + } + } + + public char[] getTextCharacters() { + if (current.isCharacters()) { + return current.asCharacters().getData().toCharArray(); + } else { + throw new IllegalStateException(current.toString()); + } + } + + /* + * FIXME: Implementation pending... (non-Javadoc) + * + * @see javax.xml.stream.util.StreamReaderDelegate#getTextCharacters(int, + * char[], int, int) + */ + public int getTextCharacters(int sourceStart, char[] target, + int targetStart, int length) throws XMLStreamException { + // TODO Auto-generated method stub + return 0; + } + + /* + * FIXME:Implementaion can be improved (non-Javadoc) + * + * @see javax.xml.stream.util.StreamReaderDelegate#getTextLength() + */ + public int getTextLength() { + if (current.isCharacters()) { + return current.asCharacters().getData().length(); + } else { + throw new IllegalStateException(current.toString()); + } + } + + /* + * FIXME: Implementation pending... (non-Javadoc) + * + * @see javax.xml.stream.util.StreamReaderDelegate#getTextStart() + */ + public int getTextStart() { + // TODO Auto-generated method stub + return 0; + } + + /* + * FIXME: Implementation pending... (non-Javadoc) + * + * @see javax.xml.stream.util.StreamReaderDelegate#getTextStart() + */ + public String getVersion() { + // TODO Auto-generated method stub + + return null; + } + + public boolean hasName() { + return false; + } + + public boolean hasNext() throws XMLStreamException { + return iterator.hasNext() || state != END_DOCUMENT; + + } + + public boolean hasText() { + // TODO Auto-generated method stub + return false; + } + + /* + * FIXME: Implementation pending... (non-Javadoc) + * + * @see javax.xml.stream.util.StreamReaderDelegate#getTextStart() + */ + public boolean isAttributeSpecified(int index) { + // TODO Auto-generated method stub + return false; + } + + public boolean isCharacters() { + return current.isCharacters(); + } + + public boolean isEndElement() { + return current.isEndElement(); + } + + public boolean isStandalone() { + // TODO Auto-generated method stub + return false; + } + + public boolean isStartElement() { + return current.isStartElement(); + } + + public boolean isWhiteSpace() { + // TODO Auto-generated method stub + return false; + } + + public int next() throws XMLStreamException { + if (!hasNext()) { + throw new IllegalStateException("No more events"); + } + if (!iterator.hasNext()) { + state = END_DOCUMENT; + current = null; + return state; + } + current = iterator.next(); + state = current.getEventType(); + return state; + } + + public int nextTag() throws XMLStreamException { + return iterator.next().getEventType(); + } + + public void require(int type, String namespaceURI, String localName) + throws XMLStreamException { + boolean require = false; + String uri = getNamespaceURI(); + String name = getLocalName(); + if (state == type && namespaceURI.equals(uri) && localName.equals(name)) { + require = true; + } + if (require != true) { + throw new XMLStreamException(); + } + } + + public boolean standaloneSet() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLFragmentStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLFragmentStreamReader.java new file mode 100644 index 0000000000..66361e1d76 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLFragmentStreamReader.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.sca.contribution.processor.xml; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +public interface XMLFragmentStreamReader extends XMLStreamReader { + QName NIL_QNAME = new QName("http://www.w3.org/2001/XMLSchema-instance", "nil", "xsi"); + String NIL_VALUE_TRUE = "true"; + + /** + * this will help to handle Text within the current element. user should + * pass the element text to the property list as this ELEMENT_TEXT as the + * key. This key deliberately has a space in it so that it is not a valid + * XML name + */ + String ELEMENT_TEXT = "Element Text"; + + /** + * Extra method to query the state of the pullparser + */ + boolean isDone(); + + /** + * add the parent namespace context to this parser + */ + void setParentNamespaceContext(NamespaceContext nsContext); + + /** + * Initiate the parser - this will do whatever the needed tasks to initiate + * the parser and must be called before attempting any specific parsing + * using this parser + */ + void init(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java new file mode 100644 index 0000000000..a4cf1b3566 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.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.sca.contribution.xml; + +import javax.xml.stream.XMLInputFactory; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * URLArtifactProcessor that handles sca-contribution-generated.xml files. + * + * @version $Rev$ $Date$ + */ +public class ContributionGeneratedMetadataDocumentProcessor extends ContributionMetadataDocumentProcessor { + + public ContributionGeneratedMetadataDocumentProcessor(XMLInputFactory inputFactory, + StAXArtifactProcessor staxProcessor, + Monitor monitor) { + super(inputFactory, staxProcessor, monitor); + } + + public ContributionGeneratedMetadataDocumentProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor staxProcessor, + Monitor monitor) { + super(modelFactories, staxProcessor, monitor); + } + + @Override + public String getArtifactType() { + return "sca-contribution-generated.xml"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java new file mode 100644 index 0000000000..e6aebc21f1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.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.sca.contribution.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.contribution.ContributionMetadata; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * URLArtifactProcessor that handles sca-contribution.xml files. + * + * @version $Rev$ $Date$ + */ +public class ContributionMetadataDocumentProcessor implements URLArtifactProcessor{ + private final StAXArtifactProcessor staxProcessor; + private final XMLInputFactory inputFactory; + private final Monitor monitor; + + public ContributionMetadataDocumentProcessor(XMLInputFactory inputFactory, + StAXArtifactProcessor staxProcessor, + Monitor monitor) { + this.inputFactory = inputFactory; + this.staxProcessor = staxProcessor; + this.monitor = monitor; + } + + public ContributionMetadataDocumentProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor staxProcessor, + Monitor monitor) { + this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); + this.staxProcessor = staxProcessor; + this.monitor = monitor; + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-xml-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public String getArtifactType() { + return "sca-contribution.xml"; + } + + public Class getModelType() { + return ContributionMetadata.class; + } + + public ContributionMetadata read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + InputStream urlStream = null; + try { + + // Create a stream reader + URLConnection connection = url.openConnection(); + connection.setUseCaches(false); + urlStream = connection.getInputStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); + reader.nextTag(); + + // Read the contribution model + ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader); + + return contribution; + + } catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", inputFactory, ex); + throw ex; + } catch (IOException e) { + ContributionReadException ex = new ContributionReadException(e); + error("IOException", inputFactory, ex); + throw ex; + } finally { + try { + if (urlStream != null) { + urlStream.close(); + urlStream = null; + } + } catch (IOException ioe) { + //ignore + } + } + } + + public void resolve(ContributionMetadata contribution, ModelResolver resolver) throws ContributionResolveException { + staxProcessor.resolve(contribution, resolver); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java new file mode 100644 index 0000000000..8ab370f93f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java @@ -0,0 +1,259 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.xml; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.ContributionMetadata; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Processor for contribution metadata + * + * @version $Rev$ $Date$ + */ +public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor implements + StAXArtifactProcessor { + + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + + private static final QName CONTRIBUTION_QNAME = new QName(SCA10_NS, "contribution"); + private static final QName DEPLOYABLE_QNAME = new QName(SCA10_NS, "deployable"); + + private final AssemblyFactory assemblyFactory; + private final ContributionFactory contributionFactory; + private final ExtensionFactory extensionFactory; + private final StAXArtifactProcessor extensionProcessor; + private final StAXAttributeProcessor attributeProcessor; + private Monitor monitor; + + public ContributionMetadataProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor attributeProcessor, + Monitor monitor) { + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.extensionProcessor = extensionProcessor; + this.attributeProcessor = attributeProcessor; + this.monitor = monitor; + } + + /* + public ContributionMetadataProcessor(AssemblyFactory assemblyFactory, + ContributionFactory contributionFactory, + StAXArtifactProcessor extensionProcessor, + Monitor monitor) { + this.assemblyFactory = assemblyFactory; + this.contributionFactory = contributionFactory; + this.extensionProcessor = extensionProcessor; + this.monitor = monitor; + } + */ + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + new ProblemImpl(this.getClass().getName(), "contribution-xml-validation-messages", Severity.ERROR, + model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = + new ProblemImpl(this.getClass().getName(), "contribution-xml-validation-messages", Severity.ERROR, + model, message, ex); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return CONTRIBUTION_QNAME; + } + + public Class getModelType() { + return ContributionMetadata.class; + } + + public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException { + ContributionMetadata contribution = null; + QName name = null; + + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + name = reader.getName(); + + if (CONTRIBUTION_QNAME.equals(name)) { + + // Read + contribution = this.contributionFactory.createContributionMetadata(); + contribution.setUnresolved(true); + readExtendedAttributes(reader, contribution, attributeProcessor, extensionFactory); + + } else if (DEPLOYABLE_QNAME.equals(name)) { + + // Read + QName compositeName = getQName(reader, "composite"); + if (compositeName == null) { + error("AttributeCompositeMissing", reader); + //throw new ContributionReadException("Attribute 'composite' is missing"); + } else { + if (contribution != null) { + Composite composite = assemblyFactory.createComposite(); + composite.setName(compositeName); + composite.setUnresolved(true); + contribution.getDeployables().add(composite); + } + } + } else { + + // Read an extension element + Object extension = extensionProcessor.read(reader); + if (extension != null && contribution != null) { + if (extension instanceof Import) { + contribution.getImports().add((Import)extension); + } else if (extension instanceof Export) { + contribution.getExports().add((Export)extension); + } else { + contribution.getExtensions().add(extension); + } + } + } + break; + + case XMLStreamConstants.END_ELEMENT: + if (CONTRIBUTION_QNAME.equals(reader.getName())) { + return contribution; + } + break; + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return contribution; + } + + public void write(ContributionMetadata contribution, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + + // Write + writeStartDocument(writer, CONTRIBUTION_QNAME.getNamespaceURI(), CONTRIBUTION_QNAME.getLocalPart()); + writeExtendedAttributes(writer, contribution, attributeProcessor); + + // Write + for (Import imp : contribution.getImports()) { + extensionProcessor.write(imp, writer); + } + + // Write + for (Export export : contribution.getExports()) { + extensionProcessor.write(export, writer); + } + + // Write + for (Composite deployable : contribution.getDeployables()) { + writeStart(writer, + DEPLOYABLE_QNAME.getNamespaceURI(), + DEPLOYABLE_QNAME.getLocalPart(), + new XAttr("composite", deployable.getName())); + writeEnd(writer); + } + + writeEndDocument(writer); + } + + public void resolve(ContributionMetadata contribution, ModelResolver resolver) throws ContributionResolveException { + + // Resolve imports and exports + for (Export export : contribution.getExports()) { + extensionProcessor.resolve(export, resolver); + } + for (Import import_ : contribution.getImports()) { + extensionProcessor.resolve(import_, resolver); + } + + // Resolve deployable composites + List deployables = contribution.getDeployables(); + for (int i = 0, n = deployables.size(); i < n; i++) { + Composite deployable = deployables.get(i); + Composite resolved = (Composite)resolver.resolveModel(Composite.class, deployable); + if (resolved != deployable) { + deployables.set(i, resolved); + } + } + + for (Object ext : contribution.getExtensions()) { + extensionProcessor.resolve(ext, resolver); + } + + contribution.setUnresolved(false); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java new file mode 100644 index 0000000000..f226dbbee3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.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.sca.contribution.xml; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Model Resolver for Contribution models. + * + * @version $Rev$ $Date$ + */ +public class ContributionModelResolver implements ModelResolver { + + private Map map = new HashMap(); + + public ContributionModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + } + + public void addModel(Object resolved) { + Contribution contribution = (Contribution)resolved; + map.put(contribution.getURI(), contribution); + } + + public Object removeModel(Object resolved) { + return map.remove(((Contribution)resolved).getURI()); + } + + public T resolveModel(Class modelClass, T unresolved) { + + // Lookup a contribution for the given URI + String uri = ((Contribution)unresolved).getURI(); + if (uri != null) { + Contribution resolved = (Contribution) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } + return unresolved; + } else { + + // If no URI was specified, just return the first contribution + if (!map.isEmpty()) { + Contribution resolved = map.values().iterator().next(); + return modelClass.cast(resolved); + } else { + return unresolved; + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..b69ea1e135 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.contribution.xml.ContributionMetadataProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#contribution,model=org.apache.tuscany.sca.contribution.ContributionMetadata +org.apache.tuscany.sca.contribution.processor.xml.AnyElementProcessor;qname=http://www.w3.org/2001/XMLSchema#anyElement,model=java.lang.Object diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor new file mode 100644 index 0000000000..b4a13295bc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the attribute processor extension +org.apache.tuscany.sca.contribution.processor.xml.AnyAttributeProcessor;qname=http://www.w3.org/2001/XMLSchema#anyAttribute,model=org.apache.tuscany.sca.assembly.Extension diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor new file mode 100644 index 0000000000..23adab56b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.contribution.xml.ContributionMetadataDocumentProcessor;type=sca-contribution.xml,model=org.apache.tuscany.sca.contribution.ContributionMetadata +org.apache.tuscany.sca.contribution.xml.ContributionGeneratedMetadataDocumentProcessor;type=sca-contribution-generated.xml diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..68030bf6e6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.xml.ContributionModelResolver;model=org.apache.tuscany.sca.contribution.Contribution diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties new file mode 100644 index 0000000000..4827fd5e94 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties @@ -0,0 +1,24 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +XMLStreamException = XMLStreamException occured due to : {0} +IOException = IOException occured due to : {0} +AttributeCompositeMissing = Attribute 'composite' is missing + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java new file mode 100644 index 0000000000..cef1f705af --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.xml; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.ContributionMetadata; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; + +/** + * Test the contribution metadata processor. + * + * @version $Rev$ $Date$ + */ + +public class ContributionMetadataProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + "" + + "" + + "" + + ""; + + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + } + + public void testRead() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); + ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader); + assertNotNull(contribution); + assertEquals(2, contribution.getDeployables().size()); + assertEquals(1, contribution.getAttributeExtensions().size()); + assertEquals(1, contribution.getExtensions().size()); + } + + public void testReadInvalid() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + /*try { + staxProcessor.read(reader); + fail("InvalidException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + }*/ + staxProcessor.read(reader); + Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + assertNotNull(problem); + assertEquals("AttributeCompositeMissing", problem.getMessageId()); + } + + public void testWrite() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); + ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader); + + validateContribution(contribution); + + //write the contribution metadata contents + StringWriter stringWriter = new StringWriter(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(stringWriter); + staxProcessor.write(contribution, writer); + stringWriter.close(); + + reader = inputFactory.createXMLStreamReader(new StringReader(stringWriter.toString())); + contribution = (ContributionMetadata)staxProcessor.read(reader); + + validateContribution(contribution); + } + + private void validateContribution(ContributionMetadata contribution) { + QName deployable; + + assertNotNull(contribution); + assertEquals(2, contribution.getDeployables().size()); + deployable = new QName("http://ns", "Composite1"); + assertEquals(deployable, contribution.getDeployables().get(0).getName()); + deployable = new QName("http://ns", "Composite2"); + assertEquals(deployable, contribution.getDeployables().get(1).getName()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/pom.xml new file mode 100644 index 0000000000..a98bb10117 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/pom.xml @@ -0,0 +1,69 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-contribution + Apache Tuscany SCA Contribution Model + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-extensibility + 1.6-SNAPSHOT + + + + javax.xml.stream + stax-api + 1.0-2 + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.contribution + ${pom.name} + org.apache.tuscany.sca.contribution* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java new file mode 100644 index 0000000000..84a6a9a8f9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.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.sca.contribution; + +import org.apache.tuscany.sca.assembly.Base; + + +/** + * Represents an artifact in an SCA contribution. + * + * @version $Rev$ $Date$ + */ +public interface Artifact extends Base { + + /** + * Returns the URI that unique identifies the artifact inside the contribution. + * + * @return The artifact URI + */ + String getURI(); + + /** + * Sets the URI that uniquely identifies the artifact inside the contribution. + * + * @param uri The artifact URI + */ + void setURI(String uri); + + /** + * Returns the location of the artifact. + * + * @return The artifact location + */ + String getLocation(); + + /** + * Set the location of the artifact. + * + * @param location The artifact location + */ + void setLocation(String location); + + + /** + * Returns the in-memory model representing the artifact. + * + * @return The model object + */ + Object getModel(); + + /** + * Sets the in-memory model representing the artifact. + * + * @param model The model object + */ + void setModel(Object model); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Constants.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Constants.java new file mode 100644 index 0000000000..14131a9806 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Constants.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.sca.contribution; + +/** + * Constants used in SCA contribution. + * + * @version $Rev$ $Date$ + */ +public interface Constants { + String XMLSCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; + + String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.0"; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java new file mode 100644 index 0000000000..81b0b08b9d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.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.sca.contribution; + +/** + * Constants for the main supported contribution package type. + * + * @version $Rev$ $Date$ + */ +@Deprecated +public interface ContentType { + + /** + * Java compressed contribution package + */ + String JAR = "application/x-compressed"; + + /** + * Filesystem folder contribution package + */ + String FOLDER = "application/vnd.tuscany.folder"; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java new file mode 100644 index 0000000000..0076e1c89f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.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.sca.contribution; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an SCA contribution. + * + * @version $Rev$ $Date$ + */ +public interface Contribution extends Artifact, Extensible { + + /** + * Default location of contribution metadata in an SCA contribution. + */ + String SCA_CONTRIBUTION_META = "META-INF/sca-contribution.xml"; + + /** + * Default location of a generated contribution metadata in an SCA contribution. + */ + String SCA_CONTRIBUTION_GENERATED_META = "META-INF/sca-contribution-generated.xml"; + + /** + * Default location of deployable composites in an SCA contribution. + */ + String SCA_CONTRIBUTION_DEPLOYABLES = "META-INF/sca-deployables/"; + + + /** + * Returns a list of exports based on the contribution metadata. + * + * @return The list of exports in this contribution + */ + List getExports(); + + /** + * Returns a list of imports based on the contribution metadata. + * + * @return The list of imports in this contribution + */ + List getImports(); + + /** + * Returns the list of deployable composites in the contribution. + * + * @return The list of deployable composites + */ + List getDeployables(); + + /** + * Returns the list of artifacts in the contribution. + * + * @return The list of artifacts in the contribution + */ + List getArtifacts(); + + /** + * Returns the model resolver for the models representing the artifacts + * visible in the scope of this contribution. + * + * @return The model resolver + */ + ModelResolver getModelResolver(); + + /** + * Sets the model resolver for the models representing the artifacts + * visible in the scope of this contribution. + * + * @param modelResolver The model resolver + */ + void setModelResolver(ModelResolver modelResolver); + + /** + * Returns the ClassLoader used to load classes and resources from + * this contribution + * + * FIXME Remove this, the base contribution model should not depend + * on Java ClassLoaders. + * + * @return The contribution ClassLoader + */ + ClassLoader getClassLoader(); + + /** + * Sets the ClassLoader used to load classes and resources from + * this contribution + * + * FIXME Remove this, the base contribution model should not depend + * on Java ClassLoaders. + * + * @param classLoader the contribution class loader + */ + void setClassLoader(ClassLoader classLoader); + + /** + * Returns the type string based on the types that appear in + * o.a.t.s.contribution.PackageType + * + * @return the contribution type string + */ + String getType(); + + /** + * Sets the type string based on the types that appear in + * o.a.t.s.contribution.PackageType + * + * @param contributionType the contribution type string + */ + void setType(String contributionType); +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java new file mode 100644 index 0000000000..67c9a05a0b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.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.sca.contribution; + + +/** + * A factory for the contribution model. + * + * @version $Rev$ $Date$ + */ +public interface ContributionFactory { + + /** + * Create a contribution model object + * + * @return The new contribution model object + */ + Contribution createContribution(); + + /** + * Create a contribution metadata model object + * + * @return The new contribution metadata model object + */ + ContributionMetadata createContributionMetadata(); + + /** + * Create a deployedArtifact model object + * + * @return The new deployedArtifact model object + */ + @Deprecated + DeployedArtifact createDeployedArtifact(); + + /** + * Create an artifact model object + * + * @return The new artifact model object + */ + Artifact createArtifact(); + + /** + * Create a default import model object. + * + * @return the new default import model object + */ + DefaultImport createDefaultImport(); + + /** + * Create a default export model object. + * + * @return the new default export model object + */ + DefaultExport createDefaultExport(); + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java new file mode 100644 index 0000000000..5f26c3d907 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.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.sca.contribution; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Extensible; + +/** + * The representation of SCA contribution metadata. + * + * @version $Rev$ $Date$ + */ +public interface ContributionMetadata extends Base, Extensible { + + /** + * Returns a list of exports based on the contribution metadata. + * + * @return The list of exports + */ + List getExports(); + + /** + * Returns a list of imports based on the contribution metadata. + * + * @return The list of imports + */ + List getImports(); + + /** + * Returns the list of deployable based on the contribution metadata. + * + * @return The list of deployable composites + */ + List getDeployables(); + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultContributionFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultContributionFactory.java new file mode 100644 index 0000000000..e13e8bcbd6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultContributionFactory.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.sca.contribution; + +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; + + +/** + * Default implementation of a contribution model factory. + * + * @version $Rev$ $Date$ + */ +public class DefaultContributionFactory extends ContributionFactoryImpl implements ContributionFactory { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultExport.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultExport.java new file mode 100644 index 0000000000..b2eddb8336 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultExport.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.sca.contribution; + + +/** + * The representation of an export that exports all artifacts in + * a contribution. + * + * @version $Rev$ $Date$ + */ +public interface DefaultExport extends Export { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultImport.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultImport.java new file mode 100644 index 0000000000..20798dcd17 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultImport.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.sca.contribution; + + +/** + * The representation of a default import that imports artifacts from + * all contributions. + * + * @version $Rev$ $Date$ + */ +public interface DefaultImport extends Import { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java new file mode 100644 index 0000000000..b69c58a0ff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution; + +import java.lang.reflect.Constructor; +import java.util.HashMap; + +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + + +/** + * Default implementation of a model factory extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultModelFactoryExtensionPoint implements ModelFactoryExtensionPoint { + + private HashMap, Object> factories = new HashMap, Object>(); + + /** + * Constructs a new DefaultModelFactoryExtensionPoint. + */ + public DefaultModelFactoryExtensionPoint() { + } + + /** + * Add a model factory extension. + * + * @param factory The factory to add + */ + public void addFactory(Object factory) { + Class[] interfaces = factory.getClass().getInterfaces(); + if (interfaces.length == 0) { + Class sc = factory.getClass().getSuperclass(); + if (sc != Object.class) { + factories.put(sc, factory); + } + } else { + for (int i = 0; i[] interfaces = factory.getClass().getInterfaces(); + if (interfaces.length == 0) { + Class sc = factory.getClass().getSuperclass(); + if (sc != Object.class) { + factories.remove(sc); + } + } else { + for (int i = 0; i T getFactory(Class factoryInterface) { + Object factory = factories.get(factoryInterface); + if (factory == null) { + + if (factoryInterface.isInterface()) { + + // Dynamically load a factory class declared under META-INF/services + try { + Class factoryClass = ServiceDiscovery.getInstance().loadFirstServiceClass(factoryInterface); + if (factoryClass != null) { + + try { + // Default empty constructor + Constructor constructor = factoryClass.getConstructor(); + factory = constructor.newInstance(); + } catch (NoSuchMethodException e) { + + // Constructor taking the model factory extension point + Constructor constructor = factoryClass.getConstructor(ModelFactoryExtensionPoint.class); + factory = constructor.newInstance(this); + } + + // Cache the loaded factory + addFactory(factory); + } + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } else { + + // Call the newInstance static method on the factory abstract class + try { + factory = ServiceDiscovery.getInstance().newFactoryClassInstance(factoryInterface); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + + // Cache the factory + addFactory(factory); + } + } + return factoryInterface.cast(factory); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java new file mode 100644 index 0000000000..ffe190132c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.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.sca.contribution; + +/** + * Representation of a deployed artifact + * + * @version $Rev$ $Date$ + */ +@Deprecated +public interface DeployedArtifact extends Artifact { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java new file mode 100644 index 0000000000..a6e5afe7b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.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.sca.contribution; + +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an export. + * + * @version $Rev$ $Date$ + */ +public interface Export extends Extensible { + + /** + * Returns the model resolver for the models representing artifacts + * made available by this export. + * + * @return The model resolver + */ + ModelResolver getModelResolver(); + + /** + * Sets the model resolver for the models representing artifacts + * made available by this export. + * + * @param modelResolver + */ + void setModelResolver(ModelResolver modelResolver); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java new file mode 100644 index 0000000000..256a2387f1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.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.sca.contribution; + +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * The representation of an import. + * + * @version $Rev$ $Date$ + */ +public interface Import extends Extensible { + + /** + * Returns the model resolver for the models representing artifacts + * made available by this import. + * + * @return The model resolver + */ + ModelResolver getModelResolver(); + + /** + * Sets the model resolver for the models representing artifacts + * made available by this import. + * + * @param modelResolver The model resolver + */ + void setModelResolver(ModelResolver modelResolver); + + /** + * Verify that a specific export actually exports what is being imported. + * + * @param export The Exported being verified + * @return true/false + */ + boolean match(Export export); + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.java new file mode 100644 index 0000000000..0ada4ebec3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.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.sca.contribution; + +/** + * An extension point for model factories. Model factories are provided to + * abstract the classes that represent artifacts in the assembly model away + * from their creation mechanism. When the runtime needs to extend the model + * as it reads in contributed artifacts it looks up the factory for the + * artifact required in this registry + * + * @version $Rev$ $Date$ + */ +public interface ModelFactoryExtensionPoint { + + /** + * Add a model factory extension. + * + * @param factory The factory to add + */ + void addFactory(Object factory); + + /** + * Remove a model factory extension. + * + * @param factory The factory to remove + */ + void removeFactory(Object factory); + + /** + * Get a factory implementing the given interface. + * @param factoryInterface the lookup key (factory interface) + * @return The factory + */ + T getFactory(Class factoryInterface); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java new file mode 100644 index 0000000000..26833bb4c0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.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.sca.contribution; + +/** + * Constants for the main supported contribution package types. + * + * @version $Rev$ $Date$ + */ +public interface PackageType { + + /** + * Java compressed contribution package + */ + String JAR = "application/x-compressed"; + + /** + * Zip archive contribution package + */ + String ZIP = "application/x-compressed"; + + /** + * Filesystem folder contribution package + */ + String FOLDER = "application/vnd.tuscany.folder"; + + + String BUNDLE = "application/osgi.bundle"; + + /** + * Java EE Web Application Archive + */ + String WAR = "application/war"; + + /** + * Java EE Enterprise Application Archive + */ + String EAR = "application/ear"; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java new file mode 100644 index 0000000000..3ce27d47c3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.impl; + +import org.apache.tuscany.sca.contribution.Artifact; + + +/** + * The model representing an artifact in a contribution. + * + * @version $Rev$ $Date$ + */ +class ArtifactImpl implements Artifact { + private String uri; + private String location; + private Object model; + private boolean unresolved; + + ArtifactImpl() { + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public Object getModel() { + return model; + } + + public void setModel(Object model) { + this.model = model; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + @Override + public int hashCode() { + return uri.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else { + if (obj instanceof Artifact) { + return uri.equals(((Artifact)obj).getURI()); + } else { + return false; + } + } + } + + @Override + public String toString() { + return "Artifact:" + uri + "\n" + + "at: " + location; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java new file mode 100644 index 0000000000..c678c2eaef --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.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.sca.contribution.impl; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.ContributionMetadata; +import org.apache.tuscany.sca.contribution.DefaultExport; +import org.apache.tuscany.sca.contribution.DefaultImport; +import org.apache.tuscany.sca.contribution.DeployedArtifact; + + +/** + * Default implementation of a contribution model factory. + * + * @version $Rev$ $Date$ + */ +public class ContributionFactoryImpl implements ContributionFactory { + + protected ContributionFactoryImpl() { + } + + public Contribution createContribution() { + return new ContributionImpl(); + } + + public ContributionMetadata createContributionMetadata() { + return new ContributionMetadataImpl(); + } + + public Artifact createArtifact() { + return new ArtifactImpl(); + } + + public DefaultExport createDefaultExport() { + return new DefaultExportImpl(); + } + + public DefaultImport createDefaultImport() { + return new DefaultImportImpl(); + } + + @Deprecated + public DeployedArtifact createDeployedArtifact() { + class DeployedArtifactImpl extends ArtifactImpl implements DeployedArtifact { + } + return new DeployedArtifactImpl(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java new file mode 100644 index 0000000000..3bad5c3612 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of a deployed contribution + * + * @version $Rev$ $Date$ + */ +class ContributionImpl extends ExtensibleImpl implements Contribution { + private String type; + private String uri; + private String location; + private Object model; + private byte[] contents; + private boolean unresolved; + private List exports = new ArrayList(); + private List imports = new ArrayList(); + private List deployables = new ArrayList(); + private List artifacts = new ArrayList(); + private ModelResolver modelResolver; + + // FIXME remove this dependency on Java ClassLoaders + private ClassLoader classLoader; + + ContributionImpl() { + } + + public String getLocation() { + return this.location; + } + + public void setLocation(String location) { + this.location = location; + } + + //FIXME Remove dependency on Java ClassLoaders + public ClassLoader getClassLoader() { + return classLoader; + } + + //FIXME Remove dependency on Java ClassLoaders + public void setClassLoader(ClassLoader classLoader) { + this.classLoader = classLoader; + } + + + public String getURI() { + return this.uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public Object getModel() { + return model; + } + + public void setModel(Object model) { + this.model = model; + } + + public byte[] getContents() { + return contents; + } + + public void setContents(byte[] contents) { + this.contents = contents; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + + public List getExports() { + return exports; + } + + public List getImports() { + return imports; + } + + public List getDeployables() { + return deployables; + } + + public List getArtifacts() { + return artifacts; + } + + @Override + public int hashCode() { + return uri.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else { + if (obj instanceof Artifact) { + return uri.equals(((Artifact)obj).getURI()); + } else { + return false; + } + } + } + + @Override + public String toString() { + return "Contribution : " + uri + " \n" + + "from: " + location; + } + + public String getType() { + return type; + } + + public void setType(String contributionType) { + this.type = contributionType; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java new file mode 100644 index 0000000000..da8c879a93 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.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.sca.contribution.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.ContributionMetadata; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; + +/** + * The representation of a deployed contribution + * + * @version $Rev$ $Date$ + */ +class ContributionMetadataImpl extends ExtensibleImpl implements ContributionMetadata { + private boolean unresolved; + private List exports = new ArrayList(); + private List imports = new ArrayList(); + private List deployables = new ArrayList(); + + ContributionMetadataImpl() { + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public List getExports() { + return exports; + } + + public List getImports() { + return imports; + } + + public List getDeployables() { + return deployables; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java new file mode 100644 index 0000000000..d4614e5427 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.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.sca.contribution.impl; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.DefaultExport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an export for the contribution + * + * @version $Rev$ $Date$ + */ +public class DefaultExportImpl extends ExtensibleImpl implements DefaultExport { + private ModelResolver modelResolver; + + protected DefaultExportImpl() { + super(); + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java new file mode 100644 index 0000000000..7ab535f916 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.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.sca.contribution.impl; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.DefaultExport; +import org.apache.tuscany.sca.contribution.DefaultImport; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an import for the contribution + * + * @version $Rev$ $Date$ + */ +public class DefaultImportImpl extends ExtensibleImpl implements DefaultImport { + private ModelResolver modelResolver; + + protected DefaultImportImpl() { + super(); + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + + + public boolean match(Export export) { + if (export instanceof DefaultExport) { + return true; + } + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java new file mode 100644 index 0000000000..b5f536c431 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.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.sca.contribution.processor; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; + +/** + * Base interface for artifact processors. + * + * @version $Rev$ $Date$ + */ +public interface ArtifactProcessor { + + /** + * Resolve references from this model to other models. For example references + * from a composite to another one, or references from a composite to a WSDL + * model. + * + * @param model The model to resolve + * @param resolver The resolver to use to resolve referenced models + */ + void resolve(M model, ModelResolver resolver) throws ContributionResolveException; + + /** + * Returns the type of model handled by this artifact processor. + * + * @return The type of model handled by this artifact processor + */ + Class getModelType(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..029df61f0f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.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.sca.contribution.processor; + +/** + * An extension point for artifact processors. + * + * @version $Rev$ $Date$ + */ +public interface ArtifactProcessorExtensionPoint

{ + + /** + * Add an artifact processor. + * + * @param artifactProcessor The artifact processor to add + */ + void addArtifactProcessor(P artifactProcessor); + + /** + * Remove an artifact processor. + * + * @param artifactProcessor The artifact processor to remove + */ + void removeArtifactProcessor(P artifactProcessor); + + /** + * Returns the processor associated with the given artifact type. + * + * @param artifactType An artifact type + * @return The processor associated with the given artifact type + */ + P getProcessor(Object artifactType); + + /** + * Returns the processor associated with the given model type. + * + * @param modelType A model type + * @return The processor associated with the given model type + */ + P getProcessor(Class modelType); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java new file mode 100644 index 0000000000..a451316883 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java @@ -0,0 +1,618 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.StringTokenizer; + +import javax.xml.XMLConstants; +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + + +/** + * A base class with utility methods for the other artifact processors in this module. + * + * @version $Rev$ $Date$ + */ +public abstract class BaseStAXArtifactProcessor { + + /** + * Returns a QName from a string. + * @param reader + * @param value + * @return + */ + protected QName getQNameValue(XMLStreamReader reader, String value) { + if (value != null) { + int index = value.indexOf(':'); + String prefix = index == -1 ? "" : value.substring(0, index); + String localName = index == -1 ? value : value.substring(index + 1); + String ns = reader.getNamespaceContext().getNamespaceURI(prefix); + if (ns == null) { + ns = ""; + } + return new QName(ns, localName, prefix); + } else { + return null; + } + } + + /** + * Returns the boolean value of an attribute. + * @param reader + * @param name + * @return + */ + protected boolean getBoolean(XMLStreamReader reader, String name) { + String value = reader.getAttributeValue(null, name); + if (value == null) { + return false; + } + return Boolean.valueOf(value); + } + + /** + * Returns the QName value of an attribute. + * @param reader + * @param name + * @return + */ + protected QName getQName(XMLStreamReader reader, String name) { + String qname = reader.getAttributeValue(null, name); + return getQNameValue(reader, qname); + } + + /** + * Returns the value of an attribute as a list of QNames. + * @param reader + * @param name + * @return + */ + protected List getQNames(XMLStreamReader reader, String name) { + String value = reader.getAttributeValue(null, name); + if (value != null) { + List qnames = new ArrayList(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + qnames.add(getQName(reader, tokens.nextToken())); + } + return qnames; + } else { + return Collections.emptyList(); + } + } + + /** + * Returns the string value of an attribute. + * @param reader + * @param name + * @return + */ + protected String getString(XMLStreamReader reader, String name) { + return reader.getAttributeValue(null, name); + } + + /** + * Test if an attribute is explicitly set + * @param reader + * @param name + * @return + */ + protected boolean isSet(XMLStreamReader reader, String name) { + return reader.getAttributeValue(null, name) != null; + } + + /** + * Returns the value of xsi:type attribute + * @param reader The XML stream reader + * @return The QName of the type, if the attribute is not present, null is + * returned. + */ + protected QName getXSIType(XMLStreamReader reader) { + String qname = reader.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); + return getQNameValue(reader, qname); + } + + /** + * Parse the next child element. + * @param reader + * @return + * @throws XMLStreamException + */ + protected boolean nextChildElement(XMLStreamReader reader) throws XMLStreamException { + while (reader.hasNext()) { + int event = reader.next(); + if (event == END_ELEMENT) { + return false; + } + if (event == START_ELEMENT) { + return true; + } + } + return false; + } + + /** + * 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 + */ + protected void skipToEndElement(XMLStreamReader reader) throws XMLStreamException { + int depth = 0; + while (reader.hasNext()) { + int event = reader.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + depth++; + } else if (event == XMLStreamConstants.END_ELEMENT) { + if (depth == 0) { + return; + } + depth--; + } + } + } + + /** + * + * @param writer + * @param uri + * @throws XMLStreamException + */ + private String writeElementPrefix(XMLStreamWriter writer, String uri) throws XMLStreamException { + if (uri == null) { + return null; + } + String prefix = writer.getPrefix(uri); + if (prefix != null) { + return null; + } else { + + // Find an available prefix and bind it to the given URI + NamespaceContext nsc = writer.getNamespaceContext(); + for (int i=1; ; i++) { + prefix = "ns" + i; + if (nsc.getNamespaceURI(prefix) == null) { + break; + } + } + // writer.setPrefix(prefix, uri); + return prefix; + } + + } + + /** + * Start an element. + * @param uri + * @param name + * @param attrs + * @throws XMLStreamException + */ + protected void writeStart(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException { + String prefix = writeElementPrefix(writer, uri); + writer.writeStartElement(uri, name); + if (prefix != null){ + writer.writeNamespace(prefix,uri); + } + writeAttributePrefixes(writer, attrs); + writeAttributes(writer, attrs); + } + + /** + * Start an element. + * @param qname + * @param attrs + * @throws XMLStreamException + */ + protected void writeStart(XMLStreamWriter writer, QName qname, XAttr... attrs) throws XMLStreamException { + writeStart(writer, qname.getNamespaceURI(), qname.getLocalPart(), attrs); + } + + /** + * End an element. + * @param writer + * @throws XMLStreamException + */ + protected void writeEnd(XMLStreamWriter writer) throws XMLStreamException { + writer.writeEndElement(); + } + + /** + * Start a document. + * @param writer + * @throws XMLStreamException + */ + protected void writeStartDocument(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException { + writer.writeStartDocument(); + writer.setDefaultNamespace(uri); + writeStart(writer, uri, name, attrs); + writer.writeDefaultNamespace(uri); + } + + /** + * Start a document. + * @param writer + * @param qname + * @param attrs + * @throws XMLStreamException + */ + protected void writeStartDocument(XMLStreamWriter writer, QName qname, XAttr... attrs) throws XMLStreamException { + writeStartDocument(writer, qname.getNamespaceURI(), qname.getLocalPart(), attrs); + } + + /** + * End a document. + * @param writer + * @throws XMLStreamException + */ + protected void writeEndDocument(XMLStreamWriter writer) throws XMLStreamException { + writer.writeEndDocument(); + } + + /** + * Write attributes to the current element. + * @param writer + * @param attrs + * @throws XMLStreamException + */ + protected void writeAttributes(XMLStreamWriter writer, XAttr... attrs) throws XMLStreamException { + for (XAttr attr : attrs) { + if (attr != null) + attr.write(writer); + } + } + + /** + * Write attribute prefixes to the current element. + * @param writer + * @param attrs + * @throws XMLStreamException + */ + protected void writeAttributePrefixes(XMLStreamWriter writer, XAttr... attrs) throws XMLStreamException { + for (XAttr attr : attrs) { + if (attr != null) + attr.writePrefix(writer); + } + } + + /** + * + * @param reader + * @param elementName + * @param extensible + * @param extensionAttributeProcessor + * @param extensionAttributeProcessor + * @param extensionFactory + * @throws ContributionReadException + * @throws XMLStreamException + */ + protected void readExtendedAttributes(XMLStreamReader reader, + Extensible extensible, + StAXAttributeProcessor extensionAttributeProcessor, + ExtensionFactory extensionFactory) throws ContributionReadException, + XMLStreamException { + QName elementName = reader.getName(); + for (int a = 0; a < reader.getAttributeCount(); a++) { + QName attributeName = reader.getAttributeName(a); + if (attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { + if (!elementName.getNamespaceURI().equals(attributeName.getNamespaceURI())) { + Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); + Extension attributeExtension; + if (attributeValue instanceof Extension) { + attributeExtension = (Extension)attributeValue; + } else { + attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true); + } + extensible.getAttributeExtensions().add(attributeExtension); + } + } + } + } + + /** + * + * @param attributeModel + * @param writer + * @param extensibleElement + * @param extensionAttributeProcessor + * @throws ContributionWriteException + * @throws XMLStreamException + */ + protected void writeExtendedAttributes(XMLStreamWriter writer, + Extensible extensibleElement, + StAXAttributeProcessor extensionAttributeProcessor) + throws ContributionWriteException, XMLStreamException { + for (Extension extension : extensibleElement.getAttributeExtensions()) { + if (extension.isAttribute()) { + extensionAttributeProcessor.write(extension, writer); + } + } + } + + protected void readExtendedElement(XMLStreamReader reader, + Extensible extensible, + StAXArtifactProcessor extensionProcessor) throws ContributionReadException, + XMLStreamException { + Object ext = extensionProcessor.read(reader); + if (extensible != null) { + extensible.getExtensions().add(ext); + } + } + + protected void writeExtendedElements(XMLStreamWriter writer, + Extensible extensible, + StAXArtifactProcessor extensionProcessor) throws ContributionWriteException, + XMLStreamException { + for (Object ext : extensible.getExtensions()) { + extensionProcessor.write(ext, writer); + } + } + + /** + * Represents an XML attribute that needs to be written to a document. + */ + public static class XAttr { + + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + + private String uri = SCA10_NS; + private String name; + private Object value; + + public XAttr(String uri, String name, String value) { + this.uri = uri; + this.name = name; + this.value = value; + } + + public XAttr(String name, String value) { + this(null, name, value); + } + + public XAttr(String uri, String name, List values) { + this.uri = uri; + this.name = name; + this.value = values; + } + + public XAttr(String name, List values) { + this(null, name, values); + } + + public XAttr(String uri, String name, Boolean value) { + this.uri = uri; + this.name = name; + this.value = value; + } + + public XAttr(String name, Boolean value) { + this(null, name, value); + } + + public XAttr(String uri, String name, Integer value) { + this.uri = uri; + this.name = name; + this.value = value; + } + + public XAttr(String name, Integer value) { + this(null, name, value); + } + + public XAttr(String uri, String name, Double value) { + this.uri = uri; + this.name = name; + this.value = value; + } + + public XAttr(String name, Double value) { + this(null, name, value); + } + + public XAttr(String uri, String name, QName value) { + this.uri = uri; + this.name = name; + this.value = value; + } + + public XAttr(String name, QName value) { + this(null, name, value); + } + + /** + * Writes a string from a QName and registers a prefix for its namespace. + * @param reader + * @param value + * @return + */ + private String writeQNameValue(XMLStreamWriter writer, QName qname) throws XMLStreamException { + if (qname != null) { + String prefix = qname.getPrefix(); + String uri = qname.getNamespaceURI(); + prefix = writer.getPrefix(uri); + if (prefix != null) { + + // Use the prefix already bound to the given URI + if (prefix.length() > 0) { + return prefix + ":" + qname.getLocalPart(); + } else { + + // Empty prefix, just return the local part of the given qname + return qname.getLocalPart(); + } + + } else { + + // Find an available prefix and bind it to the given URI + NamespaceContext nsc = writer.getNamespaceContext(); + for (int i=1; ; i++) { + prefix = "ns" + i; + if (nsc.getNamespaceURI(prefix) == null) { + break; + } + } + // writer.setPrefix(prefix, uri); + writer.writeNamespace(prefix, uri); + return prefix + ":" + qname.getLocalPart(); + } + } else { + return null; + } + } + + /** + * Registers a prefix for the namespace of a QName. + * @param reader + * @param value + * @return + */ + private void writeQNamePrefix(XMLStreamWriter writer, QName qname) throws XMLStreamException { + if (qname != null) { + String prefix = qname.getPrefix(); + String uri = qname.getNamespaceURI(); + prefix = writer.getPrefix(uri); + if (prefix != null) { + return; + } else { + + // Find an available prefix and bind it to the given URI + NamespaceContext nsc = writer.getNamespaceContext(); + for (int i=1; ; i++) { + prefix = "ns" + i; + if (nsc.getNamespaceURI(prefix) == null) { + break; + } + } + // writer.setPrefix(prefix, uri); + writer.writeNamespace(prefix, uri); + } + } + } + + /** + * Write to document + * @param writer + * @throws XMLStreamException + */ + public void write(XMLStreamWriter writer) throws XMLStreamException { + String str; + if (value instanceof QName) { + + // Write a QName + str = writeQNameValue(writer, (QName)value); + + } else if (value instanceof List) { + + // Write a list of values + List values = (List)value; + if (values.isEmpty()) { + return; + } + StringBuffer buffer = new StringBuffer(); + for (Object v: values) { + if (v == null) { + // Skip null values + continue; + } + + if (v instanceof XAttr) { + // Write an XAttr value + ((XAttr)v).write(writer); + continue; + } + + if (buffer.length() != 0) { + buffer.append(' '); + } + if (v instanceof QName) { + // Write a QName value + buffer.append(writeQNameValue(writer, (QName)v)); + } else { + // Write value as a string + buffer.append(String.valueOf(v)); + } + } + str = buffer.toString(); + + } else { + + // Write a string + if (value == null) { + return; + } + str = String.valueOf(value); + } + if (str.length() == 0) { + return; + } + + // Write the attribute + if (uri != null && !uri.equals(SCA10_NS)) { + writer.writeAttribute(uri, name, str); + } else { + writer.writeAttribute(name,str); + } + } + + /** + * Registers a prefix for the namespace of a QName or list of QNames + * @param writer + * @throws XMLStreamException + */ + public void writePrefix(XMLStreamWriter writer) throws XMLStreamException { + if (value instanceof QName) { + + // Write prefix for a single QName value + writeQNamePrefix(writer, (QName)value); + + } else if (value instanceof List) { + + // Write prefixes for a list of values + for (Object v: (List)value) { + if (v instanceof QName) { + // Write prefix for a QName value + writeQNamePrefix(writer, (QName)v); + + } else if (v instanceof XAttr) { + // Write prefix for an XAttr value + ((XAttr)v).writePrefix(writer); + } + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..3c67a8c550 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.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.sca.contribution.processor; + +import java.util.HashMap; +import java.util.Map; + +/** + * The default implementation of an artifact processor extension point. + * + * @version $Rev$ $Date$ + */ +abstract class DefaultArtifactProcessorExtensionPoint

{ + protected final Map processorsByArtifactType = new HashMap(); + protected final Map, P> processorsByModelType = new HashMap, P>(); + + /** + * Constructs a new loader registry. + */ + DefaultArtifactProcessorExtensionPoint() { + } + + /** + * Returns the processor associated with the given artifact type. + * + * @param artifactType An artifact type + * @return The processor associated with the given artifact type + */ + public P getProcessor(Object artifactType) { + return processorsByArtifactType.get(artifactType); + } + + /** + * Returns the processor associated with the given model type. + * + * @param modelType A model type + * @return The processor associated with the given model type + */ + public P getProcessor(Class modelType) { + Class[] classes = modelType.getInterfaces(); + for (Class c : classes) { + P processor = processorsByModelType.get(c); + if (processor != null) { + return processor; + } + } + return processorsByModelType.get(modelType); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java new file mode 100644 index 0000000000..3c25424325 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + +/** + * Default implementation of a package processor extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultPackageProcessorExtensionPoint implements PackageProcessorExtensionPoint { + + private Map processors = new HashMap(); + private boolean loaded; + + public DefaultPackageProcessorExtensionPoint() { + } + + public void addPackageProcessor(PackageProcessor processor) { + processors.put(processor.getPackageType(), processor); + } + + public void removePackageProcessor(PackageProcessor processor) { + processors.remove(processor.getPackageType()); + } + + public PackageProcessor getPackageProcessor(String contentType) { + loadProcessors(); + return processors.get(contentType); + } + + private synchronized void loadProcessors() { + if (loaded) + return; + + // Get the processor service declarations + Set processorDeclarations; + try { + processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(PackageProcessor.class); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + for (ServiceDeclaration processorDeclaration: processorDeclarations) { + Map attributes = processorDeclaration.getAttributes(); + + // Load a URL artifact processor + String packageType = attributes.get("type"); + + // Create a processor wrapper and register it + PackageProcessor processor = new LazyPackageProcessor(packageType, processorDeclaration); + addPackageProcessor(processor); + } + + loaded = true; + } + + /** + * A facade for package processors. + */ + private static class LazyPackageProcessor implements PackageProcessor { + + private ServiceDeclaration processorDeclaration; + private String packageType; + private PackageProcessor processor; + + private LazyPackageProcessor(String packageType, ServiceDeclaration processorDeclaration) { + this.processorDeclaration = processorDeclaration; + this.packageType = packageType; + } + + public URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException { + return getProcessor().getArtifactURL(packageSourceURL, artifact); + } + + public List getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, IOException { + return getProcessor().getArtifacts(packageSourceURL, inputStream); + } + + public String getPackageType() { + return packageType; + } + + @SuppressWarnings("unchecked") + private PackageProcessor getProcessor() { + if (processor == null) { + try { + Class processorClass = (Class)processorDeclaration.loadClass(); + Constructor constructor = processorClass.getConstructor(); + processor = constructor.newInstance(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return processor; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..a390c61eec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.util.Map; +import java.util.Set; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * The default implementation of an extension point for StAX artifact processors. + * + * @version $Rev$ $Date$ + */ +public class DefaultStAXArtifactProcessorExtensionPoint extends + DefaultArtifactProcessorExtensionPoint implements StAXArtifactProcessorExtensionPoint { + + private ExtensionPointRegistry extensionPoints; + private ModelFactoryExtensionPoint modelFactories; + private MonitorFactory monitorFactory; + private boolean loaded; + private StAXArtifactProcessor extensibleStAXProcessor; + private StAXAttributeProcessor extensibleStAXAttributeProcessor; + private Monitor monitor = null; + + /** + * Constructs a new extension point. + */ + public DefaultStAXArtifactProcessorExtensionPoint(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + if (monitorFactory != null) + this.monitor = monitorFactory.createMonitor(); + this.extensibleStAXProcessor = new ExtensibleStAXArtifactProcessor(this, inputFactory, outputFactory, this.monitor); + + StAXAttributeProcessorExtensionPoint attributeExtensionPoint = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + this.extensibleStAXAttributeProcessor = new ExtensibleStAXAttributeProcessor(attributeExtensionPoint ,inputFactory, outputFactory, this.monitor); + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public void addArtifactProcessor(StAXArtifactProcessor artifactProcessor) { + if (artifactProcessor.getArtifactType() != null) { + processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); + } + if (artifactProcessor.getModelType() != null) { + processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor); + } + } + + public void removeArtifactProcessor(StAXArtifactProcessor artifactProcessor) { + if (artifactProcessor.getArtifactType() != null) { + processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); + } + if (artifactProcessor.getModelType() != null) { + processorsByModelType.remove(artifactProcessor.getModelType()); + } + } + + @Override + public StAXArtifactProcessor getProcessor(Class modelType) { + loadArtifactProcessors(); + return super.getProcessor(modelType); + } + + @Override + public StAXArtifactProcessor getProcessor(Object artifactType) { + loadArtifactProcessors(); + return super.getProcessor(artifactType); + } + + /** + * Returns a QName object from a QName expressed as {ns}name + * or ns#name. + * + * @param qname + * @return + */ + private static QName getQName(String qname) { + if (qname == null) { + return null; + } + qname = qname.trim(); + if (qname.startsWith("{")) { + int h = qname.indexOf('}'); + if (h != -1) { + return new QName(qname.substring(1, h), qname.substring(h + 1)); + } + } else { + int h = qname.indexOf('#'); + if (h != -1) { + return new QName(qname.substring(0, h), qname.substring(h + 1)); + } + } + throw new IllegalArgumentException("Invalid qname: "+qname); + } + + /** + * Lazily load artifact processors registered in the extension point. + */ + private synchronized void loadArtifactProcessors() { + if (loaded) + return; + + // Get the processor service declarations + Set processorDeclarations; + try { + processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXArtifactProcessor.class); + } catch (IOException e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", extensibleStAXProcessor, ie); + throw ie; + } + + for (ServiceDeclaration processorDeclaration : processorDeclarations) { + Map attributes = processorDeclaration.getAttributes(); + + // Load a StAX artifact processor + + // Get the model QName + QName artifactType = getQName(attributes.get("qname")); + + // Get the model class name + String modelTypeName = attributes.get("model"); + + // Get the model factory class name + String factoryName = attributes.get("factory"); + + // Create a processor wrapper and register it + StAXArtifactProcessor processor = + new LazyStAXArtifactProcessor(artifactType, modelTypeName, factoryName, + processorDeclaration, extensionPoints, modelFactories, + extensibleStAXProcessor,extensibleStAXAttributeProcessor, monitor); + addArtifactProcessor(processor); + } + + loaded = true; + } + + /** + * A wrapper around an Artifact processor class allowing lazy loading and + * initialization of artifact processors. + */ + private static class LazyStAXArtifactProcessor implements StAXArtifactProcessor { + + private ExtensionPointRegistry extensionPoints; + private QName artifactType; + private String modelTypeName; + private String factoryName; + private ServiceDeclaration processorDeclaration; + private StAXArtifactProcessor processor; + private Class modelType; + private StAXArtifactProcessor extensionProcessor; + private StAXAttributeProcessor extensionAttributeProcessor; + private Monitor monitor; + + LazyStAXArtifactProcessor(QName artifactType, + String modelTypeName, + String factoryName, + ServiceDeclaration processorDeclaration, + ExtensionPointRegistry extensionPoints, + ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + + this.extensionPoints = extensionPoints; + this.artifactType = artifactType; + this.modelTypeName = modelTypeName; + this.factoryName = factoryName; + this.processorDeclaration = processorDeclaration; + this.extensionProcessor = extensionProcessor; + this.extensionAttributeProcessor = extensionAttributeProcessor; + this.monitor = monitor; + } + + public QName getArtifactType() { + return artifactType; + } + + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + @SuppressWarnings("unchecked") + private StAXArtifactProcessor getProcessor() { + if (processor == null) { + + if (processorDeclaration.getClassName() + .equals("org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor")) { + + // Specific initialization for the DefaultBeanModelProcessor + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + ExtensionFactory extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + PolicyFactory policyFactory = modelFactories.getFactory(PolicyFactory.class); + try { + Class processorClass = + (Class)processorDeclaration.loadClass(); + Object modelFactory; + if (factoryName != null) { + Class factoryClass = (Class)processorDeclaration.loadClass(factoryName); + modelFactory = modelFactories.getFactory(factoryClass); + } else { + modelFactory = null; + } + Constructor constructor = + processorClass.getConstructor(AssemblyFactory.class, + ExtensionFactory.class, + PolicyFactory.class, + QName.class, + Class.class, + Object.class, + Monitor.class); + processor = + constructor.newInstance(assemblyFactory, + extensionFactory, + policyFactory, + artifactType, + getModelType(), + modelFactory, + monitor); + } catch (Exception e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processor, ie); + throw ie; + } + } else { + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + + // Load and instantiate the processor class + try { + Class processorClass = + (Class)processorDeclaration.loadClass(); + try { + Constructor constructor = + processorClass.getConstructor(ModelFactoryExtensionPoint.class, Monitor.class); + processor = constructor.newInstance(modelFactories, monitor); + } catch (NoSuchMethodException e) { + try { + Constructor constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); + processor = constructor.newInstance(extensionPoints, monitor); + } catch (NoSuchMethodException e1) { + try { + Constructor constructor = + processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class); + processor = constructor.newInstance(modelFactories, extensionProcessor, monitor); + } catch (NoSuchMethodException e2) { + try { + Constructor constructor = + processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class, StAXAttributeProcessor.class, Monitor.class); + processor = constructor.newInstance(modelFactories, extensionProcessor, extensionAttributeProcessor, monitor); + } catch (NoSuchMethodException e2a) { + try { + Constructor constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class); + processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor); + } catch (NoSuchMethodException e3) { + try { + Constructor constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, StAXAttributeProcessor.class, Monitor.class); + processor = constructor.newInstance(extensionPoints, extensionProcessor, extensionAttributeProcessor, monitor); + } catch (NoSuchMethodException e3a) { + + try { + Constructor constructor = + processorClass.getConstructor(ModelFactoryExtensionPoint.class); + processor = constructor.newInstance(modelFactories); + } catch (NoSuchMethodException e4) { + try { + Constructor constructor = + processorClass.getConstructor(ExtensionPointRegistry.class); + processor = constructor.newInstance(extensionPoints); + } catch (NoSuchMethodException e4a) { + try { + Constructor constructor = + processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class); + processor = constructor.newInstance(modelFactories, extensionProcessor); + } catch (NoSuchMethodException e5) { + Constructor constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class); + processor = constructor.newInstance(extensionPoints, extensionProcessor); + } + } + } + } + } + } + } + } + } + } catch (Exception e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processor, ie); + throw ie; + } + } + } + return processor; + } + + public Object read(XMLStreamReader inputSource) throws ContributionReadException, XMLStreamException { + return getProcessor().read(inputSource); + } + + @SuppressWarnings("unchecked") + public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, + XMLStreamException { + getProcessor().write(model, outputSource); + } + + public Class getModelType() { + if (modelTypeName != null && modelType == null) { + try { + modelType = processorDeclaration.loadClass(modelTypeName); + } catch (Exception e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processorDeclaration, ie); + throw ie; + } + } + return modelType; + } + + @SuppressWarnings("unchecked") + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + getProcessor().resolve(model, resolver); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java new file mode 100644 index 0000000000..3699a09f00 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java @@ -0,0 +1,327 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.util.Map; +import java.util.Set; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * The default implementation of an extension point for StAX artifact processors. + * + * @version $Rev$ $Date$ + */ +public class DefaultStAXAttributeProcessorExtensionPoint extends + DefaultArtifactProcessorExtensionPoint implements StAXAttributeProcessorExtensionPoint { + + private ExtensionPointRegistry extensionPoints; + private ModelFactoryExtensionPoint modelFactories; + private StAXAttributeProcessor extensibleStAXAttributeProcessor; + private boolean loaded; + private Monitor monitor = null; + + /** + * Constructs a new extension point. + */ + public DefaultStAXAttributeProcessorExtensionPoint(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + if (monitorFactory != null) { + this.monitor = monitorFactory.createMonitor(); + } + this.extensibleStAXAttributeProcessor = new ExtensibleStAXAttributeProcessor(this, inputFactory, outputFactory, this.monitor); + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public void addArtifactProcessor(StAXAttributeProcessor artifactProcessor) { + if (artifactProcessor.getArtifactType() != null) { + processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); + } + if (artifactProcessor.getModelType() != null) { + processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor); + } + } + + public void removeArtifactProcessor(StAXAttributeProcessor artifactProcessor) { + if (artifactProcessor.getArtifactType() != null) { + processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); + } + if (artifactProcessor.getModelType() != null) { + processorsByModelType.remove(artifactProcessor.getModelType()); + } + } + + @Override + public StAXAttributeProcessor getProcessor(Class modelType) { + loadArtifactProcessors(); + return super.getProcessor(modelType); + } + + @Override + public StAXAttributeProcessor getProcessor(Object artifactType) { + loadArtifactProcessors(); + return super.getProcessor(artifactType); + } + + /** + * Returns a QName object from a QName expressed as {ns}name + * or ns#name. + * + * @param qname + * @return + */ + private static QName getQName(String qname) { + if (qname == null) { + return null; + } + qname = qname.trim(); + if (qname.startsWith("{")) { + int h = qname.indexOf('}'); + if (h != -1) { + return new QName(qname.substring(1, h), qname.substring(h + 1)); + } + } else { + int h = qname.indexOf('#'); + if (h != -1) { + return new QName(qname.substring(0, h), qname.substring(h + 1)); + } + } + throw new IllegalArgumentException("Invalid qname: "+qname); + } + + /** + * Lazily load artifact processors registered in the extension point. + */ + private synchronized void loadArtifactProcessors() { + if (loaded) + return; + + // Get the processor service declarations + Set processorDeclarations; + try { + processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXAttributeProcessor.class); + } catch (IOException e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", extensibleStAXAttributeProcessor, ie); + throw ie; + } + + for (ServiceDeclaration processorDeclaration : processorDeclarations) { + Map attributes = processorDeclaration.getAttributes(); + + // Load a StAX artifact processor + + // Get the model QName + QName artifactType = getQName(attributes.get("qname")); + + // Get the model class name + String modelTypeName = attributes.get("model"); + + // Get the model factory class name + String factoryName = attributes.get("factory"); + + // Create a processor wrapper and register it + StAXAttributeProcessor processor = + new LazyStAXAttributeProcessor(artifactType, modelTypeName, factoryName, + processorDeclaration, extensionPoints, modelFactories, + extensibleStAXAttributeProcessor, monitor); + addArtifactProcessor(processor); + } + + loaded = true; + } + + /** + * A wrapper around an Artifact processor class allowing lazy loading and + * initialization of artifact processors. + */ + private static class LazyStAXAttributeProcessor implements StAXAttributeProcessor { + + private ExtensionPointRegistry extensionPoints; + private QName artifactType; + private String modelTypeName; + private String factoryName; + private ServiceDeclaration processorDeclaration; + private StAXAttributeProcessor processor; + private Class modelType; + private StAXAttributeProcessor extensionProcessor; + private Monitor monitor; + + LazyStAXAttributeProcessor(QName artifactType, + String modelTypeName, + String factoryName, + ServiceDeclaration processorDeclaration, + ExtensionPointRegistry extensionPoints, + ModelFactoryExtensionPoint modelFactories, + StAXAttributeProcessor extensionProcessor, + Monitor monitor) { + + this.extensionPoints = extensionPoints; + this.artifactType = artifactType; + this.modelTypeName = modelTypeName; + this.factoryName = factoryName; + this.processorDeclaration = processorDeclaration; + this.extensionProcessor = extensionProcessor; + this.monitor = monitor; + } + + public QName getArtifactType() { + return artifactType; + } + + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + @SuppressWarnings("unchecked") + private StAXAttributeProcessor getProcessor() { + if (processor == null) { + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + + // Load and instantiate the processor class + try { + Class processorClass = + (Class)processorDeclaration.loadClass(); + try { + Constructor constructor = + processorClass.getConstructor(ModelFactoryExtensionPoint.class, Monitor.class); + processor = constructor.newInstance(modelFactories, monitor); + } catch (NoSuchMethodException e) { + try { + Constructor constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); + processor = constructor.newInstance(extensionPoints, monitor); + } catch (NoSuchMethodException e1) { + try { + Constructor constructor = + processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class); + processor = constructor.newInstance(modelFactories, extensionProcessor, monitor); + } catch (NoSuchMethodException e2) { + try { + Constructor constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class); + processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor); + } catch (NoSuchMethodException e3) { + try { + Constructor constructor = + processorClass.getConstructor(ModelFactoryExtensionPoint.class); + processor = constructor.newInstance(modelFactories); + } catch (NoSuchMethodException e4) { + try { + Constructor constructor = + processorClass.getConstructor(ExtensionPointRegistry.class); + processor = constructor.newInstance(extensionPoints); + } catch (NoSuchMethodException e4a) { + try { + Constructor constructor = + processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class); + processor = constructor.newInstance(modelFactories, extensionProcessor); + } catch (NoSuchMethodException e5) { + Constructor constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class); + processor = constructor.newInstance(extensionPoints, extensionProcessor); + } + } + } + } + } + } + } + } catch (Exception e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processor, ie); + throw ie; + } + + } + return processor; + } + + public Object read(QName attributeName, XMLStreamReader inputSource) throws ContributionReadException, XMLStreamException { + return getProcessor().read(attributeName, inputSource); + } + + @SuppressWarnings("unchecked") + public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { + getProcessor().write(model, outputSource); + } + + public Class getModelType() { + if (modelTypeName != null && modelType == null) { + try { + modelType = processorDeclaration.loadClass(modelTypeName); + } catch (Exception e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processorDeclaration, ie); + throw ie; + } + } + return modelType; + } + + @SuppressWarnings("unchecked") + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + getProcessor().resolve(model, resolver); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..7725360f6f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java @@ -0,0 +1,244 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.net.URI; +import java.net.URL; +import java.util.Map; +import java.util.Set; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + + +/** + * The default implementation of a URL artifact processor extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultURLArtifactProcessorExtensionPoint + extends DefaultArtifactProcessorExtensionPoint + implements URLArtifactProcessorExtensionPoint { + + private ExtensionPointRegistry extensionPoints; + private StAXArtifactProcessor staxProcessor; + private boolean loaded; + private Monitor monitor = null; + + /** + * Constructs a new extension point. + */ + public DefaultURLArtifactProcessorExtensionPoint(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + ModelFactoryExtensionPoint modelFactories = this.extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + if (monitorFactory != null) { + this.monitor = monitorFactory.createMonitor(); + } + StAXArtifactProcessorExtensionPoint staxProcessors = + extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, this.monitor); + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public void addArtifactProcessor(URLArtifactProcessor artifactProcessor) { + if (artifactProcessor.getArtifactType() != null) { + processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); + } + if (artifactProcessor.getModelType() != null) { + processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor); + } + } + + public void removeArtifactProcessor(URLArtifactProcessor artifactProcessor) { + if (artifactProcessor.getArtifactType() != null) { + processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); + } + if (artifactProcessor.getModelType() != null) { + processorsByModelType.remove(artifactProcessor.getModelType()); + } + } + + @Override + public URLArtifactProcessor getProcessor(Class modelType) { + loadProcessors(); + return super.getProcessor(modelType); + } + + @Override + public URLArtifactProcessor getProcessor(Object artifactType) { + loadProcessors(); + return super.getProcessor(artifactType); + } + + /** + * Lazily load artifact processors registered in the extension point. + */ + private synchronized void loadProcessors() { + if (loaded) + return; + + // Get the processor service declarations + Set processorDeclarations; + try { + processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(URLArtifactProcessor.class); + } catch (IOException e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", staxProcessor, ie); + throw ie; + } + + for (ServiceDeclaration processorDeclaration: processorDeclarations) { + Map attributes = processorDeclaration.getAttributes(); + // Load a URL artifact processor + String artifactType = attributes.get("type"); + String modelTypeName = attributes.get("model"); + + // Create a processor wrapper and register it + URLArtifactProcessor processor = new LazyURLArtifactProcessor(artifactType, modelTypeName, + processorDeclaration, extensionPoints, staxProcessor, monitor); + addArtifactProcessor(processor); + } + + loaded = true; + } + + /** + * A wrapper around an Artifact processor class allowing lazy loading and + * initialization of artifact processors. + */ + private static class LazyURLArtifactProcessor implements URLArtifactProcessor { + + private ExtensionPointRegistry extensionPoints; + private String artifactType; + private String modelTypeName; + private ServiceDeclaration processorDeclaration; + private URLArtifactProcessor processor; + private Class modelType; + private StAXArtifactProcessor staxProcessor; + private Monitor monitor; + + LazyURLArtifactProcessor(String artifactType, + String modelTypeName, + ServiceDeclaration processorDeclaration, + ExtensionPointRegistry extensionPoints, + StAXArtifactProcessor staxProcessor, + Monitor monitor) { + this.artifactType = artifactType; + this.modelTypeName = modelTypeName; + this.processorDeclaration = processorDeclaration; + this.extensionPoints = extensionPoints; + this.staxProcessor = staxProcessor; + this.monitor = monitor; + } + + public String getArtifactType() { + return artifactType; + } + + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + @SuppressWarnings("unchecked") + private URLArtifactProcessor getProcessor() { + if (processor == null) { + try { + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + Class processorClass = (Class)processorDeclaration.loadClass(); + try { + Constructor constructor = processorClass.getConstructor(ModelFactoryExtensionPoint.class, Monitor.class); + processor = constructor.newInstance(modelFactories, monitor); + } catch (NoSuchMethodException e) { + try { + Constructor constructor = processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class); + processor = constructor.newInstance(modelFactories, staxProcessor, monitor); + } catch (NoSuchMethodException e2) { + Constructor constructor = processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); + processor = constructor.newInstance(extensionPoints, monitor); + } + } + } catch (Exception e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processor, ie); + throw ie; + } + } + return processor; + } + + public Object read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { + return getProcessor().read(contributionURL, artifactURI, artifactURL); + } + + public Class getModelType() { + if (modelTypeName != null && modelType == null) { + try { + modelType = processorDeclaration.loadClass(modelTypeName); + } catch (ClassNotFoundException e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processorDeclaration, ie); + throw ie; + } + } + return modelType; + } + + @SuppressWarnings("unchecked") + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + getProcessor().resolve(model, resolver); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java new file mode 100644 index 0000000000..6fc32d4e70 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java @@ -0,0 +1,317 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.net.URL; +import java.net.URLConnection; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.XMLConstants; +import javax.xml.stream.EventFilter; +import javax.xml.stream.StreamFilter; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLReporter; +import javax.xml.stream.XMLResolver; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.util.XMLEventAllocator; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +/** + * Default implementation of an XMLInputFactory that creates validating + * XMLStreamReaders. + * + * @version $Rev$ $Date$ + */ +public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory { + private static final Logger logger = Logger.getLogger(DefaultValidatingXMLInputFactory.class.getName()); + private XMLInputFactory inputFactory; + private ValidationSchemaExtensionPoint schemas; + private Monitor monitor; + private boolean initialized; + private boolean hasSchemas; + private Schema aggregatedSchema; + + /** + * Constructs a new XMLInputFactory. + * + * @param inputFactory + * @param schemas + */ + public DefaultValidatingXMLInputFactory(XMLInputFactory inputFactory, ValidationSchemaExtensionPoint schemas, Monitor monitor) { + this.inputFactory = inputFactory; + this.schemas = schemas; + this.monitor = monitor; + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = + new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, + message, ex); + monitor.problem(problem); + } + } + + /** + * Initialize the registered schemas and create an aggregated schema for + * validation. + */ + private void initializeSchemas() { + if (initialized) { + return; + } + initialized = true; + + // Load the XSDs registered in the validation schema extension point + try { + List uris = schemas.getSchemas(); + int n = uris.size(); + if (n ==0) { + return; + } else { + hasSchemas = true; + } + final Source[] sources = new Source[n]; + for (int i =0; i < n; i++) { + final String uri = uris.get(i); + // Allow privileged access to open URL stream. Requires FilePermission in security policy. + final URL url = new URL( uri ); + InputStream urlStream; + try { + urlStream = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public InputStream run() throws IOException { + URLConnection connection = url.openConnection(); + connection.setUseCaches(false); + return connection.getInputStream(); + } + }); + } catch (PrivilegedActionException e) { + error("PrivilegedActionException", url, (IOException)e.getException()); + throw (IOException)e.getException(); + } + sources[i] = new StreamSource(urlStream, uri); + } + + // Create an aggregated validation schemas from all the XSDs + final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + // Allow privileged access to check files. Requires FilePermission + // in security policy. + try { + aggregatedSchema = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Schema run() throws SAXException { + return schemaFactory.newSchema(sources); + } + }); + } catch (PrivilegedActionException e) { + error("PrivilegedActionException", schemaFactory, (SAXException)e.getException()); + throw (SAXException)e.getException(); + } + + } catch (Error e) { + // FIXME Log this, some old JDKs don't support XMLSchema validation + logger.log(Level.WARNING, "XML Schema validation is not supported: " + e.getMessage()); + } catch (SAXParseException e) { + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", schemas, ie); + throw ie; + } catch (Exception e) { + //FIXME Log this, some old JDKs don't support XMLSchema validation + logger.log(Level.WARNING, "XML Schema validation is not supported: " + e.getMessage()); + } + } + + @Override + public XMLEventReader createFilteredReader(XMLEventReader arg0, EventFilter arg1) throws XMLStreamException { + return inputFactory.createFilteredReader(arg0, arg1); + } + + @Override + public XMLStreamReader createFilteredReader(XMLStreamReader arg0, StreamFilter arg1) throws XMLStreamException { + return inputFactory.createFilteredReader(arg0, arg1); + } + + @Override + public XMLEventReader createXMLEventReader(InputStream arg0, String arg1) throws XMLStreamException { + return inputFactory.createXMLEventReader(arg0, arg1); + } + + @Override + public XMLEventReader createXMLEventReader(InputStream arg0) throws XMLStreamException { + return inputFactory.createXMLEventReader(arg0); + } + + @Override + public XMLEventReader createXMLEventReader(Reader arg0) throws XMLStreamException { + return inputFactory.createXMLEventReader(arg0); + } + + @Override + public XMLEventReader createXMLEventReader(Source arg0) throws XMLStreamException { + return inputFactory.createXMLEventReader(arg0); + } + + @Override + public XMLEventReader createXMLEventReader(String arg0, InputStream arg1) throws XMLStreamException { + return inputFactory.createXMLEventReader(arg0, arg1); + } + + @Override + public XMLEventReader createXMLEventReader(String arg0, Reader arg1) throws XMLStreamException { + return inputFactory.createXMLEventReader(arg0, arg1); + } + + @Override + public XMLEventReader createXMLEventReader(XMLStreamReader arg0) throws XMLStreamException { + return inputFactory.createXMLEventReader(arg0); + } + + @Override + public XMLStreamReader createXMLStreamReader(InputStream arg0, String arg1) throws XMLStreamException { + initializeSchemas(); + if (hasSchemas) { + return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor); + }else { + return inputFactory.createXMLStreamReader(arg0, arg1); + } + } + + @Override + public XMLStreamReader createXMLStreamReader(InputStream arg0) throws XMLStreamException { + initializeSchemas(); + if (hasSchemas) { + return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor); + } else { + return inputFactory.createXMLStreamReader(arg0); + } + } + + @Override + public XMLStreamReader createXMLStreamReader(Reader arg0) throws XMLStreamException { + initializeSchemas(); + if (hasSchemas) { + return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor); + } else { + return inputFactory.createXMLStreamReader(arg0); + } + } + + @Override + public XMLStreamReader createXMLStreamReader(Source arg0) throws XMLStreamException { + initializeSchemas(); + if (hasSchemas) { + return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor); + } else { + return inputFactory.createXMLStreamReader(arg0); + } + } + + @Override + public XMLStreamReader createXMLStreamReader(String arg0, InputStream arg1) throws XMLStreamException { + initializeSchemas(); + if (hasSchemas) { + return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor); + } else { + return inputFactory.createXMLStreamReader(arg0, arg1); + } + } + + @Override + public XMLStreamReader createXMLStreamReader(String arg0, Reader arg1) throws XMLStreamException { + initializeSchemas(); + if (hasSchemas) { + return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor); + } else { + return inputFactory.createXMLStreamReader(arg0, arg1); + } + } + + @Override + public XMLEventAllocator getEventAllocator() { + return inputFactory.getEventAllocator(); + } + + @Override + public Object getProperty(String arg0) throws IllegalArgumentException { + return inputFactory.getProperty(arg0); + } + + @Override + public XMLReporter getXMLReporter() { + return inputFactory.getXMLReporter(); + } + + @Override + public XMLResolver getXMLResolver() { + return inputFactory.getXMLResolver(); + } + + @Override + public boolean isPropertySupported(String arg0) { + return inputFactory.isPropertySupported(arg0); + } + + @Override + public void setEventAllocator(XMLEventAllocator arg0) { + inputFactory.setEventAllocator(arg0); + } + + @Override + public void setProperty(String arg0, Object arg1) throws IllegalArgumentException { + inputFactory.setProperty(arg0, arg1); + } + + @Override + public void setXMLReporter(XMLReporter arg0) { + inputFactory.setXMLReporter(arg0); + } + + @Override + public void setXMLResolver(XMLResolver arg0) { + inputFactory.setXMLResolver(arg0); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java new file mode 100644 index 0000000000..9f4094aa12 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + +/** + * Default implementation of an extension point for XML schemas. + * + * @version $Rev$ $Date$ + */ +public class DefaultValidationSchemaExtensionPoint implements ValidationSchemaExtensionPoint { + + private List schemas = new ArrayList(); + private boolean loaded; + + public void addSchema(String uri) { + schemas.add(uri); + } + + public void removeSchema(String uri) { + schemas.remove(uri); + } + + /** + * Load schema declarations from META-INF/services/ + * org.apache.tuscany.sca.contribution.processor.ValidationSchema files + */ + private synchronized void loadSchemas() { + if (loaded) + return; + + // Get the schema declarations + Set schemaDeclarations; + try { + schemaDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations("org.apache.tuscany.sca.contribution.processor.ValidationSchema"); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // TODO - temp fix to ensure that the schema tuscany-sca.xsd always comes first + String tuscanyScaXsd = null; + + // Find each schema + for (ServiceDeclaration schemaDeclaration: schemaDeclarations) { + URL url = schemaDeclaration.getResource(schemaDeclaration.getClassName()); + if (url == null) { + throw new IllegalArgumentException(new FileNotFoundException(schemaDeclaration.getClassName())); + } + + if (url.toString().contains("tuscany-sca.xsd")){ + tuscanyScaXsd = url.toString(); + } else { + schemas.add(url.toString()); + } + } + + if (tuscanyScaXsd != null){ + schemas.add(0, tuscanyScaXsd); + } + + loaded = true; + } + + public List getSchemas() { + loadSchemas(); + return schemas; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java new file mode 100644 index 0000000000..2e24477f35 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.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.sca.contribution.processor; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.contribution.service.TypeDescriber; +import org.apache.tuscany.sca.contribution.service.UnsupportedPackageTypeException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Implementation of an extensible package processor. + * + * Takes a package processor extension point and delegates to the proper package + * processor from the extension point based on the package's content type. + * + * @version $Rev$ $Date$ + */ +public class ExtensiblePackageProcessor implements PackageProcessor { + + private PackageProcessorExtensionPoint processors; + private TypeDescriber packageTypeDescriber; + private Monitor monitor; + + public ExtensiblePackageProcessor(PackageProcessorExtensionPoint processors, + TypeDescriber packageTypeDescriber, + Monitor monitor) { + this.processors = processors; + this.packageTypeDescriber = packageTypeDescriber; + this.monitor = monitor; + } + + /** + * Marshals errors into the monitor + * + * @param problems + * @param message + * @param model + */ + protected void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + public List getArtifacts(URL packageSourceURL, InputStream inputStream) + throws ContributionException, IOException { + String packageType = this.packageTypeDescriber.getType(packageSourceURL, null); + if (packageType == null) { + error("UnsupportedPackageTypeException", packageTypeDescriber, packageSourceURL.toString()); + throw new UnsupportedPackageTypeException("Unsupported contribution package type: " + packageSourceURL.toString()); + } + + PackageProcessor packageProcessor = this.processors.getPackageProcessor(packageType); + if (packageProcessor == null) { + error("UnsupportedPackageTypeException", packageTypeDescriber, packageType); + throw new UnsupportedPackageTypeException("Unsupported contribution package type: " + packageType); + } + + return packageProcessor.getArtifacts(packageSourceURL, inputStream); + } + + public URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException { + String contentType = this.packageTypeDescriber.getType(packageSourceURL, null); + PackageProcessor packageProcessor = this.processors.getPackageProcessor(contentType); + return packageProcessor.getArtifactURL(packageSourceURL, artifact); + } + + public String getPackageType() { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java new file mode 100644 index 0000000000..cc3eaf9379 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java @@ -0,0 +1,264 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.Constants; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.contribution.service.UnrecognizedElementException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Implementation of an extensible StAX artifact processor. + * + * Takes a StAXArtifactProcessorExtensionPoint and delegates to the proper + * StAXArtifactProcessor by element QName + * + * @version $Rev$ $Date$ + */ +public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor { + + private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS, "anyElement"); + + private static final Logger logger = Logger.getLogger(ExtensibleStAXArtifactProcessor.class.getName()); + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private StAXArtifactProcessorExtensionPoint processors; + private Monitor monitor; + + /** + * Constructs a new ExtensibleStAXArtifactProcessor. + * @param processors + * @param inputFactory + * @param outputFactory + */ + public ExtensibleStAXArtifactProcessor(StAXArtifactProcessorExtensionPoint processors, + XMLInputFactory inputFactory, + XMLOutputFactory outputFactory, + Monitor monitor) { + super(); + this.processors = processors; + this.inputFactory = inputFactory; + this.outputFactory = outputFactory; + if (this.outputFactory != null) { + this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE); + } + this.monitor = monitor; + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void warning(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + + public Object read(XMLStreamReader source) throws ContributionReadException, XMLStreamException { + + // Delegate to the processor associated with the element QName + int event = source.getEventType(); + if (event == XMLStreamConstants.START_DOCUMENT) { + source.nextTag(); + } + QName name = source.getName(); + StAXArtifactProcessor processor = (StAXArtifactProcessor)processors.getProcessor(name); + if (processor == null) { + Location location = source.getLocation(); + if (logger.isLoggable(Level.WARNING)) { + logger.warning("Element " + name + " cannot be processed. (" + location + ")"); + } + warning("ElementCannotBeProcessed", processors, name, location); + + StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT); + if(anyElementProcessor != null) { + return anyElementProcessor.read(source); + } else { + return null; + } + + } + return processor.read(source); + } + + @SuppressWarnings("unchecked") + public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { + + // Delegate to the processor associated with the model type + if (model != null) { + StAXArtifactProcessor processor = processors.getProcessor(model.getClass()); + if (processor != null) { + processor.write(model, outputSource); + } else { + if (logger.isLoggable(Level.WARNING)) { + logger.warning("No StAX processor is configured to handle " + model.getClass()); + } + warning("NoStaxProcessor", processors, model.getClass()); + StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT); + if(anyElementProcessor != null) { + anyElementProcessor.write(model, outputSource); + } + } + } + } + + @SuppressWarnings("unchecked") + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + + // Delegate to the processor associated with the model type + if (model != null) { + StAXArtifactProcessor processor = processors.getProcessor(model.getClass()); + if (processor != null) { + processor.resolve(model, resolver); + } + } + } + + /** + * Read a model from an InputStream. + * @param is The artifact InputStream + * @param type Model type + * @return The model + * @throws ContributionReadException + */ + public M read(InputStream is, Class type) throws ContributionReadException { + try { + XMLStreamReader reader; + try { + reader = inputFactory.createXMLStreamReader(is); + try { + reader.nextTag(); + QName name = reader.getName(); + Object mo = read(reader); + if (type.isInstance(mo)) { + return type.cast(mo); + } else { + error("UnrecognizedElementException", reader, name); + UnrecognizedElementException e = new UnrecognizedElementException(name); + throw e; + } + } catch (ContributionReadException e) { + Location location = reader.getLocation(); + e.setLine(location.getLineNumber()); + e.setColumn(location.getColumnNumber()); + error("ContributionReadException", reader, e); + throw e; + } finally { + try { + reader.close(); + } catch (XMLStreamException e) { + // ignore + } + } + } finally { + try { + is.close(); + } catch (IOException e) { + // ignore + } + } + } catch (XMLStreamException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", inputFactory, ce); + throw ce; + } + } + + /** + * Write a model to an OutputStream. + * @param model + * @param os + * @throws ContributionWriteException + */ + public void write(Object model, OutputStream os) throws ContributionWriteException { + try { + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os); + write(model, writer); + writer.flush(); + writer.close(); + } catch (XMLStreamException e) { + ContributionWriteException cw = new ContributionWriteException(e); + error("ContributionWriteException", outputFactory, cw); + throw cw; + } + } + + public QName getArtifactType() { + return null; + } + + public Class getModelType() { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java new file mode 100644 index 0000000000..f2ee8bc786 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java @@ -0,0 +1,247 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.Constants; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Implementation of an extensible StAX attribute processor. + * + * Takes a StAXAttributeProcessorExtensionPoint and delegates to the proper + * StAXAttributeProcessor by attribute QName + * + * @version $Rev$ $Date$ + */ +public class ExtensibleStAXAttributeProcessor + implements StAXAttributeProcessor { + + private static final Logger logger = Logger.getLogger(ExtensibleStAXAttributeProcessor.class.getName()); + + private static final QName ANY_ATTRIBUTE = new QName(Constants.XMLSCHEMA_NS, "anyAttribute"); + + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private StAXAttributeProcessorExtensionPoint processors; + private Monitor monitor; + + /** + * Constructs a new ExtensibleStAXArtifactProcessor. + * @param processors + * @param inputFactory + * @param outputFactory + */ + public ExtensibleStAXAttributeProcessor(StAXAttributeProcessorExtensionPoint processors, + XMLInputFactory inputFactory, + XMLOutputFactory outputFactory, + Monitor monitor) { + super(); + this.processors = processors; + this.inputFactory = inputFactory; + this.outputFactory = outputFactory; + if (this.outputFactory != null) { + this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE); + } + this.monitor = monitor; + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void warning(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + + public Object read(QName attributeName, XMLStreamReader source) throws ContributionReadException, XMLStreamException { + + // Delegate to the processor associated with the attribute QName + int event = source.getEventType(); + if (event == XMLStreamConstants.START_DOCUMENT) { + source.nextTag(); + } + + StAXAttributeProcessor processor = null; + + //lookup for registered attribute processors + processor = (StAXAttributeProcessor)processors.getProcessor(attributeName); + if (processor == null) { + Location location = source.getLocation(); + if (logger.isLoggable(Level.WARNING)) { + logger.warning("Attribute " + attributeName + " cannot be processed. (" + location + ")"); + } + warning("AttributeCannotBeProcessed", processors, attributeName, location); + } else { + return processor.read(attributeName, source); + } + + + //handle extension attributes without processors + processor = (StAXAttributeProcessor)processors.getProcessor(ANY_ATTRIBUTE); + if (processor == null) { + Location location = source.getLocation(); + if (logger.isLoggable(Level.WARNING)) { + logger.warning("Could not find Default Attribute processor !"); + } + warning("DefaultAttributeProcessorNotAvailable", processors, ANY_ATTRIBUTE, location); + } + + return processor == null ? null : processor.read(attributeName, source); + } + + @SuppressWarnings("unchecked") + public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { + + if(model == null) { + return; + } + + // Delegate to the processor associated with the model type + StAXAttributeProcessor processor = processors.getProcessor(model.getClass()); + if(processor == null) { + if (logger.isLoggable(Level.WARNING)) { + logger.warning("No StAX processor is configured to handle " + model.getClass()); + } + warning("NoStaxProcessor", processors, model.getClass()); + } else { + processor.write(model, outputSource); + return; + } + + //handle extension attributes without processors + processor = (StAXAttributeProcessor)processors.getProcessor(ANY_ATTRIBUTE); + if(processor == null) { + if (logger.isLoggable(Level.WARNING)) { + logger.warning("No Default StAX processor is configured to handle " + model.getClass()); + } + warning("NoDefaultStaxProcessor", processors, model.getClass()); + } else { + processor.write(model, outputSource); + return; + } + } + + + + @SuppressWarnings("unchecked") + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + + // Delegate to the processor associated with the model type + if (model != null) { + StAXAttributeProcessor processor = processors.getProcessor(model.getClass()); + if (processor != null) { + processor.resolve(model, resolver); + } + } + } + + /** + * Read a model from an InputStream. + * @param is The artifact InputStream + * @param type Model type + * @return The model + * @throws ContributionReadException + */ + public M read(InputStream is, Class type) throws ContributionReadException { + return null; + } + + /** + * Write a model to an OutputStream. + * @param model + * @param os + * @throws ContributionWriteException + */ + public void write(Object model, OutputStream os) throws ContributionWriteException { + try { + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os); + write(model, writer); + writer.flush(); + writer.close(); + } catch (XMLStreamException e) { + ContributionWriteException cw = new ContributionWriteException(e); + error("ContributionWriteException", outputFactory, cw); + throw cw; + } + } + + public QName getArtifactType() { + return null; + } + + public Class getModelType() { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java new file mode 100644 index 0000000000..8427098035 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.UnrecognizedElementException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +/** + * Implementation of an extensible URL artifact processor. + * + * Takes a URLArtifactProcessorExtensionPoint and delegates to the proper URLArtifactProcessor + * by either fileName or fileExtention + * + * @version $Rev$ $Date$ + */ +public class ExtensibleURLArtifactProcessor + implements URLArtifactProcessor { + + private URLArtifactProcessorExtensionPoint processors; + private Monitor monitor; + + /** + * Constructs a new ExtensibleURLArtifactProcessor. + * + * @param processors + */ + public ExtensibleURLArtifactProcessor(URLArtifactProcessorExtensionPoint processors, Monitor monitor) { + this.processors = processors; + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + @SuppressWarnings("unchecked") + public Object read(URL contributionURL, URI sourceURI, URL sourceURL) throws ContributionReadException { + URLArtifactProcessor processor = null; + + // Delegate to the processor associated with file extension + String fileName = getFileName(sourceURL); + + //try to retrieve a processor for the specific filename + processor = (URLArtifactProcessor)processors.getProcessor(fileName); + + if (processor == null) { + //try to find my file type (extension) + String extension = sourceURL.getPath(); + + int extensionStart = extension.lastIndexOf('.'); + //handle files without extension (e.g NOTICE) + if (extensionStart > 0) { + extension = extension.substring(extensionStart); + processor = (URLArtifactProcessor)processors.getProcessor(extension); + } + } + + if (processor == null) { + return null; + } + return processor.read(contributionURL, sourceURI, sourceURL); + } + + @SuppressWarnings("unchecked") + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + + // Delegate to the processor associated with the model type + if (model != null) { + URLArtifactProcessor processor = processors.getProcessor(model.getClass()); + if (processor != null) { + processor.resolve(model, resolver); + } + } + } + + public M read(URL contributionURL, URI artifactURI, URL artifactUrl, Class type) + throws ContributionReadException { + Object mo = read(contributionURL, artifactURI, artifactUrl); + if (type.isInstance(mo)) { + return type.cast(mo); + } else { + UnrecognizedElementException e = new UnrecognizedElementException(null); + e.setResourceURI(artifactURI.toString()); + error("UnrecognizedElementException", processors, artifactURI.toString()); + throw e; + } + } + + public String getArtifactType() { + return null; + } + + public Class getModelType() { + return null; + } + + /** + * Returns the file name from a URL. + * @param url + * @return + */ + private static String getFileName(URL url){ + String fileName = url.getPath(); + int pos = fileName.lastIndexOf("/"); + + return fileName.substring(pos +1); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java new file mode 100644 index 0000000000..f17f31edb1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.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.sca.contribution.processor; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Interface for contribution package processors + * + * Package processors understand the format of the contribution and how to get the + * artifacts in the contribution. + * + * @version $Rev$ $Date$ + */ +public interface PackageProcessor { + + /** + * Returns the type of package supported by this package processor. + * + * @return the package type + */ + String getPackageType(); + + /** + * Returns a list of artifacts in the contribution. + * + * @param packageSourceURL Contribution package location URL + * @param inputStream Optional content of the package + * @return List of artifact URIs + * @throws ContributionException + * @throws IOException + */ + List getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, IOException; + + /** + * Return the URL for an artifact in the package. + * + * This is needed for archives such as jar files that have specific URL schemes + * for the artifacts they contain. + * + * @param packageSourceURL Contribution package location URL + * @param artifact The relative URI for the artifact + * @return The artifact URL + */ + URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java new file mode 100644 index 0000000000..ed99239b19 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.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.sca.contribution.processor; + +/** + * An extension point for package processors + * + * @version $Rev$ $Date$ + */ +public interface PackageProcessorExtensionPoint { + + /** + * Register a PackageProcessor using the package type as the key. + * + * @param processor The package processor + */ + void addPackageProcessor(PackageProcessor processor); + + /** + * Unregister a PackageProcessor. + * + * @param processor The package processor + */ + void removePackageProcessor(PackageProcessor processor); + + /** + * Returns the PackageProcessor for the given package type. + * + * @param packageType The package type + * @return The package processor + */ + PackageProcessor getPackageProcessor(String packageType); + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java new file mode 100644 index 0000000000..fcf9347564 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.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.sca.contribution.processor; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + +/** + * An artifact processor that can read models from a StAX XMLStreamReader. + * + * @version $Rev$ $Date$ + */ +public interface StAXArtifactProcessor extends ArtifactProcessor { + + /** + * Reads a model from an XMLStreamReader. + * + * @param reader The XMLStreamReader + * @return A model representation of the input. + */ + M read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException; + + /** + * Writes a model to an XMLStreamWriter. + * + * @param model A model representing the source + * @param writer The XML stream writer + * @throws ContributionWriteException + * @throws XMLStreamException + */ + void write(M model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException; + + /** + * Returns the type of artifact handled by this artifact processor. + * + * @return The type of artifact handled by this artifact processor + */ + QName getArtifactType(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..9700e2bc60 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.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.sca.contribution.processor; + +/** + * An extension point for StAX artifact processors. + * + * @version $Rev$ $Date$ + */ +public interface StAXArtifactProcessorExtensionPoint extends + ArtifactProcessorExtensionPoint { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java new file mode 100644 index 0000000000..e8edb743a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.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.sca.contribution.processor; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + + +/** + * An artifact processor that can read attributes from a StAX XMLStreamReader. + * + * @version $Rev$ $Date$ + */ +public interface StAXAttributeProcessor extends ArtifactProcessor{ + + /** + * Reads a model from an XMLStreamReader. + * + * @param reader The XMLStreamReader + * @return A model representation of the input. + */ + M read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException; + + /** + * Writes a model to an XMLStreamWriter. + * + * @param model A model representing the source + * @param writer The XML stream writer + * @throws ContributionWriteException + * @throws XMLStreamException + */ + void write(M model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException; + + /** + * Returns the type of artifact handled by this artifact processor. + * + * @return The type of artifact handled by this artifact processor + */ + QName getArtifactType(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java new file mode 100644 index 0000000000..ebad243c1c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.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.sca.contribution.processor; + +/** + * An extension point for StAX artifact processors. + * + * @version $Rev$ $Date$ + */ +public interface StAXAttributeProcessorExtensionPoint extends + ArtifactProcessorExtensionPoint { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java new file mode 100644 index 0000000000..2adebb9f33 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Stack; + +import javax.xml.namespace.NamespaceContext; + +public class TuscanyNamespaceContext implements NamespaceContext { + + private Stack[]> context = null; + + public TuscanyNamespaceContext(Stack[]> context) { + this.context = context; + } + + public String getNamespaceURI(String prefix) { + if (prefix == null) { + throw new IllegalArgumentException(); + } + return (String)getResult("getNSUri", prefix); + } + + public String getPrefix(String namespaceURI) { + if (namespaceURI == null) { + throw new IllegalArgumentException(); + } + return (String)getResult("getPrefix", namespaceURI); + } + + @SuppressWarnings("unchecked") + public Iterator getPrefixes(String namespaceURI) { + if (namespaceURI == null) { + throw new IllegalArgumentException(); + } + + Iterator iterator = (Iterator)getResult("getPrefixes", namespaceURI); + return iterator; + } + + /* + * Generic method to Iterate through the Stack and return required result(s) + */ + private Object getResult(String operation, String arg) { + + List[] contextList = null; + Iterator prefItr = null; + Iterator uriItr = null; + + List list = new ArrayList(); + + String toCompare = null; + + String tempPrefix = null; + String tempUri = null; + + for (int i = context.size() - 1; i >= 0; i--) { + contextList = context.get(i); + prefItr = contextList[0].iterator(); + uriItr = contextList[1].iterator(); + while (uriItr.hasNext()) { + tempPrefix = prefItr.next(); + tempUri = uriItr.next(); + if (operation.equalsIgnoreCase("getNSUri")) { + toCompare = tempPrefix; + } else if (operation.equalsIgnoreCase("getPrefix")) { + toCompare = tempUri; + } else if (operation.equalsIgnoreCase("getPrefixes")) { + toCompare = tempUri; + } + if (toCompare != null && arg.equalsIgnoreCase(toCompare)) { + if (operation.equalsIgnoreCase("getNSUri")) { + return tempUri; + } else if (operation.equalsIgnoreCase("getPrefix")) { + return tempPrefix; + } else if (operation.equalsIgnoreCase("getPrefixes")) { + list.add(tempPrefix); + } + + } + } + } + + if (operation.equalsIgnoreCase("getPrefixes")) { + return Collections.unmodifiableList(list).iterator(); + } + + return null; + } + +} //end of Class diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java new file mode 100644 index 0000000000..e1b218d9f4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java @@ -0,0 +1,131 @@ +package org.apache.tuscany.sca.contribution.processor; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import javax.xml.XMLConstants; +import javax.xml.namespace.NamespaceContext; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.util.StreamReaderDelegate; + +/* + * Custom implementaion of the XMLStreamReader to keep track of the namespace context for each element + */ +public class TuscanyXMLStreamReader extends StreamReaderDelegate implements XMLStreamReader { + + Stack[]> context = new Stack[]>(); + + String characterEncodingScheme; + List[] contextList; + List prefixList; + List uriList; + + public TuscanyXMLStreamReader(XMLStreamReader reader) { + super(reader); + this.saveCharacterEncodingScheme(); + } + + public void pushContext() throws XMLStreamException { + contextList = new List[2]; + prefixList = new ArrayList(); + uriList = new ArrayList(); + int namespaceCount = this.getNamespaceCount(); + for (int i = 0; i < namespaceCount; i++) { + prefixList.add(checkString(this.getNamespacePrefix(i))); + uriList.add(this.getNamespaceURI(i)); + } + contextList[0] = prefixList; + contextList[1] = uriList; + context.push(contextList); + } + + private String checkString(String namespacePrefix) { + if (namespacePrefix == null) { + return XMLConstants.DEFAULT_NS_PREFIX; + } else { + return namespacePrefix; + } + } + + public void popContext() throws XMLStreamException { + context.pop(); + } + + public void saveCharacterEncodingScheme() { + this.characterEncodingScheme = super.getCharacterEncodingScheme(); + } + + // A flag to indicate if the next() is called from nextTag() + private boolean withinNextTagMethod = false; + + /* + * Overriding the next() method to perform PUSH and POP operations + * for the NamespaceContext for the current element + */ + @Override + public int next() throws XMLStreamException { + // POP the namespaces if the reader leaves the end element + if (!withinNextTagMethod && this.getEventType() == END_ELEMENT) { + popContext(); + } + + // get the next event + int nextEvent = super.next(); + + // PUSH the namespaces onto the stack as the reader enters the start element + if (!withinNextTagMethod && nextEvent == START_ELEMENT) { + pushContext(); + } + return nextEvent; + } + + @Override + public int nextTag() throws XMLStreamException { + withinNextTagMethod = true; + // POP the namespaces out of the stack if the reader leaves the end element + if (this.getEventType() == END_ELEMENT) { + popContext(); + } + + // REVIEW: what if nextTag() calls next()? + int event = super.nextTag(); + + // PUSH the namespaces onto the stack as the reader enters the start element + if (event == START_ELEMENT) { + pushContext(); + } + withinNextTagMethod = false; + return event; + } + + @Override + public NamespaceContext getNamespaceContext() { + return new TuscanyNamespaceContext((Stack[]>)context.clone()); + } + + + @Override + public String getCharacterEncodingScheme() { + return characterEncodingScheme; + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java new file mode 100644 index 0000000000..2ecddf5465 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.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.sca.contribution.processor; + +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * An artifact processor that can read models from a URL. + * + * @version $Rev$ $Date$ + */ +public interface URLArtifactProcessor extends ArtifactProcessor { + + /** + * Reads a model from a URL. + * + * @param contributionURL Contribution location URL + * @param artifactURI Artifact URI + * @param artifactURL Artifact location URL + * @return A model representation of the input. + */ + M read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException; + + /** + * Returns the type of artifact handled by this artifact processor. + * + * @return The type of artifact handled by this artifact processor + */ + String getArtifactType(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..7714586951 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.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.sca.contribution.processor; + +/** + * An extension point for URL artifact processors. + * + * @version $Rev$ $Date$ + */ +public interface URLArtifactProcessorExtensionPoint extends + ArtifactProcessorExtensionPoint { + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java new file mode 100644 index 0000000000..da249a09e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.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.sca.contribution.processor; + +import javax.xml.stream.XMLInputFactory; + +/** + * Base marker class for validating XML input factories. + * + * @version $Rev$ $Date$ + */ +public abstract class ValidatingXMLInputFactory extends XMLInputFactory { + + /** + * Create a new default validating XML input factory. + * @return + */ + public static ValidatingXMLInputFactory newInstance() { + return new DefaultValidatingXMLInputFactory( + XMLInputFactory.newInstance(), + new DefaultValidationSchemaExtensionPoint(), + null); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java new file mode 100644 index 0000000000..9b4a4938d1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java @@ -0,0 +1,396 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import java.util.logging.Logger; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.validation.Schema; +import javax.xml.validation.ValidatorHandler; + +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.xml.sax.Attributes; +import org.xml.sax.ErrorHandler; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.AttributesImpl; + +/** + * + * A validating XMLStreamReader that reports XMLSchema validation errors. + * + * @version $Rev$ $Date$ + */ +class ValidatingXMLStreamReader extends TuscanyXMLStreamReader implements XMLStreamReader { + + private static final Logger logger = Logger.getLogger(ValidatingXMLStreamReader.class.getName()); + + private int level; + private ValidatorHandler handler; + private final Monitor monitor; + + /** + * Constructs a new ValidatingXMLStreamReader. + * + * @param reader + * @param schema + * @throws XMLStreamException + */ + ValidatingXMLStreamReader(XMLStreamReader reader, Schema schema, Monitor monitor) throws XMLStreamException { + super(reader); + this.monitor = monitor; + if (schema == null) { + return; + } + + handler = schema.newValidatorHandler(); + handler.setDocumentLocator(new LocatorAdapter()); + try { + handler.setFeature("http://xml.org/sax/features/namespace-prefixes", true); + } catch (SAXException e) { + XMLStreamException xse = new XMLStreamException(e); + error("XMLStreamException", handler, xse); + throw xse; + } + + // These validation errors are just warnings for us as we want to support + // running from an XML document with XSD validation errors, as long as we can + // get the metadata we need from the document + handler.setErrorHandler(new ErrorHandler() { + private String getMessage(SAXParseException e) { + return "XMLSchema validation problem in: " + e.getSystemId() + ", line: " + e.getLineNumber() + ", column: " + e.getColumnNumber() + "\n" + e.getMessage(); + } + + public void error(SAXParseException exception) throws SAXException { + if (ValidatingXMLStreamReader.this.monitor == null) + logger.warning(getMessage(exception)); + else + ValidatingXMLStreamReader.this.error("SchemaError", ValidatingXMLStreamReader.this.getClass(), exception.getSystemId(), + exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage()); + } + + public void fatalError(SAXParseException exception) throws SAXException { + if (ValidatingXMLStreamReader.this.monitor == null) + logger.warning(getMessage(exception)); + else + ValidatingXMLStreamReader.this.error("SchemaFatalError", ValidatingXMLStreamReader.this.getClass(), exception.getSystemId(), + exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage()); + } + + public void warning(SAXParseException exception) throws SAXException { + if (ValidatingXMLStreamReader.this.monitor == null) + logger.warning(getMessage(exception)); + else + ValidatingXMLStreamReader.this.warning("SchemaWarning", ValidatingXMLStreamReader.this.getClass(), exception.getSystemId(), + exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage()); + } + }); + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void warning(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + @Override + public int next() throws XMLStreamException { + if (handler == null) { + return super.next(); + } + + int event = super.next(); + try { + switch (event) { + case XMLStreamConstants.START_DOCUMENT: + level++; + handler.startDocument(); + break; + case XMLStreamConstants.START_ELEMENT: + level++; + handleStartElement(); + break; + case XMLStreamConstants.PROCESSING_INSTRUCTION: + handler.processingInstruction(super.getPITarget(), super.getPIData()); + break; + case XMLStreamConstants.CHARACTERS: + case XMLStreamConstants.CDATA: + case XMLStreamConstants.SPACE: + case XMLStreamConstants.ENTITY_REFERENCE: + handler.characters(super.getTextCharacters(), super.getTextStart(), super.getTextLength()); + break; + case XMLStreamConstants.END_ELEMENT: + handleEndElement(); + level--; + break; + case XMLStreamConstants.END_DOCUMENT: + handler.endDocument(); + break; + } + } catch (SAXException e) { + XMLStreamException xse = new XMLStreamException(e.getMessage(), e); + error("XMLStreamException", handler, xse); + throw xse; + } + return event; + } + + @Override + public int nextTag() throws XMLStreamException { + if (handler == null) { + return super.nextTag(); + } + + for (;;) { + int event = super.getEventType(); + try { + switch (event) { + case XMLStreamConstants.START_DOCUMENT: + level++; + handler.startDocument(); + break; + case XMLStreamConstants.START_ELEMENT: + level++; + handleStartElement(); + pushContext(); + return event; + case XMLStreamConstants.PROCESSING_INSTRUCTION: + handler.processingInstruction(super.getPITarget(), super.getPIData()); + break; + case XMLStreamConstants.CHARACTERS: + case XMLStreamConstants.CDATA: + case XMLStreamConstants.SPACE: + case XMLStreamConstants.ENTITY_REFERENCE: + handler.characters(super.getTextCharacters(), super.getTextStart(), super.getTextLength()); + break; + case XMLStreamConstants.END_ELEMENT: + handleEndElement(); + level--; + popContext(); + return event; + case XMLStreamConstants.END_DOCUMENT: + handler.endDocument(); + return event; + } + } catch (SAXException e) { + XMLStreamException xse = new XMLStreamException(e); + error("XMLStreamException", handler, xse); + throw xse; + } + super.next(); + } + } + + @Override + public String getElementText() throws XMLStreamException { + if (handler == null) { + return super.getElementText(); + } + + if (getEventType() != XMLStreamConstants.START_ELEMENT) { + return super.getElementText(); + } + StringBuffer text = new StringBuffer(); + + for (;;) { + int event = next(); + switch (event) { + case XMLStreamConstants.END_ELEMENT: + return text.toString(); + + case XMLStreamConstants.COMMENT: + case XMLStreamConstants.PROCESSING_INSTRUCTION: + continue; + + case CHARACTERS: + case CDATA: + case SPACE: + case ENTITY_REFERENCE: + text.append(getText()); + break; + + default: + break; + } + } + } + + @Override + public NamespaceContext getNamespaceContext(){ + return super.getNamespaceContext(); + } + + /** + * Handle a start element event. + * + * @throws SAXException + */ + private void handleStartElement() throws SAXException { + + // send startPrefixMapping events immediately before startElement event + int nsCount = super.getNamespaceCount(); + for (int i = 0; i < nsCount; i++) { + String prefix = super.getNamespacePrefix(i); + if (prefix == null) { // true for default namespace + prefix = ""; + } + handler.startPrefixMapping(prefix, super.getNamespaceURI(i)); + } + + // fire startElement + QName qname = super.getName(); + String prefix = qname.getPrefix(); + String rawname; + if (prefix == null || prefix.length() == 0) { + rawname = qname.getLocalPart(); + } else { + rawname = prefix + ':' + qname.getLocalPart(); + } + Attributes attrs = getAttributes(); + handler.startElement(qname.getNamespaceURI(), qname.getLocalPart(), rawname, attrs); + } + + /** + * Handle an endElement event. + * + * @throws SAXException + */ + private void handleEndElement() throws SAXException { + + // fire endElement + QName qname = super.getName(); + handler.endElement(qname.getNamespaceURI(), qname.getLocalPart(), qname.toString()); + + // send endPrefixMapping events immediately after endElement event + // we send them in the opposite order to that returned but this is not + // actually required by SAX + int nsCount = super.getNamespaceCount(); + for (int i = nsCount - 1; i >= 0; i--) { + String prefix = super.getNamespacePrefix(i); + if (prefix == null) { // true for default namespace + prefix = ""; + } + handler.endPrefixMapping(prefix); + } + } + + /** + * Get the attributes associated with the current START_ELEMENT event. + * + * @return the StAX attributes converted to org.xml.sax.Attributes + */ + private Attributes getAttributes() { + AttributesImpl attrs = new AttributesImpl(); + + // add namespace declarations + for (int i = 0; i < super.getNamespaceCount(); i++) { + String prefix = super.getNamespacePrefix(i); + String uri = super.getNamespaceURI(i); + if (prefix == null) { + attrs.addAttribute("", "", "xmlns", "CDATA", uri); + } else { + attrs.addAttribute("", "", "xmlns:" + prefix, "CDATA", uri); + } + } + + // Regular attributes + for (int i = 0; i < super.getAttributeCount(); i++) { + String uri = super.getAttributeNamespace(i); + if (uri == null) { + uri = ""; + } + String localName = super.getAttributeLocalName(i); + String prefix = super.getAttributePrefix(i); + String qname; + if (prefix == null || prefix.length() == 0) { + qname = localName; + } else { + qname = prefix + ':' + localName; + } + String type = super.getAttributeType(i); + String value = super.getAttributeValue(i); + + attrs.addAttribute(uri, localName, qname, type, value); + } + + return attrs; + } + + /** + * Adapter for mapping Locator information. + */ + private final class LocatorAdapter implements Locator { + + private LocatorAdapter() { + } + + public int getColumnNumber() { + Location location = getLocation(); + return location == null ? 0 : location.getColumnNumber(); + } + + public int getLineNumber() { + Location location = getLocation(); + return location == null ? 0 : location.getLineNumber(); + } + + public String getPublicId() { + Location location = getLocation(); + return location == null ? "" : location.getPublicId(); + } + + public String getSystemId() { + Location location = getLocation(); + return location == null ? "" : location.getSystemId(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.java new file mode 100644 index 0000000000..cc3bb59a5b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.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.sca.contribution.processor; + +import java.util.List; + + +/** + * An extension point for XML schemas used for validation. + * + * @version $Rev$ $Date$ + */ +public interface ValidationSchemaExtensionPoint { + + /** + * Add a schema. + * + * @param uri the URI of the schema + */ + void addSchema(String uri); + + /** + * Remove a schema. + * + * @param uri the URI of the schema + */ + void removeSchema(String uri); + + /** + * Returns the list of schemas registered in the extension point. + * @return the list of schemas + */ + List getSchemas(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java new file mode 100644 index 0000000000..f3555ee71e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resolver; + +import java.lang.ref.WeakReference; + +import org.apache.tuscany.sca.assembly.Base; + +/** + * A weak reference to a class, which should be used to register classes + * with an ArtifactResolver and resolve these classes later. + * + * FIXME The core contribution model should not have dependencies on classes + * and ClassLoaders. This should move to the Java import support module. + * + * @version $Rev$ $Date$ + */ +public class ClassReference implements Base { + + private WeakReference> clazz; + private String className; + + /** + * Constructs a new ClassReference. + * + * @param clazz The class reference + */ + public ClassReference(Class clazz) { + this.clazz = new WeakReference>(clazz); + this.className = clazz.getName(); + } + + /** + * Constructs a new ClassReference. + * + * @param className The class name + */ + public ClassReference(String className) { + this.className = className; + } + + /** + * Get the referenced class. + * + * @return The referenced class + */ + public Class getJavaClass() { + if (clazz != null) { + return clazz.get(); + } else { + return null; + } + } + + /** + * Get the referenced class name. + * + * @return The class name + */ + public String getClassName() { + return className; + } + + public boolean isUnresolved() { + return clazz == null; + } + + public void setUnresolved(boolean unresolved) { + throw new IllegalStateException(); + } + + @Override + public int hashCode() { + return className.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else { + if (obj instanceof ClassReference) { + return className.equals(((ClassReference)obj).className); + } else { + return false; + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java new file mode 100644 index 0000000000..13c622adf0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resolver; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Base; + +/** + * A model resolver implementation that delegates to a list of model resolvers. + * + * @version $Rev$ $Date$ + */ +public class DefaultDelegatingModelResolver implements ModelResolver { + + private List resolvers; + + public DefaultDelegatingModelResolver(List resolvers) { + this.resolvers = resolvers; + } + + public void addModel(Object resolved) { + throw new IllegalStateException(); + } + + public Object removeModel(Object resolved) { + throw new IllegalStateException(); + } + + public T resolveModel(Class modelClass, T unresolved) { + + //TODO optimize and cache results of the resolution later + + // Go over all resolvers + for (ModelResolver resolver: resolvers) { + + Object resolved = resolver.resolveModel(modelClass, unresolved); + + // Return the resolved model object + if (resolved instanceof Base) { + if (!((Base)resolved).isUnresolved()) { + return modelClass.cast(resolved); + } + } + } + + // Model object was not resolved + return unresolved; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java new file mode 100644 index 0000000000..c6facd2b02 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.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.sca.contribution.resolver; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; + +/** + * A model resolver implementation that considers Exports in a list of contributions. + * + * @version $Rev: 560435 $ $Date: 2007-07-27 18:26:55 -0700 (Fri, 27 Jul 2007) $ + */ +public class DefaultImportAllModelResolver implements ModelResolver { + + private Import import_; + private List contributions; + + public DefaultImportAllModelResolver(Import import_, List contributions) { + this.import_ = import_; + this.contributions = contributions; + } + + public void addModel(Object resolved) { + throw new IllegalStateException(); + } + + public Object removeModel(Object resolved) { + throw new IllegalStateException(); + } + + public T resolveModel(Class modelClass, T unresolved) { + + //TODO optimize and cache results of the resolution later + + // Go over all available contributions + for (Contribution contribution : contributions) { + + // Go over all exports in the contribution + for (Export export : contribution.getExports()) { + + // If the export matches the export, try to resolve the model object + if (import_.match(export)) { + Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved); + + // Return the resolved model object + if (resolved instanceof Base) { + if (!((Base)resolved).isUnresolved()) { + return modelClass.cast(resolved); + } + } + } + } + } + + // Model object was not resolved + return unresolved; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java new file mode 100644 index 0000000000..9ae57c41d0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.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.sca.contribution.resolver; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.contribution.Export; + +/** + * A model resolver implementation that delegates to a list of exports. + * + * @version $Rev$ $Date$ + */ +public class DefaultImportModelResolver implements ModelResolver { + + private List exports; + + public DefaultImportModelResolver(List exports) { + this.exports = exports; + } + + public void addModel(Object resolved) { + throw new IllegalStateException(); + } + + public Object removeModel(Object resolved) { + throw new IllegalStateException(); + } + + public T resolveModel(Class modelClass, T unresolved) { + + //TODO optimize and cache results of the resolution later + + // Go over all exports + for (Export export: exports) { + + Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved); + + // Return the resolved model object + if (resolved instanceof Base) { + if (!((Base)resolved).isUnresolved()) { + return modelClass.cast(resolved); + } + } + } + + // Model object was not resolved + return unresolved; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java new file mode 100644 index 0000000000..bf175813f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.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.sca.contribution.resolver; + +import java.util.HashMap; +import java.util.Map; + + +/** + * A default implementation of a model resolver based on a map. + * + * @version $Rev$ $Date$ + */ +public class DefaultModelResolver implements ModelResolver { + + private Map map = new HashMap(); + + public DefaultModelResolver() { + } + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + if (resolved != null) { + + // Return the resolved object + return modelClass.cast(resolved); + + } else { + + // Return the unresolved object + return unresolved; + } + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(resolved); + } + + // FIXME: TUSCANY-2499: temporarily give access to the models to get the jms binding + // use of definitions.xml working while the definitions.xml processing is being refactored + public Map getModels() { + return map; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java new file mode 100644 index 0000000000..61a6d084f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.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.sca.contribution.resolver; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + + +/** + * The default implementation of a model resolver extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultModelResolverExtensionPoint implements ModelResolverExtensionPoint { + private final ExtensionPointRegistry registry; + private final Map, Class> resolvers = new HashMap, Class>(); + private Map loadedResolvers; + + /** + * Constructs a new DefaultModelResolverExtensionPoint. + * @param registry The ExtensionPointRegistry + */ + public DefaultModelResolverExtensionPoint(ExtensionPointRegistry registry) { + this.registry = registry; + } + + public void addResolver(Class modelType, Class resolver) { + resolvers.put(modelType, resolver); + } + + public void removeResolver(Class modelType) { + resolvers.remove(modelType); + } + + @SuppressWarnings("unchecked") + public Class getResolver(Class modelType) { + loadModelResolvers(); + + Class[] classes = modelType.getInterfaces(); + for (Class c : classes) { + Class resolver = resolvers.get(c); + if (resolver == null) { + ServiceDeclaration resolverClass = loadedResolvers.get(c.getName()); + if (resolverClass != null) { + try { + return (Class)resolverClass.loadClass(); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(e); + } + } + } else { + return resolver; + } + } + + Class resolver = resolvers.get(modelType); + if (resolver == null) { + ServiceDeclaration resolverClass = loadedResolvers.get(modelType.getName()); + if (resolverClass != null) { + try { + return (Class)resolverClass.loadClass(); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(e); + } + } + } + return resolver; + } + + /** + * Dynamically load model resolvers declared under META-INF/services + */ + private synchronized void loadModelResolvers() { + if (loadedResolvers != null) + return; + loadedResolvers = new HashMap(); + + // Get the model resolver service declarations + Set modelResolverDeclarations; + try { + modelResolverDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ModelResolver.class); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load model resolvers + for (ServiceDeclaration modelResolverDeclaration: modelResolverDeclarations) { + Map attributes = modelResolverDeclaration.getAttributes(); + String model = attributes.get("model"); + + loadedResolvers.put(model, modelResolverDeclaration); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java new file mode 100644 index 0000000000..04352fd242 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resolver; + +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * An implementation of an extensible model resolver which delegates to the + * proper resolver extension based on the class of the model to resolve. + * + * @version $Rev$ $Date$ + */ +public class ExtensibleModelResolver implements ModelResolver { + private ExtensionPointRegistry extensionPoints; + private final ModelResolverExtensionPoint resolverExtensions; + private final ModelFactoryExtensionPoint modelFactories; + private final Contribution contribution; + private ModelResolver defaultResolver; + private final Map, ModelResolver> resolversByModelType = new HashMap, ModelResolver>(); + private final Map, ModelResolver> resolversByImplementationClass = new HashMap, ModelResolver>(); + private Map map = new HashMap(); + private Object lastUnresolved; + + /** + * Constructs an extensible model resolver + * + * @param contribution + * @param extensionPoints TODO + * @param resolverExtensions + * @param modelFactories + * @param defaultResolver + */ + @Deprecated + public ExtensibleModelResolver(Contribution contribution, + ExtensionPointRegistry extensionPoints, + ModelResolverExtensionPoint resolverExtensions, + ModelFactoryExtensionPoint modelFactories, ModelResolver defaultResolver) { + this.contribution = contribution; + this.extensionPoints = extensionPoints; + this.resolverExtensions = resolverExtensions; + this.modelFactories = modelFactories; + //FIXME Remove this default resolver, this is currently used to resolve policy declarations + // but they should be handled by the contribution import/export mechanism instead of this + // defaultResolver hack. + this.defaultResolver = defaultResolver; + } + + /** + * @param contribution + * @param extensionPoints + */ + public ExtensibleModelResolver(Contribution contribution, ExtensionPointRegistry extensionPoints) { + this.contribution = contribution; + this.extensionPoints = extensionPoints; + this.resolverExtensions = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); + this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + } + + /** + * Returns the proper resolver instance based on the interfaces of the model + * If one is not available on the registry, instantiate on demand + * + * @param modelType + * @return + */ + private ModelResolver getModelResolverInstance(Class modelType) { + // Look up a model resolver instance for the model class or + // each implemented interface + Class[] interfaces = modelType.getInterfaces(); + Class[] classes = new Class[interfaces.length + 1]; + classes[0] = modelType; + if (interfaces.length != 0) { + System.arraycopy(interfaces, 0, classes, 1, interfaces.length); + } + for (Class c : classes) { + + // Look up an existing model resolver instance + ModelResolver resolverInstance = resolversByModelType.get(c); + if (resolverInstance != null) { + return resolverInstance; + } + + // We don't have an instance, lookup a model resolver class + // and instantiate it + Class resolverClass = resolverExtensions.getResolver(c); + if (resolverClass != null) { + + // Construct the model resolver instance and cache it + resolverInstance = resolversByImplementationClass.get(resolverClass); + if (resolverInstance != null) { + resolversByModelType.put(c, resolverInstance); + return resolverInstance; + } + try { + try { + Constructor constructor = + resolverClass.getConstructor(new Class[] {Contribution.class, + ModelFactoryExtensionPoint.class}); + if (constructor != null) { + + resolverInstance = constructor.newInstance(contribution, modelFactories); + resolversByImplementationClass.put(resolverClass, resolverInstance); + resolversByModelType.put(c, resolverInstance); + return resolverInstance; + } + } catch (NoSuchMethodException e) { + Constructor constructor = + resolverClass.getConstructor(new Class[] {Contribution.class, + ExtensionPointRegistry.class}); + if (constructor != null) { + + resolverInstance = constructor.newInstance(contribution, extensionPoints); + resolversByImplementationClass.put(resolverClass, resolverInstance); + resolversByModelType.put(c, resolverInstance); + return resolverInstance; + } + } + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + } + + return null; + } + + public void addModel(Object resolved) { + ModelResolver resolver = getModelResolverInstance(resolved.getClass()); + if (resolver != null) { + resolver.addModel(resolved); + } else { + map.put(resolved, resolved); + } + } + + public Object removeModel(Object resolved) { + ModelResolver resolver = getModelResolverInstance(resolved.getClass()); + if (resolver != null) { + return resolver.removeModel(resolved); + } else { + return map.remove(resolved); + } + } + + public T resolveModel(Class modelClass, T unresolved) { + // Protect against dependency cycles causing infinite recursion + // Save the current unresolved object and check later if we are trying + // to resolve the same object again + if (unresolved == lastUnresolved) { + return unresolved; + } + lastUnresolved = unresolved; + + ModelResolver resolver = getModelResolverInstance(unresolved.getClass()); + if (resolver != null) { + Object resolved = resolver.resolveModel(modelClass, unresolved); + if (resolved != null && resolved != unresolved) { + lastUnresolved = null; + return modelClass.cast(resolved); + } + } else { + //FIXME Remove this default resolver, this is currently used to resolve policy declarations + // but they should be handled by the contribution import/export mechanism instead of this + // defaultResolver hack. + if (defaultResolver != null) { + Object resolved = defaultResolver.resolveModel(modelClass, unresolved); + if (resolved != null && resolved != unresolved) { + lastUnresolved = null; + return modelClass.cast(resolved); + } + } + + Object resolved = map.get(unresolved); + if (resolved != null) { + // Return the resolved object + lastUnresolved = null; + return modelClass.cast(resolved); + } + } + + return unresolved; + } + + // FIXME: TUSCANY-2499: temporarily give access to the defaultResolver to get the jms binding + // use of definitions.xml working while the definitions.xml processing is being refactored + public ModelResolver getDefaultModelResolver() { + return defaultResolver; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java new file mode 100644 index 0000000000..2831bebbc4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.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.sca.contribution.resolver; + +/** + * A model resolver, responsible for resolving models in the scope of an + * SCA contribution. + * + * SCA Assemblies reference artifacts of a wide variety of types. These + * include: + *
    + *
  • Reference from one SCA composite to another SCA composite + *
  • Reference to PolicySet files + *
  • Reference to interface definition files, either WSDL or Java interfaces + *
  • Reference to XSD files + *
  • Reference to any of a wide variety of implementation artifact files, + * including Java classes, BPEL scripts, C++ DLLs and classes, PHP scripts + *
+ * + * In the SCA assemblies, these various artifacts are referenced using either + * QNames or logical URIs. Model resolvers are used to resolve these references + * and get the in-memory models representing the referenced artifacts. + * + * @version $Rev$ $Date$ + */ +public interface ModelResolver { + + /** + * Resolve the model representing an artifact. + * + * @param modelClass the type of artifact + * @param unresolved the unresolved model + * @return the resolved model + */ + T resolveModel(Class modelClass, T unresolved); + + /** + * Add a resolved model. + * + * @param resolved The model + */ + void addModel(Object resolved); + + /** + * Remove a resolved model. + * + * @param resolved + * @return The removed model, or null if the model was not removed + */ + Object removeModel(Object resolved); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.java new file mode 100644 index 0000000000..4a25059792 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.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.sca.contribution.resolver; + + +/** + * An extension point for model resolvers + * + * @version $Rev$ $Date$ + */ +public interface ModelResolverExtensionPoint { + + /** + * Register a model resolver class using the model type as the key + * + * @param modelType The model type + * @param resolver The model resolver Class + */ + void addResolver(Class modelType, Class resolver); + + /** + * Remove the model resolver class for a specific model type + * + * @param modelType The model type + */ + void removeResolver(Class modelType); + + /** + * Retrieve a model resolver class for a specific model type + * + * @param modelType The model artifact type + * @return The model resolver Class + */ + Class getResolver(Class modelType); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResolverExtension.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResolverExtension.java new file mode 100644 index 0000000000..74f0f2d71d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResolverExtension.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.sca.contribution.resolver; + +/** + * Extension to assembly model implementations to provide a model resolver. + * + * @version $Rev$ $Date$ + */ +public interface ResolverExtension { + + /** + * Returns the model resolver for the models representing the artifacts + * visible in the scope of this contribution. + * + * @return The model resolver + */ + ModelResolver getModelResolver(); + + /** + * Sets the model resolver for the models representing the artifacts + * visible in the scope of this contribution. + * + * @param modelResolver The model resolver + */ + void setModelResolver(ModelResolver modelResolver); + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResourceReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResourceReference.java new file mode 100644 index 0000000000..2394f4510b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResourceReference.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resolver; + +import java.net.URL; + +/** + * A resource URL, which should be used to register resources + * with an ArtifactResolver and resolve these resources later. + * + * FIXME Don't use as its deprecated, use Artifact instead. + * + * @version $Rev$ $Date$ + */ +@Deprecated +public class ResourceReference { + + private URL resourceURL; + private String resourceName; + + /** + * Constructs a new ResourceReference. + * + * @param resourceName Name of resource + * @param resourceURL The resource URL + */ + public ResourceReference(String resourceName, URL resourceURL) { + this.resourceURL = resourceURL; + this.resourceName = resourceName; + } + + /** + * Constructs a new ResourceReference. + * + * @param resourceName Name of resource + */ + public ResourceReference(String resourceName) { + this.resourceName = resourceName; + } + + /** + * Get the resource URL. + * + * @return The resource URL + */ + public URL getResource() { + return resourceURL; + } + + /** + * Get the resource name. + * + * @return The resource name + */ + public String getResourceName() { + return resourceName; + } + + /** + * Returns true if the resource reference is unresolved. + * + * @return Whether or not the resource has been resolved + */ + public boolean isUnresolved() { + return resourceURL == null; + } + + @Override + public int hashCode() { + return resourceName.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else { + if (obj instanceof ResourceReference) { + return resourceName.equals(((ResourceReference)obj).resourceName); + } else { + return false; + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java new file mode 100644 index 0000000000..2d03381c8a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.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.sca.contribution.scanner; + +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * Interface for contribution package scanners + * + * Contribution scanners understand the format of the contribution and how to get the + * artifacts in the contribution. + * + * @version $Rev$ $Date$ + */ +public interface ContributionScanner { + + /** + * Returns the type of package supported by this package scanner. + * + * @return the package type + */ + String getContributionType(); + + /** + * Returns a list of artifacts in the contribution. + * + * @param contributionURL Contribution URL + * @return List of artifact URIs + * @throws ContributionException + * @throws IOException + */ + List getArtifacts(URL contributionURL) throws ContributionReadException; + + /** + * Return the URL for an artifact in the contribution. + * + * This is needed for archives such as jar files that have specific URL schemes + * for the artifacts they contain. + * + * @param contributionURL Contribution URL + * @param artifact The relative URI for the artifact + * @return The artifact URL + */ + URL getArtifactURL(URL contributionURL, String artifact) throws ContributionReadException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScannerExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScannerExtensionPoint.java new file mode 100644 index 0000000000..1ca9def4ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScannerExtensionPoint.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.sca.contribution.scanner; + +/** + * An extension point for contribution scanners + * + * @version $Rev$ $Date$ + */ +public interface ContributionScannerExtensionPoint { + + /** + * Add a ContributionScanner using the contribution type as the key. + * + * @param scanner The contribution scanner + */ + void addContributionScanner(ContributionScanner scanner); + + /** + * Remove a ContributionScanner. + * + * @param scanner The contribution scanner + */ + void removeContributionScanner(ContributionScanner scanner); + + /** + * Returns the ContributionScanner for the given contribution type. + * + * @param contributionType The contribution type + * @return The contribution scanner + */ + ContributionScanner getContributionScanner(String contributionType); + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java new file mode 100644 index 0000000000..cca1ae7a30 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.scanner; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + +/** + * Default implementation of a contribution scanner extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultContributionScannerExtensionPoint implements ContributionScannerExtensionPoint { + + private Map scanners = new HashMap(); + private boolean loaded; + + public DefaultContributionScannerExtensionPoint() { + } + + public void addContributionScanner(ContributionScanner scanner) { + scanners.put(scanner.getContributionType(), scanner); + } + + public void removeContributionScanner(ContributionScanner scanner) { + scanners.remove(scanner.getContributionType()); + } + + public ContributionScanner getContributionScanner(String contentType) { + loadScanners(); + return scanners.get(contentType); + } + + private synchronized void loadScanners() { + if (loaded) + return; + + // Get the scanner service declarations + Set scannerDeclarations; + try { + scannerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ContributionScanner.class); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + for (ServiceDeclaration scannerDeclaration: scannerDeclarations) { + Map attributes = scannerDeclaration.getAttributes(); + + // Load a URL artifact scanner + String contributionType = attributes.get("type"); + + // Create a scanner wrapper and register it + ContributionScanner scanner = new LazyContributionScanner(contributionType, scannerDeclaration); + addContributionScanner(scanner); + } + + loaded = true; + } + + /** + * A facade for contribution scanners. + */ + private static class LazyContributionScanner implements ContributionScanner { + + private ServiceDeclaration scannerDeclaration; + private String contributionType; + private ContributionScanner scanner; + + private LazyContributionScanner(String contributionType, ServiceDeclaration scannerDeclaration) { + this.scannerDeclaration = scannerDeclaration; + this.contributionType = contributionType; + } + + public URL getArtifactURL(URL contributionSourceURL, String artifact) throws ContributionReadException { + return getScanner().getArtifactURL(contributionSourceURL, artifact); + } + + public List getArtifacts(URL contributionSourceURL) throws ContributionReadException { + return getScanner().getArtifacts(contributionSourceURL); + } + + public String getContributionType() { + return contributionType; + } + + private ContributionScanner getScanner() { + if (scanner == null) { + try { + Class scannerClass = (Class)scannerDeclaration.loadClass(); + Constructor constructor = scannerClass.getConstructor(); + scanner = constructor.newInstance(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return scanner; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java new file mode 100644 index 0000000000..e183206894 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.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.sca.contribution.service; + +/** + * Base class for exceptions raised by contribution services. + * + * @version $Rev$ $Date$ + */ +public class ContributionException extends Exception { + + private static final long serialVersionUID = 4432880414927652578L; + + protected ContributionException() { + super(); + } + + protected ContributionException(String message) { + super(message); + } + + protected ContributionException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.java new file mode 100644 index 0000000000..5158eaf85c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.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.sca.contribution.service; + +import java.util.EventListener; + +import org.apache.tuscany.sca.contribution.Contribution; + +/** + * A listener interface used to listen to contribution repository events. + * + * @version $Rev$ $Date$ + */ +public interface ContributionListener extends EventListener { + + /** + * Notifies the listener that a contribution has been added. + * + * @param repository The contribution repository + * @param contribution The new contribution + */ + void contributionAdded(ContributionRepository repository, Contribution contribution); + + /** + * Notifies the listener that a contribution has been removed. + * + * @param repository The contribution repository + * @param contribution The removed contribution. + */ + void contributionRemoved(ContributionRepository repository, Contribution contribution); + + /** + * Notifies the listener that a contribution has been updated. + * + * @param repository The contribution repository + * @param oldContribution The old contribution + * @param contribution The new contribution + */ + void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.java new file mode 100644 index 0000000000..ce2b4b13c3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.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.sca.contribution.service; + +import java.util.List; + +public interface ContributionListenerExtensionPoint { + + /** + * Adds a contribution repository listener extension. + * @param listener The listener to add + */ + void addContributionListener(ContributionListener listener); + + /** + * Removes a contribution repository listener extension. + * @param listener The listener to remove + */ + void removeContributionListener(ContributionListener listener); + + /** + * Returns the contribution repository listeners. + * @return + */ + List getContributionListeners(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java new file mode 100644 index 0000000000..33399dcc2f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + +/** + * Denotes an exception while reading artifacts inside an SCA contribution. + * + * @version $Rev$ $Date$ + */ +public class ContributionReadException extends ContributionException { + public static final int UNDEFINED = -1; + private static final long serialVersionUID = -7459051598906813461L; + private String resourceURI; + private int line = UNDEFINED; + private int column = UNDEFINED; + + public ContributionReadException(String message) { + super(message); + } + + public ContributionReadException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionReadException(Throwable cause) { + super(cause); + } + + /** + * Returns the location of the resource that was being read. + * + * @return the location of the resource that was being read + */ + public String getResourceURI() { + return resourceURI; + } + + /** + * Sets the location of the resource that was being read. + * + * @param resourceURI the location of the resource that was being read + */ + public void setResourceURI(String resourceURI) { + this.resourceURI = resourceURI; + } + + /** + * Returns the line inside the resource that was being read. + * @return the line inside the resource that was being read + */ + public int getLine() { + return line; + } + + /** + * Sets the line inside the resource that was being read. + * @param line the line inside the resource that was being read + */ + public void setLine(int line) { + this.line = line; + } + + /** + * Returns the column inside the resource that was being read. + * @return the column inside the resource that was being read + */ + public int getColumn() { + return column; + } + + /** + * Sets the column inside the resource that was being read. + * @param column the column inside the resource that was being read + */ + public void setColumn(int column) { + this.column = column; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java new file mode 100644 index 0000000000..d7d8216f66 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.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.sca.contribution.service; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.sca.contribution.Contribution; + +/** + * Contribution repository + * + * @version $Rev$ $Date$ + */ +public interface ContributionRepository { + + /** + * Get the URI of the SCA domain + * + * @return The domain URI + */ + URI getDomain(); + + /** + * Copies a contribution to the repository. + * + * @param contribution A URl pointing to the contribution being copied to + * the repository + * @param sourceURL URL of the source. this would be used to calculate the right + * filename to be stored on the repository when a inputStream is being + * provided + * @param contributionStream InputStream with the content of the + * distribution + * @return A URL pointing to the content of the contribution in the + * repository + * @throws IOException + */ + URL store(String contribution, URL sourceURL, InputStream contributionStream) throws IOException; + /** + * Copy a contribution from the source URL to the repository + * + * @param contribution A URl pointing to the contribution being copied to + * the repository + * @param sourceURL URL of the source. this would be used to calculate the right + * filename to be stored on the repository when a inputStream is being + * provided + * @return A URL pointing to the content of the contribution in the + * repository + * @throws IOException + */ + URL store(String 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(String contribution); + + /** + * Remove a contribution from the repository + * + * @param contribution The URI of the contribution to be removed + */ + void remove(String contribution); + + /** + * Get list of URIs for all the contributions in the repository + * + * @return A list of contribution URIs + */ + List list(); + + /** + * Returns the contributions available in the repository. + * @return The list of contributions. + */ + List getContributions(); + + /** + * Adds a contribution to the repository. + * @param contribution The new contribution. + */ + void addContribution(Contribution contribution); + + /** + * Removes a contribution from the repository. + * @param contribution The contribution to remove + */ + void removeContribution(Contribution contribution); + + /** + * Updates a contribution in the repository + * @param contribution The contribution to update + */ + void updateContribution(Contribution contribution); + + /** + * Returns the contribution with the given URI. + * @param uri the URI of the contribution + * @return The contribution + */ + Contribution getContribution(String uri); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java new file mode 100644 index 0000000000..ecb774ac0c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.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.sca.contribution.service; + +/** + * Denotes a problem while resolving models inside an SCA contribution. + * + * @version $Rev$ $Date$ + */ +public class ContributionResolveException extends ContributionException { + private static final long serialVersionUID = -7459051598906813461L; + + public ContributionResolveException(String message) { + super(message); + } + + public ContributionResolveException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionResolveException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java new file mode 100644 index 0000000000..4bf29a3993 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.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.sca.contribution.service; + +/** + * Base class for runtime exceptions raised by contribution services. + * + * @version $Rev$ $Date$ + */ +public class ContributionRuntimeException extends RuntimeException { + private static final long serialVersionUID = 7711215366287498896L; + + protected ContributionRuntimeException() { + super(); + } + + protected ContributionRuntimeException(String message) { + super(message); + } + + protected ContributionRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionRuntimeException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java new file mode 100644 index 0000000000..dcdb8733b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * Service interface that manages artifacts contributed to a Tuscany runtime. + * + * @version $Rev$ $Date$ + */ +public interface ContributionService { + /** + * Contribute an artifact to the SCA Domain. The type of the contribution is + * determined by the Content-Type of the resource or, if that is undefined, + * by some implementation-specific means (such as mapping an extension in + * the URL's path). + * + * @param contributionURI The URI that is used as the contribution unique ID. + * @param sourceURL The location of the resource containing the artifact + * @param storeInRepository Flag that identifies if you want to copy the + * contribution to the repository + * @return The contribution model representing the contribution + * @throws ContributionException if there was a problem with the contribution + * @throws IOException if there was a problem reading the resource + */ + Contribution contribute(String contributionURI, URL sourceURL, boolean storeInRepository) throws ContributionException, + IOException; + + /** + * Contribute an artifact to the SCA Domain. The type of the contribution is + * determined by the Content-Type of the resource or, if that is undefined, + * by some implementation-specific means (such as mapping an extension in + * the URL's path). + * + * @param contributionURI The URI that is used as the contribution unique ID. + * @param sourceURL The location of the resource containing the artifact + * @param modelResolver The model resolver to use to resolve models in the + * scope of this contribution + * @param storeInRepository Flag that identifies if you want to copy the + * contribution to the repository + * @return The contribution model representing the contribution + * @throws ContributionException if there was a problem with the contribution + * @throws IOException if there was a problem reading the resource + */ + Contribution contribute(String contributionURI, URL sourceURL, ModelResolver modelResolver, boolean storeInRepository) throws ContributionException, + IOException; + + /** + * Contribute an artifact to the SCA Domain. + * + * @param contributionURI The URI that is used as the contribution unique ID. + * @param sourceURL The location of the resource containing the artifact. + * This is used to identify what name should be used when storing + * the contribution on the repository + * @param contributionContent A stream containing the resource being + * contributed; the stream will not be closed but the read + * position after the call is undefined + * @return The contribution model representing the contribution + * @throws ContributionException if there was a problem with the contribution + * @throws IOException if there was a problem reading the stream + */ + Contribution contribute(String contributionURI, URL sourceURL, InputStream contributionContent) + throws ContributionException, IOException; + + /** + * Contribute an artifact to the SCA Domain. + * + * @param contributionURI The URI that is used as the contribution unique ID. + * @param sourceURL The location of the resource containing the artifact. + * This is used to identify what name should be used when storing + * the contribution on the repository + * @param modelResolver The model resolver to use to resolve models in the + * scope of this contribution + * @param contributionContent A stream containing the resource being + * contributed; the stream will not be closed but the read + * position after the call is undefined + * @return The contribution model representing the contribution + * @throws ContributionException if there was a problem with the contribution + * @throws IOException if there was a problem reading the stream + */ + Contribution contribute(String contributionURI, URL sourceURL, InputStream contributionContent, ModelResolver modelResolver) + throws ContributionException, IOException; + + /** + * Get the model for an installed contribution + * + * @param contribution The URI of an installed contribution + * @return The model for the contribution or null if there is no such + * contribution + */ + Contribution getContribution(String contribution); + + /** + * Adds or updates a deployment composite using a supplied composite + * ("composite by value" - a data structure, not an existing resource in the + * domain) to the contribution identified by a supplied contribution URI. + * The added or updated deployment composite is given a relative URI that + * matches the "name" attribute of the composite, with a ".composite" + * suffix. + * + * @param contribution The contribution to where + * @param composite + * @throws ContributionException + */ + void addDeploymentComposite(Contribution contribution, Composite composite) throws ContributionException; + + /** + * Remove a contribution from the SCA domain + * + * @param contribution The URI of the contribution + * @throws DeploymentException + */ + void remove(String contribution) throws ContributionException; +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java new file mode 100644 index 0000000000..8bfdedf180 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.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.sca.contribution.service; + + +/** + * Denotes an exception while writing artifacts inside an SCA contribution. + * + * @version $Rev$ $Date$ + */ +public class ContributionWriteException extends ContributionException { + private static final long serialVersionUID = -7459051598906813461L; + private String resourceURI; + + public ContributionWriteException(String message) { + super(message); + } + + public ContributionWriteException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionWriteException(Throwable cause) { + super(cause); + } + + /** + * Returns the location of the resource that was being written. + * + * @return the location of the resource that was being written + */ + public String getResourceURI() { + return resourceURI; + } + + /** + * Sets the location of the resource that was being written. + * + * @param resourceURI the location of the resource that was being written + */ + public void setResourceURI(String resourceURI) { + this.resourceURI = resourceURI; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java new file mode 100644 index 0000000000..1ab80e344b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + +/** + * Default implementation of a contribution listener extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultContributionListenerExtensionPoint implements ContributionListenerExtensionPoint { + + private List listeners = new CopyOnWriteArrayList(); + private boolean loadedListeners; + private ModelFactoryExtensionPoint modelFactories; + + /** + * Constructs a new DefaultContributionListenerExtensionPoint. + * + */ + public DefaultContributionListenerExtensionPoint(ModelFactoryExtensionPoint modelFactories) { + this.modelFactories = modelFactories; + } + + /** + * Constructs a new DefaultContributionListenerExtensionPoint. + * + */ + public DefaultContributionListenerExtensionPoint(ExtensionPointRegistry extensionPoints) { + this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + } + + public void addContributionListener(ContributionListener listener) { + listeners.add(listener); + } + + public List getContributionListeners() { + loadListeners(); + return listeners; + } + + public void removeContributionListener(ContributionListener listener) { + listeners.remove(listener); + } + + /** + * Dynamically load listeners declared under META-INF/services + */ + @SuppressWarnings("unchecked") + private synchronized void loadListeners() { + if (loadedListeners) + return; + + // Get the listener service declarations + Set listenerDeclarations; + try { + listenerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ContributionListener.class); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load and instantiate the listeners + for (ServiceDeclaration listenerDeclaration: listenerDeclarations) { + ContributionListener listener; + try { + Class listenerClass = (Class)listenerDeclaration.loadClass(); + try { + Constructor constructor = listenerClass.getConstructor(ModelFactoryExtensionPoint.class); + try { + listener = constructor.newInstance(modelFactories); + } catch (InvocationTargetException e) { + throw new IllegalArgumentException(e); + } + } catch (NoSuchMethodException e) { + listener = listenerClass.newInstance(); + } + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(e); + } catch (InstantiationException e) { + throw new IllegalArgumentException(e); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException(e); + } + addContributionListener(listener); + } + + loadedListeners = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.java new file mode 100644 index 0000000000..fc0dc3aa99 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.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.sca.contribution.service; + +import org.apache.tuscany.sca.contribution.Contribution; + +public class ExtensibleContributionListener implements ContributionListener { + private final ContributionListenerExtensionPoint listeners; + + /** + * Default constructor receiving the listener extension point + * + * @param listeners + */ + public ExtensibleContributionListener(ContributionListenerExtensionPoint listeners) { + this.listeners = listeners; + } + + /** + * Process "contributionAdded" event to all registered listeners + */ + public void contributionAdded(ContributionRepository repository, Contribution contribution) { + for (ContributionListener listener : listeners.getContributionListeners()) { + try { + listener.contributionAdded(repository, contribution); + } catch (Exception e) { + // ignore, continue to the next listener + } + } + } + + /** + * Process "contributionRemoved" event to all registered listeners + */ + public void contributionRemoved(ContributionRepository repository, Contribution contribution) { + for (ContributionListener listener : listeners.getContributionListeners()) { + try { + listener.contributionRemoved(repository, contribution); + } catch (Exception e) { + // ignore, continue to the next listener + } + + } + } + + /** + * Process "contributionUpdated" event to all registered listeners + */ + public void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution) { + for (ContributionListener listener : listeners.getContributionListeners()) { + try { + listener.contributionUpdated(repository, oldContribution, contribution); + } catch (Exception e) { + // ignore, continue to the next listener + } + + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java new file mode 100644 index 0000000000..74f303a5a5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.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.sca.contribution.service; + +import java.net.URL; + +/** + * Provide content type for a given resource + * + * @version $Rev$ $Date$ + */ +public interface TypeDescriber { + /** + * Get the content type for the specified resource + * + * @param resourceURL The resource URL + * @param defaultType The default content type + * @return The content type + */ + String getType(URL resourceURL, String defaultType); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java new file mode 100644 index 0000000000..ff21c894de --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.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.sca.contribution.service; + +import javax.xml.namespace.QName; + +/** + * Exception that indicates an element was encountered that could not be handled. + * + * @version $Rev$ $Date$ + */ +public class UnrecognizedElementException extends ContributionReadException { + private static final long serialVersionUID = 2549543622209829032L; + private final QName element; + + /** + * Constructor that indicates which element could not be handled. + * @param element the element that could not be handled + */ + public UnrecognizedElementException(QName element) { + super("Unrecognized element: " + element); + this.element = element; + } + + /** + * Returns the element that could not be handled. + * @return the element that could not be handled. + */ + public QName getElement() { + return element; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java new file mode 100644 index 0000000000..0660d69897 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.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.sca.contribution.service; + +/** + * Exception thrown to indicate that a Content-Type is not supported by this SCA Domain. + * The Content-Type value supplied will be returned as the message text for this exception. + * + * FIXME Don't use as it's deprecated and replaced by UnsupportedPackageTypeException. + * + * @version $Rev$ $Date$ + */ +@Deprecated +public class UnsupportedContentTypeException extends ContributionException { + private static final long serialVersionUID = -1831797280021355672L; + + /** + * Constructs a new UnsupportedContentTypeException. + * + * @param message + */ + public UnsupportedContentTypeException(String message) { + super(message); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedPackageTypeException.java b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedPackageTypeException.java new file mode 100644 index 0000000000..33c847a049 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedPackageTypeException.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.sca.contribution.service; + +/** + * Exception thrown to indicate that a Content-Type is not supported by this SCA Domain. + * The Content-Type value supplied will be returned as the message text for this exception. + * + * @version $Rev$ $Date$ + */ +public class UnsupportedPackageTypeException extends ContributionException { + private static final long serialVersionUID = -1831797280021355672L; + + /** + * Constructs a new UnsupportedPackageTypeException. + * + * @param message + */ + public UnsupportedPackageTypeException(String message) { + super(message); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory new file mode 100644 index 0000000000..bcc346d9f8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.DefaultContributionFactory \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint new file mode 100644 index 0000000000..6b4d2ebdeb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint new file mode 100644 index 0000000000..9e6433ba6c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.processor.DefaultContributionPostProcessorExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint new file mode 100644 index 0000000000..7609eda0d1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.processor.DefaultPackageProcessorExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint new file mode 100644 index 0000000000..8ea5fc0a7e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint new file mode 100644 index 0000000000..607725bcfe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.processor.DefaultStAXAttributeProcessorExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint new file mode 100644 index 0000000000..9d78ca93d0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint new file mode 100644 index 0000000000..ae6e876df6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint new file mode 100644 index 0000000000..4bb65e55e7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.resolver.DefaultModelResolverExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.scanner.ContributionScannerExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.scanner.ContributionScannerExtensionPoint new file mode 100644 index 0000000000..727f8f6ce7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.scanner.ContributionScannerExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.scanner.DefaultContributionScannerExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint new file mode 100644 index 0000000000..6e61bebf79 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.contribution.service.DefaultContributionListenerExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/contribution-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/contribution-validation-messages.properties new file mode 100644 index 0000000000..4f9f85048e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/contribution/src/main/resources/contribution-validation-messages.properties @@ -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. +# +# +SchemaError = XMLSchema validation error occured in: {0} ,line = {1}, column = {2}, Message = {3} +SchemaFatalError = XMLSchema validation fatal error occured in: {0} ,line = {1}, column = {2}, Message = {3} +SchemaWarning = XMLSchema validation warning occured in: {0} ,line = {1}, column = {2}, Message = {3} +UnsupportedPackageTypeException = Unsupported contribution package type: {0} +ElementCannotBeProcessed = Element {0} cannot be processed. ({1}) +AttributeCannotBeProcessed = Attribute {0} cannot be processed. ({1}) +NoStaxProcessor = No StAX processor is configured to handle {0} +ContributionWriteException = ContributionWriteException occured due to : +ContributionReadException = ContributionReadException occured due to : +UnrecognizedElementException = Unrecognized Element : {0} +IllegalArgumentException = Invalid qname: {0} +PrivilegedActionException = PrivilegedActionException occured due to : +AttributeCannotBeProcessed = Attribute {0} cannot be processed. ({1}) + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/pom.xml new file mode 100644 index 0000000000..94779b5e4a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/pom.xml @@ -0,0 +1,139 @@ + + + + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + 4.0.0 + org.apache.tuscany.sca + tuscany-core-databinding + jar + Apache Tuscany SCA Core/DataBinding Integration + + + + org.apache.tuscany.sca + tuscany-databinding + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-databinding-jaxb + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-core + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-core-spi + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-interface-java-jaxws + ${project.version} + compile + + + + org.codehaus.woodstox + wstx-asl + runtime + 3.2.4 + + + stax + stax-api + + + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.7 + + + xerces + xercesImpl + + + javax.mail + mail + + + commons-logging + commons-logging + + + xml-apis + xml-apis + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.7 + runtime + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.core.databinding + ${pom.name} + org.apache.tuscany.sca.core.databinding* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java new file mode 100644 index 0000000000..9a84d88340 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.module; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor; +import org.apache.tuscany.sca.core.databinding.processor.WrapperJavaInterfaceProcessor; +import org.apache.tuscany.sca.core.databinding.transformers.Array2ArrayTransformer; +import org.apache.tuscany.sca.core.databinding.transformers.CallableReference2XMLStreamReader; +import org.apache.tuscany.sca.core.databinding.transformers.CallableReferenceDataBinding; +import org.apache.tuscany.sca.core.databinding.transformers.CallableReferenceXMLAdapter; +import org.apache.tuscany.sca.core.databinding.transformers.Exception2ExceptionTransformer; +import org.apache.tuscany.sca.core.databinding.transformers.Input2InputTransformer; +import org.apache.tuscany.sca.core.databinding.transformers.OMElementXMLAdapter; +import org.apache.tuscany.sca.core.databinding.transformers.Output2OutputTransformer; +import org.apache.tuscany.sca.core.databinding.transformers.XMLStreamReader2CallableReference; +import org.apache.tuscany.sca.core.databinding.wire.DataBindingRuntimeWireProcessor; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.impl.Group2GroupTransformer; +import org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor; +import org.apache.tuscany.sca.interfacedef.java.jaxws.WebServiceInterfaceProcessor; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; +import org.osoa.sca.CallableReference; + +/** + * @version $Rev$ $Date$ + */ +public class DataBindingModuleActivator implements ModuleActivator { + + public void start(ExtensionPointRegistry registry) { + DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + + XMLAdapterExtensionPoint xmlAdapterExtensionPoint = registry.getExtensionPoint(XMLAdapterExtensionPoint.class); + xmlAdapterExtensionPoint.addAdapter(CallableReference.class, CallableReferenceXMLAdapter.class); + xmlAdapterExtensionPoint.addAdapter(OMElement.class, OMElementXMLAdapter.class); + FaultExceptionMapper faultExceptionMapper = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(FaultExceptionMapper.class); + + Mediator mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); + + Input2InputTransformer input2InputTransformer = new Input2InputTransformer(); + input2InputTransformer.setMediator(mediator); + transformers.addTransformer(input2InputTransformer, true); + + Output2OutputTransformer output2OutputTransformer = new Output2OutputTransformer(); + output2OutputTransformer.setMediator(mediator); + transformers.addTransformer(output2OutputTransformer, true); + + Exception2ExceptionTransformer exception2ExceptionTransformer = new Exception2ExceptionTransformer(mediator, faultExceptionMapper); + transformers.addTransformer(exception2ExceptionTransformer, false); + + Array2ArrayTransformer array2ArrayTransformer = new Array2ArrayTransformer(); + array2ArrayTransformer.setMediator(mediator); + transformers.addTransformer(array2ArrayTransformer, true); + + Group2GroupTransformer group2GroupTransformer = new Group2GroupTransformer(); + group2GroupTransformer.setMediator(mediator); + transformers.addTransformer(group2GroupTransformer, true); + + dataBindings.addDataBinding(new CallableReferenceDataBinding()); + transformers.addTransformer(new CallableReference2XMLStreamReader(), true); + transformers.addTransformer(new XMLStreamReader2CallableReference(), false); + + ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + // Add the WebServiceInterfaceProcessor to mark the interface remotable + javaFactory.addInterfaceVisitor(new WebServiceInterfaceProcessor()); + // Introspect the data types + javaFactory.addInterfaceVisitor(new DataBindingJavaInterfaceProcessor(dataBindings)); + javaFactory.addInterfaceVisitor(new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper, xmlAdapterExtensionPoint)); + javaFactory.addInterfaceVisitor(new WrapperJavaInterfaceProcessor(dataBindings)); + + + RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint = registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class); + if (wireProcessorExtensionPoint != null) { + wireProcessorExtensionPoint.addWireProcessor(new DataBindingRuntimeWireProcessor(mediator, dataBindings, faultExceptionMapper)); + } + + } + + public void stop(ExtensionPointRegistry registry) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java new file mode 100644 index 0000000000..8f35b2b00f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.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.sca.core.databinding.processor; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.annotation.DataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev$ $Date$ + */ +public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor { + private DataBindingExtensionPoint dataBindingRegistry; + + public DataBindingJavaInterfaceProcessor(DataBindingExtensionPoint dataBindingRegistry) { + super(); + this.dataBindingRegistry = dataBindingRegistry; + } + + public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException { + if (!javaInterface.isRemotable()) { + return; + } + List operations = javaInterface.getOperations(); + processInterface(javaInterface, operations); + } + + private void processInterface(JavaInterface javaInterface, List operations) { + Class clazz = javaInterface.getJavaClass(); + DataBinding dataBinding = clazz.getAnnotation(DataBinding.class); + String dataBindingId = null; + boolean wrapperStyle = false; + if (dataBinding != null) { + dataBindingId = dataBinding.value(); + wrapperStyle = dataBinding.wrapped(); + } + + Map opMap = new HashMap(); + for (Operation op : javaInterface.getOperations()) { + opMap.put(op.getName(), op); + // In the case of @WebMethod, the method name can be different from the operation name + if (op instanceof JavaOperation) { + opMap.put(((JavaOperation)op).getJavaMethod().getName(), op); + } + if (dataBindingId != null) { + op.setDataBinding(dataBindingId); + op.setInputWrapperStyle(wrapperStyle); + op.setOutputWrapperStyle(wrapperStyle); + } + } + for (Method method : clazz.getMethods()) { + if (method.getDeclaringClass() == Object.class) { + continue; + } + Operation operation = opMap.get(method.getName()); + if (operation == null) { // @WebMethod exclude=true + continue; + } + DataBinding methodDataBinding = clazz.getAnnotation(DataBinding.class); + if (methodDataBinding == null) { + methodDataBinding = dataBinding; + } + dataBindingId = null; + wrapperStyle = false; + if (dataBinding != null) { + dataBindingId = dataBinding.value(); + wrapperStyle = dataBinding.wrapped(); + operation.setDataBinding(dataBindingId); + operation.setInputWrapperStyle(wrapperStyle); + operation.setOutputWrapperStyle(wrapperStyle); + } + + // FIXME: We need a better way to identify simple java types + int i = 0; + for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getInputType().getLogical()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + for (Annotation a : method.getParameterAnnotations()[i]) { + if (a.annotationType() == org.apache.tuscany.sca.databinding.annotation.DataType.class) { + String value = ((org.apache.tuscany.sca.databinding.annotation.DataType)a).value(); + d.setDataBinding(value); + } + } + dataBindingRegistry.introspectType(d, operation); + i++; + } + if (operation.getOutputType() != null) { + DataType d = operation.getOutputType(); + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + org.apache.tuscany.sca.databinding.annotation.DataType dt = + method.getAnnotation(org.apache.tuscany.sca.databinding.annotation.DataType.class); + if (dt != null) { + d.setDataBinding(dt.value()); + } + dataBindingRegistry.introspectType(d, operation); + } + /* It's now done in the JAXWS java interface processor + for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getFaultTypes()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + // TODO: Handle exceptions + dataBindingRegistry.introspectType(d, operation); + } + } + */ + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.java new file mode 100644 index 0000000000..702da720a0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.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.sca.core.databinding.processor; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev$ $Date$ + */ +public class WrapperJavaInterfaceProcessor implements JavaInterfaceVisitor { + private static final String JAXB_DATABINDING = "javax.xml.bind.JAXBElement"; + private DataBindingExtensionPoint dataBindingRegistry; + + public WrapperJavaInterfaceProcessor(DataBindingExtensionPoint dataBindingRegistry) { + super(); + this.dataBindingRegistry = dataBindingRegistry; + } + + public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException { + if (!javaInterface.isRemotable()) { + return; + } + for (Operation operation : javaInterface.getOperations()) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + if (inputWrapperInfo == null || outputWrapperInfo == null) { + continue; + } + // JIRA: TUSCANY-842 + String db = inputWrapperInfo.getDataBinding(); + if (db == null || JAXB_DATABINDING.equals(db)) { + db = assignOperationDataBinding(operation); + } + + // Introspect the wrapper data type + org.apache.tuscany.sca.databinding.DataBinding dbObj = dataBindingRegistry.getDataBinding(db); + WrapperHandler handler = dbObj == null ? null : dbObj.getWrapperHandler(); + if (handler != null) { + inputWrapperInfo.setWrapperType(handler.getWrapperType(operation, true)); + outputWrapperInfo.setWrapperType(handler.getWrapperType(operation, false)); + } + if (dbObj != null && handler == null) { + // To avoid JAXB wrapper bean generation + inputWrapperInfo.setWrapperType(null); + outputWrapperInfo.setWrapperType(null); + } + } + } + + /* + * Assigns an operation DB if one of the input types, output type, fault types has a non-default DB. + * However, if two of the input types, output type, fault types have two different non-default DBs + * ( e.g. SDO and JAXB), then we do nothing to the operation DB. + * + * The method logic assumes the JavaBeans DataBinding is the default + */ + private String assignOperationDataBinding(Operation operation) { + + Set dbs = new HashSet(); + + // Can't use DataType since operation.getInputType() returns: DataType> + List opDataTypes = new LinkedList(); + + opDataTypes.addAll(operation.getInputType().getLogical()); + opDataTypes.add(operation.getOutputType()); +/* + for (DataType ft : operation.getFaultTypes()) { + opDataTypes.add(ft.getLogical()); + } +*/ + + for (DataType d : opDataTypes) { + if (d != null) { + String dataBinding = d.getDataBinding(); + if ("java:array".equals(dataBinding)) { + dataBinding = ((DataType)d.getLogical()).getDataBinding(); + } + if (dataBinding != null) { + dbs.add(dataBinding); + } + } + } + + dbs.remove(JavaBeansDataBinding.NAME); + dbs.remove(SimpleJavaDataBinding.NAME); + + if (dbs.size() == 1) { + String db = dbs.iterator().next(); + operation.getInputWrapper().setDataBinding(db); + return db; + } else { + return operation.getInputWrapper().getDataBinding(); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java new file mode 100644 index 0000000000..38ca2cd10c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.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.sca.core.databinding.transformers; + +import java.lang.reflect.Array; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.osoa.sca.annotations.Reference; + +/** + * This is a special transformer to transform the output from one IDL to the + * other one + * + * @version $Rev$ $Date$ + */ +public class Array2ArrayTransformer extends BaseTransformer implements PullTransformer { + + protected Mediator mediator; + + public Array2ArrayTransformer() { + super(); + } + + /** + * @param mediator the mediator to set + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + @Override + public String getSourceDataBinding() { + return "java:array"; + } + + @Override + public String getTargetDataBinding() { + return "java:array"; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + @Override + public int getWeight() { + return 10; + } + + @SuppressWarnings("unchecked") + public Object transform(Object array, TransformationContext context) { + try { + if (array == null) { + return null; + } + DataType sourceType = context.getSourceDataType(); + DataType targetType = context.getTargetDataType(); + int length = Array.getLength(array); + Object targetArray = Array.newInstance(targetType.getPhysical().getComponentType(), length); + for (int i = 0; i < length; i++) { + Object sourceItem = Array.get(array, i); + Object targetItem = + mediator.mediate(sourceItem, sourceType.getLogical(), targetType.getLogical(), context + .getMetadata()); + Array.set(targetArray, i, targetItem); + } + return targetArray; + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.java new file mode 100644 index 0000000000..124928db24 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.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.sca.core.databinding.transformers; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.xml.StAXHelper; +import org.osoa.sca.CallableReference; + +public class CallableReference2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + @Override + protected Class getSourceType() { + return CallableReference.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + public XMLStreamReader transform(CallableReference source, TransformationContext context) { + try { + if (source != null) { + if (source instanceof CallableReferenceImpl) { + XMLStreamReader xmlReader = ((CallableReferenceImpl)source).getXMLReader(); + if (xmlReader != null) { + return xmlReader; + } else { + String xmlString = ((CallableReferenceImpl)source).toXMLString(); + + // remove "" processing instruction and wrap with a top-level element + return StAXHelper.createXMLStreamReader("" + + xmlString.substring(xmlString.indexOf("?>") + 2) + + ""); + } + } else { + throw new TransformationException("Unrecognized transformation source object"); + } + } else { + return null; + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.java new file mode 100644 index 0000000000..8733b91cd4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.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.sca.core.databinding.transformers; + +import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.osoa.sca.CallableReference; + +public class CallableReferenceDataBinding extends BaseDataBinding { + + public static final String NAME = CallableReference.class.getName(); + + private CallableReferenceTypeHelper xmlTypeHelper; + + public CallableReferenceDataBinding() { + super(NAME, CallableReference.class); + this.xmlTypeHelper = new CallableReferenceTypeHelper(); + } + + @Override + public XMLTypeHelper getXMLTypeHelper() { + return xmlTypeHelper; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.java new file mode 100644 index 0000000000..97629ea7b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.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.sca.core.databinding.transformers; + +import java.beans.Introspector; +import java.util.ArrayList; +import java.util.List; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.XSDefinition; + +/** + * + * @version $Rev$ $Date$ + */ +public class CallableReferenceTypeHelper implements XMLTypeHelper { + private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; + private static final String ANYTYPE_NAME = "anyType"; + private static final QName ANYTYPE_QNAME = new QName(SCHEMA_NS, ANYTYPE_NAME); + + public CallableReferenceTypeHelper() { + super(); + } + + public TypeInfo getTypeInfo(Class javaType, Object logical) { + QName xmlType = JavaXMLMapper.getXMLType(javaType); + if (xmlType != null) { + return new TypeInfo(xmlType, true, null); + } else if (javaType.isInterface()) { + return new TypeInfo(ANYTYPE_QNAME, true, null); + } else { + if (logical instanceof XMLType) { + xmlType = ((XMLType)logical).getTypeName(); + } + if (xmlType == null) { + xmlType = new QName(Introspector.decapitalize(javaType.getSimpleName())); + } + return new TypeInfo(xmlType, false, null); + } + } + + public List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, Interface intf) { + return new ArrayList(); + } + + public List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, List dataTypes) { + return new ArrayList(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.java new file mode 100644 index 0000000000..ff6e444dcd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.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.sca.core.databinding.transformers; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String; +import org.osoa.sca.CallableReference; + +/** + * @version $Rev$ $Date$ + */ +public class CallableReferenceXMLAdapter extends XmlAdapter { + private TransformerFactory transformerFactory = TransformerFactory.newInstance(); + private XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + @Override + public CallableReference unmarshal(Source v) throws Exception { + StringWriter sw = new StringWriter(); + StreamResult result = new StreamResult(sw); + transformerFactory.newTransformer().transform(v, result); + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(sw.toString())); + XMLStreamReader2CallableReference t2 = new XMLStreamReader2CallableReference(); + return t2.transform(reader, null); + } + + @Override + public Source marshal(CallableReference v) throws Exception { + CallableReference2XMLStreamReader t = new CallableReference2XMLStreamReader(); + XMLStreamReader reader = t.transform(v, null); + XMLStreamReader2String t2 = new XMLStreamReader2String(); + String xml = t2.transform(reader, null); + return new StreamSource(new StringReader(xml)); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java new file mode 100644 index 0000000000..6e2e714bdb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.transformers; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; + +/** + * This is a special transformer to transform the exception from one IDL to the + * other one + * + * @version $Rev$ $Date$ + */ +public class Exception2ExceptionTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + protected FaultExceptionMapper faultExceptionMapper; + + public Exception2ExceptionTransformer(Mediator mediator, FaultExceptionMapper faultExceptionMapper) { + super(); + this.mediator = mediator; + this.faultExceptionMapper = faultExceptionMapper; + } + + public Exception2ExceptionTransformer() { + super(); + } + + @Override + public String getSourceDataBinding() { + return DataBinding.IDL_FAULT; + } + + @Override + public String getTargetDataBinding() { + return DataBinding.IDL_FAULT; + } + + /** + * @param mediator the mediator to set + */ + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Throwable.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Throwable.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + @Override + public int getWeight() { + return 10000; + } + + @SuppressWarnings("unchecked") + public Throwable transform(Throwable source, TransformationContext context) { + DataType sourceType = context.getSourceDataType(); + + DataType targetType = context.getTargetDataType(); + + Object sourceFaultInfo = faultExceptionMapper.getFaultInfo(source, sourceType.getLogical().getPhysical(), context.getSourceOperation()); + Object targetFaultInfo = + mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); + + Throwable targetException = + faultExceptionMapper.wrapFaultInfo(targetType, source.getMessage(), targetFaultInfo, source.getCause(), context.getTargetOperation()); + + // FIXME + return targetException == null ? source : targetException; + + } + + public void setFaultExceptionMapper(FaultExceptionMapper faultExceptionMapper) { + this.faultExceptionMapper = faultExceptionMapper; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java new file mode 100644 index 0000000000..f537dc4524 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java @@ -0,0 +1,279 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.transformers; + +import java.util.List; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.osoa.sca.annotations.Reference; + +/** + * This is a special transformer to transform the input from one IDL to the + * other one + * + * @version $Rev$ $Date$ + */ +public class Input2InputTransformer extends BaseTransformer implements + PullTransformer { + private static final Logger logger = Logger.getLogger(Input2InputTransformer.class.getName()); + + protected Mediator mediator; + + public Input2InputTransformer() { + super(); + } + + @Override + public String getSourceDataBinding() { + return DataBinding.IDL_INPUT; + } + + @Override + public String getTargetDataBinding() { + return DataBinding.IDL_INPUT; + } + + /** + * @param mediator the mediator to set + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Object[].class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Object[].class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + @Override + public int getWeight() { + return 10000; + } + + /** + * Match the structure of the wrapper element. If it matches, then we can do + * wrapper to wrapper transformation. Otherwise, we do child to child. + * @param w1 + * @param w2 + * @return + */ + private boolean matches(WrapperInfo w1, WrapperInfo w2) { + if (w1 == null || w2 == null) { + return false; + } + if (!w1.getWrapperElement().equals(w2.getWrapperElement())) { + return false; + } + + // Compare the child elements + List list1 = w1.getChildElements(); + List list2 = w2.getChildElements(); + if (list1.size() != list2.size()) { + return false; + } + // FXIME: [rfeng] At this point, the J2W generates local elments under the namespace + // of the interface instead of "". We only compare the local parts only to work around + // the namespace mismatch + for (int i = 0; i < list1.size(); i++) { + String n1 = list1.get(i).getQName().getLocalPart(); + String n2 = list2.get(i).getQName().getLocalPart(); + if (!n1.equals(n2)) { + return false; + } + } + return true; + } + + @SuppressWarnings("unchecked") + public Object[] transform(Object[] source, TransformationContext context) { + // Check if the source operation is wrapped + DataType> sourceType = context.getSourceDataType(); + Operation sourceOp = context.getSourceOperation(); + boolean sourceWrapped = sourceOp != null && sourceOp.isInputWrapperStyle() && sourceOp.getInputWrapper() != null; + boolean sourceBare = sourceOp != null && !sourceOp.isInputWrapperStyle() && sourceOp.getInputWrapper() == null; + + // Find the wrapper handler for source data + WrapperHandler sourceWrapperHandler = null; + String sourceDataBinding = getDataBinding(sourceOp); + sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped); + + // Check if the target operation is wrapped + DataType> targetType = context.getTargetDataType(); + Operation targetOp = (Operation)context.getTargetOperation(); + boolean targetWrapped = targetOp != null && targetOp.isInputWrapperStyle() && targetOp.getInputWrapper() != null; + boolean targetBare = targetOp != null && !targetOp.isInputWrapperStyle() && targetOp.getInputWrapper() == null; + + // Find the wrapper handler for target data + WrapperHandler targetWrapperHandler = null; + String targetDataBinding = getDataBinding(targetOp); + targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped); + + if ((!sourceWrapped && !sourceBare) && targetWrapped) { + // Unwrapped --> Wrapped + WrapperInfo wrapper = targetOp.getInputWrapper(); + // ElementInfo wrapperElement = wrapper.getInputWrapperElement(); + + // Class targetWrapperClass = wrapper != null ? wrapper.getInputWrapperClass() : null; + + if (source == null) { + // Empty child elements + Object targetWrapper = targetWrapperHandler.create(targetOp, true); + return new Object[] {targetWrapper}; + } + + // If the source can be wrapped, wrapped it first + if (sourceWrapperHandler != null) { + WrapperInfo sourceWrapperInfo = sourceOp.getInputWrapper(); + DataType sourceWrapperType = sourceWrapperInfo != null ? sourceWrapperInfo.getWrapperType() : null; + + // We only do wrapper to wrapper transformation if the source has a wrapper and both sides + // match by XML structure + if (sourceWrapperType != null && matches(sourceOp.getInputWrapper(), targetOp.getInputWrapper())) { + Class sourceWrapperClass = sourceWrapperType.getPhysical(); + + // Create the source wrapper + Object sourceWrapper = sourceWrapperHandler.create(sourceOp, true); + + // Populate the source wrapper + if (sourceWrapper != null) { + sourceWrapperHandler.setChildren(sourceWrapper, + source, + sourceOp, + true); + + // Transform the data from source wrapper to target wrapper + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical().get(0), context + .getMetadata()); + return new Object[] {targetWrapper}; + } + } + } + // Fall back to child by child transformation + Object targetWrapper = targetWrapperHandler.create(targetOp, true); + List argTypes = wrapper.getUnwrappedInputType().getLogical(); + Object[] targetChildren = new Object[source.length]; + for (int i = 0; i < source.length; i++) { + // ElementInfo argElement = wrapper.getInputChildElements().get(i); + DataType argType = argTypes.get(i); + targetChildren[i] = + mediator.mediate(source[i], sourceType.getLogical().get(i), argType, context.getMetadata()); + } + targetWrapperHandler.setChildren(targetWrapper, + targetChildren, + targetOp, + true); + return new Object[] {targetWrapper}; + + } else if (sourceWrapped && (!targetWrapped && !targetBare)) { + // Wrapped to Unwrapped + Object sourceWrapper = source[0]; + Object[] target = null; + + // List childElements = sourceOp.getWrapper().getInputChildElements(); + if (targetWrapperHandler != null) { + // ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement(); + // FIXME: This is a workaround for the wsdless support as it passes in child elements + // under the wrapper that only matches by position + if (sourceWrapperHandler.isInstance(sourceWrapper, sourceOp, true)) { + + WrapperInfo targetWrapperInfo = targetOp.getInputWrapper(); + DataType targetWrapperType = + targetWrapperInfo != null ? targetWrapperInfo.getWrapperType() : null; + if (targetWrapperType != null && matches(sourceOp.getInputWrapper(), targetOp.getInputWrapper())) { + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceType.getLogical().get(0), targetWrapperType, context + .getMetadata()); + target = targetWrapperHandler.getChildren(targetWrapper, targetOp, true).toArray(); + return target; + } + } + } + Object[] sourceChildren = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, true).toArray(); + target = new Object[sourceChildren.length]; + for (int i = 0; i < sourceChildren.length; i++) { + DataType childType = sourceOp.getInputWrapper().getUnwrappedInputType().getLogical().get(i); + target[i] = + mediator.mediate(sourceChildren[i], childType, targetType.getLogical().get(i), context + .getMetadata()); + } + return target; + } else { + // Assuming wrapper to wrapper conversion can be handled here as well + Object[] newArgs = new Object[source.length]; + for (int i = 0; i < source.length; i++) { + Object child = + mediator.mediate(source[i], sourceType.getLogical().get(i), targetType.getLogical().get(i), context + .getMetadata()); + newArgs[i] = child; + } + return newArgs; + } + } + + private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) { + WrapperHandler wrapperHandler = null; + if (dataBindingId != null) { + DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId); + wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler(); + } + if (wrapperHandler == null && required) { + throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId); + } + return wrapperHandler; + } + + private String getDataBinding(Operation operation) { + WrapperInfo wrapper = operation.getInputWrapper(); + if (wrapper != null) { + return wrapper.getDataBinding(); + } else { + return null; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/OMElementXMLAdapter.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/OMElementXMLAdapter.java new file mode 100644 index 0000000000..ec67dabc15 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/OMElementXMLAdapter.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.sca.core.databinding.transformers; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.transform.Source; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.bind.annotation.adapters.XmlAdapter; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String; + +/** + * This special XmlAdapter can be used by JAXB classes to convert from OMElement to Source + */ +public class OMElementXMLAdapter extends XmlAdapter { + + private TransformerFactory transformerFactory = TransformerFactory.newInstance(); + private XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + @Override + public Source marshal(OMElement v) throws Exception { + XMLStreamReader reader = v.getXMLStreamReaderWithoutCaching(); + XMLStreamReader2String t2 = new XMLStreamReader2String(); + String xml = t2.transform(reader, null); + return new StreamSource(new StringReader(xml)); + } + + @Override + public OMElement unmarshal(Source v) throws Exception { + StringWriter sw = new StringWriter(); + StreamResult result = new StreamResult(sw); + transformerFactory.newTransformer().transform(v, result); + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(sw.toString())); + // Build OMElement from XMLStreamReader + StAXOMBuilder builder = new StAXOMBuilder(reader); + return builder.getDocumentElement(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java new file mode 100644 index 0000000000..348d8345b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java @@ -0,0 +1,257 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.databinding.transformers; + +import java.util.List; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.osoa.sca.annotations.Reference; + +/** + * This is a special transformer to transform the output from one IDL to the + * other one + * + * @version $Rev$ $Date$ + */ +public class Output2OutputTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + + /** + * @param wrapperHandler + */ + public Output2OutputTransformer() { + super(); + } + + /** + * @param mediator the mediator to set + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + @Override + public String getSourceDataBinding() { + return DataBinding.IDL_OUTPUT; + } + + @Override + public String getTargetDataBinding() { + return DataBinding.IDL_OUTPUT; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + @Override + public int getWeight() { + return 10; + } + + private String getDataBinding(Operation operation) { + WrapperInfo wrapper = operation.getOutputWrapper(); + if (wrapper != null) { + return wrapper.getDataBinding(); + } else { + return null; + } + } + + private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) { + WrapperHandler wrapperHandler = null; + if (dataBindingId != null) { + DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId); + wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler(); + } + if (wrapperHandler == null && required) { + throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId); + } + return wrapperHandler; + } + + /** + * Match the structure of the wrapper element. If it matches, then we can do + * wrapper to wrapper transformation. Otherwise, we do child to child. + * @param w1 + * @param w2 + * @return + */ + private boolean matches(WrapperInfo w1, WrapperInfo w2) { + if (w1 == null || w2 == null) { + return false; + } + if (!w1.getWrapperElement().equals(w2.getWrapperElement())) { + return false; + } + + // Compare the child elements + List list1 = w1.getChildElements(); + List list2 = w2.getChildElements(); + if (list1.size() != list2.size()) { + return false; + } + // FXIME: [rfeng] At this point, the J2W generates local elments under the namespace + // of the interface instead of "". We only compare the local parts only to work around + // the namespace mismatch + for (int i = 0; i < list1.size(); i++) { + String n1 = list1.get(i).getQName().getLocalPart(); + String n2 = list2.get(i).getQName().getLocalPart(); + if (!n1.equals(n2)) { + return false; + } + } + return true; + } + + @SuppressWarnings("unchecked") + public Object transform(Object response, TransformationContext context) { + try { + DataType sourceType = context.getSourceDataType(); + Operation sourceOp = context.getSourceOperation(); + boolean sourceWrapped = sourceOp != null && sourceOp.isOutputWrapperStyle() && sourceOp.getOutputWrapper() != null; + boolean sourceBare = sourceOp != null && !sourceOp.isOutputWrapperStyle() && sourceOp.getOutputWrapper() == null; + + WrapperHandler sourceWrapperHandler = null; + String sourceDataBinding = getDataBinding(sourceOp); + sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped); + + DataType targetType = context.getTargetDataType(); + Operation targetOp = (Operation)context.getTargetOperation(); + boolean targetWrapped = targetOp != null && targetOp.isOutputWrapperStyle() && targetOp.getOutputWrapper() != null; + boolean targetBare = targetOp != null && !targetOp.isOutputWrapperStyle() && targetOp.getOutputWrapper() == null; + + WrapperHandler targetWrapperHandler = null; + String targetDataBinding = getDataBinding(targetOp); + targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped); + + if ((!sourceWrapped &&!sourceBare) && targetWrapped) { + // Unwrapped --> Wrapped + WrapperInfo wrapper = targetOp.getOutputWrapper(); + ElementInfo wrapperElement = wrapper.getWrapperElement(); + List childElements = wrapper.getChildElements(); + Class targetWrapperClass = wrapper != null ? wrapper.getWrapperClass() : null; + + // If the source can be wrapped, wrapped it first + if (sourceWrapperHandler != null) { + WrapperInfo sourceWrapperInfo = sourceOp.getOutputWrapper(); + DataType sourceWrapperType = + sourceWrapperInfo != null ? sourceWrapperInfo.getWrapperType() : null; + + if (sourceWrapperType != null && matches(sourceOp.getOutputWrapper(), targetOp.getOutputWrapper())) { + Class sourceWrapperClass = sourceWrapperType.getPhysical(); + + Object sourceWrapper = sourceWrapperHandler.create(sourceOp, false); + if (sourceWrapper != null) { + if (!childElements.isEmpty()) { + // Set the return value + sourceWrapperHandler.setChildren(sourceWrapper, + new Object[] {response}, + sourceOp, + false); + } + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical(), context + .getMetadata()); + return targetWrapper; + } + } + } + Object targetWrapper = targetWrapperHandler.create(targetOp, false); + + if (childElements.isEmpty()) { + // void output + return targetWrapper; + } + + DataType argType = wrapper.getUnwrappedOutputType(); + Object child = response; + child = mediator.mediate(response, sourceType.getLogical(), argType, context.getMetadata()); + targetWrapperHandler.setChildren(targetWrapper, new Object[] {child}, targetOp, false); + return targetWrapper; + } else if (sourceWrapped && (!targetWrapped && !targetBare)) { + // Wrapped to Unwrapped + Object sourceWrapper = response; + List childElements = sourceOp.getOutputWrapper().getChildElements(); + if (childElements.isEmpty()) { + // The void output + return null; + } + if (targetWrapperHandler != null) { + ElementInfo wrapperElement = sourceOp.getOutputWrapper().getWrapperElement(); + + // FIXME: This is a workaround for the wsdless support as it passes in child elements + // under the wrapper that only matches by position + if (sourceWrapperHandler.isInstance(sourceWrapper, sourceOp, false)) { + + WrapperInfo targetWrapperInfo = targetOp.getOutputWrapper(); + DataType targetWrapperType = + targetWrapperInfo != null ? targetWrapperInfo.getWrapperType() : null; + + if (targetWrapperType != null && matches(sourceOp.getOutputWrapper(), targetOp.getOutputWrapper())) { + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceType.getLogical(), targetWrapperType, context + .getMetadata()); + return targetWrapperHandler.getChildren(targetWrapper, targetOp, false).get(0); + } + } + } + Object child = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, false).get(0); + DataType childType = sourceOp.getOutputWrapper().getUnwrappedOutputType(); + return mediator.mediate(child, childType, targetType.getLogical(), context.getMetadata()); + } else { + // FIXME: Do we want to handle wrapped to wrapped? + return mediator.mediate(response, sourceType.getLogical(), targetType.getLogical(), context + .getMetadata()); + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java new file mode 100644 index 0000000000..841efa9398 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.databinding.transformers; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.lang.reflect.Constructor; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.osoa.sca.CallableReference; + +@SuppressWarnings("unchecked") +public class XMLStreamReader2CallableReference extends BaseTransformer + implements PullTransformer { + + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + private static final String COMPOSITE = "composite"; + public static final QName COMPOSITE_QNAME = new QName(SCA10_NS, COMPOSITE); + + public CallableReference transform(XMLStreamReader source, TransformationContext context) { + try { + if (source != null) { + skipTopLevelElement(source); + Class refType = context.getTargetDataType().getPhysical(); + Class implType; + if (refType.isAssignableFrom(CallableReferenceImpl.class)) { + implType = CallableReferenceImpl.class; + } else if (refType.isAssignableFrom(ServiceReferenceImpl.class)) { + implType = ServiceReferenceImpl.class; + } else { + throw new TransformationException("Unrecognized transformation target type"); + } + Constructor constructor = implType.getConstructor(new Class[] {XMLStreamReader.class}); + return (CallableReference)constructor.newInstance(new Object[] {source}); + } else { + return null; + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + + /* + * Step over top-level element added by CallableReference2XMLStreamReader + */ + private void skipTopLevelElement(XMLStreamReader source) throws XMLStreamException { + while (source.hasNext()) { + int event = source.getEventType(); + if (event == START_ELEMENT) { + QName name = source.getName(); + if (COMPOSITE_QNAME.equals(name)) { + return; + } + } + source.next(); + } + throw new TransformationException(" element not found"); + } + + @Override + protected Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + protected Class getTargetType() { + return CallableReference.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java new file mode 100644 index 0000000000..bad2be6679 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java @@ -0,0 +1,198 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.wire; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; + +/** + * This processor is responsible to add an interceptor to invocation chain if + * the source and target operations have different databinding requirements + * + * @version $Rev$ $Date$ + */ +public class DataBindingRuntimeWireProcessor implements RuntimeWireProcessor { + private Mediator mediator; + private DataBindingExtensionPoint dataBindings; + private FaultExceptionMapper faultExceptionMapper; + + public DataBindingRuntimeWireProcessor(Mediator mediator, + DataBindingExtensionPoint dataBindings, + FaultExceptionMapper faultExceptionMapper) { + super(); + this.mediator = mediator; + this.dataBindings = dataBindings; + this.faultExceptionMapper = faultExceptionMapper; + } + + public boolean isTransformationRequired(DataType source, DataType target) { + if (source == null || target == null) { // void return type + return false; + } + if (source == target) { + return false; + } + + // Output type can be null + if (source == null && target == null) { + return false; + } else if (source == null || target == null) { + return true; + } + String sourceDataBinding = source.getDataBinding(); + String targetDataBinding = target.getDataBinding(); + if (sourceDataBinding == targetDataBinding) { + return false; + } + if (sourceDataBinding == null || targetDataBinding == null) { + // TODO: If any of the databinding is null, then no transformation + return false; + } + return !sourceDataBinding.equals(targetDataBinding); + } + + public boolean isTransformationRequired(Operation source, Operation target) { + if (source == target) { + return false; + } + + if (source.isInputWrapperStyle() != target.isInputWrapperStyle()) { + return true; + } + + if (source.isOutputWrapperStyle() != target.isOutputWrapperStyle()) { + return true; + } + + // Check output type + DataType sourceOutputType = source.getOutputType(); + DataType targetOutputType = target.getOutputType(); + + // Note the target output type is now the source for checking + // compatibility + if (isTransformationRequired(targetOutputType, sourceOutputType)) { + return true; + } + + List sourceInputType = source.getInputType().getLogical(); + List targetInputType = target.getInputType().getLogical(); + + int size = sourceInputType.size(); + if (size != targetInputType.size()) { + // TUSCANY-1682: The wrapper style may have different arguments + return true; + } + for (int i = 0; i < size; i++) { + if (isTransformationRequired(sourceInputType.get(i), targetInputType.get(i))) { + return true; + } + } + + return false; + } + + private boolean isTransformationRequired(InterfaceContract sourceContract, + Operation sourceOperation, + InterfaceContract targetContract, + Operation targetOperation) { + if (targetContract == null) { + targetContract = sourceContract; + } + if (sourceContract == targetContract) { + return false; + } + return isTransformationRequired(sourceOperation, targetOperation); + } + + public void process(RuntimeWire wire) { + InterfaceContract sourceContract = wire.getSource().getInterfaceContract(); + InterfaceContract targetContract = wire.getTarget().getInterfaceContract(); + if (targetContract == null) { + targetContract = sourceContract; + } + + if (!sourceContract.getInterface().isRemotable()) { + return; + } + List chains = wire.getInvocationChains(); + for (InvocationChain chain : chains) { + Operation sourceOperation = chain.getSourceOperation(); + Operation targetOperation = chain.getTargetOperation(); + + Interceptor interceptor = null; + if (isTransformationRequired(sourceContract, sourceOperation, targetContract, targetOperation)) { + // Add the interceptor to the source side because multiple + // references can be wired to the same service + interceptor = + new DataTransformationInterceptor(wire, sourceOperation, targetOperation, mediator); + } else { + // assume pass-by-values copies are required if interfaces are remotable and there is no data binding + // transformation, i.e. a transformation will result in a copy so another pass-by-value copy is unnecessary + if (!isOnMessage(targetOperation) && isRemotable(chain, sourceOperation, targetOperation)) { + interceptor = + new PassByValueInterceptor(mediator, chain, targetOperation); + } + } + if (interceptor != null) { + String phase = + (wire.getSource().getContract() instanceof ComponentReference) ? Phase.REFERENCE_INTERFACE + : Phase.SERVICE_INTERFACE; + chain.addInterceptor(phase, interceptor); + } + } + + } + + /** + * FIXME: TUSCANY-2586, temporary work around till the JIRA is fixed to prevent + * the PassByValueInterceptor being used for services when the binding protocol + * doesn't need the copies done. + */ + protected boolean isOnMessage(Operation op) { + return "onMessage".equals(op.getName()); + } + + /** + * Pass-by-value copies are required if the interfaces are remotable unless the + * implementation uses the @AllowsPassByReference annotation. + */ + protected boolean isRemotable(InvocationChain chain, Operation sourceOperation, Operation targetOperation) { + if (!sourceOperation.getInterface().isRemotable()) { + return false; + } + if (!targetOperation.getInterface().isRemotable()) { + return false; + } + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java new file mode 100644 index 0000000000..79c442450b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.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.sca.core.databinding.wire; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * An interceptor to transform data across databindings on the wire + * + * @version $Rev$ $Date$ + */ +public class DataTransformationInterceptor implements Interceptor, DataExchangeSemantics { + private Invoker next; + + private Operation sourceOperation; + + private Operation targetOperation; + private RuntimeWire wire; + private Mediator mediator; + + public DataTransformationInterceptor(RuntimeWire wire, + Operation sourceOperation, + Operation targetOperation, + Mediator mediator) { + super(); + this.sourceOperation = sourceOperation; + this.targetOperation = targetOperation; + this.mediator = mediator; + this.wire = wire; + } + + public Invoker getNext() { + return next; + } + + public Message invoke(Message msg) { + Map metadata = new HashMap(); + metadata.put("wire", wire); + Object input = mediator.mediateInput(msg.getBody(), sourceOperation, targetOperation, metadata); + msg.setBody(input); + Message resultMsg = next.invoke(msg); + if (sourceOperation.isNonBlocking()) { + // Not to reset the message body + return resultMsg; + } + + Object result = resultMsg.getBody(); + + if (resultMsg.isFault()) { + Object transformedFault = null; + if ((result instanceof Exception) && !(result instanceof RuntimeException)) { + transformedFault = mediator.mediateFault(result, sourceOperation, targetOperation, metadata); + if (transformedFault != result) { + resultMsg.setFaultBody(transformedFault); + } + } + // + // Leave it to another layer to actually throw the Exception which constitutes + // the message body. We don't throw it here. + // + } else { + assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result; + Object newResult = mediator.mediateOutput(result, sourceOperation, targetOperation, metadata); + resultMsg.setBody(newResult); + } + + return resultMsg; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public boolean allowsPassByReference() { + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java new file mode 100644 index 0000000000..44e5072e61 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.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.sca.core.databinding.wire; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Implementation of an interceptor that enforces pass-by-value semantics + * on operation invocations by copying the operation input and output data. + * + * @version $Rev$ $Date$ + */ +public class PassByValueInterceptor implements Interceptor { + + private Mediator mediator; + private Operation operation; + private Invoker nextInvoker; + private InvocationChain chain; + + /** + * Constructs a new PassByValueInterceptor. + * @param dataBindings databinding extension point + * @param operation the intercepted operation + */ + public PassByValueInterceptor(Mediator mediator, InvocationChain chain, Operation operation) { + this.mediator = mediator; + this.chain = chain; + this.operation = operation; + } + + public Message invoke(Message msg) { + if (chain.allowsPassByReference()) { + return nextInvoker.invoke(msg); + } + + msg.setBody(mediator.copyInput(msg.getBody(), operation)); + + Message resultMsg = nextInvoker.invoke(msg); + + if (!resultMsg.isFault() && operation.getOutputType() != null) { + resultMsg.setBody(mediator.copyOutput(resultMsg.getBody(), operation)); + } + + if (resultMsg.isFault()) { + resultMsg.setFaultBody(mediator.copyFault(resultMsg.getBody(), operation)); + } + return resultMsg; + } + + public Invoker getNext() { + return nextInvoker; + } + + public void setNext(Invoker next) { + this.nextInvoker = next; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..baba638c9b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.core.databinding.module.DataBindingModuleActivator diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java new file mode 100644 index 0000000000..b0c39e18ef --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.processor; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.annotation.DataBinding; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.osoa.sca.annotations.Remotable; +import org.w3c.dom.Node; + +/** + * + * @version $Rev$ $Date$ + */ +public class DataBindingJavaInterfaceProcessorTestCase extends TestCase { + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + } + + /** + * @throws InvalidServiceContractException + */ + public final void testVisitInterface() throws InvalidInterfaceException { + DataBindingExtensionPoint registry = new DefaultDataBindingExtensionPoint(); + DataBindingJavaInterfaceProcessor processor = new DataBindingJavaInterfaceProcessor(registry); + JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(); + + JavaInterface contract = javaFactory.createJavaInterface(); + contract.setJavaClass(MockInterface.class); + JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + interfaceContract.setInterface(contract); + Operation operation = newOperation("call"); + Operation operation1 = newOperation("call1"); + contract.getOperations().add(operation); + contract.getOperations().add(operation1); + contract.setRemotable(true); + processor.visitInterface(contract); + // Assert.assertEquals("org.w3c.dom.Node", contract.getDataBinding()); + // Assert.assertEquals("org.w3c.dom.Node", + // contract.getOperations().get("call").getDataBinding()); + // Assert.assertEquals("xml:string", + // contract.getOperations().get("call1").getDataBinding()); + } + + @DataBinding("org.w3c.dom.Node") + @Remotable + public static interface MockInterface { + Node call(Node msg); + + @DataBinding("xml:string") + String call1(String msg); + } + + private static Operation newOperation(String name) { + Operation operation = new OperationImpl(); + operation.setName(name); + return operation; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCaseFIXME.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCaseFIXME.java new file mode 100644 index 0000000000..7d49fb7112 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCaseFIXME.java @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.databinding.transformers; + +//import static org.apache.tuscany.spi.databinding.DataBinding.IDL_INPUT; +//import static org.apache.tuscany.spi.databinding.DataBinding.IDL_OUTPUT; +// +//import java.util.ArrayList; +//import java.util.List; +// +//import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +//import org.apache.tuscany.databinding.impl.DataBindingRegistryImpl; +//import org.apache.tuscany.databinding.impl.MediatorImpl; +//import org.apache.tuscany.databinding.impl.TransformationContextImpl; +//import org.apache.tuscany.databinding.impl.TransformerRegistryImpl; +//import org.apache.tuscany.databinding.javabeans.DOMNode2JavaBeanTransformer; +//import org.apache.tuscany.databinding.javabeans.JavaBean2DOMNodeTransformer; +//import org.apache.tuscany.databinding.xml.DOMDataBinding; +//import org.apache.tuscany.databinding.xml.Node2String; +//import org.apache.tuscany.databinding.xml.String2Node; +//import org.apache.tuscany.interfacedef.DataType; +//import org.apache.tuscany.interfacedef.Operation; +//import org.apache.tuscany.interfacedef.impl.DataTypeImpl; +//import org.apache.tuscany.interfacedef.impl.OperationImpl; +//import org.apache.tuscany.interfacedef.util.ElementInfo; +//import org.apache.tuscany.interfacedef.util.TypeInfo; +//import org.apache.tuscany.interfacedef.util.WrapperInfo; +//import org.apache.tuscany.interfacedef.util.XMLType; +//import org.apache.tuscany.spi.databinding.DataBindingRegistry; +//import org.apache.tuscany.spi.databinding.TransformationContext; +//import org.apache.tuscany.spi.databinding.extension.DOMHelper; +//import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension; +//import org.w3c.dom.Document; +//import org.w3c.dom.Element; + +public class IDLTransformerTestCaseFIXME extends TestCase { +// private static final String IPO_XML = "" + "" +// + " " +// + " Helen Zoe" +// + " 47 Eden Street" +// + " Cambridge" +// + " CB1 1JR" +// + " " +// + " " +// + " Robert Smith" +// + " 8 Oak Avenue" +// + " Old Town" +// + " PA" +// + " 95819" +// + " " +// + " " +// + " " +// + " Lapis necklace" +// + " 1" +// + " 99.95" +// + " Want this for the holidays" +// + " 1999-12-05" +// + " " +// + " " +// + ""; +// +// private static final String URI_ORDER_XSD = "http://example.com/order.xsd"; +// +// /** +// * @see junit.framework.TestCase#setUp() +// */ +// protected void setUp() throws Exception { +// super.setUp(); +// } +// +// public void testTransform() throws Exception { +// List types0 = new ArrayList(); +// DataType wrapperType = new DataTypeImpl(null, Object.class, +// new XMLType(new QName(URI_ORDER_XSD, +// "checkOrderStatus"), null)); +// types0.add(wrapperType); +// DataType> inputType0 = new DataTypeImpl>(IDL_INPUT, +// Object[].class, types0); +// +// List types1 = new ArrayList(); +// DataType customerIdType = new DataTypeImpl( +// null, +// Object.class, +// new XMLType( +// new QName(URI_ORDER_XSD, "customerId"), +// null)); +// DataType orderType = new DataTypeImpl(null, Object.class, +// new XMLType(new QName(URI_ORDER_XSD, "order"), null)); +// DataType flagType = new DataTypeImpl(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, +// "flag"), null)); +// types1.add(customerIdType); +// types1.add(orderType); +// types1.add(flagType); +// +// DataType statusType = new DataTypeImpl(null, Object.class, +// new XMLType(new QName(URI_ORDER_XSD, "status"), null)); +// DataType responseType = new DataTypeImpl(null, Object.class, +// new XMLType(new QName(URI_ORDER_XSD, +// "checkOrderStatusResponse"), +// null)); +// +// Operation op = new OperationImpl("checkOrderStatus"); +// op.setInputType(inputType0); +// op.setOutputType(responseType); +//// op.setDataBinding(DOMDataBinding.NAME); +//// +//// inputType0.setOperation(op); +// op.setWrapperStyle(true); +// ElementInfo inputElement = new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatus"), new TypeInfo(null, +// false, +// null)); +//// wrapperType.setMetadata(ElementInfo.class.getName(), inputElement); +// +// ElementInfo customerId = new ElementInfo(new QName("", "customerId"), +// SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("string")); +// ElementInfo order = new ElementInfo(new QName("", "order"), new TypeInfo(new QName(URI_ORDER_XSD), false, null)); +// ElementInfo flag = new ElementInfo(new QName("", "flag"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("int")); +// +//// customerIdType.setMetadata(ElementInfo.class.getName(), customerId); +//// orderType.setMetadata(ElementInfo.class.getName(), order); +//// flagType.setMetadata(ElementInfo.class.getName(), flag); +//// +//// customerIdType.setOperation(op); +//// orderType.setOperation(op); +//// flagType.setOperation(op); +// +// List inputElements = new ArrayList(); +// inputElements.add(customerId); +// inputElements.add(order); +// inputElements.add(flag); +// +// ElementInfo statusElement = new ElementInfo(new QName("", "status"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES +// .get("string")); +// +//// statusType.setMetadata(ElementInfo.class.getName(), statusElement); +//// statusType.setOperation(op); +// +// List outputElements = new ArrayList(); +// outputElements.add(statusElement); +// +// ElementInfo outputElement = new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatusResponse"), +// new TypeInfo(null, false, null)); +// +//// responseType.setMetadata(ElementInfo.class.getName(), inputElement); +//// responseType.setOperation(op); +// +// WrapperInfo wrapperInfo = new WrapperInfo(DOMDataBinding.NAME, inputElement, outputElement, inputElements, +// outputElements); +// op.setWrapper(wrapperInfo); +//// op.setDataBinding(DOMDataBinding.NAME); +// +// MediatorImpl m = new MediatorImpl(); +// TransformerRegistryImpl tr = new TransformerRegistryImpl(); +// tr.registerTransformer(new String2Node()); +// tr.registerTransformer(new Node2String()); +// tr.registerTransformer(new DOMNode2JavaBeanTransformer()); +// tr.registerTransformer(new JavaBean2DOMNodeTransformer()); +// m.setTransformerRegistry(tr); +// DataBindingRegistry dataBindingRegistry = new DataBindingRegistryImpl(); +// dataBindingRegistry.register(new DOMDataBinding()); +// m.setDataBindingRegistry(dataBindingRegistry); +// +// Object[] source = new Object[] {"cust001", IPO_XML, Integer.valueOf(1)}; +// Input2InputTransformer t = new Input2InputTransformer(); +// t.setMediator(m); +// +// TransformationContext context = new TransformationContextImpl(); +// context.setSourceOperation(op); +// List> types = new ArrayList>(); +// types.add(new DataTypeImpl(Object.class.getName(), String.class, String.class)); +// types.add(new DataTypeImpl("java.lang.String", String.class, String.class)); +// types.add(new DataTypeImpl(Object.class.getName(), int.class, int.class)); +// DataType>> inputType1 = new DataTypeImpl>>(IDL_INPUT, Object[].class, +// types); +// context.setSourceDataType(inputType1); +// context.setTargetDataType(op.getInputType()); +// Object[] results = t.transform(source, context); +// assertEquals(1, results.length); +// assertTrue(results[0] instanceof Element); +// Element element = (Element)results[0]; +// assertEquals("http://example.com/order.xsd", element.getNamespaceURI()); +// assertEquals("checkOrderStatus", element.getLocalName()); +// +// TransformationContext context1 = new TransformationContextImpl(); +// DataType sourceType = new DataTypeImpl(IDL_OUTPUT, Object.class, op.getOutputType()); +// +// context1.setSourceDataType(sourceType); +// DataType targetType = new DataTypeImpl(IDL_OUTPUT, Object.class, +// new DataTypeImpl("java.lang.Object", +// String.class, String.class)); +// context1.setTargetDataType(targetType); +// +// Document factory = DOMHelper.newDocument(); +// Element responseElement = factory +// .createElementNS("http://example.com/order.wsdl", "p:checkOrderStatusResponse"); +// Element status = factory.createElement("status"); +// responseElement.appendChild(status); +// status.appendChild(factory.createTextNode("shipped")); +// Output2OutputTransformer t2 = new Output2OutputTransformer(); +// t2.setMediator(m); +// Object st = t2.transform(responseElement, context1); +// assertEquals("shipped", st); +// +// } +// +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/pom.xml new file mode 100644 index 0000000000..f2a15cd1c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/pom.xml @@ -0,0 +1,122 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-core-spi + Apache Tuscany SCA Core SPI + + + + org.apache.tuscany.sca + tuscany-extensibility + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-sca-api-extension + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-definitions + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface + 1.6-SNAPSHOT + compile + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + javax.servlet + servlet-api + 2.5 + provided + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.core.spi + ${pom.name} + org.apache.tuscany.sca* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/doc/Context Model.emx b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/doc/Context Model.emx new file mode 100644 index 0000000000..0445ea5a6b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/doc/Context Model.emx @@ -0,0 +1,673 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java new file mode 100644 index 0000000000..ed4b57639c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.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.sca.context; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.osoa.sca.ComponentContext; + +/** + * Interface implemented by the provider of the ComponentContext. + * + * @version $Rev$ $Date$ + */ +public interface ComponentContextFactory { + /** + * Create an instance of ComponentContext + * + * @param component The runtime component + * @param requestContextFactory The factory to create RequestContext + * @return An instance of ComponentContext for the component + */ + ComponentContext createComponentContext(RuntimeComponent component, RequestContextFactory requestContextFactory); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.java new file mode 100644 index 0000000000..e92a8f2844 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.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.sca.context; + +/** + * An extension point for context factories. + * + * @version $Rev$ $Date$ + */ +public interface ContextFactoryExtensionPoint { + + /** + * Add a context factory extension. + * + * @param factory The factory to add + */ + void addFactory(Object factory); + + /** + * Remove a context factory extension. + * + * @param factory The factory to remove + */ + void removeFactory(Object factory); + + /** + * Get a factory implementing the given interface. + * @param factoryInterface the lookup key (factory interface) + * @return The factory + */ + T getFactory(Class factoryInterface); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java new file mode 100644 index 0000000000..5a0aefe55d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.context; + +import java.lang.reflect.Constructor; +import java.util.HashMap; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + +/** + * Default implementation of a model factory extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultContextFactoryExtensionPoint implements ContextFactoryExtensionPoint { + + /** + * The Map of Factories that have been registered. + */ + private HashMap, Object> factories = new HashMap, Object>(); + + private ExtensionPointRegistry registry; + + public DefaultContextFactoryExtensionPoint(ExtensionPointRegistry registry) { + this.registry = registry; + } + + /** + * Add a model factory extension. + * + * @param factory The factory to add. + * @throws IllegalArgumentException if factory is null + */ + public void addFactory(Object factory) throws IllegalArgumentException { + if (factory == null) { + throw new IllegalArgumentException("Cannot add null as a factory"); + } + + Class[] interfaces = factory.getClass().getInterfaces(); + for (int i = 0; i[] interfaces = factory.getClass().getInterfaces(); + for (int i = 0; i T getFactory(Class factoryInterface) throws IllegalArgumentException { + if (factoryInterface == null) { + throw new IllegalArgumentException("Cannot get null as a factory"); + } + + Object factory = factories.get(factoryInterface); + if (factory == null) { + + // Dynamically load a factory class declared under META-INF/services + try { + Class factoryClass = ServiceDiscovery.getInstance().loadFirstServiceClass(factoryInterface); + if (factoryClass != null) { + + // Default empty constructor + Constructor constructor = factoryClass.getConstructor(ExtensionPointRegistry.class); + factory = constructor.newInstance(registry); + + // Cache the loaded factory + addFactory(factory); + } + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + + } + + return factoryInterface.cast(factory); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java new file mode 100644 index 0000000000..9766e164b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.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.sca.context; + +import org.apache.tuscany.sca.assembly.ComponentProperty; + +/** + * Interface implemented by the provider of the property values + * + * @version $Rev$ $Date$ + */ +public interface PropertyValueFactory { + + /** + * This method will create an instance of the value for the specified Property. + * + * @param property The Property from which to retrieve the property value + * @param type The type of the property value being retrieved from the Property + * @param Type type of the property value being looked up + * + * @return the value for the Property + */ + B createPropertyValue(ComponentProperty property, Class type); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.java new file mode 100644 index 0000000000..546757c766 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.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.sca.context; + +import org.osoa.sca.RequestContext; + +/** + * Interface implemented by the provider of the RequestContext. + * + * @version $Rev$ $Date$ + */ +public interface RequestContextFactory { + /** + * @return An instance of RequestContext for the current invocation + */ + RequestContext createRequestContext(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java new file mode 100644 index 0000000000..04ac4ee20c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.endpointresolver; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + +/** + * Default implementation of a provider factory extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultEndpointResolverFactoryExtensionPoint implements EndpointResolverFactoryExtensionPoint { + + private ExtensionPointRegistry registry; + private final Map, EndpointResolverFactory> endpointResolverFactories = new HashMap, EndpointResolverFactory>(); + private boolean loaded; + + /** + * The default constructor. Does nothing. + * + */ + public DefaultEndpointResolverFactoryExtensionPoint(ExtensionPointRegistry registry) { + this.registry = registry; + } + + /** + * Add an endpoint resolver factory. + * + * @param endpointResolverFactory The resolver factory + */ + public void addEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory){ + endpointResolverFactories.put(endpointResolverFactory.getModelType(), endpointResolverFactory); + } + + /** + * Remove a endpoint resolver factory. + * + * @param endpointResolverFactory The endpoint resolver factory + */ + public void removeEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory){ + endpointResolverFactories.remove(endpointResolverFactory.getModelType()); + } + + /** + * Returns the provider factory associated with the given model type. + * @param modelType A model type + * @return The provider factory associated with the given model type + */ + public EndpointResolverFactory getEndpointResolverFactory(Class modelType) { + loadProviderFactories(); + + Class[] classes = modelType.getInterfaces(); + for (Class c : classes) { + EndpointResolverFactory factory = endpointResolverFactories.get(c); + if (factory != null) { + return factory; + } + } + return endpointResolverFactories.get(modelType); + } + + + /** + * Load provider factories declared under META-INF/services. + * @param registry + */ + private synchronized void loadProviderFactories() { + if (loaded) + return; + + // Get the provider factory service declarations + Set factoryDeclarations; + ServiceDiscovery serviceDiscovery = ServiceDiscovery.getInstance(); + try { + factoryDeclarations = serviceDiscovery.getServiceDeclarations(EndpointResolverFactory.class); + } catch (Exception e) { + throw new IllegalStateException(e); + } + + // Get the extension point + EndpointResolverFactoryExtensionPoint factoryExtensionPoint = + registry.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class); + List factories = new ArrayList(); + + for (ServiceDeclaration factoryDeclaration : factoryDeclarations) { + Map attributes = factoryDeclaration.getAttributes(); + + // Find the model type that identifies this resolver + String modelTypeName = attributes.get("model"); + + // Create a provider factory wrapper and register it + EndpointResolverFactory factory = + new LazyEndpointResolverFactory(registry, modelTypeName, factoryDeclaration); + factoryExtensionPoint.addEndpointResolverFactory(factory); + factories.add(factory); + } + + loaded = true; + } + + /** + * A wrapper around an endpoint provider factory allowing lazy + * loading and initialization of endpoint providers. + */ + private class LazyEndpointResolverFactory implements EndpointResolverFactory { + private ExtensionPointRegistry registry; + private String modelTypeName; + private ServiceDeclaration providerClass; + private EndpointResolverFactory factory; + private Class modelType; + + private LazyEndpointResolverFactory(ExtensionPointRegistry registry, + String modelTypeName, + ServiceDeclaration providerClass) { + this.registry = registry; + this.modelTypeName = modelTypeName; + this.providerClass = providerClass; + } + + @SuppressWarnings("unchecked") + private EndpointResolverFactory getFactory() { + if (factory == null) { + try { + Class factoryClass = (Class)providerClass.loadClass(); + Constructor constructor = + factoryClass.getConstructor(ExtensionPointRegistry.class); + factory = constructor.newInstance(registry); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return factory; + } + + public EndpointResolver createEndpointResolver(Endpoint endpoint, Binding binding) { + return getFactory().createEndpointResolver(endpoint, binding); + } + + public Class getModelType() { + if (modelType == null) { + try { + modelType = providerClass.loadClass(modelTypeName); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.java new file mode 100644 index 0000000000..79a10f6d84 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.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.sca.endpointresolver; + + +/** + * A reference binding implementation can options implement this + * interface to tie into the Tuscany SCA runtime + * + * @version $Rev$ $Date$ + */ +public interface EndpointResolver { + + /** + * This method will be invoked when the endpoint is + * activated. It gives the resolver the opportunity + * to do any set up ready for when it is asked to + * resolve the endpoint when a message arrives + */ + void start(); + + /** + * This method will be invoked when the endpoint is + * to be resolved. The resolver will attempt to resolve the + * endpoint against available services. The resolvers extending + * this interface will provide environment or binding specific + * resolution processing + */ + void resolve(); + + /** + * This method will be invoked when the endpont is + * deactivated. It gives the resolver the opportunity + * to take and required resolver shutdown actions + */ + void stop(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.java new file mode 100644 index 0000000000..fdd304a9c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.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.sca.endpointresolver; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Endpoint; + +/** + * A factory for creating the runtime artifacts that resolve endpoints. + * + * @version $Rev$ $Date$ + */ +public interface EndpointResolverFactory { + + /** + * Creates a new endpoint resolver for the given component, + * reference and binding. + * + * @param component The runtime component + * @param reference The reference on the runtime component + * @param enpoint The endpoint assembly model object + * @return The endpoint provider + */ + EndpointResolver createEndpointResolver(Endpoint endpoint, Binding binding); + + Class getModelType(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.java new file mode 100644 index 0000000000..be55981131 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.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.sca.endpointresolver; + +import java.util.List; + + +/** + * An extension point for resolver factories. Holds all of the resolver + * factories from loaded extension points. Allows a resolver factory + * to be located based on a given model type. Hence the runtime can + * generate endpoint resolvers from the in memory assembly model. + * + * @version $Rev$ $Date$ + */ +public interface EndpointResolverFactoryExtensionPoint { + + + /** + * Add an endpoint resolver factory. + * + * @param endpointResolverFactory The resolver factory + */ + void addEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory); + + /** + * Remove a endpoint resolver factory. + * + * @param endpointResolverFactory The endpoint resolver factory + */ + void removeEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory); + + /** + * Returns the endpoint resolver factory associated with the given binding type. + * @param bindingType A binding type + * @return The endpoint resolver factory associated with the given binding type + */ + EndpointResolverFactory getEndpointResolverFactory(Class bindingType); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java new file mode 100644 index 0000000000..992c1188f7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/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.sca.event; + +/** + * The base interface for events that are propagated in the runtime + * + * @version $Rev$ $Date$ + */ +public interface Event { + + /** + * Returns the source of the event + */ + Object getSource(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java new file mode 100644 index 0000000000..d17aebd7e8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.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.sca.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 + * @param event Returns true if the event matches implemented criteria + * @return Match result + */ + boolean match(Event event); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java new file mode 100644 index 0000000000..f209eb8936 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.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.sca.event; + +/** + * Publishes events in the runtime by accepting {@link Event} objects and + * forwarding them to all registered {@link RuntimeEventListener} objects. + * + * @version $Rev$ $Date$ + */ +public interface EventPublisher { + + /** + * Publish an event to all registered listeners + * @param object The event to publish + */ + void publish(Event object); + + /** + * Registers a listener to receive notifications for the context + * @param listener The listener to add + */ + void addListener(RuntimeEventListener listener); + + /** + * Registers a listener to receive notifications for the context + * @param filter The filter that will be applied before the lister is called + * @param listener The lister to add + */ + void addListener(EventFilter filter, RuntimeEventListener listener); + + + /** + * Removes a previously registered listener + * @param listener The listener to remove + */ + void removeListener(RuntimeEventListener listener); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java new file mode 100644 index 0000000000..b34dceee62 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.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.sca.event; + +import java.util.EventListener; + +/** + * Listeners observe events fired in the SCA runtime. + * + * @version $Rev$ $Date$ + */ +public interface RuntimeEventListener extends EventListener { + + /** + * Accepts and event and acts on it + * @param event The event to act on + */ + void onEvent(Event event); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java new file mode 100644 index 0000000000..f888908340 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.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.sca.event; + +/** + * An event filter that always returns a true condition + * + * @version $Rev$ $Date$ + */ +public class TrueFilter implements EventFilter { + + /** + * Performs the actual evaluation on an event. Always returns true + * in this case + * @param event The incoming event which is ignored + * @return true + */ + public boolean match(Event event) { + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/DataExchangeSemantics.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/DataExchangeSemantics.java new file mode 100644 index 0000000000..957a15ce8a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/DataExchangeSemantics.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.sca.invocation; + +/** + * An invoker or interceptor can optionally implement this interface to indicate if they can + * enforce the pass-by-value semantics for an operation on remotable interfaces. + * + * @version $Rev$ $Date$ + */ +public interface DataExchangeSemantics { + /** + * Indicate if the data can be passed in by reference as they won't be mutated. + * @return true if pass-by-reference is allowed + */ + boolean allowsPassByReference(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java new file mode 100644 index 0000000000..a5f221fc11 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.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.sca.invocation; + +/** + * Synchronous mediation associated with a client- or target- side wire. + * + * @version $Rev$ $Date$ + */ +public interface Interceptor extends Invoker { + + /** + * Sets the next invoker + * @param next The next invoker + */ + void setNext(Invoker next); + + /** + * Returns the next invoker or null + * @return The next Invoker + */ + Invoker getNext(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java new file mode 100644 index 0000000000..75719bb0cc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.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.sca.invocation; + +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * A wire consists of 1..n invocation chains associated with the operations of its source service contract. + *

+ * Invocation chains may contain Interceptors that process invocations. + *

+ * A Message is used to pass data associated with an invocation through the chain. + * + * @version $Rev$ $Date$ + */ +public interface InvocationChain { + /** + * Returns the target operation for this invocation chain. + * + * @return The target operation for this invocation chain + */ + Operation getTargetOperation(); + + /** + * Updates the target operation for this invocation chain. + * + * @param operation The new target operation for this invocation chain + */ + void setTargetOperation(Operation operation); + + /** + * Returns the source operation for this invocation chain. + * + * @return The source operation for this invocation chain + */ + Operation getSourceOperation(); + + /** + * Adds an interceptor to the chain. For reference side, it will be added to + * Phase.REFERENCE. For service side, it will be added to Phase.SERVICE + * + * @param interceptor The interceptor to add + */ + void addInterceptor(Interceptor interceptor); + + /** + * Adds an invoker to the chain + * + * @param invoker The invoker to add + */ + void addInvoker(Invoker invoker); + + /** + * Returns the first invoker in the chain. + * + * @return The first invoker in the chain + */ + Invoker getHeadInvoker(); + + /** + * @deprecated This method is not used + * Returns the last invoker in the chain. + * + * @return The last invoker in the chain + */ + @Deprecated + Invoker getTailInvoker(); + + /** + * @deprecated Please use void addInterceptor(String phase, 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 + */ + @Deprecated + void addInterceptor(int index, Interceptor interceptor); + + /** + * Add an interceptor to the given phase + * @param phase + * @param interceptor + */ + void addInterceptor(String phase, Interceptor interceptor); + + /** + * Indicate if the data can be passed in by reference as they won't be mutated. + * @return true if pass-by-reference is allowed + */ + boolean allowsPassByReference(); + /** + * Force the invocation to allow pass-by-reference + * @param allowsPBR + */ + void setAllowsPassByReference(boolean allowsPBR); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java new file mode 100644 index 0000000000..2748bbed9a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.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.sca.invocation; + +/** + * Synchronous mediation associated with a client- or target- side wire. + * + * @version $Rev$ $Date$ + */ +public interface Invoker { + + /** + * Process a synchronous wire + * + * @param msg The request Message for the wire + * @return The response Message from the wire + */ + Message invoke(Message msg); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java new file mode 100644 index 0000000000..16cb4132e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.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.sca.invocation; + +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.runtime.EndpointReference; + +/** + * 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 + * @return The body of the message + */ + T getBody(); + + /** + * Sets the body of the message. + * @param body The body of the message + */ + void setBody(T body); + + /** + * Get the end point reference of the source reference + * @return The end point reference of the reference originating the message + */ + EndpointReference getFrom(); + + /** + * Set the end point reference of the reference originating the message + * @param from The end point reference of the reference originating the message + */ + void setFrom(EndpointReference from); + + /** + * Get the end point reference of target service + * @return The end point reference of the service that the message targets + */ + EndpointReference getTo(); + + /** + * Set the end point reference of target service + * @param to The end point reference of the service that the message targets + */ + void setTo(EndpointReference to); + + /** + * Returns the id of the message + * @return The message Id + */ + Object getMessageID(); + + /** + * Sets the id of the message + * @param messageId The message ID + */ + void setMessageID(Object messageId); + + /** + * 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 setFaultBody(T fault); + + /** + * Returns the operation that created the message. + * + * @return The operation that created the message + */ + Operation getOperation(); + + /** + * Sets the operation that created the message. + * + * @param op The operation that created the message + */ + void setOperation(Operation op); + + /** + * Returns a list of objects that are contained in the message header + * + * @return + */ + List getHeaders(); + + /** + * Returns the binding context in force for this message + */ + T getBindingContext(); + + /** + * Set the binding context that is in force for this message + * @param bindingContext + */ + void setBindingContext(T bindingContext); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java new file mode 100644 index 0000000000..38c900e36a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.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.sca.invocation; + + +/** + * A factory for messages + * + * @version $Rev $Date$ + */ +public interface MessageFactory { + + /** + * Creates a new message. + * + * @return The new message + */ + Message createMessage(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java new file mode 100644 index 0000000000..af8ad6e582 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.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.sca.invocation; + +/** + * Tuscany built-in phases for the invocation chain + * + * @version $Rev$ $Date$ + */ +public interface Phase { + // The first phase for outgoing invocations via a reference + String REFERENCE = "component.reference"; + + // data transformation and validation + String REFERENCE_INTERFACE = "reference.interface"; + + // reference policy handling + String REFERENCE_POLICY = "reference.policy"; + + // reference binding invoker + String REFERENCE_BINDING = "reference.binding"; + + String REFERENCE_BINDING_WIREFORMAT = "reference.binding.wireformat"; + String REFERENCE_BINDING_POLICY = "reference.binding.policy"; + String REFERENCE_BINDING_TRANSPORT = "reference.binding.transport"; + + String SERVICE_BINDING_TRANSPORT = "service.binding.transport"; + String SERVICE_BINDING_OPERATION_SELECTOR = "service.binding.operationselector"; + String SERVICE_BINDING_WIREFORMAT = "service.binding.wireformat"; + String SERVICE_BINDING_POLICY = "service.binding.policy"; + + + // The first phase for incoming invocations via a service + String SERVICE_BINDING = "service.binding"; + + // service policy handling + String SERVICE_POLICY = "service.policy"; + + // data validation and transformation + String SERVICE_INTERFACE = "service.interface"; + + // TODO: not sure if we need to have this face + String SERVICE = "component.service"; + + // implementation policy handling + String IMPLEMENTATION_POLICY = "implementation.policy"; + + // implementation invoker + String IMPLEMENTATION = "component.implementation"; + + // String getName(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java new file mode 100644 index 0000000000..3887db4873 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.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.sca.management; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Interface for the management service abstraction. The implementation + * could be based on a variety of technologies including JMX, WSDM, + * SNMP etc. + * + * @version $Revision$ $Date$ + */ +public interface ManagementService { + + /** + * Registers a component for management. + * + * @param name Name of the component. + * @param component Component to be registered. + */ + void registerComponent(String name, RuntimeComponent component); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java new file mode 100644 index 0000000000..0f6a932c51 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.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.sca.provider; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * A factory for creating the runtime artifacts that represent bindings. + * + * @version $Rev$ $Date$ + */ +public interface BindingProviderFactory extends ProviderFactory { + + /** + * Creates a new reference binding provider for the given component and + * reference. + * + * @param component The runtime component + * @param reference The reference on the runtime component + * @param binding The binding assembly model object + * @return The binding provider + */ + ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + M binding); + + /** + * Creates a new service binding provider for the given component and + * service. + * + * @param component The runtime component + * @param service The service on the runtime component + * @param binding The binding assembly model object + * @return The binding provider + */ + ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + M binding); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java new file mode 100644 index 0000000000..df46af121c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java @@ -0,0 +1,509 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Default implementation of a provider factory extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultProviderFactoryExtensionPoint implements ProviderFactoryExtensionPoint { + + private ExtensionPointRegistry registry; + private final Map, ProviderFactory> providerFactories = new HashMap, ProviderFactory>(); + private final List policyProviderFactories = new ArrayList(); + private boolean loaded; + + /** + * The default constructor. Does nothing. + * + */ + public DefaultProviderFactoryExtensionPoint(ExtensionPointRegistry registry) { + this.registry = registry; + } + + /** + * Add a provider factory. + * + * @param providerFactory The provider factory + */ + public void addProviderFactory(ProviderFactory providerFactory) { + if(providerFactory instanceof PolicyProviderFactory) { + policyProviderFactories.add((PolicyProviderFactory)providerFactory); + } + providerFactories.put(providerFactory.getModelType(), providerFactory); + } + + /** + * Remove a provider factory. + * + * @param providerFactory The provider factory + */ + public void removeProviderFactory(ProviderFactory providerFactory) { + if(providerFactory instanceof PolicyProviderFactory) { + policyProviderFactories.remove((PolicyProviderFactory)providerFactory); + } + providerFactories.remove(providerFactory.getModelType()); + } + + /** + * Returns the provider factory associated with the given model type. + * @param modelType A model type + * @return The provider factory associated with the given model type + */ + public ProviderFactory getProviderFactory(Class modelType) { + loadProviderFactories(); + + Class[] classes = modelType.getInterfaces(); + for (Class c : classes) { + ProviderFactory factory = providerFactories.get(c); + if (factory != null) { + return factory; + } + } + return providerFactories.get(modelType); + } + + public List getPolicyProviderFactories() { + loadProviderFactories(); + return policyProviderFactories; + } + + /** + * Load provider factories declared under META-INF/services. + * @param registry + */ + private synchronized void loadProviderFactories() { + if (loaded) + return; + + loadProviderFactories(BindingProviderFactory.class); + loadProviderFactories(ImplementationProviderFactory.class); + loadProviderFactories(PolicyProviderFactory.class); + loadProviderFactories(WireFormatProviderFactory.class); + loadProviderFactories(OperationSelectorProviderFactory.class); + + loaded = true; + } + + /** + * Load provider factories declared under META-INF/services. + * @param registry + * @param factoryClass + * @return + */ + private List loadProviderFactories(Class factoryClass) { + + // Get the provider factory service declarations + Set factoryDeclarations; + ServiceDiscovery serviceDiscovery = ServiceDiscovery.getInstance(); + try { + factoryDeclarations = serviceDiscovery.getServiceDeclarations(factoryClass); + } catch (Exception e) { + throw new IllegalStateException(e); + } + + // Get the target extension point + ProviderFactoryExtensionPoint factoryExtensionPoint = + registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + List factories = new ArrayList(); + + for (ServiceDeclaration factoryDeclaration : factoryDeclarations) { + Map attributes = factoryDeclaration.getAttributes(); + + // Load an implementation provider factory + if (factoryClass == ImplementationProviderFactory.class) { + String modelTypeName = attributes.get("model"); + + // Create a provider factory wrapper and register it + ImplementationProviderFactory factory = + new LazyImplementationProviderFactory(registry, modelTypeName, factoryDeclaration); + factoryExtensionPoint.addProviderFactory(factory); + factories.add(factory); + + } else if (factoryClass == BindingProviderFactory.class) { + + // Load a binding provider factory + String modelTypeName = attributes.get("model"); + + // Create a provider factory wrapper and register it + BindingProviderFactory factory = + new LazyBindingProviderFactory(registry, modelTypeName, factoryDeclaration); + factoryExtensionPoint.addProviderFactory(factory); + factories.add(factory); + } else if (factoryClass == PolicyProviderFactory.class) { + // Load a policy provider factory + String modelTypeName = attributes.get("model"); + + // Create a provider factory wrapper and register it + PolicyProviderFactory factory = + new LazyPolicyProviderFactory(registry, modelTypeName, factoryDeclaration); + factoryExtensionPoint.addProviderFactory(factory); + factories.add(factory); + } else if (factoryClass == WireFormatProviderFactory.class) { + + // Load a wire format provider factory + String modelTypeName = attributes.get("model"); + + // Create a provider factory wrapper and register it + WireFormatProviderFactory factory = + new LazyWireFormatProviderFactory(registry, modelTypeName, factoryDeclaration); + factoryExtensionPoint.addProviderFactory(factory); + factories.add(factory); + } else if (factoryClass == OperationSelectorProviderFactory.class) { + + // Load a wire format provider factory + String modelTypeName = attributes.get("model"); + + // Create a provider factory wrapper and register it + OperationSelectorProviderFactory factory = + new LazyOperationSelectorProviderFactory(registry, modelTypeName, factoryDeclaration); + factoryExtensionPoint.addProviderFactory(factory); + factories.add(factory); + } + } + return factories; + } + + /** + * A wrapper around an implementation provider factory allowing lazy + * loading and initialization of implementation providers. + */ + private static class LazyBindingProviderFactory implements BindingProviderFactory { + + private ExtensionPointRegistry registry; + private String modelTypeName; + private ServiceDeclaration factoryDeclaration; + private BindingProviderFactory factory; + private Class modelType; + + private LazyBindingProviderFactory(ExtensionPointRegistry registry, + String modelTypeName, + ServiceDeclaration factoryDeclaration) { + this.registry = registry; + this.modelTypeName = modelTypeName; + this.factoryDeclaration = factoryDeclaration; + } + + @SuppressWarnings("unchecked") + private BindingProviderFactory getFactory() { + if (factory == null) { + try { + Class factoryClass = + (Class)factoryDeclaration.loadClass(); + Constructor constructor = + factoryClass.getConstructor(ExtensionPointRegistry.class); + factory = constructor.newInstance(registry); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return factory; + } + + @SuppressWarnings("unchecked") + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return getFactory().createReferenceBindingProvider(component, reference, binding); + } + + @SuppressWarnings("unchecked") + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return getFactory().createServiceBindingProvider(component, service, binding); + } + + public Class getModelType() { + if (modelType == null) { + try { + modelType = factoryDeclaration.loadClass(modelTypeName); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + + } + + /** + * A wrapper around an implementation provider factory allowing lazy + * loading and initialization of implementation providers. + */ + private class LazyImplementationProviderFactory implements ImplementationProviderFactory { + + private ExtensionPointRegistry registry; + private String modelTypeName; + private ServiceDeclaration providerClass; + private ImplementationProviderFactory factory; + private Class modelType; + + private LazyImplementationProviderFactory(ExtensionPointRegistry registry, + String modelTypeName, + ServiceDeclaration providerClass) { + this.registry = registry; + this.modelTypeName = modelTypeName; + this.providerClass = providerClass; + } + + @SuppressWarnings("unchecked") + private ImplementationProviderFactory getFactory() { + if (factory == null) { + try { + Class factoryClass = + (Class)providerClass.loadClass(); + Constructor constructor = + factoryClass.getConstructor(ExtensionPointRegistry.class); + factory = constructor.newInstance(registry); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return factory; + } + + @SuppressWarnings("unchecked") + public ImplementationProvider createImplementationProvider(RuntimeComponent component, + Implementation Implementation) { + return getFactory().createImplementationProvider(component, Implementation); + } + + public Class getModelType() { + if (modelType == null) { + try { + + modelType = providerClass.loadClass(modelTypeName); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + + } + + /** + * A wrapper around an policy provider factory allowing lazy + * loading and initialization of policy providers. + */ + private class LazyPolicyProviderFactory implements PolicyProviderFactory { + private ExtensionPointRegistry registry; + private String modelTypeName; + private ServiceDeclaration providerClass; + private PolicyProviderFactory factory; + private Class modelType; + + private LazyPolicyProviderFactory(ExtensionPointRegistry registry, + String modelTypeName, + ServiceDeclaration providerClass) { + this.registry = registry; + this.modelTypeName = modelTypeName; + this.providerClass = providerClass; + } + + @SuppressWarnings("unchecked") + private PolicyProviderFactory getFactory() { + if (factory == null) { + try { + Class factoryClass = (Class)providerClass.loadClass(); + Constructor constructor = + factoryClass.getConstructor(ExtensionPointRegistry.class); + factory = constructor.newInstance(registry); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return factory; + } + + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, + Implementation implementation) { + return getFactory().createImplementationPolicyProvider(component, implementation); + } + + public PolicyProvider createReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return getFactory().createReferencePolicyProvider(component, reference, binding); + } + + public PolicyProvider createServicePolicyProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return getFactory().createServicePolicyProvider(component, service, binding); + } + + public Class getModelType() { + if (modelType == null) { + try { + modelType = providerClass.loadClass(modelTypeName); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + } + + /** + * A wrapper around a wire format provider factory allowing lazy + * loading and initialization of wire format providers. + */ + private class LazyWireFormatProviderFactory implements WireFormatProviderFactory { + + private ExtensionPointRegistry registry; + private String modelTypeName; + private ServiceDeclaration providerClass; + private WireFormatProviderFactory factory; + private Class modelType; + + private LazyWireFormatProviderFactory(ExtensionPointRegistry registry, + String modelTypeName, + ServiceDeclaration providerClass) { + this.registry = registry; + this.modelTypeName = modelTypeName; + this.providerClass = providerClass; + } + + @SuppressWarnings("unchecked") + private WireFormatProviderFactory getFactory() { + if (factory == null) { + try { + Class factoryClass = + (Class)providerClass.loadClass(); + Constructor constructor = + factoryClass.getConstructor(ExtensionPointRegistry.class); + factory = constructor.newInstance(registry); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return factory; + } + + @SuppressWarnings("unchecked") + public WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding){ + return getFactory().createReferenceWireFormatProvider(component, reference, binding); + } + + @SuppressWarnings("unchecked") + public WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding){ + return getFactory().createServiceWireFormatProvider(component, service, binding); + } + + public Class getModelType() { + if (modelType == null) { + try { + + modelType = providerClass.loadClass(modelTypeName); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + } + + /** + * A wrapper around a operation selector provider factory allowing lazy + * loading and initialization of operation selector providers. + */ + private class LazyOperationSelectorProviderFactory implements OperationSelectorProviderFactory { + + private ExtensionPointRegistry registry; + private String modelTypeName; + private ServiceDeclaration providerClass; + private OperationSelectorProviderFactory factory; + private Class modelType; + + private LazyOperationSelectorProviderFactory(ExtensionPointRegistry registry, + String modelTypeName, + ServiceDeclaration providerClass) { + this.registry = registry; + this.modelTypeName = modelTypeName; + this.providerClass = providerClass; + } + + @SuppressWarnings("unchecked") + private OperationSelectorProviderFactory getFactory() { + if (factory == null) { + try { + Class factoryClass = + (Class)providerClass.loadClass(); + Constructor constructor = + factoryClass.getConstructor(ExtensionPointRegistry.class); + factory = constructor.newInstance(registry); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return factory; + } + + @SuppressWarnings("unchecked") + public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding){ + return getFactory().createReferenceOperationSelectorProvider(component, reference, binding); + } + + @SuppressWarnings("unchecked") + public OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding){ + return getFactory().createServiceOperationSelectorProvider(component, service, binding); + } + + public Class getModelType() { + if (modelType == null) { + try { + + modelType = providerClass.loadClass(modelTypeName); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java new file mode 100644 index 0000000000..76ca061bab --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + +/** + * Concrete Implementation for the SCADefinitionsProviderExtensionPoint + * + * @version $Rev$ $Date$ + */ +public class DefaultSCADefinitionsProviderExtensionPoint implements + SCADefinitionsProviderExtensionPoint { + + private ExtensionPointRegistry extensionPointRegistry = null; + + private List scaDefnsProviders = new ArrayList(); + + public DefaultSCADefinitionsProviderExtensionPoint(ExtensionPointRegistry extnPtReg) { + this.extensionPointRegistry = extnPtReg; + } + + public void addSCADefinitionsProvider(SCADefinitionsProvider provider) { + scaDefnsProviders.add(provider); + } + + public void removeSCADefinitionsProvider(SCADefinitionsProvider provider) { + scaDefnsProviders.remove(provider); + } + + public List getSCADefinitionsProviders() { + if (scaDefnsProviders.isEmpty()) { + loadProviders(); + } + return scaDefnsProviders; + } + + private synchronized void loadProviders() { + // Get the provider service declarations + Set defnProviderDecls; + SCADefinitionsProvider aProvider = null; + Class providerClass = null; + Constructor constructor = null; + + try { + defnProviderDecls = + ServiceDiscovery.getInstance().getServiceDeclarations(SCADefinitionsProvider.class); + + for (ServiceDeclaration aDefnProviderDecl : defnProviderDecls) { + providerClass = aDefnProviderDecl.loadClass(); + + try { + constructor = providerClass.getConstructor(); + aProvider = (SCADefinitionsProvider)constructor.newInstance(); + } catch (NoSuchMethodException e1) { + constructor = providerClass.getConstructor(ExtensionPointRegistry.class); + aProvider = (SCADefinitionsProvider)constructor.newInstance(extensionPointRegistry); + } + + scaDefnsProviders.add(aProvider); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java new file mode 100644 index 0000000000..015c673d66 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * A component implementation can implement this interface in order to tie + * into the Tuscany runtime + * + * @version $Rev$ $Date$ + */ +public interface ImplementationProvider { + + /** + * This method will be invoked when the component implementation + * is activated. + */ + void start(); + + /** + * This method will be invoked when the component implementation + * is deactivated. + */ + void stop(); + + /** + * Create an invoker for the component implementation in the invocation + * chain. The invoker will be responsible for calling the implementation + * logic for the given component. + * + * @param service The component service + * @param operation The operation that the interceptor will handle + * @return An invoker that handles the invocation logic, null should be + * returned if no invoker is required + */ + Invoker createInvoker(RuntimeComponentService service, Operation operation); + + /** + * For bindings that invoke one-way callback operations asynchronously, + * there is no need to perform a thread switch before calling the invoker. + * This method indicates whether the binding has this capability. + * + * @return true if the callback invoker is able to invoke one-way operations + * asynchronously, false if all invocations are synchronous + */ + boolean supportsOneWayInvocation(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java new file mode 100644 index 0000000000..6a37d1e951 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.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.sca.provider; + +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * An interface for factories that create implementation providers. + * + * @version $Rev$ $Date$ + */ +public interface ImplementationProviderFactory extends ProviderFactory { + + /** + * Creates a new implementation provider for the given + * component. + * + * @param component The runtime component + * @param Implementation The implementation type + * @return The implementation provider + */ + ImplementationProvider createImplementationProvider(RuntimeComponent component, M Implementation); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectorProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectorProvider.java new file mode 100644 index 0000000000..f385c7dfba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectorProvider.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.sca.provider; + +import org.apache.tuscany.sca.invocation.Interceptor; + +/** + * @version $Rev$ $Date$ + */ +public interface OperationSelectorProvider { + /** + * Create an interceptor for the operation selector + * @return An interceptor that realize the policySet + */ + Interceptor createInterceptor(); + + /** + * Get the phase that the interceptor should be added + * @return The phase that this interceptor belongs to + */ + String getPhase(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectorProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectorProviderFactory.java new file mode 100644 index 0000000000..183b38cb33 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/OperationSelectorProviderFactory.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.sca.provider; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public interface OperationSelectorProviderFactory extends ProviderFactory { + /** + * Create wire format provider for a given reference binding + * @param component + * @param reference + * @param binding + * @return + */ + OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding); + + /** + * Create policy provider for a given service binding + * @param component + * @param service + * @param binding + * @return + */ + OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java new file mode 100644 index 0000000000..f2b59a7c54 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.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.sca.provider; + +import java.util.List; + +import javax.xml.namespace.QName; + +/** + * This interface can be optionally implemented by the Binding or Implementation providers to + * indicate if they implement the policies in the binding/implementation provider. + * + * @version $Rev$ $Date$ + */ +public interface PolicyImplementor { + /** + * Get a list of policy names that are implemented by this policy implementor + * @return A list of policy names + */ + List getImplementedPolicies(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java new file mode 100644 index 0000000000..644283dea1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.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.sca.provider; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; + +/** + * @version $Rev$ $Date$ + */ +public interface PolicyProvider { + /** + * Create an interceptor for a given operation + * @param operation + * @return An interceptor that realize the policySet + */ + Interceptor createInterceptor(Operation operation); + + /** + * Get the phase that the interceptor should be added + * @return The phase that this interceptor belongs to + */ + String getPhase(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java new file mode 100644 index 0000000000..b60a14d2da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.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.sca.provider; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.policy.Policy; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public interface PolicyProviderFactory extends ProviderFactory { + /** + * Create policy provider for a given reference binding + * @param component + * @param reference + * @param binding + * @return + */ + PolicyProvider createReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding); + + /** + * Create policy provider for a given service binding + * @param component + * @param service + * @param binding + * @return + */ + PolicyProvider createServicePolicyProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding); + + /** + * Create policy provider for a given component implementation + * @param component + * @param implementation + * @return + */ + PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java new file mode 100644 index 0000000000..2102806881 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.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.sca.provider; + +/** + * A factory for runtime providers. + * + * @version $Rev$ $Date$ + */ +public interface ProviderFactory { + + /** + * The model type that this factory creates providers for. + * + * @return the model type + */ + Class getModelType(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java new file mode 100644 index 0000000000..d8f9973338 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.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.sca.provider; + +import java.util.List; + + +/** + * An extension point for provider factories. Holds all of the provider + * factories from loaded extension points. Allows a provider factory + * to be located based on a given model type. Hence the runtime can + * generate runtime artifacts from the in memory assembly model. + * + * @version $Rev$ $Date$ + */ +public interface ProviderFactoryExtensionPoint { + + + /** + * Add a provider factory. + * + * @param providerFactory The provider factory + */ + void addProviderFactory(ProviderFactory providerFactory); + + /** + * Remove a provider factory. + * + * @param providerFactory The provider factory + */ + void removeProviderFactory(ProviderFactory providerFactory); + + /** + * Returns the provider factory associated with the given model type. + * @param modelType A model type + * @return The provider factory associated with the given model type + */ + ProviderFactory getProviderFactory(Class modelType); + + /** + * Get a list of registered PolicyProviderFactory + * @return a list of registered PolicyProviderFactory + */ + List getPolicyProviderFactories(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java new file mode 100644 index 0000000000..b3ab1d8b87 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.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.sca.provider; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; + +/** + * A reference binding implementation can options implement this + * interface to tie into the Tuscany SCA runtime + * + * @version $Rev$ $Date$ + */ +public interface ReferenceBindingProvider { + + /** + * This method will be invoked when the component reference binding is + * activated. + */ + void start(); + + /** + * This method will be invoked when the component reference binding is + * deactivated. + */ + void stop(); + + /** + * Create an invoker for the reference binding in the invocation chain. The + * invoker is responsible for making the outbound invocation over the + * binding protocol. + * + * @param operation The operation that the interceptor will handle + * @return An invoker that handles the invocation logic, null should be + * returned if no invoker is required + */ + Invoker createInvoker(Operation operation); + + /** + * Get the effective interface contract imposed by the binding. For example, + * it will be interface contract introspected from the WSDL portType used by + * the endpoint for a WebService binding. + * + * @return The effective interface contract, if null is returned, the + * interface contract for the component reference will be used + */ + InterfaceContract getBindingInterfaceContract(); + + /** + * For bindings that invoke one-way operations asynchronously, there is no + * need to perform a thread switch before calling the invoker. This method + * indicates whether the binding has this capability. + * + * @return true if the binding invoker is able to invoke one-way operations + * asynchronously, false if all invocations are synchronous + */ + boolean supportsOneWayInvocation(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProviderRRB.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProviderRRB.java new file mode 100644 index 0000000000..3ea9d0ac3c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProviderRRB.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.sca.provider; + +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * TODO RRB experiment + * This is an experiment extension to try out the request response + * binding function + * + * @version $Rev$ $Date$ + */ +public interface ReferenceBindingProviderRRB extends ReferenceBindingProvider { + + void configureBindingChain(RuntimeWire runtimeWire); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProvider.java new file mode 100644 index 0000000000..bd0f4d4b75 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProvider.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.sca.provider; + +import org.apache.tuscany.sca.definitions.SCADefinitions; + +/** + * Models a provider of SCA Definitions. Typically SCA Definitions providers + * may either load a definitions.xml file or create the SCA Definitions model + * programmatically. + * + * @version $Rev$ $Date$ + */ +public interface SCADefinitionsProvider { + SCADefinitions getSCADefinition() throws SCADefinitionsProviderException ; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderException.java new file mode 100644 index 0000000000..b05130d6c8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderException.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.sca.provider; + +/** + * @version $Rev$ $Date$ + */ +public class SCADefinitionsProviderException extends Exception { + + public SCADefinitionsProviderException(Throwable e) { + super(e); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderExtensionPoint.java new file mode 100644 index 0000000000..a5d60cc6eb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderExtensionPoint.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.sca.provider; + +import java.util.List; + +/** + * An extension point for SCA Definitions Providers. SCA Definition providers, load SCA Definitions + * items that are being specifically contributed by the module that hosts the provider in question. + * + * @version $Rev$ $Date$ + */ +public interface SCADefinitionsProviderExtensionPoint { + + void addSCADefinitionsProvider(SCADefinitionsProvider provider); + void removeSCADefinitionsProvider(SCADefinitionsProvider provider); + List getSCADefinitionsProviders(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java new file mode 100644 index 0000000000..e15234a549 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.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.sca.provider; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +/** + * A service binding can optionally implement this interface to tie + * into the Tuscany SCA runtime + * + * @version $Rev$ $Date$ + */ +public interface ServiceBindingProvider { + /** + * This method will be invoked when the component service binding is + * activated. + */ + void start(); + + /** + * This method will be invoked when the component service binding is + * deactivated. + */ + void stop(); + + /** + * Get the effective interface contract imposed by the binding. For example, + * it will be interface contract introspected from the WSDL portType used by + * the endpoint for a WebService binding. + * + * @return The effective interface contract, if null is returned, the + * interface contract for the component service will be used + */ + InterfaceContract getBindingInterfaceContract(); + + /** + * For bindings that invoke one-way callback operations asynchronously, + * there is no need to perform a thread switch before calling the invoker. + * This method indicates whether the binding has this capability. + * + * @return true if the callback invoker is able to invoke one-way operations + * asynchronously, false if all invocations are synchronous + */ + boolean supportsOneWayInvocation(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProviderRRB.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProviderRRB.java new file mode 100644 index 0000000000..e23a37360a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProviderRRB.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.sca.provider; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * TODO RRB experiment + * This is an experiment extension to try out the request response + * binding function + * + * @version $Rev$ $Date$ + */ +public interface ServiceBindingProviderRRB extends ServiceBindingProvider { + + void configureBindingChain(RuntimeWire runtimeWire); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/WireFormatProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/WireFormatProvider.java new file mode 100644 index 0000000000..35526cb251 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/WireFormatProvider.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.sca.provider; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.Interceptor; + +/** + * @version $Rev$ $Date$ + */ +public interface WireFormatProvider { + + /** + * Set up the contract that describes the interface that + * is providing data to or accepting data from the + * wire format interceptor. The wire format's job + * is to translate between this interface contract and the + * format on the wire. The interface contract may be + * configured separately for request and response + * wire formats + * + * @return the wire format interface contract + */ + public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract); + + /** + * Create an interceptor for the wire format + * @return An interceptor that realize the policySet + */ + Interceptor createInterceptor(); + + /** + * Get the phase that the interceptor should be added + * @return The phase that this interceptor belongs to + */ + String getPhase(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/WireFormatProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/WireFormatProviderFactory.java new file mode 100644 index 0000000000..fd748df6ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/WireFormatProviderFactory.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.sca.provider; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public interface WireFormatProviderFactory extends ProviderFactory { + /** + * Create wire format provider for a given reference binding + * @param component + * @param reference + * @param binding + * @return + */ + WireFormatProvider createReferenceWireFormatProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding); + + /** + * Create policy provider for a given service binding + * @param component + * @param service + * @param binding + * @return + */ + WireFormatProvider createServiceWireFormatProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java new file mode 100644 index 0000000000..851afee3c1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.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.sca.runtime; + +import java.util.ArrayList; +import java.util.List; + + +/** + * The default implementation of a WireProcessorExtensionPoint + * + * @version $Rev$ $Date$ + */ +public class DefaultWireProcessorExtensionPoint implements RuntimeWireProcessorExtensionPoint { + + /** + * The list of WireProcessors available to the runtime + */ + private final List processors = new ArrayList(); + + /** + * Registers a wire-processor in the runtime + * + * @param processor The processor to register + */ + public void addWireProcessor(RuntimeWireProcessor processor) { + processors.add(processor); + } + + /** + * De-registers a wire-processor in the runtime + * + * @param processor The processor to de-register + */ + public void removeWireProcessor(RuntimeWireProcessor processor) { + processors.remove(processor); + } + + /** + * Returns a list of registered wire-processors. + * + * @return The list of wire processors + */ + public List getWireProcessors() { + return processors; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java new file mode 100644 index 0000000000..b6fafa5fb6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +/** + * The endpoint reference for a component service or reference + * + * @version $Rev$ $Date$ + */ +public interface EndpointReference extends Cloneable { + /** + * Get the component for the endpoint + * @return The component, null of the EPR is for a non-SCA service + */ + RuntimeComponent getComponent(); + + /** + * Get the component service or reference for the endpoint + * @return The component service or reference, null if the EPR is for a non-SCA service + */ + Contract getContract(); + + /** + * Get the binding for the endpoint + * @return The binding + */ + Binding getBinding(); + + /** + * Get the interface contract for the endpoint + * @return The interface contract + */ + InterfaceContract getInterfaceContract(); + + /** + * Update the interface contract for the endpoint + * @param interfaceContract The updated interface contract + */ + void setInterfaceContract(InterfaceContract interfaceContract); + + /** + * Get the URI for this endpoint + * @return The URI of the endpoint + */ + String getURI(); + + /** + * Set the URI for this endpoint + * @param uri The new URI of the endpoint + */ + void setURI(String uri); + + /** + * Get the callback endpoint for this endpoint + * @return The callback endpoint for this endpoint + */ + EndpointReference getCallbackEndpoint(); + + /** + * Set the callback endpoint for this endpoint + * @param callbackEndpoint The new callback endpoint for this endpoint + */ + void setCallbackEndpoint(EndpointReference callbackEndpoint); + + Object clone() throws CloneNotSupportedException; + + void setReferenceParameters(ReferenceParameters parameters); + ReferenceParameters getReferenceParameters(); + + void mergeEndpoint(EndpointReference epr); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java new file mode 100644 index 0000000000..0e19538aff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.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.sca.runtime; + +/** + * Parameters for the EndPointReference + * + * @version $Rev$ $Date$ + */ +public interface ReferenceParameters extends Cloneable { + /** + * Get the callback ID + * @return the callbackID + */ + Object getCallbackID(); + + /** + * Set the callback ID + * @param callbackID the callbackID to set + */ + void setCallbackID(Object callbackID); + + /** + * Get the conversation ID + * @return the conversationID + */ + Object getConversationID(); + + /** + * Set the conversation ID + * @param conversationID the conversationID to set + */ + void setConversationID(Object conversationID); + + /** + * Get the ID for the non-ServiceReference callback object + * @return + */ + Object getCallbackObjectID(); + + /** + * Set the ID for the non-ServiceReference callback object + * @param callbackObjectID + */ + void setCallbackObjectID(Object callbackObjectID); + + EndpointReference getCallbackReference(); + + void setCallbackReference(EndpointReference callback); + + Object clone() throws CloneNotSupportedException; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java new file mode 100644 index 0000000000..30bba78a40 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.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.sca.runtime; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.PolicyProvider; + +/** + * The runtime component interface. Provides the bridge between the + * assembly model representation of a component and its runtime + * realization. + * + * @version $Rev$ $Date$ + */ +public interface RuntimeComponent extends Component { + /** + * Set the implementation-specific configuration for this component + * @param implementationProvider The object that manages the component implementation + */ + void setImplementationProvider(ImplementationProvider implementationProvider); + + /** + * Get the implementation-specific configuration for this component + * @return The implementation provider for this component + */ + ImplementationProvider getImplementationProvider(); + + /** + * Get the associated component context + * @return + */ + RuntimeComponentContext getComponentContext(); + + /** + * Set the associated component context + * @param context + */ + void setComponentContext(RuntimeComponentContext context); + + /** + * Tests if the RuntimeComponent is started + * @return true if the RuntimeComponent is started otherwise false + */ + boolean isStarted(); + + /** + * Sets the RuntimeComponent started state + * @param started the state to set + */ + void setStarted(boolean started); + + /** + * Add a policy provider to the component + * @param policyProvider + */ + void addPolicyProvider(PolicyProvider policyProvider); + + /** + * Get a list of policy providers configured for this component + * @return + */ + List getPolicyProviders(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java new file mode 100644 index 0000000000..f61bff9735 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.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.sca.runtime; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +import org.apache.tuscany.sca.api.ComponentContextExtension; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.osoa.sca.CallableReference; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.ServiceReference; + +/** + * @version $Rev$ $Date$ + */ +public interface RuntimeComponentContext extends ComponentContextExtension { + /** + * Activate the reference (creating runtime wires) + * @param reference + */ + void start(RuntimeComponentReference reference); + + /** + * Deserialize the component reference + * @param reader + * @return A component that contains the reference + * @throws IOException + */ + RuntimeComponent read(Reader reader) throws IOException; + + /** + * Serialize the component reference + * @param reference + * @param writer + * @throws IOException + */ + void write(RuntimeComponentReference reference, Writer writer) throws IOException; + + /** + * Get the CallableReference for a given component reference + * @param + * @param businessInterface The business interface + * @param reference The reference to be wired + * @param binding The binding to be used, if it's null, either binding.sca or the 1st binding + * will be selected + * @return A service reference representing the wire + */ + ServiceReference getServiceReference(Class businessInterface, + RuntimeComponentReference reference, + Binding binding); + + /** + * Bind the reference to a target component/componentService + * @param + * @param businessInterface The business interface + * @param reference The reference to be wired + * @param component The target component + * @param service The target component service + * @return A service reference representing the wire + */ + ServiceReference getServiceReference(Class businessInterface, + RuntimeComponentReference reference, + RuntimeComponent component, + RuntimeComponentService service); + + /** + * Create a CallableReference for the given component service + * @param + * @param businessInterface + * @param component + * @param service + * @return + */ + CallableReference getCallableReference(Class businessInterface, + RuntimeComponent component, + RuntimeComponentService service); + + /** + * @param + * @param businessInterface + * @param service + * @return + */ + ServiceReference createSelfReference(Class businessInterface, ComponentService service); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java new file mode 100644 index 0000000000..44ae7f552a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.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.sca.runtime; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.endpointresolver.EndpointResolver; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; + +/** + * The runtime component reference. Provides the bridge between the + * assembly model representation of a component reference and its runtime + * realization + * + * @version $Rev$ $Date$ + */ +public interface RuntimeComponentReference extends ComponentReference { + + /** + * Get a list of runtime wires to the reference + * + * @return The list of wires + */ + List getRuntimeWires(); + + /** + * Get the runtime wire for the given binding + * @param binding The assembly model binding + * @return The runtime wire + */ + RuntimeWire getRuntimeWire(Binding binding); + + /** + * Returns the reference binding provider associated with this + * component reference and the given binding. + * + * @param binding The assembly model binding + * @return The runtime reference binding provider + */ + ReferenceBindingProvider getBindingProvider(Binding binding); + + /** + * Sets the reference binding provider associated with this + * component reference and the given binding. + * + * @param binding The assembly model binding + * @param bindingProvider The runtime reference binding provider + */ + void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider); + + /** + * Returns the endpoint resolver associated with this + * component reference and the given endpoint. + * + * @param endpont The assembly model endpoint + * @return The enpoint resolver + */ + EndpointResolver getEndpointResolver(Endpoint endpoint); + + /** + * Sets the endpoint resolver associated with this + * component reference and the given endpoint. + * + * @param binding The assembly model binding + * @param bindingProvider The runtime reference binding provider + */ + void setEndpointResolver(Endpoint endpoint, EndpointResolver endpointResolver); + + /** + * Add a policy provider for the given binding to the reference + * @param binding The assembly model binding + * @param policyProvider The policy handler + */ + void addPolicyProvider(Binding binding, PolicyProvider policyProvider); + + /** + * Get a list of policy providers for the given binding + * @param binding The assembly model binding + * @return A list of policy providers for the given binding + */ + List getPolicyProviders(Binding binding); + + /** + * Get the invoker for the given binding and operation + * @param binding The assembly model binding + * @param operation The assembly model operation + * @return The runtime Invoker + */ + Invoker getInvoker(Binding binding, Operation operation); + + /** + * Set the owning component + * @param component + */ + void setComponent(RuntimeComponent component); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java new file mode 100644 index 0000000000..982724d798 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.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.sca.runtime; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; + +/** + * The runtime component service. Provides the bridge between the + * assembly model representation of a component service and its runtime + * realization + * + * @version $Rev$ $Date$ + */ +public interface RuntimeComponentService extends ComponentService { + + /** + * Get a list of runtime wires to the service + * + * @return The list of wires + */ + List getRuntimeWires(); + /** + * Get the runtime wire for the given binding + * @param binding The assembly model binding + * @return The runtime wire + */ + RuntimeWire getRuntimeWire(Binding binding); + + /** + * Get the callback wires associated with this service + * + * @return The list of runtime callback wires + */ + List getCallbackWires(); + + /** + * Returns the service binding provider associated with this + * component service and the given binding. + * + * @param binding The assembly model binding + * @return The runtime service binding provider + */ + ServiceBindingProvider getBindingProvider(Binding binding); + + /** + * Returns the service binding provider associated with this + * component service and the given binding. + * + * @param binding + * @param interfaceContract + * @return + */ + RuntimeWire getRuntimeWire(Binding binding, InterfaceContract interfaceContract); + + /** + * Sets the service binding provider associated with this + * component service and the given binding. + * + * @param binding The assembly model binding + * @param bindingProvider The runtime service binding provider + */ + void setBindingProvider(Binding binding, ServiceBindingProvider bindingProvider); + + /** + * Get the invoker for the given binding and operation + * @param binding The assembly model binding + * @param operation The assembly model operation + * @return The runtime invoker + */ + Invoker getInvoker(Binding binding, Operation operation); + + /** + * Get the invoker for the given binding and operation + * @param binding The assembly model binding + * @param interfaceContract the client interface contract + * @param operation The assembly model operation + * @return The runtime invoker + */ + Invoker getInvoker(Binding binding, InterfaceContract interfaceContract, Operation operation); + + /** + * Get the invocation chain for the given binding and operation + * @param binding The assembly model binding + * @param operation The assembly model operation + * @return The runtime invocation chain + */ + InvocationChain getInvocationChain(Binding binding, Operation operation); + + /** + * Get the invocation chain for the given binding and operation + * @param binding The assembly model binding + * @param operation The assembly model operation + * @param interfaceContract the client interface contract + * @return The runtime invocation chain + */ + InvocationChain getInvocationChain(Binding binding, InterfaceContract interfaceContract, Operation operation); + + /** + * Add a policy provider for the given binding to the service + * @param binding The assembly model binding + * @param policyProvider The policy handler + */ + void addPolicyProvider(Binding binding, PolicyProvider policyProvider); + + /** + * Get a list of policy providers for the given binding + * @param binding The assembly model binding + * @return A list of policy providers for the given binding + */ + List getPolicyProviders(Binding binding); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java new file mode 100644 index 0000000000..a2e7152202 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.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.sca.runtime; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Message; + +/** + * The runtime wire interface that connects a component reference to a + * component service (or an external service) over the selected binding + * + * @version $Rev$ $Date$ + */ +public interface RuntimeWire extends Cloneable { + + /** + * Get the source of the wire + * + * @return The end point reference of the source + */ + EndpointReference getSource(); + + /** + * Get the target of the wire + * + * @return The end point reference of the target + */ + EndpointReference getTarget(); + + /** + * Rebind the runtime wire with the given target + * @param target The target endpoint reference + */ + void setTarget(EndpointReference target); + + /** + * Force the invocation chains to be rebuilt + */ + void rebuild(); + + /** + * Returns the invocation chains for service operations associated with the + * wire + * + * @return the invocation chains for service operations associated with the + * wire + */ + List getInvocationChains(); + + /** + * Lookup the invocation chain by operation + * @param operation The operation + * @return The invocation chain for the given operation + */ + InvocationChain getInvocationChain(Operation operation); + + /** + * Get the invocation chain for the binding-specific handling + * @return + */ + InvocationChain getBindingInvocationChain(); + + /** + * This invoke method assumes that the binding invocation chain is in force + * and that there will be an operation selector element there to + * determine which operation to call + * @param msg The message + * @return The result + * @throws InvocationTargetException + */ + Object invoke(Message msg) throws InvocationTargetException; + + /** + * Invoke an operation with given arguments + * @param operation The operation + * @param args The arguments + * @return The result + * @throws InvocationTargetException + */ + Object invoke(Operation operation, Object[] args) throws InvocationTargetException; + + /** + * Invoke an operation with a context message + * @param operation The operation + * @param msg The message + * @return The result + * @throws InvocationTargetException + */ + Object invoke(Operation operation, Message msg) throws InvocationTargetException; + + /** + * @return a clone of the runtime wire + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java new file mode 100644 index 0000000000..fbb7aae467 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.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.sca.runtime; + +/** + * Implementations are called after wires are decorated with policy and before they are connected. + * + * @version $Rev$ $Date$ + */ +public interface RuntimeWireProcessor { + + /** + * Process the runtime wire to add interceptors + * + * @param wire + */ + void process(RuntimeWire wire); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java new file mode 100644 index 0000000000..4b2c71b397 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.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.sca.runtime; + +import java.util.List; + +/** + * Acts as a delegating WireProcessorExtensionPoint, delegating + * processing of wires after policies have been applied and source and targets + * have been connected. + * + * @version $Rev$ $Date$ + */ +public interface RuntimeWireProcessorExtensionPoint { + + /** + * Registers a wire-processor in the runtime + * + * @param processor The processor to register + */ + void addWireProcessor(RuntimeWireProcessor processor); + + /** + * De-registers a wire-processor in the runtime + * + * @param processor The processor to de-register + */ + void removeWireProcessor(RuntimeWireProcessor processor); + + /** + * Returns a list of registered wire-processors. + * + * @return The list of wire processors + */ + List getWireProcessors(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java new file mode 100644 index 0000000000..7d5cd6c54b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.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.sca.store; + +/** + * thrown when a record already exists during an insert operation + * + * @version $Rev$ $Date$ + */ +public class DuplicateRecordException extends StoreWriteException { + private static final long serialVersionUID = 3116253222569378447L; + + /** + * {@inheritDoc} + */ + public DuplicateRecordException() { + super(); + } + + /** + * {@inheritDoc} + */ + public DuplicateRecordException(String message, Throwable cause) { + super(message, cause); + } + + /** + * {@inheritDoc} + */ + public DuplicateRecordException(String message) { + super(message); + } + + /** + * {@inheritDoc} + */ + public DuplicateRecordException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java new file mode 100644 index 0000000000..9d965a3369 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/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.sca.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/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java new file mode 100644 index 0000000000..b15cde066a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/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.sca.store; + +import org.apache.tuscany.sca.event.EventPublisher; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * 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(RuntimeComponent 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(RuntimeComponent 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(RuntimeComponent 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(RuntimeComponent 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/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java new file mode 100644 index 0000000000..24eaddd3e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.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.sca.store; + + +/** + * Represents a generic exception thrown by a Store + * + * @version $Rev$ $Date$ + */ +public class StoreException extends Exception { + private static final long serialVersionUID = -319152147419962709L; + + /** + * {@inheritDoc} + */ + public StoreException() { + super(); + } + + /** + * {@inheritDoc} + */ + public StoreException(String message, Throwable cause) { + super(message, cause); + } + + /** + * {@inheritDoc} + */ + public StoreException(String message) { + super(message); + } + + /** + * {@inheritDoc} + */ + public StoreException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java new file mode 100644 index 0000000000..5c1a3ca79d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/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.sca.store; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Fired when a store implementation expires a resource + * + * @version $Rev$ $Date$ + */ +public class StoreExpirationEvent implements Event { + private Object source; + private RuntimeComponent 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, RuntimeComponent 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 RuntimeComponent getOwner() { + return owner; + } + + /** + * Returns the expiring object. + * + * @return the expiring object. + */ + public Object getInstance() { + return instance; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java new file mode 100644 index 0000000000..4bc7facf39 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.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.sca.store; + + +/** + * A generic monitor interface for services to log events + * + * @version $Rev$ $Date$ + */ +public interface StoreMonitor { + + /** + * Signals the service has started + * + * @param msg + */ + void start(String msg); + + /** + * Signals the service has been shutdown + * + * @param msg + */ + void stop(String msg); + + /** + * Fired when recovery is started + */ + + void beginRecover(); + + /** + * Fired when recovery is completed + */ + + void endRecover(); + + /** + * Fired when a record is processed during recovery + * + * @param recordId the id of the record being recovered + */ + + void recover(Object recordId); + + /** + * Signals an error event + * + * @param e the error + */ + + void error(Throwable e); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java new file mode 100644 index 0000000000..c2346bddca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.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.sca.store; + +/** + * Thrown when an error occurs reading from persistent storage + * + * @version $Rev$ $Date$ + */ +public class StoreReadException extends StoreException { + private static final long serialVersionUID = -8624542082121467271L; + + /** + * {@inheritDoc} + */ + public StoreReadException() { + super(); + } + + /** + * {@inheritDoc} + */ + public StoreReadException(String message, Throwable cause) { + super(message, cause); + } + + /** + * {@inheritDoc} + */ + public StoreReadException(String message) { + super(message); + } + + /** + * {@inheritDoc} + */ + public StoreReadException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java new file mode 100644 index 0000000000..b37519b31c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.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.sca.store; + +/** + * Thrown when an error occurs writing to persistent storage + * + * @version $Rev$ $Date$ + */ +public class StoreWriteException extends StoreException { + private static final long serialVersionUID = 5539070473942048555L; + + /** + * {@inheritDoc} + */ + public StoreWriteException() { + super(); + } + + /** + * {@inheritDoc} + */ + public StoreWriteException(String message, Throwable cause) { + super(message, cause); + } + + /** + * {@inheritDoc} + */ + public StoreWriteException(String message) { + super(message); + } + + /** + * {@inheritDoc} + */ + public StoreWriteException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java new file mode 100644 index 0000000000..d32af450ff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.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.sca.work; + +/** + * A callback interface that can be optionally used for registering + * interest in status of asynchronously scheduled unit of work. + * + * @version $Rev$ $Date$ + */ +public interface NotificationListener { + + /** + * 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 successfully 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); + + /** + * Callback 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/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java new file mode 100644 index 0000000000..b1beac78e2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.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.sca.work; + +/** + * Defines the contract for scheduling asynchronous units of work. + * + *

+ * Units of work can be scheduled with an optional NotificationListener. + * 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 notified with the + * error details. + *

+ * + * @version $Rev$ $Date$ + */ +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. + */ + void scheduleWork(T work, NotificationListener 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. + */ + void scheduleWork(T work); + + /** + * Destroys the work scheduler + */ + void destroy(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java new file mode 100644 index 0000000000..18ec2dfeaa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.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.sca.work; + + +/** + * Exception thrown by the work scheduler in case of unexpected exceptions. + * + * @version $Rev$ $Date$ + * + * @version $Rev$ $Date$ + */ +public class WorkSchedulerException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** + * {@inheritDoc} + */ + public WorkSchedulerException() { + super(); + } + + /** + * {@inheritDoc} + */ + public WorkSchedulerException(String message, Throwable cause) { + super(message, cause); + } + + /** + * {@inheritDoc} + */ + public WorkSchedulerException(String message) { + super(message); + } + + /** + * {@inheritDoc} + */ + public WorkSchedulerException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.ContextFactoryExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.ContextFactoryExtensionPoint new file mode 100644 index 0000000000..ddd91bceac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.ContextFactoryExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.context.DefaultContextFactoryExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint new file mode 100644 index 0000000000..91839e998f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.endpointresolver.DefaultEndpointResolverFactoryExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint new file mode 100644 index 0000000000..e9de1f135f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.provider.DefaultProviderFactoryExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint new file mode 100644 index 0000000000..2f700671ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.provider.DefaultSCADefinitionsProviderExtensionPoint + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint new file mode 100644 index 0000000000..95591dca5d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.runtime.DefaultWireProcessorExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/test/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPointTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/test/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPointTestCase.java new file mode 100644 index 0000000000..3a27569a3b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/test/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPointTestCase.java @@ -0,0 +1,208 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.context; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +import org.junit.Assert; +import org.junit.Test; + +/** + * This test case will test the class + * org.apache.tuscany.sca.context.DefaultContextFactoryExtensionPoint + * + * $Date$ $Rev$ + */ +public class DefaultContextFactoryExtensionPointTestCase { + + /** + * Tests adding/getting/removing a factory with no interfaces + */ + @Test + public void testFactoryWithNoInterfaces() { + Object factory = new FactoryWithNoInterfaces(); + Class[] ifaces = {}; + addGetRemoveFactory(factory, ifaces); + } + + /** + * Tests adding/getting/removing a factory with one interface + */ + @Test + public void testFactoryWithOneInterface() { + Object factory = new FactoryWithOneInterface(); + Class[] ifaces = { FactoryOneInterface.class }; + addGetRemoveFactory(factory, ifaces); + } + + /** + * Tests adding/getting/removing a factory with two interfaces + */ + @Test + public void testFactoryWithTwoInterfaces() { + Object factory = new FactoryWithTwoInterfaces(); + Class[] ifaces = { FactoryTwoInterfacesA.class, FactoryTwoInterfacesB.class }; + addGetRemoveFactory(factory, ifaces); + } + + /** + * Tests having multiple factories registered + */ + @Test + public void testMultipleFactories() { + // Create new factories + FactoryWithOneInterface factory1 = new FactoryWithOneInterface(); + FactoryWithTwoInterfaces factory2 = new FactoryWithTwoInterfaces(); + + ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); + + // Register the factories + DefaultContextFactoryExtensionPoint ctxFactory = new DefaultContextFactoryExtensionPoint(registry); + ctxFactory.addFactory(factory1); + ctxFactory.addFactory(factory2); + + // Re-get each of the factories + FactoryOneInterface regotFactory1 = ctxFactory.getFactory(FactoryOneInterface.class); + Assert.assertNotNull(regotFactory1); + Assert.assertSame(factory1, regotFactory1); + FactoryTwoInterfacesA regotFactory2A = ctxFactory.getFactory(FactoryTwoInterfacesA.class); + Assert.assertNotNull(regotFactory2A); + Assert.assertSame(factory2, regotFactory2A); + FactoryTwoInterfacesB regotFactory2B = ctxFactory.getFactory(FactoryTwoInterfacesB.class); + Assert.assertNotNull(regotFactory1); + Assert.assertSame(factory2, regotFactory2B); + } + + /** + * Tests passing in null to addFactory() + */ + @Test + public void testAddingNullFactory() { + + ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); + DefaultContextFactoryExtensionPoint ctxFactory = new DefaultContextFactoryExtensionPoint(registry); + try { + ctxFactory.addFactory(null); + Assert.fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException ex) { + // As expected + } + } + + /** + * Test passing in null to removeFactory() + */ + @Test + public void testRemovingNullFactory() { + ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); + DefaultContextFactoryExtensionPoint ctxFactory = new DefaultContextFactoryExtensionPoint(registry); + try { + ctxFactory.removeFactory(null); + Assert.fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException ex) { + // As expected + } + } + + /** + * Test passing in null to getFactory() + */ + @Test + public void testGetNullFactory() { + ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); + DefaultContextFactoryExtensionPoint ctxFactory = new DefaultContextFactoryExtensionPoint(registry); + try { + ctxFactory.getFactory(null); + Assert.fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException ex) { + // As expected + } + } + + /** + * Utility method for testing adding and removing a factory + * + * @param factory The factory class to test + * @param factoryInterfaces The list of interfaces implemented by the factory + */ + private void addGetRemoveFactory(Object factory, Class[] factoryInterfaces) { + ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); + DefaultContextFactoryExtensionPoint ctxFactory = new DefaultContextFactoryExtensionPoint(registry); + + // Make sure factory not already present + for (Class iface : factoryInterfaces) { + Assert.assertNull(ctxFactory.getFactory(iface)); + } + + // Add the factory + ctxFactory.addFactory(factory); + + // Make sure we can get the factory recently registered factory + for (Class iface : factoryInterfaces) { + Object regot = ctxFactory.getFactory(iface); + Assert.assertNotNull(regot); + Assert.assertSame(factory, regot); + } + + // Remove the factory + ctxFactory.removeFactory(factory); + + // Make sure factory is no longer registered + for (Class iface : factoryInterfaces) { + Assert.assertNull(ctxFactory.getFactory(iface)); + } + } + + /** + * Simple factory with no interfaces + */ + private class FactoryWithNoInterfaces { + } + + /** + * Simple interface for the factory with one interface + */ + private interface FactoryOneInterface { + } + + /** + * Simple factory with one interface + */ + private class FactoryWithOneInterface implements FactoryOneInterface { + } + + /** + * Simple interface for the factory with two interfaces + */ + private interface FactoryTwoInterfacesA { + } + + /** + * Simple interface for the factory with two interfaces + */ + private interface FactoryTwoInterfacesB { + } + + /** + * Simple factory with two interfaces + */ + private class FactoryWithTwoInterfaces implements FactoryTwoInterfacesA, FactoryTwoInterfacesB { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/test/java/org/apache/tuscany/sca/event/TrueFilterTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/test/java/org/apache/tuscany/sca/event/TrueFilterTestCase.java new file mode 100644 index 0000000000..2425133273 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core-spi/src/test/java/org/apache/tuscany/sca/event/TrueFilterTestCase.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.sca.event; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test case for TrueFilter + * + * @version $Rev$ $Date$ + */ +public class TrueFilterTestCase { + + /** + * Test TrueFilter matching an event + */ + @Test + public void testTrueFilterMatch() { + EventFilter filter = new TrueFilter(); + + Assert.assertTrue(filter.match(new DummyEvent())); + } + + /** + * Test TrueFilter matching null + */ + @Test + public void testTrueFilterMatchNull() { + EventFilter filter = new TrueFilter(); + + Assert.assertTrue(filter.match(null)); + } + + /** + * Dummy Event implementation for testing + */ + private class DummyEvent implements Event { + + /** + * {@inheritDoc} + */ + public Object getSource() { + throw new UnsupportedOperationException(); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/core/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/core/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/core/pom.xml new file mode 100644 index 0000000000..de5e7f42d4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/pom.xml @@ -0,0 +1,114 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-core + Apache Tuscany SCA Core Runtime + + + + org.apache.tuscany.sca + tuscany-extensibility + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution-java + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + cglib + cglib-nodep + 2.2 + + + + javax.xml.ws + jaxws-api + 2.1 + + + javax.xml.soap + saaj-api + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.core + ${pom.name} + org.apache.tuscany.sca.core* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java new file mode 100644 index 0000000000..c86c876075 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.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.sca.core.assembly; + + +/** + * Denotes an error starting the runtime + * + * @version $Rev$ $Date$ + */ +public class ActivationException extends Exception { + private static final long serialVersionUID = 8612661660934426123L; + + public ActivationException(String message) { + super(message); + } + + public ActivationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java new file mode 100644 index 0000000000..29dcc20f0b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.assembly; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.core.context.ComponentContextHelper; +import org.apache.tuscany.sca.core.conversation.ConversationManager; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Start/stop a composite + * + * @version $Rev$ $Date$ + */ +public interface CompositeActivator { + /** + * Activate a composite + * @param composite + */ + void activate(Composite composite) throws ActivationException; + + /** + * Activate a component reference + * @param component + * @param ref + */ + void start(RuntimeComponent component, RuntimeComponentReference ref); + + /** + * Activate a component reference + * @param component + * @param ref + */ + void activate(RuntimeComponent component, RuntimeComponentReference ref); + + /** + * Activate a component reference + * @param component + * @param ref + */ + void activate(RuntimeComponent component, RuntimeComponentService service); + + /** + * De-activate a component reference + * @param component + * @param ref + */ + void deactivate(RuntimeComponent component, RuntimeComponentReference ref); + + /** + * De-activate a component reference + * @param component + * @param ref + */ + void deactivate(RuntimeComponent component, RuntimeComponentService service); + + /** + * Stop a composite + * @param composite + */ + void deactivate(Composite composite) throws ActivationException; + + /** + * Start a component + * @param component + */ + void start(Component component) throws ActivationException; + + /** + * Stop a component + * @param component + */ + void stop(Component component) throws ActivationException; + + /** + * Start components in a composite + * @param composite + */ + void start(Composite composite) throws ActivationException; + + /** + * Stop components in a composite + * @param composite + */ + void stop(Composite composite) throws ActivationException; + + /** + * Get the component context helper + * @return + */ + ComponentContextHelper getComponentContextHelper(); + + /** + * Get the proxy factory + * @return + */ + ProxyFactory getProxyFactory(); + + /** + * Get the java interface factory + * @return + */ + JavaInterfaceFactory getJavaInterfaceFactory(); + + ConversationManager getConversationManager(); + + /** + * Configure the runtime component with component context + * @param component + */ + void configureComponentContext(RuntimeComponent component); + + /** + * Resolve a component by URI in the domain + * @param componentURI + * @return + */ + Component resolve(String componentURI); + + /** + * Set the domain composite + * @param domainComposite + */ + void setDomainComposite(Composite domainComposite); + + /** + * Get the domain composite + * @return + */ + Composite getDomainComposite(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java new file mode 100644 index 0000000000..f51931c53b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java @@ -0,0 +1,1101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.assembly; + +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.context.RequestContextFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.context.ComponentContextHelper; +import org.apache.tuscany.sca.core.context.ComponentContextImpl; +import org.apache.tuscany.sca.core.conversation.ConversationManager; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.core.scope.ConversationalScopeContainer; +import org.apache.tuscany.sca.core.scope.Scope; +import org.apache.tuscany.sca.core.scope.ScopeContainer; +import org.apache.tuscany.sca.core.scope.ScopeRegistry; +import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent; +import org.apache.tuscany.sca.endpointresolver.EndpointResolver; +import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory; +import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentContext; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; +import org.apache.tuscany.sca.work.WorkScheduler; + +/** + * @version $Rev$ $Date$ + */ +public class CompositeActivatorImpl implements CompositeActivator { + private static final Logger logger = Logger.getLogger(CompositeActivatorImpl.class.getName()); + + private final AssemblyFactory assemblyFactory; + private final MessageFactory messageFactory; + private final InterfaceContractMapper interfaceContractMapper; + private final ScopeRegistry scopeRegistry; + private final WorkScheduler workScheduler; + private final RuntimeWireProcessor wireProcessor; + private final ProviderFactoryExtensionPoint providerFactories; + private final EndpointResolverFactoryExtensionPoint endpointResolverFactories; + + private final RequestContextFactory requestContextFactory; + private final ProxyFactory proxyFactory; + private final JavaInterfaceFactory javaInterfaceFactory; + private final ConversationManager conversationManager; + + private final ComponentContextHelper componentContextHelper; + + private Composite domainComposite; + + /** + * @param assemblyFactory + * @param interfaceContractMapper + * @param workScheduler + * @param conversationManager TODO + * @param workContext + * @param wirePostProcessorRegistry + */ + public CompositeActivatorImpl(AssemblyFactory assemblyFactory, + MessageFactory messageFactory, + JavaInterfaceFactory javaInterfaceFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + ScopeRegistry scopeRegistry, + WorkScheduler workScheduler, + RuntimeWireProcessor wireProcessor, + RequestContextFactory requestContextFactory, + ProxyFactory proxyFactory, + ProviderFactoryExtensionPoint providerFactories, + EndpointResolverFactoryExtensionPoint endpointResolverFactories, + StAXArtifactProcessorExtensionPoint processors, + ConversationManager conversationManager) { + this.assemblyFactory = assemblyFactory; + this.messageFactory = messageFactory; + this.interfaceContractMapper = interfaceContractMapper; + this.scopeRegistry = scopeRegistry; + this.workScheduler = workScheduler; + this.wireProcessor = wireProcessor; + this.providerFactories = providerFactories; + this.endpointResolverFactories = endpointResolverFactories; + this.javaInterfaceFactory = javaInterfaceFactory; + this.requestContextFactory = requestContextFactory; + this.proxyFactory = proxyFactory; + this.conversationManager = conversationManager; + this.componentContextHelper = new ComponentContextHelper(assemblyFactory, javaInterfaceFactory, processors); + } + + /** + * @see org.apache.tuscany.sca.core.assembly.CompositeActivator#activate(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference) + */ + public void activate(RuntimeComponent component, RuntimeComponentReference ref) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Activating component reference: " + component.getURI() + "#" + ref.getName()); + } + resolveTargets(ref); + for (Binding binding : ref.getBindings()) { + addReferenceBindingProvider(component, ref, binding); + } + + for (Endpoint endpoint : ref.getEndpoints()){ + // TODO - source component should be set in the builder but the + // way the builder is written it's difficult to get at it + endpoint.setSourceComponent(component); + + addEndpointResolver(component, ref, endpoint); + } + } + + public void start(RuntimeComponent component, RuntimeComponentReference ref) { + synchronized (ref) { + resolveTargets(ref); + for (Binding binding : ref.getBindings()) { + ReferenceBindingProvider provider = ref.getBindingProvider(binding); + if (provider == null) { + provider = addReferenceBindingProvider(component, ref, binding); + } + if (provider != null) { + provider.start(); + } + addReferenceWire(component, ref, binding); + } + + // targets now have an endpoint representation. We can use this to + // look for unresolved endpoints using dummy wires for late resolution + for (Endpoint endpoint : ref.getEndpoints()){ + addReferenceEndpointWire(component, ref, endpoint); + } + } + } + + public void stop(Component component, ComponentReference reference) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Stopping component reference: " + component.getURI() + "#" + reference.getName()); + } + RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference); + for (Binding binding : reference.getBindings()) { + ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.stop(); + } + } + } + + public void deactivate(RuntimeComponent component, RuntimeComponentReference ref) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Deactivating component reference: " + component.getURI() + "#" + ref.getName()); + } + removeReferenceWires(ref); + for (Binding binding : ref.getBindings()) { + removeReferenceBindingProvider(component, ref, binding); + } + + } + + /** + * @param component + * @param reference + * @param binding + */ + private EndpointResolver addEndpointResolver(RuntimeComponent component, + RuntimeComponentReference reference, + Endpoint endpoint){ + + // only create endpoint resolvers for unresolved endpoints currently + // this will also prevent a wire from being created later + if (!endpoint.isUnresolved()){ + return null; + } + + // This souldn't happen as the endpoint resolver extension point is in core-spi but + // just in case returning null here will mean that no wire is created and calling + // the reference will fail with NPE + if (endpointResolverFactories == null){ + return null; + } + + EndpointResolverFactory resolverFactory = + (EndpointResolverFactory)endpointResolverFactories.getEndpointResolverFactory(endpoint.getClass()); + + if (resolverFactory != null) { + @SuppressWarnings("unchecked") + EndpointResolver endpointResolver = + resolverFactory.createEndpointResolver(endpoint, null); + if (endpointResolver != null) { + ((RuntimeComponentReference)reference).setEndpointResolver(endpoint, endpointResolver); + } + + return endpointResolver; + } else { + // TODO - for the time being allow the lack of an endpoint provider to be the + // switch to turn off endpoint processing + return null; + //throw new IllegalStateException("Endpoint provider factory not found for class: " + endpoint.getClass().getName()); + } + } + + public void addReferenceBindingProviderForEndpoint(Endpoint endpoint){ + addReferenceBindingProvider((RuntimeComponent)endpoint.getSourceComponent(), + (RuntimeComponentReference)endpoint.getSourceComponentReference(), + endpoint.getSourceBinding()); + } + + /** + * @param component + * @param reference + * @param binding + */ + private ReferenceBindingProvider addReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + BindingProviderFactory providerFactory = + (BindingProviderFactory)providerFactories.getProviderFactory(binding.getClass()); + if (providerFactory != null) { + @SuppressWarnings("unchecked") + ReferenceBindingProvider bindingProvider = + providerFactory.createReferenceBindingProvider((RuntimeComponent)component, + (RuntimeComponentReference)reference, + binding); + if (bindingProvider != null) { + ((RuntimeComponentReference)reference).setBindingProvider(binding, bindingProvider); + } + for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) { + PolicyProvider policyProvider = f.createReferencePolicyProvider(component, reference, binding); + if (policyProvider != null) { + reference.addPolicyProvider(binding, policyProvider); + } + } + + return bindingProvider; + } else { + throw new IllegalStateException("Provider factory not found for class: " + binding.getClass().getName()); + } + } + + /** + * @param reference + */ + private void resolveTargets(RuntimeComponentReference reference) { + // The code that used to be here to resolved unresolved targets is now + // at the bottom of BaseWireBuilder.connectComponentReferences() + } + + /** + * Create the runtime wires for a reference endpoint. Currently this method + * only deals with the late binding case and creates a dummy wire that + * will use the Endpoint to resolve the target at the point when the + * wire chains are created. + * + * @param component + * @param reference + * @param binding + */ + private void addReferenceEndpointWire(Component component, ComponentReference reference, Endpoint endpoint) { + // only deal with unresolved endpoints as, to prevent breaking changes, targets that are resolved + // at build time are still represented as bindings in the binding list + if (((RuntimeComponentReference)reference).getEndpointResolver(endpoint) == null){ + // no endpoint provider has previously been created so don't create the + // wire + return; + } + + // TODO: TUSCANY-2580: avoid NPE if the InterfaceCOntract is null + Reference ctref = endpoint.getSourceComponentReference().getReference(); + if (ctref != null && ctref.getInterfaceContract() == null) { + ctref.setInterfaceContract(reference.getInterfaceContract()); + } + + RuntimeWire wire = new EndpointWireImpl(endpoint, this); + + RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference; + runtimeRef.getRuntimeWires().add(wire); + } + + + /** + * Create the runtime wires for a reference binding + * + * @param component + * @param reference + * @param binding + */ + private void addReferenceWire(Component component, ComponentReference reference, Binding binding) { + if (!(reference instanceof RuntimeComponentReference)) { + return; + } + + // create wire if binding has an endpoint + Component targetComponent = null; + ComponentService targetComponentService = null; + Binding targetBinding = null; + + if (binding instanceof OptimizableBinding) { + OptimizableBinding endpoint = (OptimizableBinding)binding; + targetComponent = endpoint.getTargetComponent(); + targetComponentService = endpoint.getTargetComponentService(); + targetBinding = endpoint.getTargetBinding(); + // FIXME: TUSCANY-2136, For unresolved binding, don't add wire. Is it the right solution? + if (!reference.isCallback() && binding.getURI() == null && targetComponentService == null) { + return; + } + } + + // create a forward wire, either static or dynamic + addReferenceWire(component, reference, binding, targetComponent, targetComponentService, targetBinding); + + /* + // if static forward wire (not from self-reference), try to create a static callback wire + if (targetComponentService != null && !reference.getName().startsWith("$self$.")) { + ComponentReference callbackReference = targetComponentService.getCallbackReference(); + if (callbackReference != null) { + Binding callbackBinding = null; + Binding callbackServiceBinding = null; + // select a service callback binding that can be wired back to this component + for (Binding refBinding : callbackReference.getBindings()) { + // first look for a callback binding whose name matches the target binding name + if (refBinding.getName().equals(targetBinding.getName())) { + callbackBinding = refBinding; + break; + } + } + // see if there is a matching reference callback binding + if (callbackBinding != null) { + callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass()); + } + // if there isn't an end-to-end match, try again based on target binding type + if (callbackBinding == null || callbackServiceBinding == null) { + callbackBinding = callbackReference.getBinding(targetBinding.getClass()); + if (callbackBinding != null) { + callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass()); + } + } + if (callbackBinding != null && callbackServiceBinding != null) { + // end-to-end match, so create a static callback wire as well as the static forward wire + + addReferenceWire(targetComponent, callbackReference, callbackBinding, component, reference + .getCallbackService(), callbackServiceBinding); + } else { + // no end-to-end match, so do not create a static callback wire + } + } + } + */ + } + + public void addReferenceWireForEndpoint(Endpoint endpoint){ + addReferenceWire(endpoint.getSourceComponent(), + endpoint.getSourceComponentReference(), + endpoint.getSourceBinding(), + endpoint.getTargetComponent(), + endpoint.getTargetComponentService(), + endpoint.getTargetBinding()); + } + /** + * Create a reference wire for a forward call or a callback + * @param reference + * @param service + * @param serviceBinding + * @param component + * @param referenceBinding + */ + private RuntimeWire addReferenceWire(Component refComponent, + ComponentReference reference, + Binding refBinding, + Component serviceComponent, + ComponentService service, + Binding serviceBinding) { + RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference; + InterfaceContract bindingContract = getInterfaceContract(reference, refBinding); + + // Use the interface contract of the reference on the component type + Reference componentTypeRef = reference.getReference(); + + InterfaceContract sourceContract; + if (componentTypeRef == null || componentTypeRef.getInterfaceContract() == null) { + sourceContract = reference.getInterfaceContract(); + } else { + sourceContract = componentTypeRef.getInterfaceContract(); + } + + sourceContract = sourceContract.makeUnidirectional(false); + + EndpointReference wireSource = + new EndpointReferenceImpl((RuntimeComponent)refComponent, reference, refBinding, sourceContract); + ComponentService callbackService = reference.getCallbackService(); + if (callbackService != null) { + // select a reference callback binding to pass with invocations on this wire + Binding callbackBinding = null; + for (Binding binding : callbackService.getBindings()) { + // first look for a callback binding whose name matches the reference binding name + if (refBinding.getName().startsWith(binding.getName())) { + callbackBinding = binding; + break; + } + } + // if no callback binding found, try again based on reference binding type + if (callbackBinding == null) { + callbackBinding = callbackService.getBinding(refBinding.getClass()); + } + InterfaceContract callbackContract = callbackService.getInterfaceContract(); + EndpointReference callbackEndpoint = + new EndpointReferenceImpl((RuntimeComponent)refComponent, callbackService, callbackBinding, + callbackContract); + wireSource.setCallbackEndpoint(callbackEndpoint); + } + + EndpointReference wireTarget = + new EndpointReferenceImpl((RuntimeComponent)serviceComponent, service, serviceBinding, bindingContract); + + // TUSCANY-2029 - We should use the URI of the serviceBinding because the target may be a Component in a + // nested composite. + if (serviceBinding != null) { + wireTarget.setURI(serviceBinding.getURI()); + } + + RuntimeWire wire = + new RuntimeWireImpl(wireSource, wireTarget, interfaceContractMapper, workScheduler, wireProcessor, + messageFactory, conversationManager); + runtimeRef.getRuntimeWires().add(wire); + + return wire; + } + + private void addImplementationProvider(RuntimeComponent component, Implementation implementation) { + ImplementationProviderFactory providerFactory = + (ImplementationProviderFactory)providerFactories.getProviderFactory(implementation.getClass()); + if (providerFactory != null) { + @SuppressWarnings("unchecked") + ImplementationProvider implementationProvider = + providerFactory.createImplementationProvider(component, implementation); + if (implementationProvider != null) { + component.setImplementationProvider(implementationProvider); + } + } else { + throw new IllegalStateException("Provider factory not found for class: " + implementation.getClass() + .getName()); + } + for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) { + PolicyProvider policyProvider = f.createImplementationPolicyProvider(component, implementation); + if (policyProvider != null) { + component.addPolicyProvider(policyProvider); + } + } + + } + + private void removeImplementationProvider(RuntimeComponent component) { + component.setImplementationProvider(null); + component.getPolicyProviders().clear(); + } + + /** + * @param component + * @param service + * @param binding + */ + private ServiceBindingProvider addServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + BindingProviderFactory providerFactory = + (BindingProviderFactory)providerFactories.getProviderFactory(binding.getClass()); + if (providerFactory != null) { + @SuppressWarnings("unchecked") + ServiceBindingProvider bindingProvider = + providerFactory.createServiceBindingProvider((RuntimeComponent)component, + (RuntimeComponentService)service, + binding); + if (bindingProvider != null) { + ((RuntimeComponentService)service).setBindingProvider(binding, bindingProvider); + } + for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) { + PolicyProvider policyProvider = f.createServicePolicyProvider(component, service, binding); + if (policyProvider != null) { + service.addPolicyProvider(binding, policyProvider); + } + } + return bindingProvider; + } else { + throw new IllegalStateException("Provider factory not found for class: " + binding.getClass().getName()); + } + } + + private void removeServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + service.setBindingProvider(binding, null); + for (Binding b : service.getBindings()) { + List pps = service.getPolicyProviders(b); + if (pps != null) { + pps.clear(); + } + } + } + + private void removeReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + reference.setBindingProvider(binding, null); + for (Binding b : reference.getBindings()) { + List pps = reference.getPolicyProviders(b); + if (pps != null) { + pps.clear(); + } + } + } + + public void start(Composite composite) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Starting composite: " + composite.getName()); + } + for (Component component : composite.getComponents()) { + start(component); + } + } + + public void stop(Composite composite) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Stopping composite: " + composite.getName()); + } + for (final Component component : composite.getComponents()) { + stop(component); + } + } + + public void start(Component component) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Starting component: " + component.getURI()); + } + RuntimeComponent runtimeComponent = ((RuntimeComponent)component); + if(runtimeComponent.isStarted()) { + return; + } + + configureComponentContext(runtimeComponent); + + for (ComponentReference reference : component.getReferences()) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName()); + } + RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference); + runtimeRef.setComponent(runtimeComponent); + + for (Endpoint endpoint : reference.getEndpoints()) { + final EndpointResolver endpointResolver = runtimeRef.getEndpointResolver(endpoint); + if (endpointResolver != null) { + // Allow endpoint resolvers to do any startup reference manipulation + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + endpointResolver.start(); + return null; + } + }); + } + } + + for (Binding binding : reference.getBindings()) { + final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding); + if (bindingProvider != null) { + // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + bindingProvider.start(); + return null; + } + }); + } + } + } + + for (ComponentService service : component.getServices()) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Starting component service: " + component.getURI() + "#" + service.getName()); + } + RuntimeComponentService runtimeService = (RuntimeComponentService)service; + for (Binding binding : service.getBindings()) { + final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(binding); + if (bindingProvider != null) { + // bindingProvider.start(); + // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + bindingProvider.start(); + return null; + } + }); + } + } + } + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + start((Composite)implementation); + } else { + ImplementationProvider implementationProvider = runtimeComponent.getImplementationProvider(); + if (implementationProvider != null) { + implementationProvider.start(); + } + } + + if (component instanceof ScopedRuntimeComponent) { + ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component; + if (scopedRuntimeComponent.getScopeContainer() != null) { + scopedRuntimeComponent.getScopeContainer().start(); + } + } + + runtimeComponent.setStarted(true); + } + + /** + * @param runtimeComponent + */ + public void configureComponentContext(RuntimeComponent runtimeComponent) { + RuntimeComponentContext componentContext = + new ComponentContextImpl(this, assemblyFactory, proxyFactory, interfaceContractMapper, + requestContextFactory, javaInterfaceFactory, runtimeComponent); + runtimeComponent.setComponentContext(componentContext); + } + + /** + * Stop a component + */ + public void stop(Component component) { + if (!((RuntimeComponent)component).isStarted()) { + return; + } + if (logger.isLoggable(Level.FINE)) { + logger.fine("Stopping component: " + component.getURI()); + } + for (ComponentService service : component.getServices()) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Stopping component service: " + component.getURI() + "#" + service.getName()); + } + for (Binding binding : service.getBindings()) { + final ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(binding); + if (bindingProvider != null) { + // Allow bindings to read properties. Requires PropertyPermission read in security policy. + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + bindingProvider.stop(); + return null; + } + }); + } + } + } + for (ComponentReference reference : component.getReferences()) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName()); + } + RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference); + + for (Binding binding : reference.getBindings()) { + final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding); + if (bindingProvider != null) { + // Allow bindings to read properties. Requires PropertyPermission read in security policy. + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + bindingProvider.stop(); + return null; + } + }); + } + } + + for (Endpoint endpoint : reference.getEndpoints()) { + final EndpointResolver endpointResolver = runtimeRef.getEndpointResolver(endpoint); + if (endpointResolver != null) { + // Allow endpoint resolvers to do any shutdown reference manipulation + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + endpointResolver.stop(); + return null; + } + }); + } + } + } + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + stop((Composite)implementation); + } else { + final ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider(); + if (implementationProvider != null) { + // Allow bindings to read properties. Requires PropertyPermission read in security policy. + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + implementationProvider.stop(); + return null; + } + }); + } + } + + if (component instanceof ScopedRuntimeComponent) { + ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; + if (runtimeComponent.getScopeContainer() != null && + runtimeComponent.getScopeContainer().getLifecycleState() != ScopeContainer.STOPPED) { + runtimeComponent.getScopeContainer().stop(); + } + } + + ((RuntimeComponent)component).setStarted(false); + } + + /** + * Get the effective interface contract for a reference binding + * + * @param reference + * @param binding + * @return + */ + private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) { + InterfaceContract interfaceContract = reference.getInterfaceContract(); + ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); + if (provider != null) { + InterfaceContract bindingContract = provider.getBindingInterfaceContract(); + if (bindingContract != null) { + interfaceContract = bindingContract; + } + } + return interfaceContract.makeUnidirectional(false); + } + + /** + * Remove the runtime wires for a reference binding + * @param reference + */ + private void removeReferenceWires(ComponentReference reference) { + if (!(reference instanceof RuntimeComponentReference)) { + return; + } + // [rfeng] Comment out the following statements to avoid the on-demand activation + // RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference; + // runtimeRef.getRuntimeWires().clear(); + } + + /** + * Get the effective interface contract for the service binding + * + * @param service + * @param binding + * @return + */ + private InterfaceContract getInterfaceContract(ComponentService service, Binding binding) { + InterfaceContract interfaceContract = service.getInterfaceContract(); + + ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding); + if (provider != null) { + InterfaceContract bindingContract = provider.getBindingInterfaceContract(); + if (bindingContract != null) { + interfaceContract = bindingContract; + } + } + return interfaceContract.makeUnidirectional(false); + } + + /** + * Remove runtime wires for a service binding + * + * @param component + * @param service + */ + private void removeServiceWires(ComponentService service) { + if (!(service instanceof RuntimeComponentService)) { + return; + } + RuntimeComponentService runtimeService = (RuntimeComponentService)service; + runtimeService.getRuntimeWires().clear(); + } + + /** + * Create a service wire for a forward call or a callback + * @param service + * @param serviceBinding + * @param reference + * @param component + * @param referenceBinding + */ + private RuntimeWire addServiceWire(Component serviceComponent, ComponentService service, Binding serviceBinding) { + if (!(service instanceof RuntimeComponentService)) { + return null; + } + RuntimeComponentService runtimeService = (RuntimeComponentService)service; + + // FIXME: [rfeng] We might need a better way to get the impl interface contract + Service targetService = service.getService(); + if (targetService == null) { + targetService = service; + } + InterfaceContract targetContract = targetService.getInterfaceContract().makeUnidirectional(false); + + InterfaceContract sourceContract = getInterfaceContract(service, serviceBinding); + + EndpointReference wireSource = new EndpointReferenceImpl(null, null, serviceBinding, sourceContract); + + EndpointReference wireTarget = + new EndpointReferenceImpl((RuntimeComponent)serviceComponent, (RuntimeComponentService)service, + serviceBinding, targetContract); + + RuntimeWire wire = + new RuntimeWireImpl(wireSource, wireTarget, interfaceContractMapper, workScheduler, wireProcessor, + messageFactory, conversationManager); + runtimeService.getRuntimeWires().add(wire); + + return wire; + } + + public void activate(RuntimeComponent component, RuntimeComponentService service) { + if (service.getService() == null) { + if (logger.isLoggable(Level.WARNING)) { + logger.warning("Skipping component service not defined in the component type: " + component.getURI() + + "#" + + service.getName()); + } + return; + } + if (service.getService() instanceof CompositeService) { + return; + } + if (logger.isLoggable(Level.FINE)) { + logger.fine("Activating component service: " + component.getURI() + "#" + service.getName()); + } + + for (Binding binding : service.getBindings()) { + addServiceBindingProvider(component, service, binding); + addServiceWire(component, service, binding); + } + } + + public void deactivate(RuntimeComponent component, RuntimeComponentService service) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Deactivating component service: " + component.getURI() + "#" + service.getName()); + } + removeServiceWires(service); + for (Binding binding : service.getBindings()) { + removeServiceBindingProvider(component, service, binding); + } + } + + private void addScopeContainer(Component component) { + if (!(component instanceof ScopedRuntimeComponent)) { + return; + } + ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; + ScopeContainer scopeContainer = scopeRegistry.getScopeContainer(runtimeComponent); + if (scopeContainer != null && scopeContainer.getScope() == Scope.CONVERSATION) { + conversationManager.addListener((ConversationalScopeContainer)scopeContainer); + } + runtimeComponent.setScopeContainer(scopeContainer); + } + + private void removeScopeContainer(Component component) { + if (!(component instanceof ScopedRuntimeComponent)) { + return; + } + ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; + ScopeContainer scopeContainer = runtimeComponent.getScopeContainer(); + if(scopeContainer != null && scopeContainer.getScope() == Scope.CONVERSATION) { + conversationManager.removeListener((ConversationalScopeContainer) scopeContainer); + } + runtimeComponent.setScopeContainer(null); + } + + public void activateComponent(Component component) + throws ActivationException { + try { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Activating component: " + component.getURI()); + } + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + activate((Composite) implementation); + } else if (implementation != null) { + addImplementationProvider((RuntimeComponent) component, + implementation); + addScopeContainer(component); + } + + for (ComponentService service : component.getServices()) { + activate((RuntimeComponent) component, + (RuntimeComponentService) service); + } + + for (ComponentReference reference : component.getReferences()) { + activate((RuntimeComponent) component, + (RuntimeComponentReference) reference); + } + } catch (Exception e) { + throw new ActivationException(e); + } + } + + public void deactivateComponent(Component component) + throws ActivationException { + try { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Deactivating component: " + component.getURI()); + } + for (ComponentService service : component.getServices()) { + deactivate((RuntimeComponent) component, + (RuntimeComponentService) service); + } + + for (ComponentReference reference : component.getReferences()) { + deactivate((RuntimeComponent) component, + (RuntimeComponentReference) reference); + } + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + deactivate((Composite) implementation); + } else if (implementation != null) { + removeImplementationProvider((RuntimeComponent) component); + removeScopeContainer(component); + } + } catch (Exception e) { + throw new ActivationException(e); + } + } + + public void activate(Composite composite) throws ActivationException { + try { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Activating composite: " + composite.getName()); + } + for (Component component : composite.getComponents()) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Activating component: " + component.getURI()); + } + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + activate((Composite)implementation); + } else if (implementation != null) { + addImplementationProvider((RuntimeComponent)component, implementation); + addScopeContainer(component); + } + + for (ComponentService service : component.getServices()) { + activate((RuntimeComponent)component, (RuntimeComponentService)service); + } + + for (ComponentReference reference : component.getReferences()) { + activate((RuntimeComponent)component, (RuntimeComponentReference)reference); + } + } + } catch (Exception e) { + throw new ActivationException(e); + } + } + + public void deactivate(Composite composite) throws ActivationException { + try { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Deactivating composite: " + composite.getName()); + } + for (Component component : composite.getComponents()) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Deactivating component: " + component.getURI()); + } + for (ComponentService service : component.getServices()) { + deactivate((RuntimeComponent)component, (RuntimeComponentService)service); + } + + for (ComponentReference reference : component.getReferences()) { + deactivate((RuntimeComponent)component, (RuntimeComponentReference)reference); + } + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + deactivate((Composite)implementation); + } else if (implementation != null) { + removeImplementationProvider((RuntimeComponent)component); + removeScopeContainer(component); + } + } + } catch (Exception e) { + throw new ActivationException(e); + } + } + + /** + * @return the referenceHelper + */ + public ComponentContextHelper getComponentContextHelper() { + return componentContextHelper; + } + + /** + * @return the proxyFactory + */ + public ProxyFactory getProxyFactory() { + return proxyFactory; + } + + /** + * @return the domainComposite + */ + public Composite getDomainComposite() { + return domainComposite; + } + + /** + * @param domainComposite the domainComposite to set + */ + public void setDomainComposite(Composite domainComposite) { + this.domainComposite = domainComposite; + } + + public Component resolve(String componentURI) { + for (Composite composite : domainComposite.getIncludes()) { + Component component = resolve(composite, componentURI); + if (component != null) { + return component; + } + } + return null; + } + + public Component resolve(Composite composite, String componentURI) { + for (Component component : composite.getComponents()) { + String uri = component.getURI(); + if (uri.equals(componentURI)) { + return component; + } + if (componentURI.startsWith(uri)) { + Implementation implementation = component.getImplementation(); + if (!(implementation instanceof Composite)) { + return null; + } + return resolve((Composite)implementation, componentURI); + } + } + return null; + } + + /** + * @return the javaInterfaceFactory + */ + public JavaInterfaceFactory getJavaInterfaceFactory() { + return javaInterfaceFactory; + } + + /** + * @return the conversationManager + */ + public ConversationManager getConversationManager() { + return conversationManager; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java new file mode 100644 index 0000000000..78096b20ab --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.assembly; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class EndpointReferenceImpl implements EndpointReference { + private RuntimeComponent component; + private Contract contract; + private Binding binding; + private InterfaceContract interfaceContract; + private String uri; + private EndpointReference callbackEndpoint; + private ReferenceParameters parameters = new ReferenceParametersImpl(); + + /** + * @param component + * @param contract + * @param binding + * @param interfaceContract + */ + public EndpointReferenceImpl(RuntimeComponent component, + Contract contract, + Binding binding, + InterfaceContract interfaceContract) { + super(); + this.component = component; + this.contract = contract; + this.binding = binding; + this.interfaceContract = interfaceContract; + this.uri = (component != null ? component.getURI() : "") + '/' + + (contract != null ? contract.getName() : ""); + } + + /** + * @param uri + */ + public EndpointReferenceImpl(String uri) { + super(); + this.uri = uri; + } + + public Binding getBinding() { + return binding; + } + + public void setBinding(Binding binding) { + this.binding = binding; + } + + public RuntimeComponent getComponent() { + return component; + } + + public void setComponent(RuntimeComponent component) { + this.component = component; + } + + public Contract getContract() { + return contract; + } + + public void setContract(Contract contract) { + this.contract = contract; + } + + public InterfaceContract getInterfaceContract() { + return interfaceContract; + } + + public void setInterfaceContract(InterfaceContract interfaceContract) { + this.interfaceContract = interfaceContract; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public EndpointReference getCallbackEndpoint() { + return callbackEndpoint; + } + + public void setCallbackEndpoint(EndpointReference callbackEndpoint) { + this.callbackEndpoint = callbackEndpoint; + } + + @Override + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((uri == null) ? 0 : uri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final EndpointReferenceImpl other = (EndpointReferenceImpl)obj; + if (uri == null) { + if (other.uri != null) { + return false; + } + } else if (!uri.equals(other.uri)) { + return false; + } + return true; + } + + /** + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + EndpointReferenceImpl copy = (EndpointReferenceImpl)super.clone(); + /* [nash] no need to copy callback endpoint + if (callbackEndpoint != null) { + copy.callbackEndpoint = (EndpointReference)callbackEndpoint.clone(); + } + */ + if (parameters != null) { + copy.parameters = (ReferenceParameters)parameters.clone(); + } + return copy; + } + + /** + * @return the parameters + */ + public ReferenceParameters getReferenceParameters() { + return parameters; + } + + /** + * @param parameters the parameters to set + */ + public void setReferenceParameters(ReferenceParameters parameters) { + this.parameters = parameters; + } + + public void mergeEndpoint(EndpointReference epr) { + this.component = epr.getComponent(); + this.contract = epr.getContract(); + this.binding = epr.getBinding(); + this.interfaceContract = epr.getInterfaceContract(); + this.uri = epr.getURI(); + this.callbackEndpoint = epr.getCallbackEndpoint(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java new file mode 100644 index 0000000000..4f463b105d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.assembly; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.core.invocation.InvocationChainImpl; +import org.apache.tuscany.sca.endpointresolver.EndpointResolver; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.ServiceUnavailableException; + +/** + * @version $Rev$ $Date$ + */ +public class EndpointWireImpl implements RuntimeWire { + + private Endpoint endpoint; + private CompositeActivatorImpl compositeActivator; + + private EndpointResolver endpointResolver; + private EndpointReference source; + private RuntimeWire wire; + private InvocationChain binidngInvocationChain; + + /** + * @param endpoint + */ + public EndpointWireImpl(Endpoint endpoint, CompositeActivator compositeActivator) { + super(); + this.endpoint = endpoint; + // TODO - improve the SPI to get rid of this cast + this.compositeActivator = (CompositeActivatorImpl)compositeActivator; + + // store source configuration as we have most of this now. We don't though know what the + // target is yet. + Reference componentTypeRef = endpoint.getSourceComponentReference().getReference(); + InterfaceContract sourceContract = + componentTypeRef == null ? endpoint.getSourceComponentReference().getInterfaceContract() : componentTypeRef.getInterfaceContract(); + sourceContract = sourceContract.makeUnidirectional(false); + + source = new EndpointReferenceImpl((RuntimeComponent)endpoint.getSourceComponent(), + endpoint.getSourceComponentReference(), + null, + sourceContract); + + RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)endpoint.getSourceComponentReference()); + endpointResolver = runtimeRef.getEndpointResolver(endpoint); + + } + + public synchronized List getInvocationChains() { + // where late binding happens. Find the endpoint provider and + // ask it to do the endpoint resolution. + if (endpoint.isUnresolved()){ + + // this method should locate a viable target service and complete the + // endpoint configuration + endpointResolver.resolve(); + + if (endpoint.isUnresolved()){ + throw new ServiceUnavailableException("Unable to resolve service for component: " + + endpoint.getSourceComponent().getName() + + " reference: " + + endpoint.getSourceComponentReference().getName() + + " target: " + + endpoint.getTargetName()); + } + } + + if (wire == null){ + RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)endpoint.getSourceComponentReference()); + + // add the resolved binding into the reference + runtimeRef.getBindings().add(endpoint.getSourceBinding()); + + // add a binding provider into the reference for the resolved binding + compositeActivator.addReferenceBindingProviderForEndpoint(endpoint); + + // extract the binding provider that has been created + ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpoint.getSourceBinding()); + + // start the binding provider + bindingProvider.start(); + + // create the wire + compositeActivator.addReferenceWireForEndpoint(endpoint); + + // extract the wire that has been created + wire = runtimeRef.getRuntimeWire(endpoint.getSourceBinding()); + } + + return wire.getInvocationChains(); + } + + public InvocationChain getInvocationChain(Operation operation) { + if (wire ==null){ + return null; + } else { + return wire.getInvocationChain(operation); + } + } + + public Object invoke(Message msg) throws InvocationTargetException { + // not called as the endpoint wire only appears on the reference side + return null; + } + + public Object invoke(Operation operation, Object[] args) throws InvocationTargetException { + // not called as the endpoint wire only appears on the reference side + return null; + } + + public Object invoke(Operation operation, Message msg) throws InvocationTargetException { + // not called as the endpoint wire only appears on the reference side + return null; + } + + + public EndpointReference getSource() { + return source; + } + + public EndpointReference getTarget() { + return null; + } + + public void setTarget(EndpointReference target) { + } + + public void rebuild() { + } + + public synchronized InvocationChain getBindingInvocationChain() { + if (binidngInvocationChain == null) { + if (source instanceof RuntimeComponentReference) { + binidngInvocationChain = new InvocationChainImpl(null, null, true); + } else { + binidngInvocationChain = new InvocationChainImpl(null, null, false); + } + } + return binidngInvocationChain; + } + + // TODO: TUSCANY-2580: give RuntimeComponentReferenceImpl a way to get at the endpoint + public Endpoint getEndpoint() { + return endpoint; + } + + /** + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + EndpointWireImpl copy = (EndpointWireImpl)super.clone(); + return copy; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.java new file mode 100644 index 0000000000..c82543c4ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.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.sca.core.assembly; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.runtime.ReferenceParameters; + +/** + * Artifact processor for reference parameters. + * + * @version $Rev$ $Date$ + */ +public class ReferenceParameterProcessor implements StAXArtifactProcessor { + private static final QName REFERENCE_PARAMETERS = + new QName("http://tuscany.apache.org/xmlns/sca/1.0", "referenceParameters", "tuscany"); + + /** + * Constructs a new processor. + * + * @param modelFactories + */ + public ReferenceParameterProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#getArtifactType() + */ + public QName getArtifactType() { + return REFERENCE_PARAMETERS; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#read(javax.xml.stream.XMLStreamReader) + */ + public ReferenceParameters read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + ReferenceParameters parameters = new ReferenceParametersImpl(); + parameters.setConversationID(reader.getAttributeValue(null, "conversationID")); + parameters.setCallbackID(reader.getAttributeValue(null, "callbackID")); + return parameters; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#write(java.lang.Object, javax.xml.stream.XMLStreamWriter) + */ + public void write(ReferenceParameters model, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + writer.writeStartElement(REFERENCE_PARAMETERS.getPrefix(), + REFERENCE_PARAMETERS.getLocalPart(), + REFERENCE_PARAMETERS.getNamespaceURI()); + writer.writeNamespace(REFERENCE_PARAMETERS.getPrefix(), REFERENCE_PARAMETERS.getNamespaceURI()); + if (model.getConversationID() != null) { + writer.writeAttribute("conversationID", model.getConversationID().toString()); + } + if (model.getCallbackID() != null) { + writer.writeAttribute("callbackID", model.getCallbackID().toString()); + } + writer.writeEndElement(); + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#getModelType() + */ + public Class getModelType() { + return ReferenceParameters.class; + } + + /** + * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#resolve(java.lang.Object, org.apache.tuscany.sca.contribution.resolver.ModelResolver) + */ + public void resolve(ReferenceParameters model, ModelResolver resolver) throws ContributionResolveException { + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.java new file mode 100644 index 0000000000..14a5f565fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.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.sca.core.assembly; + +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.ReferenceParameters; + +/** + * @version $Rev$ $Date$ + */ +public class ReferenceParametersImpl implements ReferenceParameters { + private Object callbackID; + private Object conversationID; + private EndpointReference callbackReference; + private Object callbackObjectID; + + /** + * @return the callbackID + */ + public Object getCallbackID() { + return callbackID; + } + /** + * @param callbackID the callbackID to set + */ + public void setCallbackID(Object callbackID) { + this.callbackID = callbackID; + } + /** + * @return the conversationID + */ + public Object getConversationID() { + return conversationID; + } + /** + * @param conversationID the conversationID to set + */ + public void setConversationID(Object conversationID) { + this.conversationID = conversationID; + } + + /** + * @see org.apache.tuscany.sca.runtime.ReferenceParameters#getCallbackReference() + */ + public EndpointReference getCallbackReference() { + return callbackReference; + } + /** + * @see org.apache.tuscany.sca.runtime.ReferenceParameters#setCallback(java.lang.Object) + */ + public void setCallbackReference(EndpointReference callback) { + this.callbackReference = callback; + } + + /** + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + /** + * @return the callbackObjectID + */ + public Object getCallbackObjectID() { + return callbackObjectID; + } + /** + * @param callbackObjectID the callbackObjectID to set + */ + public void setCallbackObjectID(Object callbackObjectID) { + this.callbackObjectID = callbackObjectID; + } + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((callbackID == null) ? 0 : callbackID.hashCode()); + result = prime * result + ((callbackObjectID == null) ? 0 : callbackObjectID.hashCode()); + result = prime * result + ((callbackReference == null) ? 0 : callbackReference.hashCode()); + result = prime * result + ((conversationID == null) ? 0 : conversationID.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 (!(obj instanceof ReferenceParametersImpl)) + return false; + final ReferenceParametersImpl other = (ReferenceParametersImpl)obj; + if (callbackID == null) { + if (other.callbackID != null) + return false; + } else if (!callbackID.equals(other.callbackID)) + return false; + if (callbackObjectID == null) { + if (other.callbackObjectID != null) + return false; + } else if (!callbackObjectID.equals(other.callbackObjectID)) + return false; + if (callbackReference == null) { + if (other.callbackReference != null) + return false; + } else if (!callbackReference.equals(other.callbackReference)) + return false; + if (conversationID == null) { + if (other.conversationID != null) + return false; + } else if (!conversationID.equals(other.conversationID)) + return false; + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java new file mode 100644 index 0000000000..b174dea6ce --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.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.sca.core.assembly; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; + +/** + * The runtime version of assembly factory + * @version $Rev$ $Date$ + */ +public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements AssemblyFactory { + + public RuntimeAssemblyFactory() { + super(); + } + + @Override + public Component createComponent() { + return new RuntimeComponentImpl(); + } + + @Override + public ComponentReference createComponentReference() { + return new RuntimeComponentReferenceImpl(); + } + + @Override + public ComponentService createComponentService() { + return new RuntimeComponentServiceImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java new file mode 100644 index 0000000000..32ac611e54 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.assembly; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.impl.ComponentImpl; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ResolverExtension; +import org.apache.tuscany.sca.core.scope.ScopeContainer; +import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentContext; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeComponentImpl extends ComponentImpl implements RuntimeComponent, + ScopedRuntimeComponent, ResolverExtension { + protected RuntimeComponentContext componentContext; + protected ImplementationProvider implementationProvider; + protected List policyProviders = new ArrayList(); + protected ScopeContainer scopeContainer; + protected boolean started; + protected ModelResolver modelResolver; + + /** + */ + public RuntimeComponentImpl() { + super(); + } + + public ImplementationProvider getImplementationProvider() { + return implementationProvider; + } + + public void setImplementationProvider(ImplementationProvider provider) { + this.implementationProvider = provider; + } + + public ScopeContainer getScopeContainer() { + return scopeContainer; + } + + public void setScopeContainer(ScopeContainer scopeContainer) { + this.scopeContainer = scopeContainer; + } + + public boolean isStarted() { + return started; + } + + public void setStarted(boolean started) { + this.started = started; + } + + /** + * @return the componentContext + */ + public RuntimeComponentContext getComponentContext() { + return componentContext; + } + + /** + * @param componentContext the componentContext to set + */ + public void setComponentContext(RuntimeComponentContext componentContext) { + this.componentContext = componentContext; + } + + public void addPolicyProvider(PolicyProvider policyProvider) { + policyProviders.add(policyProvider); + } + + public List getPolicyProviders() { + return policyProviders; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + + @Override + public String toString() { + return getName(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java new file mode 100644 index 0000000000..b386495a08 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.assembly; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl; +import org.apache.tuscany.sca.endpointresolver.EndpointResolver; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of a Component Reference. + * + * @version $Rev$ $Date$ + */ +public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implements RuntimeComponentReference { + private ArrayList wires; + private HashMap bindingProviders = + new HashMap(); + private HashMap endpointResolvers = + new HashMap(); + private HashMap> policyProviders = new HashMap>(); + + private RuntimeComponent component; + + public RuntimeComponentReferenceImpl() { + super(); + } + + public synchronized List getRuntimeWires() { + if (wires == null) { + wires = new ArrayList(); + component.getComponentContext().start(this); + } + return wires; + } + + public RuntimeWire getRuntimeWire(Binding binding) { + for (RuntimeWire wire : getRuntimeWires()) { + if (wire.getSource().getBinding() == binding) { + return wire; + } + } + + // TODO: TUSCANY-2580: before returning null see if a candidate binding matches + for (RuntimeWire wire : getRuntimeWires()) { + if (wire instanceof EndpointWireImpl) { + Endpoint endpoint = ((EndpointWireImpl)wire).getEndpoint(); + for (Binding b : endpoint.getCandidateBindings()) { + if (b == binding) { + return wire; + } + } + } + } + return null; + } + + public ReferenceBindingProvider getBindingProvider(Binding binding) { + return bindingProviders.get(binding); + } + + public void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider) { + bindingProviders.put(binding, bindingProvider); + } + + public EndpointResolver getEndpointResolver(Endpoint endpoint){ + return endpointResolvers.get(endpoint); + } + + public void setEndpointResolver(Endpoint endpoint, EndpointResolver endpointResolver){ + endpointResolvers.put(endpoint, endpointResolver); + } + + public Invoker getInvoker(Binding binding, Operation operation) { + RuntimeWire wire = getRuntimeWire(binding); + if (wire == null) { + return null; + } + InvocationChain chain = wire.getInvocationChain(operation); + return chain == null ? null : chain.getHeadInvoker(); + } + + /** + * @return the component + */ + public RuntimeComponent getComponent() { + return component; + } + + /** + * @param component the component to set + */ + public void setComponent(RuntimeComponent component) { + this.component = component; + } + + /** + * @see org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + RuntimeComponentReferenceImpl ref = (RuntimeComponentReferenceImpl)super.clone(); + ref.wires = null; + ref.bindingProviders = new HashMap(); + ref.policyProviders = new HashMap>(); + return ref; + } + + public void addPolicyProvider(Binding binding, PolicyProvider policyProvider) { + List providers = policyProviders.get(binding); + if (providers == null) { + providers = new ArrayList(); + policyProviders.put(binding, providers); + } + providers.add(policyProvider); + } + + public List getPolicyProviders(Binding binding) { + return policyProviders.get(binding); + } + + @Override + public String toString() { + return getName(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java new file mode 100644 index 0000000000..af5230a163 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.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.sca.core.assembly; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Implementation of a Component Service. + * + * @version $Rev$ $Date$ + */ +public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements RuntimeComponentService { + private ArrayList wires = new ArrayList(); + private ArrayList callbackWires = new ArrayList(); + private HashMap bindingProviders = new HashMap(); + private HashMap> policyProviders = new HashMap>(); + + public RuntimeComponentServiceImpl() { + super(); + } + + public List getRuntimeWires() { + return wires; + } + + public RuntimeWire getRuntimeWire(Binding binding) { + for (RuntimeWire wire : wires) { + if (wire.getTarget().getBinding() == binding) { + return wire; + } + } + return null; + } + + public RuntimeWire getRuntimeWire(Binding binding, InterfaceContract interfaceContract) { + RuntimeWire wire = getRuntimeWire(binding); + if (wire == null) { + return null; + } + if (interfaceContract != null && interfaceContract != wire.getSource().getInterfaceContract()) { + try { + // FIXME: [rfeng] We could avoid clone() using a better comparison of the two interface contracts + wire = (RuntimeWire)wire.clone(); + wire.getSource().setInterfaceContract(interfaceContract); + wire.rebuild(); + } catch (CloneNotSupportedException e) { + throw new ServiceRuntimeException(e); + } + } + + return wire; + } + + public List getCallbackWires() { + return callbackWires; + } + + public ServiceBindingProvider getBindingProvider(Binding binding) { + return bindingProviders.get(binding); + } + + public void setBindingProvider(Binding binding, ServiceBindingProvider bindingProvider) { + bindingProviders.put(binding, bindingProvider); + } + + public Invoker getInvoker(Binding binding, Operation operation) { + return getInvoker(binding, null, operation); + } + + public Invoker getInvoker(Binding binding, InterfaceContract interfaceContract, Operation operation) { + InvocationChain chain = getInvocationChain(binding, interfaceContract, operation); + if (chain != null) { + return chain.getHeadInvoker(); + } else { + return null; + } + } + + public InvocationChain getInvocationChain(Binding binding, InterfaceContract interfaceContract, Operation operation) { + RuntimeWire wire = getRuntimeWire(binding); + if (wire == null) { + return null; + } + if (interfaceContract != null && interfaceContract != wire.getSource().getInterfaceContract()) { + try { + // FIXME: [rfeng] We could avoid clone() using a better comparison of the two interface contracts + wire = (RuntimeWire)wire.clone(); + wire.getSource().setInterfaceContract(interfaceContract); + wire.rebuild(); + } catch (CloneNotSupportedException e) { + throw new ServiceRuntimeException(e); + } + } + return wire.getInvocationChain(operation); + } + + public InvocationChain getInvocationChain(Binding binding, Operation operation) { + return getInvocationChain(binding, null, operation); + } + + /** + * @see org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl#clone() + */ + @SuppressWarnings("unchecked") + @Override + public Object clone() throws CloneNotSupportedException { + RuntimeComponentServiceImpl clone = (RuntimeComponentServiceImpl)super.clone(); + clone.bindingProviders = (HashMap)bindingProviders.clone(); + clone.wires = (ArrayList)wires.clone(); + clone.callbackWires = (ArrayList)callbackWires.clone(); + clone.policyProviders = (HashMap>)policyProviders.clone(); + return clone; + } + + public void addPolicyProvider(Binding binding, PolicyProvider policyProvider) { + List providers = policyProviders.get(binding); + if (providers == null) { + providers = new ArrayList(); + policyProviders.put(binding, providers); + } + providers.add(policyProvider); + } + + public List getPolicyProviders(Binding binding) { + return policyProviders.get(binding); + } + + @Override + public String toString() { + return getName(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java new file mode 100644 index 0000000000..e31186ed35 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java @@ -0,0 +1,473 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.assembly; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.core.conversation.ConversationManager; +import org.apache.tuscany.sca.core.invocation.InvocationChainImpl; +import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor; +import org.apache.tuscany.sca.core.invocation.RuntimeWireInvoker; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ReferenceBindingProviderRRB; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProviderRRB; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.osoa.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeWireImpl implements RuntimeWire { + private EndpointReference wireSource; + private EndpointReference wireTarget; + + private transient RuntimeWireProcessor wireProcessor; + private transient InterfaceContractMapper interfaceContractMapper; + private transient WorkScheduler workScheduler; + private transient MessageFactory messageFactory; + private transient ConversationManager conversationManager; + private transient RuntimeWireInvoker invoker; + + // the following is a very simple cache that avoids re-cloning a wire + // when consecutive callbacks to the same endpoint are made + private EndpointReference lastCallback; + private RuntimeWire cachedWire; + private boolean wireReserved; + private RuntimeWireImpl clonedFrom; + + private List chains; + private InvocationChain bindingInvocationChain; + // Cache + private transient final Map invocationChainMap = + new ConcurrentHashMap(); + + + /** + * @param source + * @param target + * @param interfaceContractMapper + * @param workScheduler + * @param wireProcessor + * @param messageFactory + * @param conversationManager + */ + public RuntimeWireImpl(EndpointReference source, + EndpointReference target, + InterfaceContractMapper interfaceContractMapper, + WorkScheduler workScheduler, + RuntimeWireProcessor wireProcessor, + MessageFactory messageFactory, + ConversationManager conversationManager) { + super(); + this.wireSource = source; + this.wireTarget = target; + this.interfaceContractMapper = interfaceContractMapper; + this.workScheduler = workScheduler; + this.wireProcessor = wireProcessor; + this.messageFactory = messageFactory; + this.conversationManager = conversationManager; + this.invoker = new RuntimeWireInvoker(this.messageFactory, this.conversationManager, this); + } + + public synchronized List getInvocationChains() { + if (chains == null) { + initInvocationChains(); + } + return chains; + } + + public synchronized InvocationChain getBindingInvocationChain() { + if (bindingInvocationChain == null) { + Contract source = wireSource.getContract(); + if (source instanceof RuntimeComponentReference) { + bindingInvocationChain = new InvocationChainImpl(null, null, true); + initReferenceBindingInvocationChains(); + } else { + bindingInvocationChain = new InvocationChainImpl(null, null, false); + initServiceBindingInvocationChains(); + } + } + return bindingInvocationChain; + } + + public InvocationChain getInvocationChain(Operation operation) { + InvocationChain cached = invocationChainMap.get(operation); + if (cached == null) { + for (InvocationChain chain : getInvocationChains()) { + Operation op = null; + if (wireSource.getContract() != null) { + // Reference chain + op = chain.getSourceOperation(); + } else { + // Service chain + op = chain.getTargetOperation(); + } + if (interfaceContractMapper.isCompatible(operation, op, op.getInterface().isRemotable())) { + invocationChainMap.put(operation, chain); + return chain; + } + } + invocationChainMap.put(operation, null); + return null; + + } else { + return cached; + } + } + + public Object invoke(Message msg) throws InvocationTargetException { + return getBindingInvocationChain().getHeadInvoker().invoke(msg); + } + + public Object invoke(Operation operation, Object[] args) throws InvocationTargetException { + Message msg = messageFactory.createMessage(); + msg.setBody(args); + return invoker.invoke(operation, msg); + } + + public Object invoke(Operation operation, Message msg) throws InvocationTargetException { + return invoker.invoke(operation, msg); + } + + /** + * Initialize the invocation chains + */ + private void initInvocationChains() { + chains = new ArrayList(); + InterfaceContract sourceContract = wireSource.getInterfaceContract(); + InterfaceContract targetContract = wireTarget.getInterfaceContract(); + + Contract source = wireSource.getContract(); + if (source instanceof RuntimeComponentReference) { + // It's the reference wire + RuntimeComponentReference reference = (RuntimeComponentReference)wireSource.getContract(); + Binding refBinding = wireSource.getBinding(); + for (Operation operation : sourceContract.getInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation); + if (targetOperation == null) { + throw new ServiceRuntimeException("No matching operation for " + operation.getName() + + " is found in reference " + + wireSource.getComponent().getURI() + + "#" + + reference.getName()); + } + InvocationChain chain = new InvocationChainImpl(operation, targetOperation, true); + if (operation.isNonBlocking()) { + addNonBlockingInterceptor(reference, refBinding, chain); + } + addReferenceBindingInterceptor(reference, refBinding, chain, operation); + chains.add(chain); + } + + } else { + // It's the service wire + RuntimeComponentService service = (RuntimeComponentService)wireTarget.getContract(); + RuntimeComponent serviceComponent = wireTarget.getComponent(); + Binding serviceBinding = wireTarget.getBinding(); + for (Operation operation : sourceContract.getInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation); + if (targetOperation == null) { + throw new ServiceRuntimeException("No matching operation for " + operation.getName() + + " is found in service " + + serviceComponent.getURI() + + "#" + + service.getName()); + } + InvocationChain chain = new InvocationChainImpl(operation, targetOperation, false); + if (operation.isNonBlocking()) { + addNonBlockingInterceptor(service, serviceBinding, chain); + } + addServiceBindingInterceptor(service, serviceBinding, chain, operation); + addImplementationInterceptor(serviceComponent, service, chain, targetOperation); + chains.add(chain); + } + + } + wireProcessor.process(this); + } + + private void initReferenceBindingInvocationChains() { + RuntimeComponentReference reference = (RuntimeComponentReference)wireSource.getContract(); + Binding referenceBinding = wireSource.getBinding(); + + // add the binding interceptors to the reference binding wire + ReferenceBindingProvider provider = reference.getBindingProvider(referenceBinding); + if ((provider != null) && + (provider instanceof ReferenceBindingProviderRRB)){ + ((ReferenceBindingProviderRRB)provider).configureBindingChain(this); + } + + // add the policy interceptors to the service binding wire + // find out which policies are active + List pps = ((RuntimeComponentReference)reference).getPolicyProviders(referenceBinding); + if (pps != null) { + for (PolicyProvider p : pps) { + if (p.getPhase().equals(Phase.REFERENCE_BINDING_POLICY)) { + Interceptor interceptor = p.createInterceptor(null); + if (interceptor != null) { + bindingInvocationChain.addInterceptor(Phase.REFERENCE_BINDING_POLICY, interceptor); + } + } + } + } + } + + private void initServiceBindingInvocationChains() { + RuntimeComponentService service = (RuntimeComponentService)wireTarget.getContract(); + Binding serviceBinding = wireTarget.getBinding(); + + // add the binding interceptors to the service binding wire + ServiceBindingProvider provider = service.getBindingProvider(serviceBinding); + if ((provider != null) && + (provider instanceof ServiceBindingProviderRRB)){ + ((ServiceBindingProviderRRB)provider).configureBindingChain(this); + } + + // add the policy interceptors to the service binding wire + List pps = ((RuntimeComponentService)service).getPolicyProviders(serviceBinding); + if (pps != null) { + for (PolicyProvider p : pps) { + if (p.getPhase().equals(Phase.SERVICE_BINDING_POLICY)) { + Interceptor interceptor = p.createInterceptor(null); + if (interceptor != null) { + bindingInvocationChain.addInterceptor(Phase.SERVICE_BINDING_POLICY, interceptor); + } + } + } + } + + // TODO - add something on the end of the wire to invoke the + // invocation chain. Need to split out the runtime + // wire invoker into conversation, callback interceptors etc + bindingInvocationChain.addInvoker(invoker); + + } + + public EndpointReference getSource() { + return wireSource; + } + + public EndpointReference getTarget() { + return wireTarget; + } + + public void setTarget(EndpointReference target) { + if (this.wireTarget != target) { + rebuild(); + } + this.wireTarget = target; + } + + public void rebuild() { + this.chains = null; + } + + /** + * Add the interceptor for a reference binding + * + * @param reference + * @param binding + * @param chain + * @param operation + */ + private void addReferenceBindingInterceptor(ComponentReference reference, + Binding binding, + InvocationChain chain, + Operation operation) { + ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); + if (provider != null) { + Invoker invoker = provider.createInvoker(operation); + if (invoker != null) { + chain.addInvoker(invoker); + } + } + List pps = ((RuntimeComponentReference)reference).getPolicyProviders(binding); + if (pps != null) { + for (PolicyProvider p : pps) { + Interceptor interceptor = p.createInterceptor(operation); + if (interceptor != null) { + chain.addInterceptor(p.getPhase(), p.createInterceptor(operation)); + } + } + } + } + + /** + * Add the interceptor for a binding + * + * @param reference + * @param binding + * @param chain + * @param operation + */ + private void addServiceBindingInterceptor(ComponentService service, + Binding binding, + InvocationChain chain, + Operation operation) { + List pps = ((RuntimeComponentService)service).getPolicyProviders(binding); + if (pps != null) { + for (PolicyProvider p : pps) { + Interceptor interceptor = p.createInterceptor(operation); + if (interceptor != null) { + chain.addInterceptor(p.getPhase(), p.createInterceptor(operation)); + } + } + } + } + + /** + * Add a non-blocking interceptor if the reference binding needs it + * + * @param reference + * @param binding + * @param chain + */ + private void addNonBlockingInterceptor(ComponentReference reference, Binding binding, InvocationChain chain) { + ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); + if (provider != null) { + boolean supportsOneWayInvocation = provider.supportsOneWayInvocation(); + if (!supportsOneWayInvocation) { + chain.addInterceptor(Phase.REFERENCE, new NonBlockingInterceptor(workScheduler)); + } + } + } + + /** + * Add a non-blocking interceptor if the service binding needs it + * + * @param service + * @param binding + * @param chain + */ + private void addNonBlockingInterceptor(ComponentService service, Binding binding, InvocationChain chain) { + ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding); + if (provider != null) { + if (!provider.supportsOneWayInvocation()) { + chain.addInterceptor(Phase.SERVICE, new NonBlockingInterceptor(workScheduler)); + } + } + } + + /** + * Add the interceptor for a component implementation + * + * @param component + * @param service + * @param chain + * @param operation + */ + private void addImplementationInterceptor(Component component, + ComponentService service, + InvocationChain chain, + Operation operation) { + ImplementationProvider provider = ((RuntimeComponent)component).getImplementationProvider(); + if (provider != null) { + Invoker invoker = null; + invoker = provider.createInvoker((RuntimeComponentService)service, operation); + chain.addInvoker(invoker); + } + List pps = ((RuntimeComponent)component).getPolicyProviders(); + if (pps != null) { + for (PolicyProvider p : pps) { + Interceptor interceptor = p.createInterceptor(operation); + if (interceptor != null) { + chain.addInterceptor(p.getPhase(), p.createInterceptor(operation)); + } + } + } + } + + /** + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + RuntimeWireImpl copy = (RuntimeWireImpl)super.clone(); + copy.wireSource = (EndpointReference)wireSource.clone(); + copy.wireTarget = (EndpointReference)wireTarget.clone(); + copy.invoker = new RuntimeWireInvoker(copy.messageFactory, copy.conversationManager, copy); + copy.cachedWire = null; // TUSCANY-2630 + return copy; + } + + /** + * @return the conversationManager + */ + public ConversationManager getConversationManager() { + return conversationManager; + } + + public synchronized RuntimeWire lookupCache(EndpointReference callback) { + if (lastCallback != null && callback.getURI().equals(lastCallback.getURI()) && !wireReserved) { + wireReserved = true; + return cachedWire; + } else { + return null; + } + } + + public synchronized void addToCache(EndpointReference callback, RuntimeWire clonedWire) { + ((RuntimeWireImpl)clonedWire).setClonedFrom(this); + lastCallback = callback; + cachedWire = clonedWire; + wireReserved = true; + } + + public synchronized void releaseClonedWire(RuntimeWire wire) { + if (cachedWire == wire) { + wireReserved = false; + } + } + + public synchronized void releaseWire() { + clonedFrom.releaseClonedWire(this); + } + + private void setClonedFrom(RuntimeWireImpl wire) { + clonedFrom = wire; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java new file mode 100644 index 0000000000..7d94e73f35 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java @@ -0,0 +1,605 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.context; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.UUID; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.core.assembly.CompositeActivator; +import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl; +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.core.assembly.EndpointWireImpl; +import org.apache.tuscany.sca.core.assembly.ReferenceParametersImpl; +import org.apache.tuscany.sca.core.conversation.ConversationManager; +import org.apache.tuscany.sca.core.conversation.ConversationState; +import org.apache.tuscany.sca.core.conversation.ExtendedConversation; +import org.apache.tuscany.sca.core.factory.ObjectCreationException; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; +import org.osoa.sca.Conversation; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Base class for implementations of service and callback references. + * + * @version $Rev$ $Date$ + * @param the type of the business interface + */ +public class CallableReferenceImpl implements CallableReference, Externalizable { + static final long serialVersionUID = -521548304761848325L; + protected transient CompositeActivator compositeActivator; + protected transient ProxyFactory proxyFactory; + protected transient Class businessInterface; + protected transient Object proxy; + + // if the wire targets a conversational service this holds the conversation state + protected transient ConversationManager conversationManager; + protected transient ExtendedConversation conversation; + protected transient Object conversationID; + protected Object callbackID; // The callbackID should be serializable + + protected transient RuntimeComponent component; + protected transient RuntimeComponentReference reference; + protected transient Binding binding; + + protected String scdl; + + private transient RuntimeComponentReference clonedRef; + private transient ReferenceParameters refParams; + private transient XMLStreamReader xmlReader; + + private transient RuntimeWire endpointWire; + + /* + * Public constructor for Externalizable serialization/deserialization + */ + public CallableReferenceImpl() { + super(); + } + + /* + * Public constructor for use by XMLStreamReader2CallableReference + */ + public CallableReferenceImpl(XMLStreamReader xmlReader) throws Exception { + this.xmlReader = xmlReader; + resolve(); + } + + protected CallableReferenceImpl(Class businessInterface, + RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding, + ProxyFactory proxyFactory, + CompositeActivator compositeActivator) { + this.proxyFactory = proxyFactory; + this.businessInterface = businessInterface; + this.component = component; + this.reference = reference; + this.binding = binding; + // FIXME: The SCA Specification is not clear how we should handle multiplicity + // for CallableReference + if (this.binding == null) { + this.binding = this.reference.getBinding(SCABinding.class); + if (this.binding == null) { + + // TODO: TUSCANY-2580: if the refernece doesn't have a binding yet then instead of NPE use a candidate one if its avaialable + if (reference.getBindings() != null && reference.getBindings().size() > 0) { + this.binding = this.reference.getBindings().get(0); + } else { + this.binding = this.reference.getEndpoints().get(0).getCandidateBindings().get(0); + if (this.reference.getEndpoints().get(0).getInterfaceContract() == null) { + this.reference.getEndpoints().get(0).setInterfaceContract(reference.getInterfaceContract()); + } + } + } + } + + // FIXME: Should we normalize the componentName/serviceName URI into an absolute SCA URI in the SCA binding? + // sca:component1/component11/component112/service1? + this.compositeActivator = compositeActivator; + this.conversationManager = this.compositeActivator.getConversationManager(); + initCallbackID(); + } + + public CallableReferenceImpl(Class businessInterface, RuntimeWire wire, ProxyFactory proxyFactory) { + this.proxyFactory = proxyFactory; + this.businessInterface = businessInterface; + bind(wire); + } + + public RuntimeWire getRuntimeWire() { + try { + resolve(); + if (endpointWire != null){ + return endpointWire; + } else if (reference != null) { + return reference.getRuntimeWire(binding); + } else { + return null; + } + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + protected void bind(RuntimeWire wire) { + if (wire != null) { + + if (wire instanceof EndpointWireImpl){ + endpointWire = wire; + } + this.component = wire.getSource().getComponent(); + this.reference = (RuntimeComponentReference)wire.getSource().getContract(); + this.binding = wire.getSource().getBinding(); + this.compositeActivator = ((ComponentContextImpl)component.getComponentContext()).getCompositeActivator(); + this.conversationManager = this.compositeActivator.getConversationManager(); + initCallbackID(); + } + } + + protected void initCallbackID() { + if (reference.getInterfaceContract() != null) { + if (reference.getInterfaceContract().getCallbackInterface() != null) { + this.callbackID = createCallbackID(); + } + } + } + + public B getProxy() throws ObjectCreationException { + try { + if (proxy == null) { + proxy = createProxy(); + } + return businessInterface.cast(proxy); + } catch (Exception e) { + throw new ObjectCreationException(e); + } + } + + public void setProxy(Object proxy) { + this.proxy = proxy; + } + + protected Object createProxy() throws Exception { + return proxyFactory.createProxy(this); + } + + public B getService() { + try { + resolve(); + return getProxy(); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + public Class getBusinessInterface() { + try { + resolve(); + return businessInterface; + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + public boolean isConversational() { + try { + resolve(); + return reference == null ? false : reference.getInterfaceContract().getInterface().isConversational(); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + public Conversation getConversation() { + try { + // resolve from XML just in case this CallableReference is the result of + // passing a CallableReference as a parameter + resolve(); + + if (conversation == null || conversation.getState() == ConversationState.ENDED) { + conversation = null; + } + return conversation; + + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + public Object getCallbackID() { + try { + resolve(); + return callbackID; + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + /** + * @see java.io.Externalizable#readExternal(java.io.ObjectInput) + */ + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + final boolean hasSCDL = in.readBoolean(); + if (hasSCDL) { + this.scdl = in.readUTF(); + } else { + this.scdl = null; + } + } + + /** + * @throws IOException + */ + private synchronized void resolve() throws Exception { + if ((scdl != null || xmlReader != null) && component == null && reference == null) { + ComponentContextHelper componentContextHelper = ComponentContextHelper.getCurrentComponentContextHelper(); + if (componentContextHelper != null) { + this.compositeActivator = ComponentContextHelper.getCurrentCompositeActivator(); + this.conversationManager = this.compositeActivator.getConversationManager(); + Component c; + if (xmlReader != null) { + c = componentContextHelper.fromXML(xmlReader); + xmlReader = null; // OK to GC this now + } else { + c = componentContextHelper.fromXML(scdl); + scdl = null; // OK to GC this now + } + this.component = (RuntimeComponent)c; + compositeActivator.configureComponentContext(this.component); + this.reference = (RuntimeComponentReference)c.getReferences().get(0); + this.reference.setComponent(this.component); + clonedRef = reference; + ReferenceParameters parameters = null; + for (Object ext : reference.getExtensions()) { + if (ext instanceof ReferenceParameters) { + parameters = (ReferenceParameters)ext; + break; + } + } + if (parameters != null) { + refParams = parameters; + this.callbackID = parameters.getCallbackID(); + attachConversation(parameters.getConversationID()); + } + + for (Binding binding : reference.getBindings()) { + if (binding instanceof OptimizableBinding) { + // Resolve the Component + final String bindingURI = binding.getURI(); + final Component targetComponent = resolveComponentURI(bindingURI); + + // Find the Service + ComponentService targetService = resolveServiceURI(bindingURI, targetComponent); + + // if the target service is a promoted service then find the + // service it promotes + if ((targetService != null) && (targetService.getService() instanceof CompositeService)) { + CompositeService compositeService = (CompositeService) targetService.getService(); + // Find the promoted component service + ComponentService promotedComponentService = getPromotedComponentService(compositeService); + if (promotedComponentService != null && !promotedComponentService.isUnresolved()) { + targetService = promotedComponentService; + } + } + + OptimizableBinding optimizableBinding = (OptimizableBinding)binding; + optimizableBinding.setTargetComponent(targetComponent); + optimizableBinding.setTargetComponentService(targetService); + if (targetService != null) { + for (Binding serviceBinding : targetService.getBindings()) { + if (serviceBinding.getClass() == binding.getClass()) { + optimizableBinding.setTargetBinding(serviceBinding); + break; + } + } + } + } + } + // FIXME: The SCA Specification is not clear how we should handle multiplicity + // for CallableReference + if (binding == null) { + binding = reference.getBinding(SCABinding.class); + if (binding == null) { + binding = reference.getBindings().get(0); + } + } + Interface i = reference.getInterfaceContract().getInterface(); + if (i instanceof JavaInterface) { + JavaInterface javaInterface = (JavaInterface)i; + if (javaInterface.isUnresolved()) { + // Allow privileged access to get ClassLoader. Requires RuntimePermission in + // security policy. + ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction() { + public ClassLoader run() { + return Thread.currentThread().getContextClassLoader(); + } + }); + javaInterface.setJavaClass(classLoader.loadClass(javaInterface.getName())); + compositeActivator.getJavaInterfaceFactory().createJavaInterface(javaInterface, + javaInterface.getJavaClass()); + //FIXME: If the interface needs XSDs to be loaded (e.g., for static SDO), + // this needs to be done here. We usually search for XSDs in the current + // contribution at resolve time. Is it possible to locate the current + // contribution at runtime? + } + this.businessInterface = (Class)javaInterface.getJavaClass(); + } + if (binding instanceof BindingBuilderExtension) { + ((BindingBuilderExtension)binding).getBuilder().build(component, reference, binding, null); + } + this.proxyFactory = compositeActivator.getProxyFactory(); + } + } else if (compositeActivator == null || proxyFactory == null) { + this.compositeActivator = ComponentContextHelper.getCurrentCompositeActivator(); + if (this.compositeActivator != null) { + this.proxyFactory = this.compositeActivator.getProxyFactory(); + } + } + } + + /** + * Follow a service promotion chain down to the inner most (non composite) + * component service. + * + * @param topCompositeService + * @return + */ + private ComponentService getPromotedComponentService(CompositeService compositeService) { + ComponentService componentService = compositeService.getPromotedService(); + if (componentService != null) { + Service service = componentService.getService(); + if (componentService.getName() != null && service instanceof CompositeService) { + + // Continue to follow the service promotion chain + return getPromotedComponentService((CompositeService)service); + + } else { + + // Found a non-composite service + return componentService; + } + } else { + + // No promoted service + return null; + } + } + + /** + * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) + */ + public void writeExternal(ObjectOutput out) throws IOException { + try { + final String xml = toXMLString(); + if (xml == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + out.writeUTF(xml); + } + } catch (Exception e) { + // e.printStackTrace(); + throw new IOException(e.toString()); + } + } + + public String toXMLString() throws IOException { + if (reference != null) { + if (clonedRef == null) { + try { + clonedRef = (RuntimeComponentReference)reference.clone(); + } catch (CloneNotSupportedException e) { + // will not happen + } + } + if (refParams == null) { + refParams = new ReferenceParametersImpl(); + + // remove any existing reference parameters from the clone + Object toRemove = null; + for (Object extension : clonedRef.getExtensions()){ + if (extension instanceof ReferenceParameters){ + toRemove = extension; + } + } + + if (toRemove != null){ + clonedRef.getExtensions().remove(toRemove); + } + + // add the new reference parameter object + clonedRef.getExtensions().add(refParams); + } + refParams.setCallbackID(callbackID); + if (conversation != null){ + refParams.setConversationID(conversation.getConversationID()); + } + return ((CompositeActivatorImpl)compositeActivator).getComponentContextHelper() + .toXML(component, clonedRef); + } else { + return scdl; + } + } + + /** + * Create a callback id + * + * @return the callback id + */ + private String createCallbackID() { + return UUID.randomUUID().toString(); + } + + public void attachCallbackID(Object callbackID) { + this.callbackID = callbackID; + } + + public void attachConversationID(Object conversationID) { + this.conversationID = conversationID; + } + + public void attachConversation(ExtendedConversation conversation) { + this.conversation = conversation; + } + + public void attachConversation(Object conversationID) { + if (conversationID != null) { + ExtendedConversation conversation = conversationManager.getConversation(conversationID); + if (conversation == null){ + conversation = conversationManager.startConversation(conversationID); + } + this.conversation = conversation; + } else { + this.conversation = null; + } + } + + protected ReferenceParameters getReferenceParameters() { + ReferenceParameters parameters = new ReferenceParametersImpl(); + parameters.setCallbackID(callbackID); + if (getConversation() != null) { + parameters.setConversationID(conversation.getConversationID()); + } + return parameters; + } + + public EndpointReference getEndpointReference() { + try { + resolve(); + + // Use the interface contract of the reference on the component type + Reference componentTypeRef = reference.getReference(); + InterfaceContract sourceContract = + componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract(); + sourceContract = sourceContract.makeUnidirectional(false); + EndpointReference epr = new EndpointReferenceImpl(component, reference, binding, sourceContract); + ReferenceParameters parameters = getReferenceParameters(); + epr.setReferenceParameters(parameters); + return epr; + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + public XMLStreamReader getXMLReader() { + return xmlReader; + } + + /** + * Resolves the specified URI to a Component using the compositeActivator. + * There are two cases that we need to handle: + *
    + *
  • URI containing just Composite name(s) (i.e. no Service name specified) + *
  • URI containing Composite name(s) and a Service Name + *
+ * + * @param componentURI The URI of the Component to resolve + * @return The Component for the specified URI or null if not founds + */ + protected Component resolveComponentURI(String componentURI) { + // If the URI has come from a binding, it may well start with a '/'. We will need + // to remove this so we can match it to the composite names. + if (componentURI.startsWith("/")) { + componentURI = componentURI.substring(1); + } + + // First assume that we are dealing with a Component URI without a Service Name + Component component = compositeActivator.resolve(componentURI); + if (component != null) { + return component; + } + + // Perhaps we have a ComponentURI that has a ServiceName on the end of it + final int index = componentURI.lastIndexOf('/'); + if (index > -1) { + componentURI = componentURI.substring(0, index); + return compositeActivator.resolve(componentURI); + } + + // We could not resolve the Component URI + return null; + } + + /** + * Examines the Services on the specified Component and returns the Service that matches the + * specified Binding URI. + * + * @param bindingURI The Binding URI to resolve on the Component + * @param targetComponent The Component containing the Services + * @return The Service with the specified serviceName or null if no such Service found. + */ + protected ComponentService resolveServiceURI(String bindingURI, Component targetComponent) { + + ComponentService targetService = null; + + if (targetComponent != null) { + if (bindingURI.startsWith("/")) { + bindingURI = bindingURI.substring(1); + } + + final String componentURI = targetComponent.getURI(); + final String serviceName; + if (componentURI.equals(bindingURI)) { + // No service specified + serviceName = ""; + } else { + // Get the Service name from the Binding URI + serviceName = bindingURI.substring(componentURI.length() + 1); + } + + if ("".equals(serviceName)) { + targetService = ComponentContextHelper.getSingleService(targetComponent); + } else { + for (ComponentService service : targetComponent.getServices()) { + if (service.getName().equals(serviceName)) { + targetService = service; + break; + } + } + } + } + + return targetService; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java new file mode 100644 index 0000000000..78b0887482 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java @@ -0,0 +1,320 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.context; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.assembly.CompositeActivator; +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.osoa.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class ComponentContextHelper { + + private final AssemblyFactory assemblyFactory; + private final JavaInterfaceFactory javaInterfaceFactory; + private final StAXArtifactProcessorExtensionPoint staxProcessors; + + /** + * @param assemblyFactory The factory to create assembly models + * @param processors The extension point for StAX artifact processors + */ + public ComponentContextHelper(AssemblyFactory assemblyFactory, + JavaInterfaceFactory javaInterfaceFactory, + StAXArtifactProcessorExtensionPoint processors) { + this.assemblyFactory = assemblyFactory; + this.javaInterfaceFactory = javaInterfaceFactory; + this.staxProcessors = processors; + } + + /** + * Create a self-reference for a component service + * @param component + * @param service + * @throws CloneNotSupportedException + * @throws InvalidInterfaceException + */ + public ComponentReference createSelfReference(Component component, + ComponentService service, + Class businessInterface) throws CloneNotSupportedException, + InvalidInterfaceException { + ComponentReference componentReference = assemblyFactory.createComponentReference(); + componentReference.setName("$self$." + service.getName()); + for (Binding binding : service.getBindings()) { + if (binding instanceof OptimizableBinding) { + OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone(); + optimizableBinding.setTargetBinding(binding); + optimizableBinding.setTargetComponent(component); + optimizableBinding.setTargetComponentService(service); + componentReference.getBindings().add(optimizableBinding); + } else { + componentReference.getBindings().add(binding); + } + } + + componentReference.setCallback(service.getCallback()); + componentReference.getTargets().add(service); + componentReference.getPolicySets().addAll(service.getPolicySets()); + componentReference.getRequiredIntents().addAll(service.getRequiredIntents()); + + InterfaceContract interfaceContract = service.getInterfaceContract(); + Service componentTypeService = service.getService(); + if (componentTypeService != null && componentTypeService.getInterfaceContract() != null) { + interfaceContract = componentTypeService.getInterfaceContract(); + } + interfaceContract = getInterfaceContract(interfaceContract, businessInterface); + componentReference.setInterfaceContract(interfaceContract); + componentReference.setMultiplicity(Multiplicity.ONE_ONE); + // component.getReferences().add(componentReference); + return componentReference; + } + + /** + * @param interfaceContract + * @param businessInterface + * @return + * @throws CloneNotSupportedException + * @throws InvalidInterfaceException + */ + private InterfaceContract getInterfaceContract(InterfaceContract interfaceContract, Class businessInterface) + throws CloneNotSupportedException, InvalidInterfaceException { + Interface interfaze = interfaceContract.getInterface(); + boolean compatible = false; + if (interfaze instanceof JavaInterface) { + Class cls = ((JavaInterface)interfaze).getJavaClass(); + if (businessInterface.isAssignableFrom(cls)) { + compatible = true; + } + } + if (!compatible) { + // The interface is not assignable from the interface contract + interfaceContract = (InterfaceContract)interfaceContract.clone(); + interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface)); + } + + return interfaceContract; + } + + /** + * Bind a component reference to a component service + * @param + * @param businessInterface + * @param reference + * @param service + * @return + * @throws CloneNotSupportedException + * @throws InvalidInterfaceException + */ + public RuntimeComponentReference bindComponentReference(Class businessInterface, + RuntimeComponentReference reference, + RuntimeComponent component, + RuntimeComponentService service) + throws CloneNotSupportedException, InvalidInterfaceException { + RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone(); + InterfaceContract interfaceContract = reference.getInterfaceContract(); + Reference componentTypeReference = reference.getReference(); + if (componentTypeReference != null && componentTypeReference.getInterfaceContract() != null) { + interfaceContract = componentTypeReference.getInterfaceContract(); + } + InterfaceContract refInterfaceContract = getInterfaceContract(interfaceContract, businessInterface); + if (refInterfaceContract != interfaceContract) { + ref = (RuntimeComponentReference)reference.clone(); + ref.setInterfaceContract(interfaceContract); + } + ref.setComponent(component); + ref.getTargets().add(service); + ref.getBindings().clear(); + for (Binding binding : service.getBindings()) { + if (binding instanceof OptimizableBinding) { + OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone(); + optimizableBinding.setTargetBinding(binding); + optimizableBinding.setTargetComponent(component); + optimizableBinding.setTargetComponentService(service); + ref.getBindings().add(optimizableBinding); + } else { + ref.getBindings().add(binding); + } + } + return ref; + } + + public void write(Component component, ComponentReference reference, Writer writer) throws IOException { + write(component, reference, null, writer); + } + + public void write(Component component, ComponentReference reference, ComponentService service, Writer writer) throws IOException { + try { + StAXArtifactProcessor processor = staxProcessors.getProcessor(Composite.class); + Composite composite = assemblyFactory.createComposite(); + composite.setName(new QName("http://tuscany.apache.org/xmlns/sca/1.0", "default")); + Component comp = assemblyFactory.createComponent(); + comp.setName("default"); + comp.setURI(component.getURI()); + composite.getComponents().add(comp); + if (reference != null) { + comp.getReferences().add(reference); + } + if (service != null) { + comp.getServices().add(service); + } + + XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); + processor.write(composite, streamWriter); + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } + + public String toXML(Component component, ComponentReference reference) throws IOException { + StringWriter writer = new StringWriter(); + write(component, reference, writer); + return writer.toString(); + } + + public String toXML(Component component, ComponentService service) throws IOException { + StringWriter writer = new StringWriter(); + write(component, null, service, writer); + return writer.toString(); + } + + public RuntimeComponent read(Reader reader) throws IOException { + try { + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + XMLStreamReader streamReader = inputFactory.createXMLStreamReader(reader); + return read(streamReader); + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } + + public RuntimeComponent read(XMLStreamReader streamReader) throws IOException { + try { + StAXArtifactProcessor processor = staxProcessors.getProcessor(Composite.class); + Composite composite = processor.read(streamReader); + RuntimeComponent component = (RuntimeComponent)composite.getComponents().get(0); + return component; + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } + + public Component fromXML(String xml) throws IOException { + return read(new StringReader(xml)); + } + + public Component fromXML(XMLStreamReader streamReader) throws IOException { + return read(streamReader); + } + + public static RuntimeComponent getCurrentComponent() { + Message message = ThreadMessageContext.getMessageContext(); + if (message != null) { + EndpointReference to = message.getTo(); + if (to == null) { + return null; + } + RuntimeComponent component = message.getTo().getComponent(); + return component; + } + return null; + } + + public static CompositeActivator getCurrentCompositeActivator() { + RuntimeComponent component = getCurrentComponent(); + if (component != null) { + ComponentContextImpl context = (ComponentContextImpl)component.getComponentContext(); + return context.getCompositeActivator(); + } + return null; + } + + public static ComponentContextHelper getCurrentComponentContextHelper() { + CompositeActivator activator = getCurrentCompositeActivator(); + if (activator != null) { + return activator.getComponentContextHelper(); + } + return null; + } + + /** + * @param component + */ + public static ComponentService getSingleService(Component component) { + ComponentService targetService; + List services = component.getServices(); + List regularServices = new ArrayList(); + for (ComponentService service : services) { + if (service.isCallback()) { + continue; + } + String name = service.getName(); + if (!name.startsWith("$") || name.startsWith("$dynamic$")) { + regularServices.add(service); + } + } + if (regularServices.size() == 0) { + throw new ServiceRuntimeException("No service is declared on component " + component.getURI()); + } + if (regularServices.size() != 1) { + throw new ServiceRuntimeException("More than one service is declared on component " + component.getURI() + + ". Service name is required to get the service."); + } + targetService = regularServices.get(0); + return targetService; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java new file mode 100644 index 0000000000..2bcf13f679 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java @@ -0,0 +1,452 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.context; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.Collection; +import java.util.ArrayList; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.context.PropertyValueFactory; +import org.apache.tuscany.sca.context.RequestContextFactory; +import org.apache.tuscany.sca.core.assembly.CompositeActivator; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentContext; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.osoa.sca.CallableReference; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Implementation of ComponentContext that delegates to a ComponentContextProvider. + * + * @version $Rev$ $Date$ + */ +public class ComponentContextImpl implements RuntimeComponentContext { + private final RuntimeComponent component; + + private final CompositeActivator compositeActivator; + private final RequestContextFactory requestContextFactory; + private final ProxyFactory proxyFactory; + private final AssemblyFactory assemblyFactory; + private final JavaInterfaceFactory javaInterfaceFactory; + + /** + * This is a reference to the PropertyValueFactory that is provided by the Implementation + * that can be used to get the value from a Property Object. + * + * @see #setPropertyValueFactory(PropertyValueFactory) + * @see #getProperty(Class, String) + */ + private PropertyValueFactory propertyFactory; + + public ComponentContextImpl(CompositeActivator compositeActivator, + AssemblyFactory assemblyFactory, + ProxyFactory proxyFactory, + InterfaceContractMapper interfaceContractMapper, + RequestContextFactory requestContextFactory, + JavaInterfaceFactory javaInterfaceFactory, + RuntimeComponent component) { + super(); + this.compositeActivator = compositeActivator; + this.assemblyFactory = assemblyFactory; + this.proxyFactory = proxyFactory; + this.requestContextFactory = requestContextFactory; + this.javaInterfaceFactory = javaInterfaceFactory; + this.component = component; + } + + public String getURI() { + return component.getURI(); + } + + public > R cast(B target) throws IllegalArgumentException { + return (R)proxyFactory.cast(target); + } + + public B getService(Class businessInterface, String referenceName) { + ServiceReference serviceRef = getServiceReference(businessInterface, referenceName); + return serviceRef.getService(); + } + + public ServiceReference getServiceReference(Class businessInterface, String referenceName) { + try { + for (ComponentReference ref : component.getReferences()) { + if (referenceName.equals(ref.getName())) { + /* ******************** Contribution for issue TUSCANY-2281 ******************** */ + Multiplicity multiplicity = ref.getMultiplicity(); + if( multiplicity == Multiplicity.ZERO_N || multiplicity == Multiplicity.ONE_N) + { + throw new IllegalArgumentException("Reference " + referenceName + " has multiplicity " + multiplicity); + } + /* ******************** Contribution for issue TUSCANY-2281 ******************** */ + + return getServiceReference(businessInterface, (RuntimeComponentReference)ref, null); + } + } + throw new ServiceRuntimeException("Reference not found: " + referenceName); + } catch (ServiceRuntimeException e) { + throw e; + } catch (Exception e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + /** + * The Implementation is responsible for calling this method to set the + * PropertyValueFactory that is used to get the Property Value from + * a Tuscany Property object. + * + * @param factory The PropertyValueFactory to use + * + * @see #getProperty(Class, String) + */ + public void setPropertyValueFactory(PropertyValueFactory factory) { + propertyFactory = factory; + } + + /** + * Gets the value for the specified property with the specified type. + * + * @param type The type of the property value we are getting + * @param propertyName The name of the property we are getting + * @param B The class of the property value we are getting + * + * @throws ServiceRuntimeException If a Property for the specified propertyName + * is not found + * + * @see #setPropertyValueFactory(PropertyValueFactory) + */ + public B getProperty(Class type, String propertyName) { + for (ComponentProperty p : component.getProperties()) { + if (propertyName.equals(p.getName())) { + return propertyFactory.createPropertyValue(p, type); + } + } + throw new ServiceRuntimeException("Property not found: " + propertyName); + } + + public ServiceReference createSelfReference(Class businessInterface) { + ComponentService service = ComponentContextHelper.getSingleService(component); + try { + return createSelfReference(businessInterface, service); + } catch (Exception e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public ServiceReference createSelfReference(Class businessInterface, String serviceName) { + try { + for (ComponentService service : component.getServices()) { + if (serviceName.equals(service.getName())) { + return createSelfReference(businessInterface, service); + } + } + throw new ServiceRuntimeException("Service not found: " + serviceName); + } catch (ServiceRuntimeException e) { + throw e; + } catch (Exception e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + /** + * @param + * @param businessInterface + * @param service + * @return + */ + public ServiceReference createSelfReference(Class businessInterface, ComponentService service) { + try { + RuntimeComponentReference ref = + (RuntimeComponentReference)createSelfReference(component, service, businessInterface); + ref.setComponent(component); + return getServiceReference(businessInterface, ref, null); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + public RequestContext getRequestContext() { + if (requestContextFactory != null) { + return requestContextFactory.createRequestContext(); + } else { + return new RequestContextImpl(proxyFactory); + } + } + + /** + * @param businessInterface + * @param reference + * @return + * @throws CloneNotSupportedException + * @throws InvalidInterfaceException + */ + public ServiceReference getServiceReference(Class businessInterface, RuntimeComponentReference reference, Binding binding) { + try { + RuntimeComponentReference ref = (RuntimeComponentReference)reference; + InterfaceContract interfaceContract = reference.getInterfaceContract(); + Reference componentTypeReference = reference.getReference(); + if (componentTypeReference != null && componentTypeReference.getInterfaceContract() != null) { + interfaceContract = componentTypeReference.getInterfaceContract(); + } + InterfaceContract refInterfaceContract = getInterfaceContract(interfaceContract, businessInterface); + if (refInterfaceContract != interfaceContract) { + ref = (RuntimeComponentReference)reference.clone(); + if (interfaceContract != null) { + ref.setInterfaceContract(interfaceContract); + } else { + ref.setInterfaceContract(refInterfaceContract); + } + } + ref.setComponent(component); + return new ServiceReferenceImpl(businessInterface, component, ref, binding, proxyFactory, compositeActivator); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + /** + * Bind a component reference to a component service + * @param + * @param businessInterface + * @param reference + * @param service + * @return + * @throws CloneNotSupportedException + * @throws InvalidInterfaceException + */ + public ServiceReference getServiceReference(Class businessInterface, + RuntimeComponentReference reference, + RuntimeComponent component, + RuntimeComponentService service) { + try { + RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone(); + InterfaceContract interfaceContract = reference.getInterfaceContract(); + Reference componentTypeReference = reference.getReference(); + if (componentTypeReference != null && componentTypeReference.getInterfaceContract() != null) { + interfaceContract = componentTypeReference.getInterfaceContract(); + } + InterfaceContract refInterfaceContract = getInterfaceContract(interfaceContract, businessInterface); + if (refInterfaceContract != interfaceContract) { + ref = (RuntimeComponentReference)reference.clone(); + ref.setInterfaceContract(interfaceContract); + } + ref.getTargets().add(service); + ref.getBindings().clear(); + for (Binding binding : service.getBindings()) { + if (binding instanceof OptimizableBinding) { + OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone(); + optimizableBinding.setTargetBinding(binding); + optimizableBinding.setTargetComponent(component); + optimizableBinding.setTargetComponentService(service); + ref.getBindings().add(optimizableBinding); + } else { + ref.getBindings().add(binding); + } + } + return new ServiceReferenceImpl(businessInterface, component, ref, proxyFactory, compositeActivator); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + public CallableReference getCallableReference(Class businessInterface, + RuntimeComponent component, + RuntimeComponentService service) { + try { + if (businessInterface == null) { + InterfaceContract contract = service.getInterfaceContract(); + businessInterface = (Class)((JavaInterface)contract.getInterface()).getJavaClass(); + } + RuntimeComponentReference ref = + (RuntimeComponentReference)createSelfReference(component, service, businessInterface); + ref.setComponent(component); + return new CallableReferenceImpl(businessInterface, component, ref, null, proxyFactory, + compositeActivator); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + /** + * Create a self-reference for a component service + * @param component + * @param service + * @throws CloneNotSupportedException + * @throws InvalidInterfaceException + */ + private ComponentReference createSelfReference(Component component, + ComponentService service, + Class businessInterface) throws CloneNotSupportedException, + InvalidInterfaceException { + ComponentReference componentReference = assemblyFactory.createComponentReference(); + componentReference.setName("$self$." + service.getName()); + for (Binding binding : service.getBindings()) { + if (binding instanceof OptimizableBinding) { + OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone(); + optimizableBinding.setTargetBinding(binding); + optimizableBinding.setTargetComponent(component); + optimizableBinding.setTargetComponentService(service); + componentReference.getBindings().add(optimizableBinding); + } else { + componentReference.getBindings().add(binding); + } + } + + componentReference.setCallback(service.getCallback()); + componentReference.getTargets().add(service); + componentReference.getPolicySets().addAll(service.getPolicySets()); + componentReference.getRequiredIntents().addAll(service.getRequiredIntents()); + + InterfaceContract interfaceContract = service.getInterfaceContract(); + Service componentTypeService = service.getService(); + if (componentTypeService != null && componentTypeService.getInterfaceContract() != null) { + interfaceContract = componentTypeService.getInterfaceContract(); + } + interfaceContract = getInterfaceContract(interfaceContract, businessInterface); + componentReference.setInterfaceContract(interfaceContract); + componentReference.setMultiplicity(Multiplicity.ONE_ONE); + // component.getReferences().add(componentReference); + return componentReference; + } + + /** + * @param interfaceContract + * @param businessInterface + * @return + * @throws CloneNotSupportedException + * @throws InvalidInterfaceException + */ + private InterfaceContract getInterfaceContract(InterfaceContract interfaceContract, Class businessInterface) + throws CloneNotSupportedException, InvalidInterfaceException { + boolean compatible = false; + if (interfaceContract != null && interfaceContract.getInterface() != null) { + Interface interfaze = interfaceContract.getInterface(); + if (interfaze instanceof JavaInterface) { + Class cls = ((JavaInterface)interfaze).getJavaClass(); + if (businessInterface.isAssignableFrom(cls)) { + compatible = true; + } + } + } + + if (!compatible) { + // The interface is not assignable from the interface contract + interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); + JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(businessInterface); + interfaceContract.setInterface(callInterface); + if (callInterface.getCallbackClass() != null) { + interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(callInterface + .getCallbackClass())); + } + } + + return interfaceContract; + } + + /** + * @return the compositeActivator + */ + public CompositeActivator getCompositeActivator() { + return compositeActivator; + } + + /** + * @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#start(org.apache.tuscany.sca.runtime.RuntimeComponentReference) + */ + public void start(RuntimeComponentReference reference) { + compositeActivator.start(component, reference); + } + + /** + * @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#read(java.io.Reader) + */ + public RuntimeComponent read(Reader reader) throws IOException { + RuntimeComponent component = compositeActivator.getComponentContextHelper().read(reader); + compositeActivator.configureComponentContext(component); + return component; + } + + /** + * @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#write(org.apache.tuscany.sca.runtime.RuntimeComponentReference, java.io.Writer) + */ + public void write(RuntimeComponentReference reference, Writer writer) throws IOException { + compositeActivator.getComponentContextHelper().write(component, reference, writer); + } + + /* ******************** Contribution for issue TUSCANY-2281 ******************** */ + + /** + * @see ComponentContext#getServices(Class, String) + */ + public Collection getServices(Class businessInterface, String referenceName) { + ArrayList services = new ArrayList(); + Collection> serviceRefs = getServiceReferences(businessInterface, referenceName); + for (ServiceReference serviceRef : serviceRefs) { + services.add(serviceRef.getService()); + } + return services; + } + + /** + * @see ComponentContext#getServiceReferences(Class, String) + */ + public Collection> getServiceReferences(Class businessInterface, String referenceName) { + try { + for (ComponentReference ref : component.getReferences()) { + if (referenceName.equals(ref.getName())) { + ArrayList> serviceRefs = new ArrayList>(); + for(Binding binding : ref.getBindings()) + { + serviceRefs.add( getServiceReference(businessInterface, (RuntimeComponentReference) ref, binding) ); + } + return serviceRefs; + } + } + throw new ServiceRuntimeException("Reference not found: " + referenceName); + } catch (ServiceRuntimeException e) { + throw e; + } catch (Exception e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + /* ******************** Contribution for issue TUSCANY-2281 ******************** */ + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java new file mode 100644 index 0000000000..c5b68389b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.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.sca.core.context; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.context.ComponentContextFactory; +import org.apache.tuscany.sca.context.RequestContextFactory; +import org.apache.tuscany.sca.core.assembly.CompositeActivator; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.osoa.sca.ComponentContext; + +/** + * @version $Rev$ $Date$ + */ +public class DefaultComponentContextFactory implements ComponentContextFactory { + private final CompositeActivator compositeActivator; + private final RequestContextFactory requestContextFactory; + private final ProxyFactory proxyFactory; + private final AssemblyFactory assemblyFactory; + private final JavaInterfaceFactory javaInterfaceFactory; + private final InterfaceContractMapper interfaceContractMapper; + + public DefaultComponentContextFactory(CompositeActivator compositeActivator, + AssemblyFactory assemblyFactory, + ProxyFactory proxyFactory, + InterfaceContractMapper interfaceContractMapper, + RequestContextFactory requestContextFactory, + JavaInterfaceFactory javaInterfaceFactory) { + super(); + this.compositeActivator = compositeActivator; + this.assemblyFactory = assemblyFactory; + this.proxyFactory = proxyFactory; + this.requestContextFactory = requestContextFactory; + this.javaInterfaceFactory = javaInterfaceFactory; + this.interfaceContractMapper = interfaceContractMapper; + } + + /** + * @see org.apache.tuscany.sca.context.ComponentContextFactory#createComponentContext(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.context.RequestContextFactory) + */ + public ComponentContext createComponentContext(RuntimeComponent component, + RequestContextFactory requestContextFactory) { + if (requestContextFactory == null) { + requestContextFactory = this.requestContextFactory; + } + return new ComponentContextImpl(compositeActivator, assemblyFactory, proxyFactory, interfaceContractMapper, + requestContextFactory, javaInterfaceFactory, component); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.java new file mode 100644 index 0000000000..b577180291 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.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.sca.core.context; + +import org.apache.tuscany.sca.core.scope.TargetDestructionException; +import org.apache.tuscany.sca.core.scope.TargetInitializationException; + + +/** + * Provides lifecycle management for an implementation instance associated with + * a component for use by the component's associated {@link org.apache.tuscany.sca.core.scope.ScopeContainer} + * + * @version $Rev$ $Date$ + */ +public interface InstanceWrapper { + + /** + * @return + */ + T getInstance(); + + /** + * @throws TargetInitializationException + */ + void start() throws TargetInitializationException; + + /** + * @throws TargetDestructionException + */ + void stop() throws TargetDestructionException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java new file mode 100644 index 0000000000..ed6c3df8fa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.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.sca.core.context; + +import java.util.List; + +import javax.security.auth.Subject; + +import org.apache.tuscany.sca.core.invocation.CallbackReferenceImpl; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; +import org.osoa.sca.RequestContext; + +/** + * @version $Rev$ $Date$ + */ +public class RequestContextImpl implements RequestContext { + + private ProxyFactory proxyFactory; + + public RequestContextImpl(ProxyFactory proxyFactory) { + this.proxyFactory = proxyFactory; + } + + public Subject getSecuritySubject() { + Subject subject = null; + + for (Object header : ThreadMessageContext.getMessageContext().getHeaders()){ + if (header instanceof Subject){ + subject = (Subject)header; + break; + } + } + return subject; + } + + public String getServiceName() { + return ThreadMessageContext.getMessageContext().getTo().getContract().getName(); + } + + @SuppressWarnings("unchecked") + public CallableReference getServiceReference() { + Message msgContext = ThreadMessageContext.getMessageContext(); + // FIXME: [rfeng] Is this the service reference matching the caller side? + EndpointReference to = msgContext.getTo(); + RuntimeComponentService service = (RuntimeComponentService) to.getContract(); + RuntimeComponent component = (RuntimeComponent) to.getComponent(); + + CallableReference callableReference = component.getComponentContext().getCallableReference(null, component, service); + ReferenceParameters parameters = msgContext.getFrom().getReferenceParameters(); + ((CallableReferenceImpl) callableReference).attachCallbackID(parameters.getCallbackID()); + ((CallableReferenceImpl) callableReference).attachConversation(parameters.getConversationID()); + return callableReference; + } + + @SuppressWarnings("unchecked") + public CB getCallback() { + CallableReference cb = getCallbackReference(); + if (cb == null) { + return null; + } + return cb.getService(); + } + + @SuppressWarnings("unchecked") + public CallableReference getCallbackReference() { + Message msgContext = ThreadMessageContext.getMessageContext(); + EndpointReference to = msgContext.getTo(); + RuntimeComponentService service = (RuntimeComponentService) to.getContract(); + RuntimeComponentReference callbackReference = (RuntimeComponentReference)service.getCallbackReference(); + if (callbackReference == null) { + return null; + } + JavaInterface javaInterface = (JavaInterface) callbackReference.getInterfaceContract().getInterface(); + Class javaClass = (Class)javaInterface.getJavaClass(); + List wires = callbackReference.getRuntimeWires(); + CallbackReferenceImpl ref = CallbackReferenceImpl.newInstance(javaClass, proxyFactory, wires); + if (ref != null) { + //ref.resolveTarget(); + ReferenceParameters parameters = msgContext.getFrom().getReferenceParameters(); + ref.attachCallbackID(parameters.getCallbackID()); + if (ref.getConversation() != null) { + ref.attachConversationID(parameters.getConversationID()); + } + } + return ref; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java new file mode 100644 index 0000000000..1d178421cf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.context; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.core.assembly.CompositeActivator; +import org.apache.tuscany.sca.core.conversation.ConversationState; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; +import org.osoa.sca.ServiceReference; + +/** + * Default implementation of a ServiceReference. + * + * @version $Rev$ $Date$ + * @param the type of the business interface + */ +public class ServiceReferenceImpl extends CallableReferenceImpl implements ServiceReference { + private static final long serialVersionUID = 6763709434194361540L; + + protected transient Object callback; + + /* + * Public constructor for Externalizable serialization/deserialization + */ + public ServiceReferenceImpl() { + super(); + } + + /* + * Public constructor for use by XMLStreamReader2CallableReference + */ + public ServiceReferenceImpl(XMLStreamReader xmlReader) throws Exception { + super(xmlReader); + } + + /** + * @param businessInterface + * @param wire + * @param proxyFactory + */ + public ServiceReferenceImpl(Class businessInterface, RuntimeWire wire, ProxyFactory proxyFactory) { + super(businessInterface, wire, proxyFactory); + } + + public ServiceReferenceImpl(Class businessInterface, + RuntimeComponent component, + RuntimeComponentReference reference, + ProxyFactory proxyFactory, + CompositeActivator compositeActivator) { + super(businessInterface, component, reference, null, proxyFactory, compositeActivator); + } + + public ServiceReferenceImpl(Class businessInterface, + RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding, + ProxyFactory proxyFactory, + CompositeActivator compositeActivator) { + super(businessInterface, component, reference, binding, proxyFactory, compositeActivator); + } + + public Object getConversationID() { + return conversationID; + } + + public void setConversationID(Object conversationID) throws IllegalStateException { + if (conversation == null || conversation.getState() != ConversationState.ENDED) { + this.conversationID = conversationID; + this.conversation = null; + } else { + throw new IllegalStateException("Trying to set the conversationId on a service reference but the state of the conversation " + + conversation.getConversationID() + + " is " + + conversation.getState()); + } + } + + public void setCallbackID(Object callbackID) { + this.callbackID = callbackID; + } + + public Object getCallback() { + return callback; + } + + public void setCallback(Object callback) { + if (callback != null && !(callback instanceof CallableReference)) { + //FIXME: need to check if callback object supports the callback interface + // returned by reference.getInterfaceContract().getCallbackInterface() + } + this.callback = callback; + } + + @Override + protected ReferenceParameters getReferenceParameters() { + ReferenceParameters parameters = super.getReferenceParameters(); + if (callback != null) { + if (callback instanceof ServiceReference) { + EndpointReference callbackRef = ((CallableReferenceImpl)callback).getEndpointReference(); + parameters.setCallbackReference(callbackRef); + } else { + EndpointReference callbackRef = getRuntimeWire().getSource().getCallbackEndpoint(); + parameters.setCallbackReference(callbackRef); + parameters.setCallbackObjectID(callback); + } + } + return parameters; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.java new file mode 100644 index 0000000000..efa362a929 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.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.sca.core.conversation; + +/** + * Listener for the events of a conversation + * + * @version $Rev$ $Date$ + */ +public interface ConversationListener { + /** + * The conversation is started + */ + void conversationStarted(ExtendedConversation conversation); + /** + * The conversation is ended + */ + void conversationEnded(ExtendedConversation conversation); + /** + * The conversation is expired + */ + void conversationExpired(ExtendedConversation conversation); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java new file mode 100644 index 0000000000..f928f91a02 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.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.sca.core.conversation; + +/** + * The manager of conversations + * + * @version $Rev$ $Date$ + */ +public interface ConversationManager { + /** + * @param conversationID + * @return + */ + ExtendedConversation startConversation(Object conversationID); + + /** + * @param conversationID + */ + void endConversation(Object conversationID); + + /** + * @param conversationID + * @return + */ + ExtendedConversation getConversation(Object conversationID); + + /** + * @param conversationID + */ + void expireConversation(Object conversationID); + + /** + * Add a listener to this conversation + * @param listener + */ + void addListener(ConversationListener listener); + + /** + * Remove a listener from this conversation + * @param listener + */ + void removeListener(ConversationListener listener); + + /** + * @return the default max age for a conversation + */ + long getMaxAge(); + + /** + * @return the default max idle time for a conversation + */ + long getMaxIdleTime(); + + void destroy(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java new file mode 100644 index 0000000000..3bea79b076 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java @@ -0,0 +1,225 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.conversation; + +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +/** + * @version $Rev$ $Date$ + */ +public class ConversationManagerImpl implements ConversationManager { + + private List listeners = Collections.synchronizedList(new ArrayList()); + private Map conversations = new ConcurrentHashMap(); + + /** + * the default max age. this is set to 1 hour + */ + private static final long DEFAULT_MAX_AGE = 60 * 60 * 1000; ; + + /** + * the default max idle time. this is set to 1 hour + */ + private static final long DEFAULT_MAX_IDLE_TIME = 60 * 60 * 1000; + + /** + * the globally used max age + */ + private final long maxAge; + + /** + * the globally used max idle time + */ + private final long maxIdleTime; + + /** + * the reaper thread + */ + private final ScheduledExecutorService scheduler; + + /** + * constructor + */ + public ConversationManagerImpl() { + long mit = DEFAULT_MAX_IDLE_TIME; + long ma = DEFAULT_MAX_AGE; + + scheduler = Executors.newSingleThreadScheduledExecutor(); + + // Allow privileged access to read system property. Requires PropertyPermission in security + // policy. + String aProperty = AccessController.doPrivileged(new PrivilegedAction() { + public String run() { + return System.getProperty("org.apache.tuscany.sca.core.scope.ConversationalScopeContainer.MaxIdleTime"); + } + }); + if (aProperty != null) { + try { + mit = (new Long(aProperty) * 1000); + } catch (NumberFormatException nfe) { + // Ignore + } + } + + // Allow privileged access to read system property. Requires PropertyPermission in security + // policy. + aProperty = AccessController.doPrivileged(new PrivilegedAction() { + public String run() { + return System.getProperty("org.apache.tuscany.sca.core.scope.ConversationalScopeContainer.MaxAge"); + } + }); + if (aProperty != null) { + try { + ma = (new Long(aProperty) * 1000); + } catch (NumberFormatException nfe) { + // Ignore + } + } + + maxAge = ma; + maxIdleTime = mit; + } + + /** + * @see org.apache.tuscany.sca.core.conversation.ConversationManager#addListener(org.apache.tuscany.sca.core.conversation.ConversationListener) + */ + public void addListener(ConversationListener listener) { + listeners.add(listener); + } + + /** + * @see org.apache.tuscany.sca.core.conversation.ConversationManager#endConversation(org.apache.tuscany.sca.core.conversation.ExtendedConversation) + */ + public void endConversation(Object conversationID) { + ExtendedConversation conv = getConversation(conversationID); + if (conv != null) { + conv.setState(ConversationState.ENDED); + for (ConversationListener listener : listeners) { + listener.conversationEnded(conv); + } + conv.setConversationID(null); + conversations.remove(conversationID); + } else { + throw new IllegalStateException("Conversation " + conversationID + " doesn't exist."); + } + } + + public void expireConversation(Object conversationID) { + ExtendedConversation conv = getConversation(conversationID); + if (conv != null) { + for (ConversationListener listener : listeners) { + listener.conversationExpired(conv); + } + conversations.remove(conversationID); + } else { + throw new IllegalStateException("Conversation " + conversationID + " doesn't exist."); + } + + } + + /** + * @see org.apache.tuscany.sca.core.conversation.ConversationManager#getConversation(java.lang.Object) + */ + public ExtendedConversation getConversation(Object conversationID) { + // ConcurrentHashMap cannot take null key + return conversationID == null ? null : conversations.get(conversationID); + } + + /** + * @see org.apache.tuscany.sca.core.conversation.ConversationManager#removeListener(org.apache.tuscany.sca.core.conversation.ConversationListener) + */ + public void removeListener(ConversationListener listener) { + listeners.remove(listener); + } + + /** + * starts the reaper thread + */ + public void scheduleConversation(ExtendedConversationImpl aConversation, long time) + { + this.scheduler.schedule(aConversation, time, TimeUnit.MILLISECONDS); + } + + /** + * stops the reaper thread + */ + public synchronized void stopReaper() { + + // Prevent the scheduler from submitting any additional reapers, + // initiate an orderly shutdown if a reaper task is in progress. + this.scheduler.shutdown(); + } + + + /** + * @see org.apache.tuscany.sca.core.conversation.ConversationManager#startConversation(java.lang.Object) + */ + public ExtendedConversation startConversation(Object conversationID) { + + if (conversationID == null) { + conversationID = UUID.randomUUID().toString(); + } + ExtendedConversation conversation = getConversation(conversationID); + if (conversation != null && conversation.getState() != ConversationState.ENDED) { + throw new IllegalStateException(conversation + " already exists."); + } + + conversation = new ExtendedConversationImpl( + this, conversationID, ConversationState.STARTED); + conversations.put(conversationID, conversation); + for (ConversationListener listener : listeners) { + listener.conversationStarted(conversation); + } + return conversation; + } + + /** + * return the default max idle time + * @param impProvider the implementation Provider to extract any ConversationAttribute details + */ + public long getMaxIdleTime() { + return maxIdleTime; + } + + /** + * returns the default max age + * @param impProvider the implementation Provider to extract any ConversationAttribute details + */ + public long getMaxAge(){ + return maxAge; + } + + public void destroy() { + // REVIEW: A more graceful way? + scheduler.shutdownNow(); + this.listeners.clear(); + this.conversations.clear(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.java new file mode 100644 index 0000000000..692d6861ba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.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.sca.core.conversation; + +/** + * The states of a conversation + * + * @version $Rev$ $Date$ + */ +public enum ConversationState { + STARTED, ENDED, EXPIRED +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.java new file mode 100644 index 0000000000..03c18c26b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.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.sca.core.conversation; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.osoa.sca.Conversation; + +/** + * An extended interface over org.osoa.Conversation + * + * @version $Rev$ $Date$ + */ +public interface ExtendedConversation extends Conversation { + /** + * Get the state of a conversation + * @return The state + */ + ConversationState getState(); + + /** + * @param state the state to set + */ + void setState(ConversationState state); + + /** + * @param conversationID the conversationID to set + */ + void setConversationID(Object conversationID); + + + /** + * will check whether this conversation has expired and update state if it has + * @return true if it has expired + */ + boolean isExpired(); + + /** + * updates the last time this conversation was referenced + */ + void updateLastReferencedTime(); + + void initializeConversationAttributes(RuntimeComponent targetComponent); + + + /** + * @return true if the conversational attributes have been initialized + */ + boolean conversationalAttributesInitialized(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java new file mode 100644 index 0000000000..0bf66b2817 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java @@ -0,0 +1,265 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.conversation; + +import org.apache.tuscany.sca.core.scope.ScopedImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + + +/** + * + * @version $Rev$ $Date$ + */ +public class ExtendedConversationImpl implements ExtendedConversation, Runnable { + + private final ConversationManagerImpl manager; + private volatile Object conversationID; + private ConversationState state; + + /** + * syncs access to the state + */ + private final Object stateSync = new Object(); + + /** + * the maximum time a conversation can exist + */ + private long expirationTime = 0; + + /** + * the maximum time this conversation can be idle + */ + private long maxIdleTime = 0; + + /** + * the maximum age of this conversation + */ + private long maxAge = 0; + + /** + * the time that this object was created + */ + private long creationTime; + + /** + * the time that this object was last referenced + */ + private long lastReferencedTime; + + /** + * boolean to ensure expiry only occurs once + */ + private boolean expired = false; + + /** + * boolean to indicate if the conversation attributes have + * been set. In the case where a remote binding is used + * within a composite the JDKInvocationHandler can create the + * conversation but the conversationAttributes are not available + * until the conversation is retrieved by the RuntimeWireInvoker + */ + private boolean conversationAttributesInitialized = false; + + /** + * Constructor + * @param manager the conversation manager + * @param conversationID the conversation id associated with this conversation + * @param state the initial state of this conversation + * @param aMaxAge the maximum age of the conversation + * @param aMaxIdleTime the maximum idle time + */ + public ExtendedConversationImpl(ConversationManagerImpl manager, + Object conversationID, ConversationState state) { + super(); + + this.creationTime = System.currentTimeMillis(); + this.lastReferencedTime = creationTime; + this.manager = manager; + this.conversationID = conversationID; + this.state = state; + } + + /** + * will check whether this conversation has expired and update state if it has + * @return true if it has expired + */ + public boolean isExpired() { + long currentTime; + synchronized (stateSync) { + + // if the attributes haven't been initialized then + // this conversation object can't expire + if (conversationAttributesInitialized == false) { + return false; + } + + // check state first + if (state == ConversationState.EXPIRED) { + return true; + } + + // check whether the time is finished + currentTime = System.currentTimeMillis(); + if (((this.lastReferencedTime + this.maxIdleTime) <= currentTime) + || (this.expirationTime <= currentTime)) { + setState(ConversationState.EXPIRED); + return true; + } + } + scheduleNextExpiryTime(currentTime); + return false; + } + + /** + * schedule next expiry time + */ + public void scheduleNextExpiryTime(long currentTime) { + if ((lastReferencedTime + maxIdleTime) < expirationTime){ + manager.scheduleConversation(this, (lastReferencedTime + maxIdleTime) - currentTime); + } else { + manager.scheduleConversation(this, expirationTime - currentTime); + } + } + /** + * updates the last time this conversation was referenced + */ + public void updateLastReferencedTime() { + this.lastReferencedTime = System.currentTimeMillis(); + if (conversationAttributesInitialized == true){ + scheduleNextExpiryTime(lastReferencedTime); + } + } + + public ConversationState getState() { + synchronized (stateSync){ + return state; + } + } + + public void end() { + manager.endConversation(conversationID); + } + + public Object getConversationID() { + return conversationID; + } + + /** + * @param state the state to set + */ + public void setState(ConversationState state) { + synchronized (stateSync){ + this.state = state; + } + } + + /** + * @param conversationID the conversationID to set + */ + public void setConversationID(Object conversationID) { + synchronized (stateSync){ + if (state != ConversationState.ENDED) { + throw new IllegalStateException("The state of conversation " + conversationID + " " + state); + } + } + this.conversationID = conversationID; + } + + /** + * @param maxAge the maximum age of this conversation + */ + public void initializeConversationAttributes(RuntimeComponent targetComponent){ + if (targetComponent != null){ + this.maxAge = getMaxIdleTime(targetComponent.getImplementationProvider()); + this.maxIdleTime = getMaxAge(targetComponent.getImplementationProvider()); + this.expirationTime = creationTime + maxAge; + this.conversationAttributesInitialized = true; + } + } + + /** + * @return true if the conversational attributes have been initialized + */ + public boolean conversationalAttributesInitialized(){ + return this.conversationAttributesInitialized; + } + + /** + * return the max idle time + * @param impProvider the implementation Provider to extract any ConversationAttribute details + */ + private long getMaxIdleTime(ImplementationProvider impProvider) { + // Check to see if the maxIdleTime has been specified using @ConversationAttributes. + // Implementation annotated attributes are honoured first. + if ((impProvider != null) && + (impProvider instanceof ScopedImplementationProvider)) { + ScopedImplementationProvider aScopedImpl = + (ScopedImplementationProvider) impProvider; + + long maxIdleTime = aScopedImpl.getMaxIdleTime(); + if (maxIdleTime > 0) { + return maxIdleTime; + } + } + return manager.getMaxIdleTime(); + } + + /** + * returns the max age + * @param impProvider the implementation Provider to extract any ConversationAttribute details + */ + private long getMaxAge(ImplementationProvider impProvider){ + + // Check to see if the maxAge has been specified using @ConversationAttributes. + // Implementation annotated attributes are honoured first. + if ((impProvider != null) && + (impProvider instanceof ScopedImplementationProvider)) { + ScopedImplementationProvider aScopedImpl = + (ScopedImplementationProvider) impProvider; + + long maxAge = aScopedImpl.getMaxAge(); + if (maxAge > 0) { + return maxAge; + } + } + return manager.getMaxAge(); + } + + /** + * called when expiring + */ + public void run() { + synchronized (stateSync){ + if (!expired){ + if (isExpired()) { + expired = true; + try { + manager.expireConversation(getConversationID()); + } catch (IllegalStateException ise) { + // ignore this.. this can occur if another thread has subsequently ended + // the conversation + } + } + } + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java new file mode 100644 index 0000000000..517e5579a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.event.EventFilter; +import org.apache.tuscany.sca.event.EventPublisher; +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.event.TrueFilter; + +/** + * Base implementation of an EventPublisher + * + * @version $Rev$ $Date$ + */ +public abstract class BaseEventPublisher implements EventPublisher { + protected static final EventFilter TRUE_FILTER = new TrueFilter(); + protected Map> 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 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 list = getListeners().get(filter); + if (list == null) { + list = new CopyOnWriteArrayList(); + listeners.put(filter, list); + } + list.add(listener); + } + } + + public void publish(Event event) { + assert event != null : "Event object was null"; + for (Map.Entry> entry : getListeners().entrySet()) { + if (entry.getKey().match(event)) { + for (RuntimeEventListener listener : entry.getValue()) { + listener.onEvent(event); + } + } + } + } + + protected Map> getListeners() { + if (listeners == null) { + listeners = new ConcurrentHashMap>(); + } + return listeners; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java new file mode 100644 index 0000000000..45eab7da1b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.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.sca.core.event; + +import java.net.URI; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a component starts + * + * @version $Rev$ $Date$ + */ +public class ComponentStart implements Event { + + private Object source; + private URI uri; + + /** + * Creates a component start event + * + * @param source the source of the event + * @param componentURI the URI of the component being started + */ + public ComponentStart(Object source, URI componentURI) { + this.source = source; + this.uri = componentURI; + } + + public URI getComponentURI() { + return uri; + } + + public Object getSource() { + return source; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java new file mode 100644 index 0000000000..4dc79c3844 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.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.sca.core.event; + +import java.net.URI; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a component stops + * + * @version $Rev$ $Date$ + */ +public class ComponentStop implements Event { + + private Object source; + private URI uri; + + /** + * Creates a component stop event + * + * @param source the source of the event + * @param componentUri the composite component associated the component being stopped + */ + public ComponentStop(Object source, URI componentUri) { + this.source = source; + this.uri = componentUri; + } + + public URI getComponentURI() { + return uri; + } + + public Object getSource() { + return source; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java new file mode 100644 index 0000000000..d3106c7052 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.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.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + + +/** + * Propagated when a conversation is expired + * + * @version $Rev$ $Date$ + */ +public class ConversationEnd implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the conversation being ended + */ + public ConversationEnd(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getConversationID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java new file mode 100644 index 0000000000..123400fbdd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.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.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + +/** + * Propagated when a conversation has started + * + * @version $Rev$ $Date$ + */ +public class ConversationStart implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the conversation being started + */ + public ConversationStart(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getConversationID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java new file mode 100644 index 0000000000..68cb5c2966 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.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.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + + +/** + * Propagated when an HTTP-based session is expired + * + * @version $Rev$ $Date$ + */ +public class HttpSessionEnd implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the HTTP session being ended + */ + public HttpSessionEnd(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getSessionID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java new file mode 100644 index 0000000000..38a4fb10d6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.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.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + +/** + * Propagated when an HTTP-based session has started + * + * @version $Rev$ $Date$ + */ +public class HttpSessionStart implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the HTTP session being started + */ + public HttpSessionStart(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getSessionID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java new file mode 100644 index 0000000000..d7e797bbb9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.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.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a request completes or is ended + * + * @version $Rev$ $Date$ + */ +public class RequestEnd implements Event { + + private Object source; + + /** + * Creates a new event + * + * @param source the source of the event + */ + public RequestEnd(Object source) { + this.source = source; + } + + public Object getSource() { + return source; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java new file mode 100644 index 0000000000..7530156b11 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.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.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a request is started in the runtime + * + * @version $Rev$ $Date$ + */ +public class RequestStart implements Event { + + private Object source; + + /** + * Creates a new event + * + * @param source the source of the event + */ + public RequestStart(Object source) { + this.source = source; + } + + public Object getSource() { + return source; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java new file mode 100644 index 0000000000..d35b27fd24 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.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.sca.core.factory; + + +/** + * Denotes an error creating a new object instance + * + * @version $Rev$ $Date$ + */ +public class ObjectCreationException extends RuntimeException { + private static final long serialVersionUID = -6423113430265944499L; + + public ObjectCreationException() { + super(); + } + + public ObjectCreationException(String message, Throwable cause) { + super(message, cause); + } + + public ObjectCreationException(String message) { + super(message); + } + + public ObjectCreationException(Throwable cause) { + super(cause); + } + +} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java new file mode 100644 index 0000000000..3f64d2405b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/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.sca.core.factory; + +/** + * Implementations create new instances of a particular type + * + * @version $Rev$ $Date$ + */ +public interface ObjectFactory { + + /** + * Return a instance of the type that this factory creates. + * + * @return a instance from this factory + */ + T getInstance() throws ObjectCreationException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java new file mode 100644 index 0000000000..588c43b8b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.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.sca.core.invocation; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.core.factory.ObjectCreationException; +import org.apache.tuscany.sca.core.factory.ObjectFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.osoa.sca.CallableReference; + +/** + * Uses a wire to return a CallableReference + * + * @version $Rev$ $Date$ + */ +public class CallableReferenceObjectFactory implements ObjectFactory> { + private Class businessInterface; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private Binding binding; + + /** + * Constructor. + * + * To support the @Reference protected CallableReference ref; + * + * @param businessInterface the interface to inject + * @param component the component defining the reference to be injected + * @param reference the reference to be injected + * @param binding the binding for the reference + */ + public CallableReferenceObjectFactory(Class businessInterface, + RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + this.businessInterface = businessInterface; + this.component = component; + this.reference = reference; + this.binding = binding; + } + + public CallableReference getInstance() throws ObjectCreationException { + return component.getComponentContext().getServiceReference(businessInterface, reference, binding); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java new file mode 100644 index 0000000000..d19aa237cd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.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.sca.core.invocation; + +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.osoa.sca.NoRegisteredCallbackException; + +/** + * An interceptor applied to the forward direction of a wire that ensures the callback target implements the required + * service contract. This is required as callback targets may be set dynamically by service implementations. + * + * @version $Rev$ $Date$ + */ +public class CallbackInterfaceInterceptor implements Interceptor { + private Invoker next; + + public CallbackInterfaceInterceptor() { + } + + public Message invoke(Message msg) { + ReferenceParameters parameters = msg.getFrom().getReferenceParameters(); + if (parameters.getCallbackObjectID() != null || parameters.getCallbackReference() != msg.getFrom() + .getCallbackEndpoint()) { + return next.invoke(msg); + } else { + throw new NoRegisteredCallbackException("Callback target does not implement the callback interface"); + } + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Invoker getNext() { + return next; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java new file mode 100644 index 0000000000..97c69c33cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java @@ -0,0 +1,268 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.core.assembly.RuntimeComponentReferenceImpl; +import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl; +import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +import org.apache.tuscany.sca.core.context.ComponentContextHelper; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Returns proxy instance for a wire callback + * + * @version $Rev: 576055 $ $Date: 2007-09-16 08:11:45 +0100 (Sun, 16 Sep 2007) $ + */ +public class CallbackReferenceImpl extends CallableReferenceImpl { + private RuntimeWire wire; + private List wires; + private EndpointReference resolvedEndpoint; + private Object convID; + + public static CallbackReferenceImpl newInstance(Class interfaze, + ProxyFactory proxyFactory, + List wires) { + if (getCallbackEndpoint(ThreadMessageContext.getMessageContext()) != null) { + return new CallbackReferenceImpl(interfaze, proxyFactory, wires); + } else { + return null; + } + } + + /** + * Public constructor for Externalizable serialization/deserialization. + */ + public CallbackReferenceImpl() { + super(); + } + + private CallbackReferenceImpl(Class interfaze, ProxyFactory proxyFactory, List wires) { + super(interfaze, null, proxyFactory); + this.wires = wires; + init(); + } + + public void init() { + Message msgContext = ThreadMessageContext.getMessageContext(); + wire = selectCallbackWire(msgContext); + if (wire == null) { + //FIXME: need better exception + throw new RuntimeException("No callback binding found for " + msgContext.getTo().getURI()); + } + resolvedEndpoint = getCallbackEndpoint(msgContext); + convID = msgContext.getFrom().getReferenceParameters().getConversationID(); + callbackID = msgContext.getFrom().getReferenceParameters().getCallbackID(); + } + + @Override + protected Object createProxy() throws Exception { + return proxyFactory.createCallbackProxy(this); + } + + protected RuntimeWire getCallbackWire() { + if (resolvedEndpoint == null) { + return null; + } else { + return cloneAndBind(wire); + } + } + + protected Object getConvID() { + return convID; + } + + protected EndpointReference getResolvedEndpoint() { + return resolvedEndpoint; + } + + private RuntimeWire selectCallbackWire(Message msgContext) { + // look for callback binding with same name as service binding + EndpointReference to = msgContext.getTo(); + if (to == null) { + //FIXME: need better exception + throw new RuntimeException("Destination for forward call is not available"); + } + for (RuntimeWire wire : wires) { + if (wire.getSource().getBinding().getName().equals(to.getBinding().getName())) { + return wire; + } + } + + // if no match, look for callback binding with same type as service binding + for (RuntimeWire wire : wires) { + if (wire.getSource().getBinding().getClass() == to.getBinding().getClass()) { + return wire; + } + } + + // no suitable callback wire was found + return null; + } + + /** + * @param msgContext + */ + private static EndpointReference getCallbackEndpoint(Message msgContext) { + EndpointReference from = msgContext.getFrom(); + if (from == null) { + return null; + } + return from.getReferenceParameters().getCallbackReference(); + } + + private RuntimeWire cloneAndBind(RuntimeWire wire) { + RuntimeWire boundWire = null; + if (resolvedEndpoint != null) { + boundWire = ((RuntimeWireImpl)wire).lookupCache(resolvedEndpoint); + if (boundWire != null) { + return boundWire; + } + try { + Contract contract = resolvedEndpoint.getContract(); + RuntimeComponentReference ref = null; + if (contract == null) { + boundWire = (RuntimeWire)wire.clone(); + + } else if (contract instanceof RuntimeComponentReference) { + ref = (RuntimeComponentReference)contract; + boundWire = ref.getRuntimeWire(resolvedEndpoint.getBinding()); + + } else { // contract instanceof RuntimeComponentService + ref = bind((RuntimeComponentReference)wire.getSource().getContract(), + resolvedEndpoint.getComponent(), + (RuntimeComponentService)contract); + boundWire = ref.getRuntimeWires().get(0); + } + configureWire(boundWire); + ((RuntimeWireImpl)wire).addToCache(resolvedEndpoint, boundWire); + } catch (CloneNotSupportedException e) { + // will not happen + } + } + return boundWire; + } + + private static RuntimeComponentReference bind(RuntimeComponentReference reference, + RuntimeComponent component, + RuntimeComponentService service) throws CloneNotSupportedException { + RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone(); + ref.getTargets().add(service); + ref.getBindings().clear(); + for (Binding binding : service.getBindings()) { + if (binding instanceof OptimizableBinding) { + OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone(); + optimizableBinding.setTargetBinding(binding); + optimizableBinding.setTargetComponent(component); + optimizableBinding.setTargetComponentService(service); + ref.getBindings().add(optimizableBinding); + } else { + ref.getBindings().add(binding); + } + } + return ref; + } + + private void configureWire(RuntimeWire wire) { + // need to set the endpoint on the binding also so that when the chains are created next + // the sca binding can decide whether to provide local or remote invokers. + // TODO - there is a problem here though in that I'm setting a target on a + // binding that may possibly be trying to point at two things in the multi threaded + // case. Need to confirm the general model here and how the clone and bind part + // is intended to work + Binding binding = wire.getSource().getBinding(); + binding.setURI(resolvedEndpoint.getURI()); + + // also need to set the target contract as it varies for the sca binding depending on + // whether it is local or remote + RuntimeComponentReference ref = (RuntimeComponentReference)wire.getSource().getContract(); + wire.getTarget().setInterfaceContract(ref.getBindingProvider(binding).getBindingInterfaceContract()); + } + + /** + * {@inheritDoc} + */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + super.readExternal(in); + this.callbackID = in.readObject(); + this.convID = in.readObject(); + + this.compositeActivator = ComponentContextHelper.getCurrentCompositeActivator(); + + // Get the target Component and Service from the URI + final String uri = in.readUTF(); + final Component targetComponent = super.resolveComponentURI(uri); + final ComponentService targetService = super.resolveServiceURI(uri, targetComponent); + final InterfaceContract targetServiceIfaceContract = targetService.getInterfaceContract(); + + // Re-create the resolved Endpoint + this.resolvedEndpoint = new EndpointReferenceImpl( + (RuntimeComponent) targetComponent, targetService, null, + targetServiceIfaceContract); + + // Copy the Java Interface from the Service + final JavaInterface ji = (JavaInterface) targetServiceIfaceContract.getInterface(); + this.businessInterface = (Class) ji.getJavaClass(); + + // We need to re-create the callback wire. We need to do this on a clone of the Service + // wire since we need to change some details on it. + // FIXME: Is this the best way to do this? + final RuntimeWire cbWire = ((RuntimeComponentService) targetService).getRuntimeWires().get(0); + try { + this.wire = (RuntimeWireImpl) cbWire.clone(); + } catch (CloneNotSupportedException e) { + throw new IOException(e.toString()); + } + + // Setup the reference on the cloned wire + final RuntimeComponentReference ref = new RuntimeComponentReferenceImpl(); + ref.setComponent((RuntimeComponent) targetComponent); + ref.setInterfaceContract(targetServiceIfaceContract); + ((EndpointReferenceImpl) this.wire.getSource()).setContract(ref); + } + + /** + * {@inheritDoc} + */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + super.writeExternal(out); + out.writeObject(this.callbackID); + out.writeObject(this.convID); + out.writeUTF(this.resolvedEndpoint.getURI()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java new file mode 100644 index 0000000000..b5b40811ad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.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.sca.core.invocation; + +import java.util.List; + +import org.apache.tuscany.sca.core.factory.ObjectCreationException; +import org.apache.tuscany.sca.core.factory.ObjectFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; + +/** + * Uses a wire to return a CallableReference + * + * @version $Rev: 574648 $ $Date: 2007-09-11 18:45:36 +0100 (Tue, 11 Sep 2007) $ + */ +public class CallbackReferenceObjectFactory implements ObjectFactory> { + private Class businessInterface; + private ProxyFactory proxyFactory; + private List wires; + + public CallbackReferenceObjectFactory(Class interfaze, ProxyFactory proxyFactory, List wires) { + this.businessInterface = interfaze; + this.proxyFactory = proxyFactory; + this.wires = wires; + } + + public CallableReference getInstance() throws ObjectCreationException { + return CallbackReferenceImpl.newInstance(businessInterface, proxyFactory, wires); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java new file mode 100644 index 0000000000..2b37c30451 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.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.sca.core.invocation; + +import java.util.List; + +import org.apache.tuscany.sca.core.factory.ObjectCreationException; +import org.apache.tuscany.sca.core.factory.ObjectFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Returns proxy instance for a wire callback + * + * @version $Rev$ $Date$ + */ +public class CallbackWireObjectFactory implements ObjectFactory { + private Class businessInterface; + private ProxyFactory proxyFactory; + private List wires; + + public CallbackWireObjectFactory(Class interfaze, ProxyFactory proxyFactory, List wires) { + this.businessInterface = interfaze; + this.proxyFactory = proxyFactory; + this.wires = wires; + } + + public B getInstance() throws ObjectCreationException { + return proxyFactory.createCallbackProxy(businessInterface, wires); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java new file mode 100644 index 0000000000..0b3c043340 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java @@ -0,0 +1,172 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.invocation; + +import java.lang.reflect.Method; +import java.util.List; + +import net.sf.cglib.proxy.Callback; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.Factory; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; +import org.osoa.sca.ServiceReference; + +/** + * The implementation of a wire service that uses cglib dynamic proxies + * + * @version $Rev$ $Date$ + */ +@SuppressWarnings("unused") +public class CglibProxyFactory implements ProxyFactory { + private MessageFactory messageFactory; + + public CglibProxyFactory(MessageFactory messageFactory, InterfaceContractMapper mapper) { + this.messageFactory = messageFactory; + + } + + public T createProxy(Class interfaze, RuntimeWire wire) throws ProxyCreationException { + ServiceReference serviceReference = new ServiceReferenceImpl(interfaze, wire, this); + return createProxy(serviceReference); + } + + private class CglibClassLoader extends ClassLoader { + private ClassLoader appLoader; + private ClassLoader bundleLoader; + + @Override + public Class loadClass(String className) + throws ClassNotFoundException { + try { + return appLoader.loadClass(className); + } catch (ClassNotFoundException ex ) { + return bundleLoader.loadClass(className); + } + } + + CglibClassLoader(ClassLoader app, ClassLoader bundle) { + this.appLoader = app; + this.bundleLoader = bundle; + } + } + /** + * create the proxy with cglib. use the same JDKInvocationHandler as + * JDKProxyService. + */ + public T createProxy(CallableReference callableReference) throws ProxyCreationException { + Enhancer enhancer = new Enhancer(); + Class interfaze = callableReference.getBusinessInterface(); + ClassLoader cl = new CglibClassLoader(interfaze.getClassLoader(), getClass().getClassLoader()); + enhancer.setClassLoader(cl); + enhancer.setSuperclass(interfaze); + enhancer.setCallback(new CglibMethodInterceptor(callableReference)); + Object proxy = enhancer.create(); + ((CallableReferenceImpl)callableReference).setProxy(proxy); + return interfaze.cast(proxy); + } + + /** + * create the callback proxy with cglib. use the same + * JDKCallbackInvocationHandler as JDKProxyService. + */ + public T createCallbackProxy(Class interfaze, final List wires) throws ProxyCreationException { + CallbackReferenceImpl callbackReference = CallbackReferenceImpl.newInstance(interfaze, this, wires); + return callbackReference != null ? createCallbackProxy(callbackReference) : null; + } + + /** + * create the callback proxy with cglib. use the same + * JDKCallbackInvocationHandler as JDKProxyService. + */ + public T createCallbackProxy(CallbackReferenceImpl callbackReference) throws ProxyCreationException { + Enhancer enhancer = new Enhancer(); + Class interfaze = callbackReference.getBusinessInterface(); + enhancer.setSuperclass(interfaze); + enhancer.setCallback(new CglibMethodInterceptor(callbackReference)); + Object proxy = enhancer.create(); + callbackReference.setProxy(proxy); + return interfaze.cast(proxy); + } + + @SuppressWarnings("unchecked") + public > R cast(B target) throws IllegalArgumentException { + if (isProxyClass(target.getClass())) { + Factory factory = (Factory)target; + Callback[] callbacks = factory.getCallbacks(); + if (callbacks.length != 1 || !(callbacks[0] instanceof CglibMethodInterceptor)) { + throw new IllegalArgumentException("The object is not a known proxy."); + } + CglibMethodInterceptor interceptor = (CglibMethodInterceptor)callbacks[0]; + return (R)interceptor.invocationHandler.getCallableReference(); + } else { + throw new IllegalArgumentException("The object is not a known proxy."); + } + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#isProxyClass(java.lang.Class) + */ + public boolean isProxyClass(Class clazz) { + return Factory.class.isAssignableFrom(clazz); + } + + private class CglibMethodInterceptor implements MethodInterceptor { + private JDKInvocationHandler invocationHandler; + + public CglibMethodInterceptor(CallableReference callableReference) { + invocationHandler = new JDKInvocationHandler(messageFactory, callableReference); + } + + public CglibMethodInterceptor(CallbackReferenceImpl callbackReference) { + invocationHandler = new JDKCallbackInvocationHandler(messageFactory, callbackReference); + } + + /* + public CglibMethodInterceptor(Class interfaze, RuntimeWire wire) { + ServiceReference serviceRef = new ServiceReferenceImpl(interfaze, wire, CglibProxyFactory.this); + invocationHandler = new JDKInvocationHandler(messageFactory, serviceRef); + } + + public CglibMethodInterceptor(Class interfaze, List wires) { + CallbackReferenceImpl ref = new CallbackReferenceImpl(interfaze, CglibProxyFactory.this, wires); + invocationHandler = new JDKCallbackInvocationHandler(messageFactory, ref); + } + */ + + /** + * @see net.sf.cglib.proxy.MethodInterceptor#intercept(java.lang.Object, java.lang.reflect.Method, java.lang.Object[], net.sf.cglib.proxy.MethodProxy) + */ + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { + Object result = invocationHandler.invoke(proxy, method, args); + return result; + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java new file mode 100644 index 0000000000..9acb4be6f8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.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.sca.core.invocation; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.invocation.MessageFactory; + +/** + * Default implementation of a ProxyFactoryExtensionPoint. + * + * @version $Rev$ $Date$ + */ +public class DefaultProxyFactoryExtensionPoint implements ProxyFactoryExtensionPoint { + private InterfaceContractMapper interfaceContractMapper; + private MessageFactory messageFactory; + + private ProxyFactory interfaceFactory; + private ProxyFactory classFactory; + + public DefaultProxyFactoryExtensionPoint(ExtensionPointRegistry extensionPoints) { + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + + interfaceFactory = new JDKProxyFactory(messageFactory, interfaceContractMapper); + } + + public DefaultProxyFactoryExtensionPoint(MessageFactory messageFactory, InterfaceContractMapper mapper) { + this.interfaceContractMapper = mapper; + this.messageFactory = messageFactory; + interfaceFactory = new JDKProxyFactory(messageFactory, mapper); + } + + public ProxyFactory getClassProxyFactory() { + return classFactory; + } + + public ProxyFactory getInterfaceProxyFactory() { + return interfaceFactory; + } + + public void setClassProxyFactory(ProxyFactory factory) { + this.classFactory = factory; + + } + + public void setInterfaceProxyFactory(ProxyFactory factory) { + this.interfaceFactory = factory; + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java new file mode 100644 index 0000000000..fcb48259b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.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.sca.core.invocation; + +import java.util.List; + +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; + +/** + * An extensible proxy factory. + * + * @version $Rev: $ $Date: $ + */ +public class ExtensibleProxyFactory implements ProxyFactory { + + private ProxyFactoryExtensionPoint proxyFactories; + + public ExtensibleProxyFactory(ProxyFactoryExtensionPoint proxyFactories) { + this.proxyFactories = proxyFactories; + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#cast(java.lang.Object) + */ + @SuppressWarnings("unchecked") + public > R cast(B target) throws IllegalArgumentException { + ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory(); + ProxyFactory classFactory = proxyFactories.getClassProxyFactory(); + if (interfaceFactory.isProxyClass(target.getClass())) { + return (R)interfaceFactory.cast(target); + } else if (classFactory != null && classFactory.isProxyClass(target.getClass())) { + return (R)classFactory.cast(target); + } else { + throw new IllegalArgumentException("The target is not a callable proxy"); + } + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#createCallbackProxy(java.lang.Class, + * java.util.List) + */ + public T createCallbackProxy(Class interfaze, List wires) throws ProxyCreationException { + ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory(); + ProxyFactory classFactory = proxyFactories.getClassProxyFactory(); + if (interfaze.isInterface()) { + return interfaceFactory.createCallbackProxy(interfaze, wires); + } else { + return classFactory.createCallbackProxy(interfaze, wires); + } + } + + public T createProxy(CallableReference callableReference) throws ProxyCreationException { + ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory(); + ProxyFactory classFactory = proxyFactories.getClassProxyFactory(); + if (callableReference.getBusinessInterface().isInterface()) { + return interfaceFactory.createProxy(callableReference); + } else { + return classFactory.createProxy(callableReference); + } + } + + public T createCallbackProxy(CallbackReferenceImpl callbackReference) throws ProxyCreationException { + ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory(); + ProxyFactory classFactory = proxyFactories.getClassProxyFactory(); + if (callbackReference.getBusinessInterface().isInterface()) { + return interfaceFactory.createCallbackProxy(callbackReference); + } else { + return classFactory.createCallbackProxy(callbackReference); + } + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#createProxy(java.lang.Class, + * org.apache.tuscany.sca.runtime.RuntimeWire) + */ + public T createProxy(Class interfaze, RuntimeWire wire) throws ProxyCreationException { + ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory(); + ProxyFactory classFactory = proxyFactories.getClassProxyFactory(); + if (interfaze.isInterface()) { + return interfaceFactory.createProxy(interfaze, wire); + } else { + return classFactory.createProxy(interfaze, wire); + } + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#isProxyClass(java.lang.Class) + */ + public boolean isProxyClass(Class clazz) { + ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory(); + ProxyFactory classFactory = proxyFactories.getClassProxyFactory(); + return interfaceFactory.isProxyClass(clazz) || (classFactory != null && classFactory.isProxyClass(clazz)); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java new file mode 100644 index 0000000000..934f2f7aa0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.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.sca.core.invocation; + +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; + +/** + * The default implementation of an extensible WireProcessor + * + * @version $Rev$ $Date$ + */ +public class ExtensibleWireProcessor implements RuntimeWireProcessor { + + private RuntimeWireProcessorExtensionPoint processors; + + public ExtensibleWireProcessor(RuntimeWireProcessorExtensionPoint processors) { + this.processors = processors; + } + + public void process(RuntimeWire wire) { + for (RuntimeWireProcessor processor : processors.getWireProcessors()) { + processor.process(wire); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java new file mode 100644 index 0000000000..c559a42bdc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Phase; + +/** + * Default implementation of an invocation chain + * + * @version $Rev$ $Date$ + */ +public class InvocationChainImpl implements InvocationChain { + private Operation sourceOperation; + private Operation targetOperation; + private List nodes = new ArrayList(); + + // FIXME: Not a good practice to use static reference + private static final PhaseManager phaseManager = new PhaseManager(); + private boolean forReference; + private boolean allowsPassByReference; + + public InvocationChainImpl(Operation sourceOperation, Operation targetOperation, boolean forReference) { + // TODO - binding invocation chain doesn't provide operations + //assert sourceOperation != null; + //assert targetOperation != null; + this.targetOperation = targetOperation; + this.sourceOperation = sourceOperation; + this.forReference = forReference; + } + + public Operation getTargetOperation() { + return targetOperation; + } + + public void setTargetOperation(Operation operation) { + this.targetOperation = operation; + } + + public void addInterceptor(Interceptor interceptor) { + String phase = forReference ? Phase.REFERENCE : Phase.SERVICE; + addInterceptor(phase, interceptor); + } + + public void addInvoker(Invoker invoker) { + String phase = forReference ? Phase.REFERENCE_BINDING : Phase.IMPLEMENTATION; + addInvoker(phase, invoker); + } + + public Invoker getHeadInvoker() { + return nodes.isEmpty() ? null : nodes.get(0).getInvoker(); + } + + public Invoker getTailInvoker() { + return nodes.isEmpty() ? null : nodes.get(nodes.size() - 1).getInvoker(); + } + + /** + * @return the sourceOperation + */ + public Operation getSourceOperation() { + return sourceOperation; + } + + /** + * @param sourceOperation the sourceOperation to set + */ + public void setSourceOperation(Operation sourceOperation) { + this.sourceOperation = sourceOperation; + } + + public void addInterceptor(int index, Interceptor interceptor) { + addInterceptor(interceptor); + } + + public void addInterceptor(String phase, Interceptor interceptor) { + addInvoker(phase, interceptor); + } + + private void addInvoker(String phase, Invoker invoker) { + int index = phaseManager.getAllPhases().indexOf(phase); + if (index == -1) { + throw new IllegalArgumentException("Invalid phase name: " + phase); + } + Node node = new Node(index, invoker); + ListIterator li = nodes.listIterator(); + Node before = null, after = null; + boolean found = false; + while (li.hasNext()) { + before = after; + after = li.next(); + if (after.getPhaseIndex() > index) { + // Move back + li.previous(); + li.add(node); + found = true; + break; + } + } + if (!found) { + // Add to the end + nodes.add(node); + before = after; + after = null; + } + + // Relink the interceptors + if (before != null) { + if (before.getInvoker() instanceof Interceptor) { + ((Interceptor)before.getInvoker()).setNext(invoker); + } + } + if (after != null) { + if (invoker instanceof Interceptor) { + ((Interceptor)invoker).setNext(after.getInvoker()); + } + } + + } + + public boolean allowsPassByReference() { + if (allowsPassByReference) { + // No need to check the invokers + return true; + } + // Check if any of the invokers allows pass-by-reference + boolean allowsPBR = false; + for (Node i : nodes) { + if (i.getInvoker() instanceof DataExchangeSemantics) { + if (((DataExchangeSemantics)i.getInvoker()).allowsPassByReference()) { + allowsPBR = true; + break; + } + } + } + return allowsPBR; + } + + public void setAllowsPassByReference(boolean allowsPBR) { + this.allowsPassByReference = allowsPBR; + } + + private static class Node { + private int phaseIndex; + private Invoker invoker; + + public Node(int phaseIndex, Invoker invoker) { + super(); + this.phaseIndex = phaseIndex; + this.invoker = invoker; + } + + public int getPhaseIndex() { + return phaseIndex; + } + + public Invoker getInvoker() { + return invoker; + } + + @Override + public String toString() { + return "(" + phaseIndex + ")" + invoker; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java new file mode 100644 index 0000000000..62e8b4d3ee --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.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.sca.core.invocation; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl; +import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +import org.apache.tuscany.sca.core.conversation.ConversationState; +import org.apache.tuscany.sca.core.scope.TargetResolutionException; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.NoRegisteredCallbackException; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Responsible for dispatching to a callback through a wire.

TODO cache + * target invoker + * + * @version $Rev$ $Date$ + */ +public class JDKCallbackInvocationHandler extends JDKInvocationHandler { + private static final long serialVersionUID = -3350283555825935609L; + + public JDKCallbackInvocationHandler(MessageFactory messageFactory, CallbackReferenceImpl ref) { + super(messageFactory, ref); + this.fixedWire = false; + } + + @Override + @SuppressWarnings( {"unchecked"}) + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if (Object.class == method.getDeclaringClass()) { + return invokeObjectMethod(method, args); + } + + // obtain a dedicated wire to be used for this callback invocation + RuntimeWire wire = ((CallbackReferenceImpl)callableReference).getCallbackWire(); + if (wire == null) { + //FIXME: need better exception + throw new ServiceRuntimeException("No callback wire found"); + } + + // set the conversational state based on the interface that + // is specified for the reference that this wire belongs to + initConversational(wire); + + // set the conversation id into the conversation object. This is + // a special case for callbacks as, unless otherwise set manually, + // the callback should use the same conversation id as was received + // on the incoming call to this component + if (conversational) { + + if (conversation == null || conversation.getState() == ConversationState.ENDED) { + conversation = null; + } + Object convID = conversation == null ? null : conversation.getConversationID(); + + // create a conversation id if one doesn't exist + // already, i.e. the conversation is just starting + if (convID == null) { + convID = ((CallbackReferenceImpl)callableReference).getConvID(); + if (convID != null) { + conversation = ((RuntimeWireImpl)wire).getConversationManager().getConversation(convID); + if (callableReference != null) { + ((CallableReferenceImpl)callableReference).attachConversation(conversation); + } + } + } + } + + setEndpoint(((CallbackReferenceImpl)callableReference).getResolvedEndpoint()); + + InvocationChain chain = getInvocationChain(method, wire); + if (chain == null) { + throw new IllegalArgumentException("No matching operation is found: " + method); + } + + try { + return invoke(chain, args, wire, wire.getSource()); + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof NoRegisteredCallbackException) { + throw t; + } + throw e; + } finally { + // allow the cloned wire to be reused by subsequent callbacks + ((RuntimeWireImpl)wire).releaseWire(); + } + } + + /** + * + */ + @Override + protected void handleCallback(Message msg, RuntimeWire wire, Object currentConversationID) + throws TargetResolutionException { + ReferenceParameters parameters = msg.getFrom().getReferenceParameters(); + parameters.setCallbackID(getCallbackID()); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java new file mode 100644 index 0000000000..4c6abc726c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java @@ -0,0 +1,614 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.invocation; + +import java.io.Serializable; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.xml.ws.Holder; + +import org.apache.tuscany.sca.core.assembly.CompositeActivator; +import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl; +import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +import org.apache.tuscany.sca.core.context.ComponentContextImpl; +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.core.conversation.ConversationManager; +import org.apache.tuscany.sca.core.conversation.ConversationState; +import org.apache.tuscany.sca.core.conversation.ExtendedConversation; +import org.apache.tuscany.sca.core.scope.Scope; +import org.apache.tuscany.sca.core.scope.ScopeContainer; +import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent; +import org.apache.tuscany.sca.core.scope.TargetDestructionException; +import org.apache.tuscany.sca.core.scope.TargetResolutionException; +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.ParameterMode; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; +import org.osoa.sca.ConversationEndedException; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class JDKInvocationHandler implements InvocationHandler, Serializable { + private static final long serialVersionUID = -3366410500152201371L; + + protected boolean conversational; + protected ExtendedConversation conversation; + protected MessageFactory messageFactory; + protected EndpointReference source; + protected EndpointReference target; + protected RuntimeWire wire; + protected CallableReference callableReference; + protected Class businessInterface; + + protected boolean fixedWire = true; + + protected transient Map chains = new IdentityHashMap(); + + public JDKInvocationHandler(MessageFactory messageFactory, Class businessInterface, RuntimeWire wire) { + this.messageFactory = messageFactory; + this.wire = wire; + this.businessInterface = businessInterface; + init(this.wire); + } + + public JDKInvocationHandler(MessageFactory messageFactory, CallableReference callableReference) { + this.messageFactory = messageFactory; + this.callableReference = callableReference; + if (callableReference != null) { + this.businessInterface = callableReference.getBusinessInterface(); + this.conversation = (ExtendedConversation)callableReference.getConversation(); + this.wire = ((CallableReferenceImpl)callableReference).getRuntimeWire(); + + /* ==========================================================================*/ + // TUSCANY-3140 - in some cases we have noticed that the runtime engine for a + // component implementation uses a different classloader compared + // to the classloader used in the first instance to introspect the + // component type and create the component model. If the business + // interface of the callable reference is different from the + // interface of the reference then set the reference interface to the + // business interface + if (wire != null){ + Interface iface = wire.getSource().getInterfaceContract().getInterface(); + if (iface instanceof JavaInterface) { + JavaInterface javaIFace = (JavaInterface)iface; + // only reset the interface if the classes have the same name but the + // class object is different + if ((javaIFace.getJavaClass().getName().equals(this.businessInterface.getName())) && + (javaIFace.getJavaClass() != this.businessInterface)) { + try { + RuntimeComponent wireSourceComponent = wire.getSource().getComponent(); + CompositeActivator compositeActivator = ((ComponentContextImpl)wireSourceComponent.getComponentContext()).getCompositeActivator(); + if (compositeActivator != null && compositeActivator.getJavaInterfaceFactory() != null) { + //reconstruct java interface using interface loaded by implementation class loader + iface.getOperations().clear(); + compositeActivator.getJavaInterfaceFactory().createJavaInterface((JavaInterface) iface, this.businessInterface); + } + } catch (InvalidInterfaceException e) { + e.printStackTrace(); + } + } + } + } + /* ==========================================================================*/ + + if (wire != null) { + init(wire); + } + } + } + + protected void init(RuntimeWire wire) { + if (wire != null) { + try { + // Clone the endpoint reference so that reference parameters can be changed + source = (EndpointReference)wire.getSource().clone(); + } catch (CloneNotSupportedException e) { + throw new ServiceRuntimeException(e); + } + initConversational(wire); + } + } + + protected void initConversational(RuntimeWire wire) { + InterfaceContract contract = wire.getSource().getInterfaceContract(); + this.conversational = contract.getInterface().isConversational(); + } + + protected Object getCallbackID() { + if (callableReference != null) { + return callableReference.getCallbackID(); + } else { + return null; + } + } + + protected Object getConversationID() { + if (callableReference != null && callableReference instanceof ServiceReference) { + return ((ServiceReference)callableReference).getConversationID(); + } else { + return null; + } + } + + protected Object getCallbackObject() { + if (callableReference != null && callableReference instanceof ServiceReference) { + return ((ServiceReference)callableReference).getCallback(); + } else { + return null; + } + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if (Object.class == method.getDeclaringClass()) { + return invokeObjectMethod(method, args); + } + if (wire == null) { + throw new ServiceRuntimeException("No runtime wire is available"); + } + InvocationChain chain = getInvocationChain(method, wire); + if (chain == null) { + throw new IllegalArgumentException("No matching operation is found: " + method); + } + + Object result = invoke(chain, args, wire, source); + + Operation operation = chain.getSourceOperation(); + if (operation != null && operation.getInterface().isRemotable()) { + List inputTypes = operation.getInputType().getLogical(); + // Returned Holder data are placed back in Holder. + for (int i = 0, size = inputTypes.size(); i < size; i++) { + if (operation.getParameterModes().get(i) != ParameterMode.IN) { + // Pop results and place in holder (demote). + Holder holder = (Holder)args[i]; + holder.value = result; + } + } + } + + return result; + } + + /** + * Handle the methods on the Object.class + * @param method + * @param args + */ + protected Object invokeObjectMethod(Method method, Object[] args) throws Throwable { + String name = method.getName(); + if ("toString".equals(name)) { + return "[Proxy - " + toString() + "]"; + } else if ("equals".equals(name)) { + Object obj = args[0]; + if (obj == null) { + return false; + } + if (!Proxy.isProxyClass(obj.getClass())) { + return false; + } + return equals(Proxy.getInvocationHandler(obj)); + } else if ("hashCode".equals(name)) { + return hashCode(); + } else { + return method.invoke(this); + } + } + + /** + * Determines if the given operation matches the given method + * + * @return true if the operation matches, false if does not + */ + // FIXME: Should it be in the InterfaceContractMapper? + @SuppressWarnings("unchecked") + private static boolean match(Operation operation, Method method) { + if (operation instanceof JavaOperation) { + JavaOperation javaOp = (JavaOperation)operation; + Method m = javaOp.getJavaMethod(); + if (!method.getName().equals(m.getName())) { + return false; + } + if (method.equals(m)) { + return true; + } + } else { + if (!method.getName().equals(operation.getName())) { + return false; + } + } + + // For remotable interface, operation is not overloaded. + if (operation.getInterface().isRemotable()) { + return true; + } + + Class[] params = method.getParameterTypes(); + + DataType> inputType = null; + if (operation.isInputWrapperStyle()) { + inputType = operation.getInputWrapper().getUnwrappedInputType(); + } else { + inputType = operation.getInputType(); + } + List types = inputType.getLogical(); + boolean matched = true; + if (types.size() == params.length && method.getName().equals(operation.getName())) { + for (int i = 0; i < params.length; i++) { + Class clazz = params[i]; + Class type = types.get(i).getPhysical(); + // Object.class.isAssignableFrom(int.class) returns false + if (type != Object.class && (!type.isAssignableFrom(clazz))) { + matched = false; + } + } + } else { + matched = false; + } + return matched; + + } + + protected synchronized InvocationChain getInvocationChain(Method method, RuntimeWire wire) { + if (fixedWire) { + InvocationChain chain = chains.get(method); + if (chain != null) { + return chain; + } + } + InvocationChain found = null; + for (InvocationChain chain : wire.getInvocationChains()) { + Operation operation = chain.getSourceOperation(); + if (operation.isDynamic()) { + operation.setName(method.getName()); + found = chain; + break; + } else if (match(operation, method)) { + found = chain; + break; + } + } + if (fixedWire) { + chains.put(method, found); + } + return found; + } + + protected void setEndpoint(EndpointReference endpoint) { + this.target = endpoint; + } + + protected Object invoke(InvocationChain chain, Object[] args, RuntimeWire wire, EndpointReference source) + throws Throwable { + Message msg = messageFactory.createMessage(); + msg.setFrom(source); + if (target != null) { + msg.setTo(target); + } else { + msg.setTo(wire.getTarget()); + } + Invoker headInvoker = chain.getHeadInvoker(); + Operation operation = chain.getTargetOperation(); + + msg.setOperation(operation); + + // Holder pattern. Items stored in a Holder are promoted to T. + // After the invoke, the returned data are placed back in Holder. + if (operation != null && operation.getInterface().isRemotable()) { + args = promoteHolderArgs(chain.getSourceOperation(), args); + } + msg.setBody(args); + + Message msgContext = ThreadMessageContext.getMessageContext(); + Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID(); + + conversationPreinvoke(msg, wire); + handleCallback(msg, wire, currentConversationID); + ThreadMessageContext.setMessageContext(msg); + boolean abnormalEndConversation = false; + try { + // dispatch the wire down the chain and get the response + Message resp = headInvoker.invoke(msg); + Object body = resp.getBody(); + if (resp.isFault()) { + // mark the conversation as ended if the exception is not a business exception + if (currentConversationID != null) { + try { + boolean businessException = false; + + for (DataType dataType : operation.getFaultTypes()) { + if (dataType.getPhysical() == ((Throwable)body).getClass()) { + businessException = true; + break; + } + } + + if (businessException == false) { + abnormalEndConversation = true; + } + } catch (Exception ex) { + // TODO - sure what the best course of action is here. We have + // a system exception in the middle of a business exception + } + } + throw (Throwable)body; + } + return body; + } finally { + conversationPostInvoke(msg, wire, abnormalEndConversation); + ThreadMessageContext.setMessageContext(msgContext); + } + } + + /** + * @param msg + * @param wire + * @param interfaze + * @throws TargetResolutionException + */ + protected void handleCallback(Message msg, RuntimeWire wire, Object currentConversationID) + throws TargetResolutionException { + + if (msg.getFrom() == null || msg.getFrom().getCallbackEndpoint() == null) { + return; + } + + ReferenceParameters parameters = msg.getFrom().getReferenceParameters(); + parameters.setCallbackID(getCallbackID()); + parameters.setCallbackReference(msg.getFrom().getCallbackEndpoint()); + + // If we are passing out a callback target + // register the calling component instance against this + // new conversation id so that stateful callbacks will be + // able to find it + Object callbackObject = getCallbackObject(); + if (conversational && callbackObject == null) { + // the component instance is already registered + // so add another registration + ScopeContainer scopeContainer = getConversationalScopeContainer(wire); + + if (scopeContainer != null && currentConversationID != null) { + scopeContainer.addWrapperReference(currentConversationID, conversation.getConversationID()); + } + } + + Interface interfaze = msg.getFrom().getCallbackEndpoint().getInterfaceContract().getInterface(); + if (callbackObject != null) { + if (callbackObject instanceof ServiceReference) { + EndpointReference callbackRef = ((CallableReferenceImpl)callbackObject).getEndpointReference(); + parameters.setCallbackReference(callbackRef); + } else { + if (interfaze != null) { + if (!interfaze.isConversational()) { + throw new IllegalArgumentException( + "Callback object for stateless callback is not a ServiceReference"); + } else { + if (!(callbackObject instanceof Serializable)) { + throw new IllegalArgumentException( + "Callback object for stateful callback is not Serializable"); + } + ScopeContainer scopeContainer = getConversationalScopeContainer(wire); + if (scopeContainer != null) { + InstanceWrapper wrapper = new CallbackObjectWrapper(callbackObject); + scopeContainer.registerWrapper(wrapper, conversation.getConversationID()); + } + parameters.setCallbackObjectID(callbackObject); + } + } + } + } + } + + /** + * Pre-invoke for the conversation handling + * @param msg + * @throws TargetResolutionException + */ + private void conversationPreinvoke(Message msg, RuntimeWire wire) { + if (!conversational) { + // Not conversational or the conversation has been started + return; + } + + ConversationManager conversationManager = ((RuntimeWireImpl)wire).getConversationManager(); + + if (conversation == null || conversation.getState() == ConversationState.ENDED) { + + conversation = conversationManager.startConversation(getConversationID()); + + // if this is a local wire then set up the conversation timeouts here based on the + // parameters from the component + if (wire.getTarget().getComponent() != null) { + conversation.initializeConversationAttributes(wire.getTarget().getComponent()); + } + + // connect the conversation to the CallableReference so it can be retrieve in the future + if (callableReference != null) { + ((CallableReferenceImpl)callableReference).attachConversation(conversation); + } + } else if (conversation.isExpired()) { + throw new ConversationEndedException("Conversation " + conversation.getConversationID() + " has expired."); + } + + // if this is a local wire then schedule conversation timeouts based on the timeout + // parameters from the service implementation. If this isn't a local wire then + // the RuntimeWireInvoker will take care of this + if (wire.getTarget().getComponent() != null) { + conversation.updateLastReferencedTime(); + } + + msg.getFrom().getReferenceParameters().setConversationID(conversation.getConversationID()); + + } + + /** + * Post-invoke for the conversation handling + * @param wire + * @param operation + * @throws TargetDestructionException + */ + @SuppressWarnings("unchecked") + private void conversationPostInvoke(Message msg, RuntimeWire wire, boolean abnormalEndConversation) + throws TargetDestructionException { + Operation operation = msg.getOperation(); + ConversationSequence sequence = operation.getConversationSequence(); + // We check that conversation has not already ended as there is only one + // conversation manager in the runtime and so, in the case of remote bindings, + // the conversation will already have been stopped when we get back to the client + if ((sequence == ConversationSequence.CONVERSATION_END || abnormalEndConversation) && (conversation.getState() != ConversationState.ENDED)) { + + // remove conversation id from scope container + ScopeContainer scopeContainer = getConversationalScopeContainer(wire); + + if (scopeContainer != null) { + scopeContainer.remove(conversation.getConversationID()); + } + + conversation.end(); + } + } + + private ScopeContainer getConversationalScopeContainer(RuntimeWire wire) { + ScopeContainer scopeContainer = null; + + RuntimeComponent runtimeComponent = wire.getSource().getComponent(); + + if (runtimeComponent instanceof ScopedRuntimeComponent) { + ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)runtimeComponent; + ScopeContainer tmpScopeContainer = scopedRuntimeComponent.getScopeContainer(); + + if ((tmpScopeContainer != null) && (tmpScopeContainer.getScope() == Scope.CONVERSATION)) { + scopeContainer = tmpScopeContainer; + } + } + + return scopeContainer; + } + + /** + * Creates a new conversation id + * + * @return the conversation id + */ + private Object createConversationID() { + if (getConversationID() != null) { + return getConversationID(); + } else { + return UUID.randomUUID().toString(); + } + } + + /** + * @return the callableReference + */ + public CallableReference getCallableReference() { + return callableReference; + } + + /** + * @param callableReference the callableReference to set + */ + public void setCallableReference(CallableReference callableReference) { + this.callableReference = callableReference; + } + + /** + * Minimal wrapper for a callback object contained in a ServiceReference + */ + private static class CallbackObjectWrapper implements InstanceWrapper { + + private T instance; + + private CallbackObjectWrapper(T instance) { + this.instance = instance; + } + + public T getInstance() { + return instance; + } + + public void start() { + // do nothing + } + + public void stop() { + // do nothing + } + + } + + /** + * Creates a copy of arguments. Holder values are promoted to T. + * Note. It is essential that arg Holders not be destroyed here. + * PromotedArgs should not destroy holders. They are used on response return. + * @param args containing Holders and other objects. + * @return Object [] + */ + protected static Object[] promoteHolderArgs(Operation operation, Object[] args) { + if (args == null) + return args; + + Object[] promotedArgs = new Object[args.length]; + List modes = operation.getParameterModes(); + for (int i = 0; i < args.length; i++) { + Object argument = args[i]; + if (argument != null) { + if (modes.get(i) != ParameterMode.IN) { + promotedArgs[i] = ((Holder)argument).value; + } else { + promotedArgs[i] = args[i]; + } + + } + } + return promotedArgs; + } + + /** + * Given an Object, tells if it is a Holder by comparing to "javax.xml.ws.Holder" + * @param testClass + * @return boolean stating whether Object is a Holder type. + */ + protected static boolean isHolder(Object object) { + return Holder.class.isInstance(object); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java new file mode 100644 index 0000000000..a2cbd1365b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.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.sca.core.invocation; + +import java.lang.reflect.InvocationHandler; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.List; +import java.util.HashMap; + +import org.apache.tuscany.sca.core.invocation.SCAProxy; +import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; +import org.osoa.sca.ServiceReference; + +/** + * the default implementation of a wire service that uses JDK dynamic proxies + * + * @version $Rev$ $Date$ + */ +public class JDKProxyFactory implements ProxyFactory { + protected InterfaceContractMapper contractMapper; + private MessageFactory messageFactory; + + public JDKProxyFactory(MessageFactory messageFactory, InterfaceContractMapper mapper) { + this.contractMapper = mapper; + this.messageFactory = messageFactory; + } + + /** + * The original createProxy method assumes that the proxy doesn't want to + * share conversation state so sets the conversation object to null + */ + public T createProxy(Class interfaze, RuntimeWire wire) throws ProxyCreationException { + ServiceReference serviceReference = new ServiceReferenceImpl(interfaze, wire, this); + return createProxy(serviceReference); + } + + public T createProxy(CallableReference callableReference) throws ProxyCreationException { + assert callableReference != null; + final Class interfaze = callableReference.getBusinessInterface(); + InvocationHandler handler = new JDKInvocationHandler(messageFactory, callableReference); + // Allow privileged access to class loader. Requires RuntimePermission in security policy. + ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction() { + public ClassLoader run() { + return interfaze.getClassLoader(); + } + }); + Object proxy = SCAProxy.newProxyInstance(cl, new Class[] {interfaze}, handler); + ((CallableReferenceImpl)callableReference).setProxy(proxy); + return interfaze.cast(proxy); + } + + public T createCallbackProxy(Class interfaze, List wires) throws ProxyCreationException { + CallbackReferenceImpl callbackReference = CallbackReferenceImpl.newInstance(interfaze, this, wires); + return callbackReference != null ? createCallbackProxy(callbackReference) : null; + } + + public T createCallbackProxy(CallbackReferenceImpl callbackReference) throws ProxyCreationException { + assert callbackReference != null; + Class interfaze = callbackReference.getBusinessInterface(); + InvocationHandler handler = new JDKCallbackInvocationHandler(messageFactory, callbackReference); + ClassLoader cl = interfaze.getClassLoader(); + Object proxy = SCAProxy.newProxyInstance(cl, new Class[] {interfaze}, handler); + callbackReference.setProxy(proxy); + return interfaze.cast(proxy); + } + + public > R cast(B target) throws IllegalArgumentException { + InvocationHandler handler = SCAProxy.getInvocationHandler(target); + if (handler instanceof JDKInvocationHandler) { + return (R)((JDKInvocationHandler)handler).getCallableReference(); + } else { + throw new IllegalArgumentException("The object is not a known proxy."); + } + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#isProxyClass(java.lang.Class) + */ + public boolean isProxyClass(Class clazz) { + return SCAProxy.isProxyClass(clazz); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java new file mode 100644 index 0000000000..6e182a6a14 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.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.sca.core.invocation; + +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; + +/** + * Implementation of MessageFactory. + * + * @version $Rev$ $Date$ + */ +public class MessageFactoryImpl implements MessageFactory { + + public Message createMessage() { + return new MessageImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java new file mode 100644 index 0000000000..ca2bf051c8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.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.sca.core.invocation; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; + +/** + * The default implementation of a message flowed through a wire during an invocation + * + * @version $Rev $Date$ + */ +public class MessageImpl implements Message { + private Object bindingContext; + private List headers = new ArrayList(); + private Object body; + private Object messageID; + private boolean isFault; + private Operation operation; + + private EndpointReference from; + private EndpointReference to; + + public MessageImpl() { + this.from = new EndpointReferenceImpl("/"); + this.to = new EndpointReferenceImpl("/"); + } + + @SuppressWarnings("unchecked") + public T getBody() { + return (T)body; + } + + public void setBody(T body) { + this.isFault = false; + this.body = body; + } + + public Object getMessageID() { + return messageID; + } + + public void setMessageID(Object messageId) { + this.messageID = messageId; + } + + public boolean isFault() { + return isFault; + } + + public void setFaultBody(Object fault) { + this.isFault = true; + this.body = fault; + } + + public EndpointReference getFrom() { + return from; + } + + public void setFrom(EndpointReference from) { + this.from = from; + } + + public EndpointReference getTo() { + return to; + } + + public void setTo(EndpointReference to) { + this.to = to; + } + + public Operation getOperation() { + return operation; + } + + public void setOperation(Operation op) { + this.operation = op; + } + + public List getHeaders() { + return headers; + } + + @SuppressWarnings("unchecked") + public T getBindingContext() { + return (T)bindingContext; + } + + public void setBindingContext(T bindingContext) { + this.bindingContext = bindingContext; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java new file mode 100644 index 0000000000..733544d387 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.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.sca.core.invocation; + + +/** + * Thrown when an {@link org.apache.tuscany.sca.core.factory.model.Operation} cannot be mapped to a method on an interface + * @version $Rev$ $Date$ + */ +public class NoMethodForOperationException extends ProxyCreationException { + private static final long serialVersionUID = 5116536602309483679L; + + public NoMethodForOperationException() { + } + + public NoMethodForOperationException(String message) { + super(message); + } + + public NoMethodForOperationException(String message, Throwable cause) { + super(message, cause); + } + + public NoMethodForOperationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java new file mode 100644 index 0000000000..d6911281c8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Adds non-blocking behavior to an invocation chain + * + * @version $Rev$ $Date$ + */ +public class NonBlockingInterceptor implements Interceptor { + + private static final Message RESPONSE = new ImmutableMessage(); + + /** + * The JDK logger that will be used to log messages. + */ + private static final Logger LOGGER = Logger.getLogger(NonBlockingInterceptor.class.getName()); + + private WorkScheduler workScheduler; + private Invoker next; + + public NonBlockingInterceptor(WorkScheduler workScheduler) { + this.workScheduler = workScheduler; + } + + public NonBlockingInterceptor(WorkScheduler workScheduler, Interceptor next) { + this.workScheduler = workScheduler; + this.next = next; + } + + /** + * Sets desired workScheduler to NonBlockingInterceptor. This is a useful function for the extension framework + * to set desired workmanager on the InvocationChain, other than default workmanager which is set per Tuscany runtime. + * Using this function, extension framework can set desired workmanager on InvocationChain during post wire processing. + * @param workScheduler workScheduler which contains workmanager + */ + public void setWorkScheduler(WorkScheduler workScheduler){ + this.workScheduler = workScheduler; + } + + public Message invoke(final Message msg) { + // Schedule the invocation of the next interceptor in a new Work instance + try { + workScheduler.scheduleWork(new Runnable() { + public void run() { + Message context = ThreadMessageContext.setMessageContext(msg); + try { + Message response = null; + + Throwable ex = null; + try { + response = next.invoke(msg); + } catch (Throwable t) { + ex = t; + } + + // Tuscany-2225 - Did the @OneWay method complete successfully? + // (i.e. no exceptions) + if (response != null && response.isFault()) { + // The @OneWay method threw an Exception. Lets log it and + // then pass it on to the WorkScheduler so it can notify any + // listeners + ex = (Throwable)response.getBody(); + } + if (ex != null) { + LOGGER.log(Level.SEVERE, "Exception from @OneWay invocation", ex); + throw new ServiceRuntimeException("Exception from @OneWay invocation", ex); + } + } finally { + ThreadMessageContext.setMessageContext(context); + } + } + }); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + return RESPONSE; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + /** + * A dummy message passed back on an invocation + */ + private static class ImmutableMessage implements Message { + + @SuppressWarnings("unchecked") + public Object getBody() { + return null; + } + + public void setBody(Object body) { + if (body != null) { + throw new UnsupportedOperationException(); + } + } + + public void setCallbackWires(LinkedList wires) { + + } + + public Object getMessageID() { + return null; + } + + public void setMessageID(Object messageId) { + throw new UnsupportedOperationException(); + } + + public boolean isFault() { + return false; + } + + public void setFaultBody(Object fault) { + throw new UnsupportedOperationException(); + } + + public EndpointReference getFrom() { + return null; + } + + public EndpointReference getTo() { + return null; + } + + public void setFrom(EndpointReference from) { + throw new UnsupportedOperationException(); + } + + public void setTo(EndpointReference to) { + throw new UnsupportedOperationException(); + } + + public Operation getOperation() { + return null; + } + + public void setOperation(Operation op) { + throw new UnsupportedOperationException(); + } + + /** + * @see org.apache.tuscany.sca.invocation.Message#getReplyTo() + */ + public EndpointReference getReplyTo() { + return null; + } + + public Map getQoSContext() { + return null; + } + + public List getHeaders() { + return null; + } + + public T getBindingContext() { + return null; + } + + public void setBindingContext(T bindingContext) { + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java new file mode 100644 index 0000000000..a3c8429c7b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java @@ -0,0 +1,298 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.invocation; + +import static org.apache.tuscany.sca.invocation.Phase.IMPLEMENTATION; +import static org.apache.tuscany.sca.invocation.Phase.IMPLEMENTATION_POLICY; +import static org.apache.tuscany.sca.invocation.Phase.REFERENCE; +import static org.apache.tuscany.sca.invocation.Phase.REFERENCE_BINDING; +import static org.apache.tuscany.sca.invocation.Phase.REFERENCE_BINDING_POLICY; +import static org.apache.tuscany.sca.invocation.Phase.REFERENCE_BINDING_TRANSPORT; +import static org.apache.tuscany.sca.invocation.Phase.REFERENCE_BINDING_WIREFORMAT; +import static org.apache.tuscany.sca.invocation.Phase.REFERENCE_INTERFACE; +import static org.apache.tuscany.sca.invocation.Phase.REFERENCE_POLICY; +import static org.apache.tuscany.sca.invocation.Phase.SERVICE; +import static org.apache.tuscany.sca.invocation.Phase.SERVICE_BINDING; +import static org.apache.tuscany.sca.invocation.Phase.SERVICE_BINDING_OPERATION_SELECTOR; +import static org.apache.tuscany.sca.invocation.Phase.SERVICE_BINDING_POLICY; +import static org.apache.tuscany.sca.invocation.Phase.SERVICE_BINDING_TRANSPORT; +import static org.apache.tuscany.sca.invocation.Phase.SERVICE_BINDING_WIREFORMAT; +import static org.apache.tuscany.sca.invocation.Phase.SERVICE_INTERFACE; +import static org.apache.tuscany.sca.invocation.Phase.SERVICE_POLICY; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +import org.apache.tuscany.sca.invocation.Phase; +import org.osoa.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class PhaseManager { + private static final Logger log = Logger.getLogger(PhaseManager.class.getName()); + + public static final String STAGE_REFERENCE = "reference"; + public static final String STAGE_REFERENCE_BINDING = "reference.binding"; + public static final String STAGE_SERVICE_BINDING = "service.binding"; + public static final String STAGE_SERVICE = "service"; + public static final String STAGE_IMPLEMENTATION = "implementation"; + + private static final String[] SYSTEM_REFERENCE_PHASES = + {REFERENCE, REFERENCE_INTERFACE, REFERENCE_POLICY, REFERENCE_BINDING}; + + private static final String[] SYSTEM_REFERENCE_BINDING_PHASES = + {REFERENCE_BINDING_WIREFORMAT, REFERENCE_BINDING_POLICY, REFERENCE_BINDING_TRANSPORT}; + + private static final String[] SYSTEM_SERVICE_BINDING_PHASES = + {SERVICE_BINDING_TRANSPORT, SERVICE_BINDING_OPERATION_SELECTOR, SERVICE_BINDING_WIREFORMAT, SERVICE_BINDING_POLICY}; + + private static final String[] SYSTEM_SERVICE_PHASES = + {SERVICE_BINDING, SERVICE_POLICY, SERVICE_INTERFACE, SERVICE}; + + private static final String[] SYSTEM_IMPLEMENTATION_PHASES = {IMPLEMENTATION_POLICY, IMPLEMENTATION}; + + private String pattern = Phase.class.getName(); + private Map stages; + private List phases; + + public class Stage { + private String name; + private PhaseSorter sorter = new PhaseSorter(); + private Set firstSet = new HashSet(); + private Set lastSet = new HashSet(); + private List phases = new ArrayList(); + + public Stage(String name) { + super(); + this.name = name; + } + + public String getName() { + return name; + } + + public PhaseSorter getSorter() { + return sorter; + } + + public Set getFirstSet() { + return firstSet; + } + + public Set getLastSet() { + return lastSet; + } + + public List getPhases() { + return phases; + } + + @Override + public String toString() { + return name + phases; + } + } + + // For unit test purpose + PhaseManager(String pattern) { + super(); + this.pattern = pattern; + } + + public PhaseManager() { + } + + private List getPhases(String stage) { + Stage s = getStages().get(stage); + return s == null ? null : s.getPhases(); + } + + public List getReferencePhases() { + return getPhases(STAGE_REFERENCE); + } + + public List getServicePhases() { + return getPhases(STAGE_SERVICE); + } + + public List getReferenceBindingPhases() { + return getPhases(STAGE_REFERENCE_BINDING); + } + + public List getServiceBindingPhases() { + return getPhases(STAGE_SERVICE_BINDING); + } + + public List getImplementationPhases() { + return getPhases(STAGE_IMPLEMENTATION); + } + + public synchronized List getAllPhases() { + if (phases == null) { + phases = new ArrayList(); + phases.addAll(getReferencePhases()); + phases.addAll(getReferenceBindingPhases()); + phases.addAll(getServiceBindingPhases()); + phases.addAll(getServicePhases()); + phases.addAll(getImplementationPhases()); + } + return phases; + } + + public synchronized Map getStages() { + if (stages != null) { + return stages; + } + init(); + + Set services; + try { + services = ServiceDiscovery.getInstance().getServiceDeclarations(pattern); + } catch (IOException e) { + throw new ServiceRuntimeException(e); + } + + for (ServiceDeclaration d : services) { + if (log.isLoggable(Level.FINE)) { + log.fine(d.getLocation() + ": " + d.getAttributes()); + } + String name = d.getAttributes().get("name"); + if (name == null) { + throw new ServiceRuntimeException("Required attribute 'name' is missing."); + } + String stageName = d.getAttributes().get("stage"); + if (stageName == null) { + throw new ServiceRuntimeException("Required attribute 'stage' is missing."); + } + Stage stage = stages.get(stageName); + if (stage == null) { + throw new ServiceRuntimeException("Invalid stage: " + stage); + } + PhaseSorter graph = stage.getSorter(); + Set firstSet = stage.getFirstSet(), lastSet = stage.getLastSet(); + + String before = d.getAttributes().get("before"); + String after = d.getAttributes().get("after"); + if (before != null) { + StringTokenizer tokenizer = new StringTokenizer(before); + while (tokenizer.hasMoreTokens()) { + String p = tokenizer.nextToken(); + if (!"*".equals(p)) { + graph.addEdge(name, p); + } else { + firstSet.add(name); + } + } + } + if (after != null) { + StringTokenizer tokenizer = new StringTokenizer(after); + while (tokenizer.hasMoreTokens()) { + String p = tokenizer.nextToken(); + if (!"*".equals(p)) { + graph.addEdge(p, name); + } else { + lastSet.add(name); + } + } + } + graph.addVertext(name); + if(firstSet.size()>1) { + log.warning("More than one phases are declared to be first: "+firstSet); + } + for (String s : firstSet) { + for (String v : new HashSet(graph.getVertices().keySet())) { + if (!firstSet.contains(v)) { + graph.addEdge(s, v); + } + } + } + if(lastSet.size()>1) { + log.warning("More than one phases are declared to be the last: "+lastSet); + } + for (String s : lastSet) { + for (String v : new HashSet(graph.getVertices().keySet())) { + if (!lastSet.contains(v)) { + graph.addEdge(v, s); + } + } + } + + } + + for (Stage s : stages.values()) { + List phases = s.getSorter().topologicalSort(false); + s.getPhases().clear(); + s.getPhases().addAll(phases); + } + if (log.isLoggable(Level.FINE)) { + log.fine("Stages: " + stages); + } + return stages; + } + + private void init() { + stages = new HashMap(); + + Stage referenceStage = new Stage(STAGE_REFERENCE); + for (int i = 1; i < SYSTEM_REFERENCE_PHASES.length; i++) { + referenceStage.getSorter().addEdge(SYSTEM_REFERENCE_PHASES[i - 1], SYSTEM_REFERENCE_PHASES[i]); + } + referenceStage.getLastSet().add(REFERENCE_BINDING); + stages.put(referenceStage.getName(), referenceStage); + + Stage referenceBindingStage = new Stage(STAGE_REFERENCE_BINDING); + for (int i = 1; i < SYSTEM_REFERENCE_BINDING_PHASES.length; i++) { + referenceBindingStage.getSorter().addEdge(SYSTEM_REFERENCE_BINDING_PHASES[i - 1], SYSTEM_REFERENCE_BINDING_PHASES[i]); + } + stages.put(referenceBindingStage.getName(), referenceBindingStage); + + Stage serviceBindingStage = new Stage(STAGE_SERVICE_BINDING); + for (int i = 1; i < SYSTEM_SERVICE_BINDING_PHASES.length; i++) { + serviceBindingStage.getSorter().addEdge(SYSTEM_SERVICE_BINDING_PHASES[i - 1], SYSTEM_SERVICE_BINDING_PHASES[i]); + } + stages.put(serviceBindingStage.getName(), serviceBindingStage); + + + Stage serviceStage = new Stage(STAGE_SERVICE); + for (int i = 1; i < SYSTEM_SERVICE_PHASES.length; i++) { + serviceStage.getSorter().addEdge(SYSTEM_SERVICE_PHASES[i - 1], SYSTEM_SERVICE_PHASES[i]); + } + stages.put(serviceStage.getName(), serviceStage); + + Stage implementationStage = new Stage(STAGE_IMPLEMENTATION); + for (int i = 1; i < SYSTEM_IMPLEMENTATION_PHASES.length; i++) { + implementationStage.getSorter().addEdge(SYSTEM_IMPLEMENTATION_PHASES[i - 1], + SYSTEM_IMPLEMENTATION_PHASES[i]); + } + implementationStage.getLastSet().add(IMPLEMENTATION); + stages.put(implementationStage.getName(), implementationStage); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java new file mode 100644 index 0000000000..fc4bea3d9f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.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.sca.core.invocation; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Directed, weighted graph + * + * @param The type of vertex object + * @param The type of edge object + * + * @version $Rev$ $Date$ + */ +public class PhaseSorter implements Cloneable { + private final Map vertices = new HashMap(); + + /** + * Vertex of a graph + */ + public final class Vertex { + private V value; + + // TODO: Do we want to support multiple edges for a vertex pair? If so, + // we should use a List instead of Map + private Map outEdges = new HashMap(); + private Map inEdges = new HashMap(); + + private Vertex(V value) { + this.value = value; + } + + @Override + public String toString() { + return "(" + value + ")"; + } + + public V getValue() { + return value; + } + + public Map getOutEdges() { + return outEdges; + } + + public Map getInEdges() { + return inEdges; + } + + } + + /** + * An Edge connects two vertices in one direction + */ + public final class Edge { + private Vertex sourceVertex; + + private Vertex targetVertex; + + public Edge(Vertex source, Vertex target) { + this.sourceVertex = source; + this.targetVertex = target; + } + + @Override + public String toString() { + return sourceVertex + "->" + targetVertex; + } + + public Vertex getTargetVertex() { + return targetVertex; + } + + public void setTargetVertex(Vertex vertex) { + this.targetVertex = vertex; + } + + public Vertex getSourceVertex() { + return sourceVertex; + } + + public void setSourceVertex(Vertex sourceVertex) { + this.sourceVertex = sourceVertex; + } + } + + public void addEdge(V source, V target) { + Vertex s = getVertex(source); + if (s == null) { + s = new Vertex(source); + vertices.put(source, s); + } + Vertex t = getVertex(target); + if (t == null) { + t = new Vertex(target); + vertices.put(target, t); + } + Edge edge = new Edge(s, t); + s.outEdges.put(t, edge); + t.inEdges.put(s, edge); + } + + public void addVertext(V source) { + Vertex s = getVertex(source); + if (s == null) { + s = new Vertex(source); + vertices.put(source, s); + } + } + + public Vertex getVertex(V source) { + Vertex s = vertices.get(source); + return s; + } + + public boolean removeEdge(V source, V target) { + Vertex s = getVertex(source); + if (s == null) { + return false; + } + + Vertex t = getVertex(target); + if (t == null) { + return false; + } + + return s.outEdges.remove(t) != null && t.inEdges.remove(s) != null; + + } + + public void removeEdge(Edge edge) { + edge.sourceVertex.outEdges.remove(edge.targetVertex); + edge.targetVertex.inEdges.remove(edge.sourceVertex); + } + + public void removeVertex(Vertex vertex) { + vertices.remove(vertex.getValue()); + for (Edge e : new ArrayList(vertex.outEdges.values())) { + removeEdge(e); + } + for (Edge e : new ArrayList(vertex.inEdges.values())) { + removeEdge(e); + } + } + + public Edge getEdge(Vertex source, Vertex target) { + return source.outEdges.get(target); + } + + public Edge getEdge(V source, V target) { + Vertex sv = getVertex(source); + if (sv == null) { + return null; + } + Vertex tv = getVertex(target); + if (tv == null) { + return null; + } + return getEdge(getVertex(source), getVertex(target)); + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + for (Vertex v : vertices.values()) { + sb.append(v.outEdges.values()).append("\n"); + } + return sb.toString(); + } + + public Map getVertices() { + return vertices; + } + + public void addGraph(PhaseSorter otherGraph) { + for (Vertex v : otherGraph.vertices.values()) { + for (Edge e : v.outEdges.values()) { + addEdge(e.sourceVertex.value, e.targetVertex.value); + } + } + } + + private Vertex getFirst() { + for (Vertex v : vertices.values()) { + if (v.inEdges.isEmpty()) { + return v; + } + } + if (!vertices.isEmpty()) { + throw new IllegalArgumentException("Circular ordering has been detected: " + toString()); + } else { + return null; + } + } + + public List topologicalSort(boolean readOnly) { + PhaseSorter graph = (!readOnly) ? this : (PhaseSorter)clone(); + List list = new ArrayList(); + while (true) { + Vertex v = graph.getFirst(); + if (v == null) { + break; + } + list.add(v.getValue()); + graph.removeVertex(v); + } + + return list; + } + + @Override + public Object clone() { + PhaseSorter copy = new PhaseSorter(); + copy.addGraph(this); + return copy; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java new file mode 100644 index 0000000000..0b36b178f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.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.sca.core.invocation; + +import org.apache.tuscany.sca.core.factory.ObjectCreationException; + + +/** + * Denotes an error creating a proxy + * + * @version $Rev$ $Date$ + */ +public class ProxyCreationException extends ObjectCreationException { + private static final long serialVersionUID = 8002454344828513781L; + + public ProxyCreationException() { + super(); + } + + public ProxyCreationException(String message, Throwable cause) { + super(message, cause); + } + + public ProxyCreationException(String message) { + super(message); + } + + public ProxyCreationException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java new file mode 100644 index 0000000000..cb836e42c1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.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.sca.core.invocation; + +import java.util.List; + +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; + +/** + * Creates proxies that implement Java interfaces and invocation handlers for fronting wires + * + * @version $Rev$ $Date$ + */ + +public interface ProxyFactory { + + /** + * 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 + */ + T createProxy(Class interfaze, RuntimeWire wire) throws ProxyCreationException; + + /** + * Creates a Java proxy for the given CallableReference + * + * @param callableReference The CallableReference + * @return the proxy + * @throws ProxyCreationException + */ + T createProxy(CallableReference callableReference) throws ProxyCreationException; + + /** + * Creates a Java proxy for the service contract callback + * + * @param interfaze the interface the proxy should implement + * @return the proxy + * @throws ProxyCreationException + */ + T createCallbackProxy(Class interfaze, List wires) throws ProxyCreationException; + + /** + * Creates a Java proxy for the given callback reference + * + * @param callableReference The CallableReference + * @return the proxy + * @throws ProxyCreationException + */ + T createCallbackProxy(CallbackReferenceImpl callbackReference) throws ProxyCreationException; + + /** + * Cast a proxy to a CallableReference. + * + * @param target a proxy generated by this implementation + * @return a CallableReference (or subclass) equivalent to this proxy + * @throws IllegalArgumentException if the object supplied is not a proxy + */ + > R cast(B target) throws IllegalArgumentException; + + /** + * Test if a given class is a generated proxy class by this factory + * @param clazz A java class or interface + * @return true if the class is a generated proxy class by this factory + */ + boolean isProxyClass(Class clazz); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java new file mode 100644 index 0000000000..875a252798 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.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.sca.core.invocation; + + +/** + * The extension point to plug in proxy factories + * @version $Rev$ $Date$ + */ +public interface ProxyFactoryExtensionPoint { + + /** + * Get the proxy factory for java interfaces + * @return + */ + ProxyFactory getInterfaceProxyFactory(); + + /** + * Get the proxy factory for java classes + * @return + */ + ProxyFactory getClassProxyFactory(); + + /** + * Set the proxy factory for java interfaces + * @param factory + */ + void setInterfaceProxyFactory(ProxyFactory factory); + + /** + * Set the proxy factory for java classes + * @param factory + */ + void setClassProxyFactory(ProxyFactory factory); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java new file mode 100644 index 0000000000..906628ee32 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java @@ -0,0 +1,264 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.invocation; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.core.conversation.ConversationManager; +import org.apache.tuscany.sca.core.conversation.ConversationState; +import org.apache.tuscany.sca.core.conversation.ExtendedConversation; +import org.apache.tuscany.sca.core.scope.Scope; +import org.apache.tuscany.sca.core.scope.ScopeContainer; +import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent; +import org.apache.tuscany.sca.core.scope.TargetDestructionException; +import org.apache.tuscany.sca.core.scope.TargetResolutionException; +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.ReferenceParameters; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.ConversationEndedException; +import org.osoa.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeWireInvoker implements Invoker{ + protected ConversationManager conversationManager; + protected boolean conversational; + protected ExtendedConversation conversation; + protected MessageFactory messageFactory; + protected Object conversationID; + protected Object callbackID; + protected Object callbackObject; + protected RuntimeWire wire; + + public RuntimeWireInvoker(MessageFactory messageFactory, ConversationManager conversationManager, RuntimeWire wire) { + this.messageFactory = messageFactory; + this.wire = wire; + this.conversationManager = conversationManager; + init(wire); + } + + protected void init(RuntimeWire wire) { + if (wire != null) { + ReferenceParameters parameters = wire.getSource().getReferenceParameters(); + this.callbackID = parameters.getCallbackID(); + this.callbackObject = parameters.getCallbackReference(); + this.conversationID = parameters.getConversationID(); + InterfaceContract contract = wire.getSource().getInterfaceContract(); + this.conversational = contract.getInterface().isConversational(); + } + } + + /* + * TODO - Introduced to allow the RuntimeWireInvoker to sit on the end of the + * service binding chain. Runtime wire invoke needs splitting up into + * separate conversation, callback interceptors etc. + */ + public Message invoke(Message msg) { + + try { + Object response = invoke(msg.getOperation(),msg); + // Hack to put the response back in a message. + // shouldn't take it out of the response message in the first place + msg.setBody(response); + } catch (InvocationTargetException e) { +// throw new ServiceRuntimeException(e); + } + + return msg; + } + + public Object invoke(Operation operation, Message msg) throws InvocationTargetException { + return invoke(wire, operation, msg); + } + + public Object invoke(RuntimeWire wire, Operation operation, Message msg) throws InvocationTargetException { + RuntimeWire runtimeWire = wire == null ? this.wire : wire; + InvocationChain chain = runtimeWire.getInvocationChain(operation); + return invoke(chain, msg, runtimeWire); + } + + protected Object invoke(InvocationChain chain, Message msg, RuntimeWire wire) throws InvocationTargetException { + EndpointReference from = msg.getFrom(); + EndpointReference epFrom = wire.getSource(); + if (from != null) { + from.mergeEndpoint(epFrom); + } else { + msg.setFrom(epFrom); + } + msg.setTo(wire.getTarget()); + + Invoker headInvoker = chain.getHeadInvoker(); + Operation operation = chain.getTargetOperation(); + msg.setOperation(operation); + + Message msgContext = ThreadMessageContext.getMessageContext(); + Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID(); + + ThreadMessageContext.setMessageContext(msg); + try { + conversationPreinvoke(msg); + // handleCallback(msg, currentConversationID); + // dispatch the wire down the chain and get the response + Message resp = headInvoker.invoke(msg); + Object body = resp.getBody(); + if (resp.isFault()) { + throw new InvocationTargetException((Throwable)body); + } + return body; + } catch (InvocationTargetException e) { + throw e; + } catch (Throwable e) { + throw new ServiceRuntimeException(e); + } finally { + try { + conversationPostInvoke(msg); + } catch (TargetDestructionException e) { + throw new ServiceRuntimeException(e); + } finally { + ThreadMessageContext.setMessageContext(msgContext); + } + } + } + + /** + * @param msgContext + */ + protected EndpointReference getCallbackEndpoint(Message msgContext) { + EndpointReference from = msgContext.getFrom(); + return from == null ? null : from.getReferenceParameters().getCallbackReference(); + } + + /** + * Pre-invoke for the conversation handling + * @param msg + * @throws TargetResolutionException + */ + private void conversationPreinvoke(Message msg) { + if (conversational) { + ReferenceParameters parameters = msg.getFrom().getReferenceParameters(); + // in some cases the ConversationID that should be used comes in with the + // message, e.g. when ws binding is in use. + Object convID = parameters.getConversationID(); + if (convID != null) { + conversationID = convID; + } + conversation = conversationManager.getConversation(conversationID); + + if (conversation == null || conversation.getState() == ConversationState.ENDED) { + conversation = conversationManager.startConversation(conversationID); + conversation.initializeConversationAttributes(wire.getTarget().getComponent()); + } else if (conversation.conversationalAttributesInitialized() == false) { + conversation.initializeConversationAttributes(wire.getTarget().getComponent()); + } else if (conversation.isExpired()){ + throw new ConversationEndedException("Conversation has expired."); + } + + conversation.updateLastReferencedTime(); + + parameters.setConversationID(conversation.getConversationID()); + } + } + + /** + * Post-invoke for the conversation handling + * @param wire + * @param operation + * @throws TargetDestructionException + */ + @SuppressWarnings("unchecked") + private void conversationPostInvoke(Message msg) throws TargetDestructionException { + if (conversational) { + Operation operation = msg.getOperation(); + ConversationSequence sequence = operation.getConversationSequence(); + if (sequence == ConversationSequence.CONVERSATION_END) { + // in some cases the ConversationID that should be used comes in with the + // message, e.g. when ws binding is in use. + Object convID = msg.getFrom().getReferenceParameters().getConversationID(); + if (convID != null) { + conversationID = convID; + } + conversation = conversationManager.getConversation(conversationID); + + // remove conversation id from scope container + ScopeContainer scopeContainer = getConversationalScopeContainer(msg); + + if (scopeContainer != null) { + scopeContainer.remove(conversation.getConversationID()); + } + + conversation.end(); + } + } + } + + @SuppressWarnings("unchecked") + private ScopeContainer getConversationalScopeContainer(Message msg) { + ScopeContainer scopeContainer = null; + + RuntimeComponent component = msg.getTo().getComponent(); + + if (component instanceof ScopedRuntimeComponent) { + ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component; + ScopeContainer container = scopedRuntimeComponent.getScopeContainer(); + + if ((container != null) && (container.getScope() == Scope.CONVERSATION)) { + scopeContainer = container; + } + } + + return scopeContainer; + } + + + /** + * Minimal wrapper for a callback object contained in a ServiceReference + */ + private static class CallbackObjectWrapper implements InstanceWrapper { + + private T instance; + + private CallbackObjectWrapper(T instance) { + this.instance = instance; + } + + public T getInstance() { + return instance; + } + + public void start() { + // do nothing + } + + public void stop() { + // do nothing + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java new file mode 100644 index 0000000000..f2907638ad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.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.sca.core.invocation; + +import java.lang.ref.WeakReference; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Proxy; +import java.lang.reflect.Constructor; +import java.util.WeakHashMap; + +public class SCAProxy extends Proxy +{ + protected SCAProxy (InvocationHandler handler) { + super(handler); + } + + // This is a cache containing the proxy class constructor for each business interface. + // This improves performance compared to calling Proxy.newProxyInstance() + // every time that a proxy is needed. + private static WeakHashMap cache = new WeakHashMap>(); + + public static Object newProxyInstance(ClassLoader classloader, Class aclass[], InvocationHandler invocationhandler) + throws IllegalArgumentException + { + try { + if(invocationhandler == null) + throw new NullPointerException(); + // Lookup cached constructor. aclass[0] is the reference's business interface. + Constructor proxyCTOR = null; + synchronized(cache) { + WeakReference ref = (WeakReference) cache.get(aclass[0]); + if (ref != null){ + proxyCTOR = ref.get(); + } + } + if(proxyCTOR == null) { + Class proxyClass = getProxyClass(classloader, aclass); + proxyCTOR = proxyClass.getConstructor(constructorParams); + synchronized(cache){ + cache.put(aclass[0],new WeakReference(proxyCTOR)); + } + } + return proxyCTOR.newInstance(new Object[] { invocationhandler }); + } + catch(NoSuchMethodException e) { + throw new InternalError(e.toString()); + } + catch(IllegalAccessException e) { + throw new InternalError(e.toString()); + } + catch (InstantiationException e) { + throw new InternalError(e.toString()); + } + catch (InvocationTargetException e) { + throw new InternalError(e.toString()); + } + } + + private static final Class constructorParams[] = { InvocationHandler.class }; + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java new file mode 100644 index 0000000000..2c4d657882 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.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.sca.core.invocation; + +/** + * Raised when an error is encountered during a target invocation + * + * @version $Rev$ $Date$ + */ +public class TargetInvocationException extends Exception { + + private static final long serialVersionUID = -6553427708442761743L; + + public TargetInvocationException() { + super(); + } + + public TargetInvocationException(String message, Throwable cause) { + super(message, cause); + } + + public TargetInvocationException(String message) { + super(message); + } + + public TargetInvocationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java new file mode 100644 index 0000000000..dd3a4f9ac3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.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.sca.core.invocation; + +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Class for tunnelling a WorkContext through the invocation of a user class. + * + * @version $Rev$ $Date$ + */ +public final class ThreadMessageContext { + + private static final ThreadLocal CONTEXT = new ThreadLocal() { + @Override + protected synchronized Message initialValue() { + Message msg = new MessageImpl(); + msg.setFrom(new EndpointReferenceImpl("/")); + return msg; + } + }; + + private ThreadMessageContext() { + } + + /** + * Set the WorkContext for the current thread. + * The current work context is returned and must be restored after the invocation is complete. + * Typical usage would be: + *
+     *   WorkContext old = PojoWorkContextTunnel.setThreadWorkContext(newContext);
+     *   try {
+     *      ... invoke user code ...
+     *   } finally {
+     *     PojoWorkContextTunnel.setThreadWorkContext(old);
+     *   }
+     * 
+ * @param context + * @return the current work context for the thread; this must be restored after the invocation is made + */ + public static Message setMessageContext(Message context) { + Message old = CONTEXT.get(); + CONTEXT.set(context); + return old; + } + + /** + * Returns the WorkContext for the current thread. + * + * @return the WorkContext for the current thread + */ + public static Message getMessageContext() { + return CONTEXT.get(); + } + + /** + * Removes and state from the current thread to ensure that + * any associated classloaders can be GCd + */ + public static void removeMessageContext() { + CONTEXT.remove(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java new file mode 100644 index 0000000000..246f9c45d6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.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.sca.core.invocation; + +import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; +import org.apache.tuscany.sca.core.factory.ObjectCreationException; +import org.apache.tuscany.sca.core.factory.ObjectFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Uses a wire to return an object instance + * + * @version $Rev$ $Date$ + */ +public class WireObjectFactory implements ObjectFactory { + private Class interfaze; + private RuntimeWire wire; + private ProxyFactory proxyService; + + /** + * Constructor. + * + * @param interfaze the interface to inject on the client + * @param wire the backing wire + * @param proxyService the wire service to create the proxy + * @throws NoMethodForOperationException + */ + public WireObjectFactory(Class interfaze, RuntimeWire wire, ProxyFactory proxyService) { + this.interfaze = interfaze; + this.wire = wire; + this.proxyService = proxyService; + } + + public T getInstance() throws ObjectCreationException { + return new ServiceReferenceImpl(interfaze, wire, proxyService).getProxy(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java new file mode 100644 index 0000000000..1168d1d0dd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java @@ -0,0 +1,200 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.scope; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Implements functionality common to scope contexts. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractScopeContainer implements ScopeContainer { + protected Map> wrappers = new ConcurrentHashMap>(); + protected final Scope scope; + + protected RuntimeComponent component; + protected volatile int lifecycleState = UNINITIALIZED; + + + public AbstractScopeContainer(Scope scope, RuntimeComponent component) { + this.scope = scope; + this.component = component; + } + + protected void checkInit() { + if (getLifecycleState() != RUNNING) { + throw new IllegalStateException("Scope container not running [" + getLifecycleState() + "]"); + } + } + + /** + * Creates a new physical instance of a component, wrapped in an + * InstanceWrapper. + * + * @param component the component whose instance should be created + * @return a wrapped instance that has been injected but not yet started + * @throws TargetResolutionException if there was a problem creating the + * instance + */ + protected InstanceWrapper createInstanceWrapper() throws TargetResolutionException { + ImplementationProvider implementationProvider = component.getImplementationProvider(); + if (implementationProvider instanceof ScopedImplementationProvider) { + return ((ScopedImplementationProvider)implementationProvider).createInstanceWrapper(); + } + return null; + } + + public InstanceWrapper getAssociatedWrapper(KEY contextId) throws TargetResolutionException { + return getWrapper(contextId); // TODO: what is this method supposed to do diff than getWrapper? + } + + public Scope getScope() { + return scope; + } + + public InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException { + return wrappers.get(contextId); + } + + public void addWrapperReference(KEY existingContextId, KEY newContextId) + throws TargetResolutionException { + // do nothing here. the conversational scope container implements this + } + + public void registerWrapper(InstanceWrapper wrapper, KEY contextId) throws TargetResolutionException { + // do nothing here. the conversational scope container implements this + } + + public void onEvent(Event event) { + } + + protected boolean isEagerInit() { + ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider(); + if (implementationProvider instanceof ScopedImplementationProvider) { + return ((ScopedImplementationProvider)implementationProvider).isEagerInit(); + } + return false; + } + + public void returnWrapper(InstanceWrapper wrapper, KEY contextId) throws TargetDestructionException { + } + + /** + * Default implementation of remove which does nothing + * + * @param contextId the identifier of the context to remove. + */ + public void remove(KEY contextId) + throws TargetDestructionException { + } + + public synchronized void start() { + int lifecycleState = getLifecycleState(); + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + setLifecycleState(RUNNING); + } + + public void startContext(KEY contextId) { + if(isEagerInit()) { + try { + getWrapper(contextId); + } catch (TargetResolutionException e) { + // + } + } + } + + public synchronized void stop() { + int lifecycleState = getLifecycleState(); + if (lifecycleState != RUNNING) { + throw new IllegalStateException("Scope in wrong state [" + lifecycleState + "]"); + } + setLifecycleState(STOPPED); + } + + public void stopContext(KEY contextId) { + wrappers.remove(contextId); + } + + @Override + public String toString() { + String s; + switch (lifecycleState) { + case ScopeContainer.CONFIG_ERROR: + s = "CONFIG_ERROR"; + break; + case ScopeContainer.ERROR: + s = "ERROR"; + break; + case ScopeContainer.INITIALIZING: + s = "INITIALIZING"; + break; + case ScopeContainer.INITIALIZED: + s = "INITIALIZED"; + break; + case ScopeContainer.RUNNING: + s = "RUNNING"; + break; + case ScopeContainer.STOPPING: + s = "STOPPING"; + break; + case ScopeContainer.STOPPED: + s = "STOPPED"; + break; + case ScopeContainer.UNINITIALIZED: + s = "UNINITIALIZED"; + break; + default: + s = "UNKNOWN"; + break; + } + return "In state [" + s + ']'; + } + + public RuntimeComponent getComponent() { + return component; + } + + public void setComponent(RuntimeComponent component) { + this.component = component; + } + + 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; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java new file mode 100644 index 0000000000..7a1965198a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * A scope context which manages atomic component instances keyed by composite + * + * @version $Rev$ $Date$ + */ +public class CompositeScopeContainer extends AbstractScopeContainer { + private InstanceWrapper wrapper; + + public CompositeScopeContainer(RuntimeComponent component) { + super(Scope.COMPOSITE, component); + } + + @Override + public synchronized void stop() { + super.stop(); + if (wrapper != null) { + try { + wrapper.stop(); + } catch (TargetDestructionException e) { + throw new IllegalStateException(e); + } + } + wrapper = null; + } + + @Override + public synchronized InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException { + if (wrapper == null) { + wrapper = createInstanceWrapper(); + try { + wrapper.start(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e) { + try { + wrapper.stop(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e2) { + } + wrapper = null; + throw new TargetInitializationException(e); + } + } + return wrapper; + } + + @Override + public InstanceWrapper getAssociatedWrapper(KEY contextId) throws TargetResolutionException { + if (wrapper == null) { + throw new TargetNotFoundException(component.getURI()); + } + return wrapper; + } + + @Override + public synchronized void start() { + super.start(); + if (isEagerInit()) { + try { + getWrapper(null); + } catch (TargetResolutionException e) { + throw new IllegalStateException(e); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java new file mode 100644 index 0000000000..786988613b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.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.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class CompositeScopeContainerFactory implements ScopeContainerFactory { + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new CompositeScopeContainer(component); + } + + public Scope getScope() { + return Scope.COMPOSITE; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java new file mode 100644 index 0000000000..3ae1ca51c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java @@ -0,0 +1,290 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.scope; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.core.conversation.ConversationListener; +import org.apache.tuscany.sca.core.conversation.ConversationManager; +import org.apache.tuscany.sca.core.conversation.ExtendedConversation; +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.store.Store; + +/** + * A scope context which manages atomic component instances keyed on ConversationID + * + * @version $Rev$ $Date$ + */ +public class ConversationalScopeContainer extends AbstractScopeContainer implements ConversationListener { + private ConversationManager conversationManager; + private Map instanceLifecycleCollection = + new ConcurrentHashMap(); + + public ConversationalScopeContainer(Store aStore, RuntimeComponent component) { + super(Scope.CONVERSATION, component); + + // Note: aStore is here to preserve the original factory interface. It is not currently used in this + // implementation since we do not support instance persistence. + + // Check System properties to see if timeout values have been specified. All timeout values + // will be specified in seconds. + // + + } + + + protected InstanceWrapper getInstanceWrapper(boolean create, Object contextId) throws TargetResolutionException { + + // we might get a null context if the target service has + // conversational scope but only its callback interface + // is conversational. In this case we need to invent a + // conversation Id here to store the service against + // and populate the thread context + if (contextId == null) { + contextId = UUID.randomUUID().toString(); + Message msgContext = ThreadMessageContext.getMessageContext(); + + if (msgContext != null) { + msgContext.getFrom().getReferenceParameters().setConversationID(contextId); + } + } + + InstanceLifeCycleWrapper anInstanceWrapper = this.instanceLifecycleCollection.get(contextId); + + if (anInstanceWrapper == null && !create) + return null; + + if (anInstanceWrapper == null) { + anInstanceWrapper = new InstanceLifeCycleWrapper(contextId); + this.instanceLifecycleCollection.put(contextId, anInstanceWrapper); + } + + return anInstanceWrapper.getInstanceWrapper(contextId); + + } + + @Override + public InstanceWrapper getWrapper(Object contextId) throws TargetResolutionException { + return getInstanceWrapper(true, contextId); + } + + /** + * This method allows a new context id to be registered alongside an existing one. This happens in + * one case, when a conversation includes a stateful callback. The client component instance + * must be registered against all outgoing conversation ids so that the component instance + * can be found when the callback arrives + * + * @param existingContextId the context id against which the component is already registered + * @param context this should be a conversation object so that the conversation can b stored + * and reset when the component instance is removed + */ + @Override + public void addWrapperReference(Object existingContextId, Object contextId) throws TargetResolutionException { + + + // get the instance wrapper via the existing id + InstanceLifeCycleWrapper existingInstanceWrapper = this.instanceLifecycleCollection.get(existingContextId); + InstanceLifeCycleWrapper newInstanceWrapper = this.instanceLifecycleCollection.get(contextId); + + // only add the extra reference once + if (newInstanceWrapper == null) { + // add the id to the list of ids that the wrapper holds. Used for reference + // counting and conversation resetting on destruction. + existingInstanceWrapper.addCallbackConversation(contextId); + + // add the reference to the collection + this.instanceLifecycleCollection.put(contextId, existingInstanceWrapper); + } + } + + @Override + public void registerWrapper(InstanceWrapper wrapper, Object contextId) throws TargetResolutionException { + // if a wrapper for a different instance is already registered for this contextId, remove it + InstanceLifeCycleWrapper anInstanceWrapper = this.instanceLifecycleCollection.get(contextId); + if (anInstanceWrapper != null) { + if (anInstanceWrapper.getInstanceWrapper(contextId).getInstance() != wrapper.getInstance()) { + remove(contextId); + } else { + return; + } + } + + anInstanceWrapper = new InstanceLifeCycleWrapper(wrapper, contextId); + this.instanceLifecycleCollection.put(contextId, anInstanceWrapper); + } + + // The remove is invoked when a conversation is explicitly ended. This can occur by using the @EndsConversation or API. + // In this case the instance is immediately removed. A new conversation will be started on the next operation + // associated with this conversationId's service reference. + // + @Override + public void remove(Object contextId) throws TargetDestructionException { + if (contextId != null) { + if (this.instanceLifecycleCollection.containsKey(contextId)) { + InstanceLifeCycleWrapper anInstanceLifeCycleWrapper = this.instanceLifecycleCollection.get(contextId); + this.instanceLifecycleCollection.remove(contextId); + anInstanceLifeCycleWrapper.removeInstanceWrapper(contextId); + } + } + } + + /* + * This is an inner class that keeps track of the lifecycle of a conversation scoped + * implementation instance. + * + */ + + private class InstanceLifeCycleWrapper { + private Object clientConversationId; + private List callbackConversations = new ArrayList(); + + private InstanceLifeCycleWrapper(Object contextId) throws TargetResolutionException { + this.clientConversationId = contextId; + this.createInstance(contextId); + } + + private InstanceLifeCycleWrapper(InstanceWrapper wrapper, Object contextId) throws TargetResolutionException { + this.clientConversationId = contextId; + wrappers.put(contextId, wrapper); + } + + + // Associates a callback conversation with this instance. Each time the scope container + // is asked to remove an object given a ontextId an associated conversation object will + // have its conversationId reset to null. When the list of ids is empty the component instance + // will be removed from the scope container + private void addCallbackConversation(Object conversationID) { + InstanceWrapper ctx = getInstanceWrapper(clientConversationId); + callbackConversations.add(conversationID); + wrappers.put(conversationID, ctx); + } + + // + // Return the backing implementation instance + // + private InstanceWrapper getInstanceWrapper(Object contextId) { + InstanceWrapper ctx = wrappers.get(contextId); + return ctx; + } + + private void removeInstanceWrapper(Object contextId) throws TargetDestructionException { + InstanceWrapper ctx = getInstanceWrapper(contextId); + wrappers.remove(contextId); + + // find out if we are dealing with the original client conversation id + // and reset accordingly + if ( ( clientConversationId != null ) && ( clientConversationId.equals(contextId)) ) { + clientConversationId = null; + } else { + // reset the conversationId in the conversation object if present + // so that and ending callback causes the conversation in the originating + // service reference in the client to be reset + callbackConversations.remove(contextId); + } + + // stop the component if this removes the last reference + if (clientConversationId == null && callbackConversations.isEmpty()) { + ctx.stop(); + } + } + + private void createInstance(Object contextId) throws TargetResolutionException { + InstanceWrapper instanceWrapper = createInstanceWrapper(); + instanceWrapper.start(); + wrappers.put(contextId, instanceWrapper); + } + + } + + /** + * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationEnded(org.apache.tuscany.sca.core.conversation.ExtendedConversation) + */ + public void conversationEnded(ExtendedConversation conversation) { + try { + remove(conversation.getConversationID()); + } catch (Exception ex) { + + } + } + + /** + * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationExpired(org.apache.tuscany.sca.core.conversation.ExtendedConversation) + */ + public void conversationExpired(ExtendedConversation conversation) { + + Object conversationId = conversation.getConversationID(); + InstanceLifeCycleWrapper ilcw = instanceLifecycleCollection.get(conversationId); + if (ilcw != null) { + // cycle through all the references to this instance and + // remove them from the underlying wrappers collection and + // from the lifecycle wrappers collection + + for (Object conversationID : ilcw.callbackConversations) { + try{ + ilcw.removeInstanceWrapper(conversationID); + remove(conversationID); + } catch(TargetDestructionException tde) { + System.out.println("Could not remove conversation id " + conversationID); + } + } + + + if (ilcw.clientConversationId != null) { + try{ + ilcw.removeInstanceWrapper(ilcw.clientConversationId); + remove(ilcw.clientConversationId); + } catch(TargetDestructionException tde) { + System.out.println("Could not remove conversation id " + ilcw.clientConversationId); + } + } + + } + + } + + /** + * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationStarted(org.apache.tuscany.sca.core.conversation.ExtendedConversation) + */ + public void conversationStarted(ExtendedConversation conversation) { + startContext(conversation.getConversationID()); + } + + /** + * @return the conversationManager + */ + public ConversationManager getConversationManager() { + return conversationManager; + } + + /** + * @param conversationManager the conversationManager to set + */ + public void setConversationManager(ConversationManager conversationManager) { + this.conversationManager = conversationManager; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java new file mode 100644 index 0000000000..a6663aba09 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.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.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.store.Store; + +/** + * @version $Rev$ $Date$ + */ +public class ConversationalScopeContainerFactory implements ScopeContainerFactory { + private Store store; + + public ConversationalScopeContainerFactory(Store store) { + super(); + this.store = store; + } + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new ConversationalScopeContainer(store, component); + } + + public Scope getScope() { + return Scope.CONVERSATION; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java new file mode 100644 index 0000000000..5ae8b94647 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.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.sca.core.scope; + +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.core.event.HttpSessionEnd; +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * A scope context which manages atomic component instances keyed on HTTP + * session + * + * @version $Rev$ $Date$ + */ +public class HttpSessionScopeContainer extends AbstractScopeContainer { + + public HttpSessionScopeContainer(RuntimeComponent component) { + super(Scope.SESSION, component); + } + + @Override + public void onEvent(Event event) { + checkInit(); + if (event instanceof HttpSessionEnd) { + //FIXME key is not used + //Object key = ((HttpSessionEnd)event).getSessionID(); + // FIXME: Remove the session id + } + } + + @Override + public synchronized void start() { + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + lifecycleState = RUNNING; + } + + @Override + public synchronized void stop() { + lifecycleState = STOPPED; + } + + protected InstanceWrapper getInstanceWrapper(boolean create) throws TargetResolutionException { +// Object key = workContext.getIdentifier(Scope.SESSION); + // FIXME: Need to fix this + Object key ="http-session-id"; + assert key != null : "HTTP session key not bound in work context"; + InstanceWrapper ctx = wrappers.get(key); + if (ctx == null && !create) { + return null; + } + if (ctx == null) { + ctx = super.createInstanceWrapper(); + ctx.start(); + wrappers.put(key, ctx); + } + return ctx; + } + + @Override + public InstanceWrapper getWrapper(Object contextId) throws TargetResolutionException { + return getInstanceWrapper(true); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java new file mode 100644 index 0000000000..49f89661b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.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.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class HttpSessionScopeContainerFactory implements ScopeContainerFactory { + + public HttpSessionScopeContainerFactory() { + super(); + } + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new HttpSessionScopeContainer(component); + } + + public Scope getScope() { + return Scope.SESSION; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java new file mode 100644 index 0000000000..8fdfcc63c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.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.sca.core.scope; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.core.event.RequestEnd; +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * A scope context which manages atomic component instances keyed on the current + * request context + * + * @version $Rev$ $Date$ + */ +public class RequestScopeContainer extends AbstractScopeContainer { + private final Map contexts; + + public RequestScopeContainer(RuntimeComponent component) { + super(Scope.REQUEST, component); + contexts = new ConcurrentHashMap(); + } + + @Override + public void onEvent(Event event) { + checkInit(); + if (event instanceof RequestEnd) { + // shutdownInstances(Thread.currentThread()); + } + } + + @Override + public synchronized void start() { + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + lifecycleState = RUNNING; + } + + @Override + public synchronized void stop() { + contexts.clear(); + // synchronized (destroyQueues) { + // destroyQueues.clear(); + // } + for (InstanceWrapper ctx : wrappers.values()) { + try { + ctx.stop(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e2) { + } + } + lifecycleState = STOPPED; + } + + protected InstanceWrapper getInstanceWrapper(boolean create) throws TargetResolutionException { + InstanceWrapper ctx = wrappers.get(Thread.currentThread()); + if (ctx == null && !create) { + return null; + } + if (ctx == null) { + ctx = super.createInstanceWrapper(); + try { + ctx.start(); + wrappers.put(Thread.currentThread(), ctx); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e) { + try { + ctx.stop(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e2) { + } + throw new TargetInitializationException(e); + } + } + return ctx; + } + + @Override + public InstanceWrapper getWrapper(Thread contextId) throws TargetResolutionException { + return getInstanceWrapper(true); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java new file mode 100644 index 0000000000..1cfb6b06a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.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.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class RequestScopeContainerFactory implements ScopeContainerFactory { + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new RequestScopeContainer(component); + } + + public Scope getScope() { + return Scope.REQUEST; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.java new file mode 100644 index 0000000000..0a20d793f7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.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.sca.core.scope; + +/** + * 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; + } + + @Override + 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); + } + + @Override + public int hashCode() { + return scope != null ? scope.hashCode() : 0; + } + + @Override + public String toString() { + return scope; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java new file mode 100644 index 0000000000..6b2980b989 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + + +/** + * Manages the lifecycle and visibility of instances associated with a an {@link RuntimeComponent}. + * + * @version $Rev$ $Date$ + * @param 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 extends RuntimeEventListener { + + /** + * Returns the Scope that this container supports. + * + * @return the Scope that this container supports + */ + Scope getScope(); + + /** + * Start a new context with the supplied ID. + * + * @param contextId an ID that uniquely identifies the context. + */ + void startContext(KEY contextId); + + /** + * 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 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 + */ + InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException; + + /** + * Allows a component to be registered against more than one context id. This is required in the + * case of stateful callbacks where we want to identify the originating client component instance + * as the callback target but we don't want to reuse the clients original conversation id + * + * @param existingContextId an id that identifies an existing component instance + * @param newContextId a new id against which this component will also be registered + * @throws TargetResolutionException + */ + void addWrapperReference(KEY existingContextId, KEY newContextId) + throws TargetResolutionException; + + /** + * Register an existing instance against a context id. This is needed + * for a stateful callback where the service reference for the forward call + * contains a callback object that is not a service reference. + * + * @param wrapper the instance wrapper for the instance to be registered + * @param contextId the id for the scope context + * @throws TargetResolutionException + */ + void registerWrapper(InstanceWrapper wrapper, 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 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 + */ + InstanceWrapper getAssociatedWrapper(KEY contextId) + throws TargetResolutionException; + + /** + * Return a wrapper after use (for example, after invoking the instance). + * @param wrapper the wrapper for the target instance being returned + * @param contextId the id for the scope context + * + * @throws TargetDestructionException if there was a problem returning the target instance + */ + void returnWrapper(InstanceWrapper wrapper, KEY contextId) + throws TargetDestructionException; + + /** + * Removes an identified component implementation instance associated with the current + * context from persistent storage + * + * @param contextId the identifier of the context to remove. + */ + void remove(KEY contextId) + throws TargetDestructionException; + + /* 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. + */ + void start(); + + /** + * Stops the Lifecycle. + */ + void stop(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.java new file mode 100644 index 0000000000..b19c14b3e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.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.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Factory to create ScopeContainer for components + * + * @version $Rev$ $Date$ + */ +public interface ScopeContainerFactory { + ScopeContainer createScopeContainer(RuntimeComponent component); + Scope getScope(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.java new file mode 100644 index 0000000000..842ed4c547 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.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.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + + +/** + * 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(RuntimeComponent component); + + /** + * @param factory + */ + void register(ScopeContainerFactory factory); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java new file mode 100644 index 0000000000..75261e11a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.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.sca.core.scope; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * The default implementation of a scope registry + * + * @version $Rev$ $Date$ + */ +public class ScopeRegistryImpl implements ScopeRegistry { + private final Map scopeCache = new ConcurrentHashMap(); + + public void register(ScopeContainerFactory factory) { + scopeCache.put(factory.getScope(), factory); + } + + public ScopeContainer getScopeContainer(RuntimeComponent runtimeComponent) { + if (!(runtimeComponent instanceof ScopedRuntimeComponent)) { + return null; + } + ScopedRuntimeComponent component = (ScopedRuntimeComponent)runtimeComponent; + if (component.getScopeContainer() != null) { + return component.getScopeContainer(); + } + ImplementationProvider implementationProvider = component.getImplementationProvider(); + if (implementationProvider instanceof ScopedImplementationProvider) { + ScopedImplementationProvider provider = (ScopedImplementationProvider)implementationProvider; + Scope scope = provider.getScope(); + if (scope == null) { + scope = Scope.STATELESS; + } + ScopeContainerFactory factory = scopeCache.get(scope); + ScopeContainer container = factory.createScopeContainer(component); + component.setScopeContainer(container); + return container; + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.java new file mode 100644 index 0000000000..85a6626cdd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.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.sca.core.scope; + +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.provider.ImplementationProvider; + +/** + * A component implementation can implement this interface to provide scope + * management for the components + * + * @version $Rev$ $Date$ + */ +public interface ScopedImplementationProvider extends ImplementationProvider { + /** + * Get the scope for the component implementation + * + * @return The scope for the component implementation, if null is returned, + * STATELESS will be used + */ + Scope getScope(); + + /** + * Indicate if the component needs to be eagerly initialized + * + * @return true if the component is marked to be eagerly initialized, false + * otherwise + */ + boolean isEagerInit(); + + /** + * @return the maxAge + */ + long getMaxAge(); + + /** + * @return the maxIdleTime + */ + long getMaxIdleTime(); + + /** + * Create a wrapper for the component instance for the scope management + * + * @return A wrapper for the component instance + */ + InstanceWrapper createInstanceWrapper(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.java new file mode 100644 index 0000000000..c27b112f8a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.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.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Scoped runtime component + * + * @version $Rev$ $Date$ + */ +public interface ScopedRuntimeComponent extends RuntimeComponent { + /** + * Set the associated scope container + * @param scopeContainer + */ + void setScopeContainer(ScopeContainer scopeContainer); + /** + * Get the assoicated scope container + * @return + */ + ScopeContainer getScopeContainer(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java new file mode 100644 index 0000000000..24125b154c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.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.sca.core.scope; + +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * A scope context which manages stateless atomic component instances in a non-pooled fashion. + * + * @version $Rev$ $Date$ + */ +public class StatelessScopeContainer extends AbstractScopeContainer { + + public StatelessScopeContainer(RuntimeComponent component) { + super(Scope.STATELESS, component); + } + + @Override + public InstanceWrapper getWrapper(KEY contextId) + throws TargetResolutionException { + InstanceWrapper ctx = createInstanceWrapper(); + try { + ctx.start(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e) { + try { + ctx.stop(); + } catch (ThreadDeath td) { + throw td; + } catch (Throwable e2) { + } + throw new TargetInitializationException(e); + } + return ctx; + } + + @Override + public InstanceWrapper getAssociatedWrapper(KEY contextId) + throws TargetResolutionException { + return getWrapper(contextId); + } + + @Override + public void returnWrapper(InstanceWrapper wrapper, KEY contextId) + throws TargetDestructionException { + wrapper.stop(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java new file mode 100644 index 0000000000..0471b2c52e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.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.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class StatelessScopeContainerFactory implements ScopeContainerFactory { + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new StatelessScopeContainer(component); + } + + public Scope getScope() { + return Scope.STATELESS; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.java new file mode 100644 index 0000000000..0f83dad97d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.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.sca.core.scope; + +/** + * Denotes an error destroying a target + * + * @version $Rev$ $Date$ + */ +public class TargetDestructionException extends TargetResolutionException { + private static final long serialVersionUID = -6126684147851674709L; + + public TargetDestructionException() { + super(); + } + + public TargetDestructionException(String message, Throwable cause) { + super(message, cause); + } + + public TargetDestructionException(String message) { + super(message); + } + + public TargetDestructionException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.java new file mode 100644 index 0000000000..15959c0608 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.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.sca.core.scope; + +/** + * Denotes an error initializing a target + * + * @version $Rev$ $Date$ + */ +public class TargetInitializationException extends TargetResolutionException { + private static final long serialVersionUID = -6228778208649752698L; + + public TargetInitializationException() { + super(); + } + + public TargetInitializationException(String message, Throwable cause) { + super(message, cause); + } + + public TargetInitializationException(String message) { + super(message); + } + + public TargetInitializationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.java new file mode 100644 index 0000000000..bb46a2499b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.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.sca.core.scope; + +/** + * Thrown when a target of an operation cannot be found + * + * @version $Rev$ $Date$ + */ +public class TargetNotFoundException extends TargetResolutionException { + private static final long serialVersionUID = 5541830480658471186L; + + public TargetNotFoundException() { + super(); + } + + public TargetNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public TargetNotFoundException(String message) { + super(message); + } + + public TargetNotFoundException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.java new file mode 100644 index 0000000000..ea8d0e876c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.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.sca.core.scope; + +/** + * Denotes an error retrieving a target instance + * + * @version $Rev$ $Date$ + */ +public class TargetResolutionException extends Exception { + private static final long serialVersionUID = 2912513650522019405L; + + public TargetResolutionException() { + super(); + } + + public TargetResolutionException(String message, Throwable cause) { + super(message, cause); + } + + public TargetResolutionException(String message) { + super(message); + } + + public TargetResolutionException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java new file mode 100644 index 0000000000..5b838116c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.store; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import org.apache.tuscany.sca.core.event.BaseEventPublisher; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.store.DuplicateRecordException; +import org.apache.tuscany.sca.store.RecoveryListener; +import org.apache.tuscany.sca.store.Store; +import org.apache.tuscany.sca.store.StoreExpirationEvent; +import org.apache.tuscany.sca.store.StoreMonitor; +import org.apache.tuscany.sca.store.StoreWriteException; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Service; + +/** + * Implements a non-durable, non-transactional store using a simple in-memory map + * + * @version $Rev$ $Date$ + */ +@Service(Store.class) +@EagerInit +public class MemoryStore extends BaseEventPublisher implements Store { + private Map> store; + // TODO integrate with a core threading scheme + private ScheduledExecutorService scheduler; + private long reaperInterval = 300000; + private StoreMonitor monitor; + private long defaultExpirationOffset = 600000; // 10 minutes + + public MemoryStore(StoreMonitor monitor) { + this.monitor = monitor; + this.store = new ConcurrentHashMap>(); + this.scheduler = Executors.newSingleThreadScheduledExecutor(); + } + + /** + * Returns the maximum default expiration offset for records in the store + * + * @return the maximum default expiration offset for records in the store + */ + public long getDefaultExpirationOffset() { + return defaultExpirationOffset; + } + + /** + * Sets the maximum default expiration offset for records in the store + */ + @Property + public void setDefaultExpirationOffset(long defaultExpirationOffset) { + this.defaultExpirationOffset = defaultExpirationOffset; + } + + /** + * Sets the interval for expired entry scanning to be performed + */ + @Property + public void setReaperInterval(long reaperInterval) { + this.reaperInterval = reaperInterval; + } + + public long getReaperInterval() { + return reaperInterval; + } + + @Init + public void init() { + scheduler.scheduleWithFixedDelay(new Reaper(), reaperInterval, reaperInterval, TimeUnit.MILLISECONDS); + monitor.start("In-memory store started"); + } + + @Destroy + public void destroy() { + scheduler.shutdown(); + monitor.stop("In-memory store stopped"); + } + + public void insertRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException { + Map map = store.get(owner); + if (map == null) { + map = new ConcurrentHashMap(); + store.put(owner, map); + } + if (map.containsKey(id)) { + throw new DuplicateRecordException("Duplicate record: " + owner.getURI() +" : " + id); + } + map.put(id, new Record(object, expiration)); + } + + public void updateRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException { + Map map = store.get(owner); + if (map == null) { + throw new StoreWriteException("Record not found: " + owner.getURI() +" : " + id); + } + Record record = map.get(id); + if (record == null) { + throw new StoreWriteException("Record not found: " + owner.getURI() +" : " + id); + } + record.data = object; + } + + public Object readRecord(RuntimeComponent owner, String id) { + Map map = store.get(owner); + if (map == null) { + return null; + } + Record record = map.get(id); + if (record != null) { + return record.data; + } + return null; + } + + public void removeRecords() { + store.clear(); + } + + public void removeRecord(RuntimeComponent owner, String id) throws StoreWriteException { + Map map = store.get(owner); + if (map == null) { + throw new StoreWriteException("Owner not found: " + owner.getURI() +" : " + id); + } + if (map.remove(id) == null) { + throw new StoreWriteException("Owner not found: " + owner.getURI() +" : " + id); + } + } + + public void recover(RecoveryListener listener) { + throw new UnsupportedOperationException(); + } + + private class Record { + private Object data; + private long expiration = NEVER; + + public Record(Object data, long expiration) { + this.data = data; + this.expiration = expiration; + } + + public Object getData() { + return data; + } + + public long getExpiration() { + return expiration; + } + } + + private class Reaper implements Runnable { + + public void run() { + long now = System.currentTimeMillis(); + for (Map.Entry> entries : store.entrySet()) { + for (Map.Entry entry : entries.getValue().entrySet()) { + final long expiration = entry.getValue().expiration; + if (expiration != NEVER && now >= expiration) { + RuntimeComponent owner = entries.getKey(); + Object instance = entry.getValue().getData(); + // notify listeners of the expiration + StoreExpirationEvent event = new StoreExpirationEvent(this, owner, instance); + publish(event); + entries.getValue().remove(entry.getKey()); + } + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java new file mode 100644 index 0000000000..55b0acded9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +import org.apache.tuscany.sca.work.NotificationListener; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.apache.tuscany.sca.work.WorkSchedulerException; + +/** + * A work scheduler implementation based on a JSR 237 work manager. + *

+ *

+ * This needs a JSR 237 work manager implementation available for scheduling work. Instances can be configured with a + * work manager implementation that is injected in. It is the responsibility of the runtime environment to make a work + * manager implementation available. For example, if the managed environment supports work manager the runtime can use + * the appropriate lookup mechanism to inject the work manager implementation.

+ * + * @version $Rev$ $Date$ + */ +public class DefaultWorkScheduler implements WorkScheduler { + + /** + * Underlying JSR-237 work manager + */ + private ThreadPoolWorkManager jsr237WorkManager; + + /** + * Initializes the JSR 237 work manager. + * + * @param jsr237WorkManager JSR 237 work manager. + */ + public DefaultWorkScheduler() { + } + + private synchronized ThreadPoolWorkManager getWorkManager() { + if (jsr237WorkManager != null) { + return jsr237WorkManager; + } +// try { +// InitialContext ctx = new InitialContext(); +// jsr237WorkManager = (ThreadPoolWorkManager)ctx.lookup("java:comp/env/wm/TuscanyWorkManager"); +// } catch (Throwable e) { +// // ignore +// } + if (jsr237WorkManager == null) { + jsr237WorkManager = new ThreadPoolWorkManager(0); + } + return jsr237WorkManager; + } + + /** + * 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. + */ + public void scheduleWork(T work) { + scheduleWork(work, null); + } + + /** + * 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. + */ + public void scheduleWork(T work, NotificationListener listener) { + + if (work == null) { + throw new IllegalArgumentException("Work cannot be null"); + } + + Work jsr237Work = new Work(work); + try { + if (listener == null) { + getWorkManager().schedule(jsr237Work); + } else { + Jsr237WorkListener jsr237WorkListener = new Jsr237WorkListener(listener, work); + getWorkManager().schedule(jsr237Work, jsr237WorkListener); + } + } catch (IllegalArgumentException ex) { + if (listener != null) { + listener.workRejected(work); + } else { + throw new WorkSchedulerException(ex); + } + } catch (Exception ex) { + throw new WorkSchedulerException(ex); + } + + } + + public void destroy() { + if (jsr237WorkManager instanceof ThreadPoolWorkManager) { + // Allow privileged access to modify threads. Requires RuntimePermission in security + // policy. + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + ((ThreadPoolWorkManager)jsr237WorkManager).destroy(); + return null; + } + }); + } + } + + /* + * WorkListener for keeping track of work status callbacks. + * + */ + private class Jsr237WorkListener implements WorkListener { + + // Notification listener + private NotificationListener listener; + + // Work + private T work; + + /* + * Initializes the notification listener. + */ + public Jsr237WorkListener(NotificationListener listener, T work) { + this.listener = listener; + this.work = work; + } + + /* + * Callback when the work is accepted. + */ + public void workAccepted(WorkEvent workEvent) { + T work = getWork(); + listener.workAccepted(work); + } + + /* + * Callback when the work is rejected. + */ + public void workRejected(WorkEvent workEvent) { + T work = getWork(); + listener.workRejected(work); + } + + /* + * Callback when the work is started. + */ + public void workStarted(WorkEvent workEvent) { + T work = getWork(); + listener.workStarted(work); + } + + /* + * Callback when the work is completed. + */ + public void workCompleted(WorkEvent workEvent) { + T work = getWork(); + Exception exception = workEvent.getException(); + if (exception != null) { + listener.workFailed(work, exception); + } else { + listener.workCompleted(work); + } + } + + /* + * Gets the underlying work from the work event. + */ + private T getWork() { + return work; + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java new file mode 100644 index 0000000000..91d00a58d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + +import java.rmi.server.UID; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ThreadFactory; + +import org.apache.tuscany.sca.work.WorkSchedulerException; +import org.osoa.sca.annotations.Destroy; + +/** + * A thread-pool based implementation for the JSR-237 work manager. + *

+ *

+ * This implementation supports only local work. + *

+ * TODO Elaborate the implementation.

+ * + * @version $Rev$ $Date$ + */ +public class ThreadPoolWorkManager { + + // Map of work items currently handled by the work manager + private Map workItems = new ConcurrentHashMap(); + + // Thread-pool + private ExecutorService executor; + + /** + * Initializes the thread-pool. + * + * @param threadPoolSize Thread-pool size. If the size <1, then a cached pool is created + */ + public ThreadPoolWorkManager(int threadPoolSize) { + ThreadFactory factory = new ThreadFactory() { + public Thread newThread(Runnable r) { + Thread thread = new Thread(r); + thread.setDaemon(true); + return thread; + } + }; + if (threadPoolSize <= 1) { + + // Creates a new Executor, use a custom ThreadFactory that + // creates daemon threads. + executor = Executors.newCachedThreadPool(factory); + } else { + executor = Executors.newFixedThreadPool(threadPoolSize); + } + } + + /** + * Schedules a unit of work asynchronously. + * + * @param work Work that needs to be scheduled. + * @return Work Work item representing the asynchronous work + */ + public WorkItem schedule(Work work) throws IllegalArgumentException { + return schedule(work, null); + } + + /** + * Schedules a unit of work asynchronously. + * + * @param work Work that needs to be scheduled. + * @param workListener Work listener for callbacks. + * @return Work Work item representing the asynchronous work + */ + public WorkItem schedule(Work work, WorkListener workListener) throws IllegalArgumentException { + + WorkItem workItem = new WorkItem(new UID().toString(), work); + if (workListener != null) { + workItems.put(workItem, workListener); + } + workAccepted(workItem, work); + if (scheduleWork(work, workItem)) { + return workItem; + } else { + workItem.setStatus(WorkEvent.WORK_REJECTED); + if (workListener != null) { + workListener.workRejected(new WorkEvent(workItem)); + } + throw new IllegalArgumentException("Unable to schedule work"); + } + } + + /** + * Wait for all the specified units of work to finish. + * + * @param works Units of the work that need to finish. + * @param timeout Timeout for waiting for the units of work to finish. + */ + public boolean waitForAll(Collection works, long timeout) { + throw new UnsupportedOperationException("waitForAll not supported"); + } + + /** + * Wait for any of the specified units of work to finish. + * + * @param works Units of the work that need to finish. + * @param timeout Timeout for waiting for the units of work to finish. + */ + public Collection waitForAny(Collection works, long timeout) { + throw new UnsupportedOperationException("waitForAny not supported"); + } + + /** + * Method provided for subclasses to indicate a work acceptance. + * + * @param workItem Work item representing the work that was accepted. + * @param work Work that was accepted. + */ + private void workAccepted(final WorkItem workItem, final Work work) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_ACCEPTED); + WorkEvent event = new WorkEvent(workItem); + listener.workAccepted(event); + } + } + + /* + * Method to indicate a work start. + */ + private void workStarted(final WorkItem workItem, final Work work) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_STARTED); + WorkEvent event = new WorkEvent(workItem); + listener.workStarted(event); + } + } + + /* + * Method to indicate a work completion. + */ + private void workCompleted(final WorkItem workItem, final Work work) { + workCompleted(workItem, work, null); + } + + /* + * Method to indicate a work completion. + */ + private void workCompleted(final WorkItem workItem, final Work work, final WorkSchedulerException exception) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_COMPLETED); + workItem.setResult(work); + workItem.setException(exception); + WorkEvent event = new WorkEvent(workItem); + listener.workCompleted(event); + workItems.remove(workItem); + } + } + + /* + * Schedules the work using the ThreadPool. + */ + private boolean scheduleWork(final Work work, final WorkItem workItem) { + try { + executor.execute(new DecoratingWork(workItem, work)); + return true; + } catch (RejectedExecutionException ex) { + return false; + } + } + + /* + * Class that decorates the original worker so that it can get callbacks when work is done. + */ + private final class DecoratingWork implements Runnable { + + // Work item for this work. + private WorkItem workItem; + + // The original work. + private Work decoratedWork; + + /* + * Initializes the work item and underlying work. + */ + private DecoratingWork(final WorkItem workItem, final Work decoratedWork) { + this.workItem = workItem; + this.decoratedWork = decoratedWork; + } + + /* + * Overrides the run method. + */ + public void run() { + workStarted(workItem, decoratedWork); + try { + decoratedWork.run(); + workCompleted(workItem, decoratedWork); + } catch (Throwable th) { + workCompleted(workItem, decoratedWork, new WorkSchedulerException(th.getMessage(), th)); + } + } + + } + + @Destroy + public void destroy() { + executor.shutdown(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Work.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Work.java new file mode 100644 index 0000000000..c521c60f79 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Work.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.sca.core.work; + +/** + * JCA work wrapper. + * + * @version $Rev$ $Date$ + */ +public class Work { + + // Work that is being executed. + private T work; + + /* + * Initializes the work instance. + */ + public Work(T work) { + this.work = work; + } + + /* + * Returns the completed work. + */ + public T getWork() { + return work; + } + + /* + * Release the work. + */ + public void release() { + } + + /* + * Work attributes are not daemon. + */ + public boolean isDaemon() { + return false; + } + + /* + * Runs the work. + */ + public void run() { + work.run(); + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEvent.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEvent.java new file mode 100644 index 0000000000..8e9a3b4c53 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEvent.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.sca.core.work; + +import org.apache.tuscany.sca.work.WorkSchedulerException; + + + +/** + * Default immutable implementation of the WorkEvent class. + * + * @version $Rev$ $Date$ + */ +class WorkEvent { + + public static final int WORK_ACCEPTED = 1; + public static final int WORK_REJECTED = 2; + public static final int WORK_STARTED = 3; + public static final int WORK_COMPLETED = 4; + + // Work item for this event + private WorkItem workItem; + + // Exception if something has gone wrong + private WorkSchedulerException exception; + + /** + * Instantiates the event. + * + * @param workItem Work item for this event. + */ + public WorkEvent(final WorkItem workItem) { + this.workItem = workItem; + this.exception = workItem.getException(); + } + + /** + * Returns the work type based on whether the work was accepted, started, + * rejected or completed. + * + * @return Work type. + */ + public int getType() { + return workItem.getStatus(); + } + + /** + * Returns the work item associated with this work type. + * + * @return Work item. + */ + public WorkItem getWorkItem() { + return workItem; + } + + /** + * Returns the exception if the work completed with an exception. + * + * @return Work exception. + */ + public WorkSchedulerException getException() { + return exception; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItem.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItem.java new file mode 100644 index 0000000000..8320c7364f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItem.java @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + +import org.apache.tuscany.sca.work.WorkSchedulerException; + +/** + * An identity based immutable implementation of the WorkItem + * interface. + * + * @version $Rev$ $Date$ + */ +class WorkItem { + + // Id scoped for the VM + private String id; + + // Status + private int status = -1; + + // Result + private Work result; + + // Original work + private Work originalWork; + + // Exception + private WorkSchedulerException exception; + + /** + * Instantiates an id for this item. + * + * @param id of this work event. + */ + protected WorkItem(final String id, final Work orginalWork) { + this.id = id; + this.originalWork = orginalWork; + } + + /** + * Returns the id. + * + * @return Id of this item. + */ + public String getId() { + return id; + } + + /** + * Returns the original work. + * + * @return Original work. + */ + public Work getOriginalWork() { + return originalWork; + } + + /** + * Returns the work result if the work completed. + * + * @return Work. + * @throws WorkException If the work completed with an exception. + */ + public Work getResult() { + return result; + } + + /** + * Sets the result. + * + * @param result Result. + */ + protected void setResult(final Work result) { + this.result = result; + } + + /** + * Returns the exception if work completed with an exception. + * + * @return Work exception. + */ + protected WorkSchedulerException getException() { + return exception; + } + + /** + * Sets the exception. + * + * @param exception Exception. + */ + protected void setException(final WorkSchedulerException exception) { + this.exception = exception; + } + + /** + * Returns the work type based on whether the work was accepted, started, + * rejected or completed. + * + * @return Work status. + */ + public int getStatus() { + return status; + } + + /** + * Sets the status. + * + * @param status Status. + */ + protected void setStatus(final int status) { + this.status = status; + } + + /** + * @see Object#hashCode() + */ + @Override + public int hashCode() { + return id.hashCode(); + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param obj Object to be compared. + * @return true if this object is the same as the obj argument; false + * otherwise.. + */ + @Override + public boolean equals(final Object obj) { + return (obj != null) && (obj.getClass() == WorkItem.class) && ((WorkItem) obj).id.equals(id); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * + * @param o Object to be compared. + * @return A negative integer, zero, or a positive integer as this object + * is less than, equal to, or greater than the specified object. + * @throws ClassCastException needs better documentation. + */ + public int compareTo(final Object o) { + if (o.getClass() != WorkItem.class) { + throw new ClassCastException(o.getClass().getName()); + } else { + return ((WorkItem) o).getId().compareTo(getId()); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkListener.java new file mode 100644 index 0000000000..19bfaaa560 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkListener.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.sca.core.work; + +public interface WorkListener { + + static long IMMEDIATE = 0; + static long INDEFINITE = java.lang.Long.MAX_VALUE; + + void workAccepted(WorkEvent event); + void workCompleted(WorkEvent event); + void workRejected(WorkEvent event); + void workStarted(WorkEvent event); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..5f54178483 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.core.assembly.ReferenceParameterProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#referenceParameters,model=org.apache.tuscany.sca.runtime.ReferenceParameters diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.conversation.ConversationManager b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.conversation.ConversationManager new file mode 100644 index 0000000000..898054509b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.conversation.ConversationManager @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.core.conversation.ConversationManagerImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint new file mode 100644 index 0000000000..af281d8f4d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.core.invocation.DefaultProxyFactoryExtensionPoint diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.invocation.MessageFactory b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.invocation.MessageFactory new file mode 100644 index 0000000000..bcbd5b0abf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.invocation.MessageFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.core.invocation.MessageFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler new file mode 100644 index 0000000000..93d93491a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.core.work.DefaultWorkScheduler diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java new file mode 100644 index 0000000000..7b44736d4b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.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.sca.core; + +import junit.framework.TestCase; + +public class DefaultExtensionPointRegistryTestCase extends TestCase { + private ExtensionPointRegistry registry; + + @Override + protected void setUp() throws Exception { + super.setUp(); + registry = new DefaultExtensionPointRegistry(); + } + + public void testRegistry() { + MyRegistry service = new MyREgistryImpl(); + registry.addExtensionPoint(service); + assertSame(service, registry.getExtensionPoint(MyRegistry.class)); + registry.removeExtensionPoint(service); + assertNull(registry.getExtensionPoint(MyRegistry.class)); + } + + public static interface MyRegistry { + void doSomething(); + } + + private static class MyREgistryImpl implements MyRegistry { + + public void doSomething() { + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java new file mode 100644 index 0000000000..2bc78c3d35 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.event.EventFilter; +import org.apache.tuscany.sca.event.EventPublisher; +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.event.TrueFilter; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class BaseEventPublisherTestCase 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); + } + + @Override + protected void setUp() throws Exception { + publisher = new BaseEventPublisher() { + }; + } + + 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/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java new file mode 100644 index 0000000000..48dcf8df07 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.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.sca.core.event; + +import java.net.URI; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class EventTestCase extends TestCase { + private URI uri = URI.create("foo"); + + public void testCompositeStart() { + ComponentStart event = new ComponentStart(this, uri); + assertEquals(uri, event.getComponentURI()); + } + + public void testCompositeStop() { + ComponentStop event = new ComponentStop(this, uri); + assertEquals(uri, event.getComponentURI()); + } + + public void testHttpSessionStart() { + Object id = new Object(); + HttpSessionStart event = new HttpSessionStart(this, id); + assertEquals(this, event.getSource()); + assertEquals(id, event.getSessionID()); + } + + public void testHttpSessionEnd() { + Object id = new Object(); + HttpSessionEnd event = new HttpSessionEnd(this, id); + assertEquals(this, event.getSource()); + assertEquals(id, event.getSessionID()); + } + + public void testRequestStart() { + RequestStart event = new RequestStart(this); + assertEquals(this, event.getSource()); + } + + public void testReequestEnd() { + RequestEnd event = new RequestEnd(this); + assertEquals(this, event.getSource()); + } + + + @Override + protected void setUp() throws Exception { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java new file mode 100644 index 0000000000..99d5ec7bc9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.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.sca.core.invocation; + +import java.util.List; + +import junit.framework.Assert; + +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class PhaseManagerTestCase { + + @Test + public void testDiscovery() { + PhaseManager pm = new PhaseManager("org.apache.tuscany.sca.invocation.PhaseTest"); + List phases = pm.getAllPhases(); + System.out.println(phases.size()); + System.out.println(phases); + // Assert.assertEquals(15, phases.size()); + Assert.assertEquals("reference.first", phases.get(0)); + + int rt = phases.indexOf("reference.transaction"); + Assert.assertTrue(rt > phases.indexOf("reference.interface")); + + int st = phases.indexOf("service.transaction"); + Assert.assertTrue(st > phases.indexOf("service.binding")); + + int it = phases.indexOf("implementation.transaction"); + Assert.assertTrue(it < phases.indexOf("implementation.policy")); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java new file mode 100644 index 0000000000..61164fa2de --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.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.sca.core.invocation; + +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +public class PhaseSorterTestCase extends TestCase { + private PhaseSorter graph; + + @Override + protected void setUp() throws Exception { + super.setUp(); + graph = new PhaseSorter(); + } + + public void testSort() { + graph.addEdge("a", "b"); + graph.addEdge("a", "c"); + graph.addEdge("c", "d"); + graph.addEdge("b", "c"); + List order = graph.topologicalSort(true); + assertEquals(Arrays.asList("a", "b", "c", "d"), order); + assertTrue(!graph.getVertices().isEmpty()); + + graph.addEdge("d", "a"); + try { + order = graph.topologicalSort(true); + assertTrue("Should have failed", false); + } catch (IllegalArgumentException e) { + assertTrue(true); + } + + graph.removeEdge("d", "a"); + order = graph.topologicalSort(false); + assertEquals(Arrays.asList("a", "b", "c", "d"), order); + assertTrue(graph.getVertices().isEmpty()); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java new file mode 100644 index 0000000000..64114f7fb2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.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.sca.core.scope; + +import java.net.URI; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.context.InstanceWrapper; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; + +/** + * @version $Rev$ $Date$ + */ +public abstract class AbstractScopeContainerTestCase extends TestCase { + protected IMocksControl control; + protected ScopeContainer scopeContainer; + protected URI groupId; + protected KEY contextId; + protected RuntimeComponent component; + protected ScopedImplementation implementation; + protected InstanceWrapper wrapper; + + @SuppressWarnings("unchecked") + @Override + protected void setUp() throws Exception { + super.setUp(); + control = EasyMock.createStrictControl(); + component = control.createMock(RuntimeComponent.class); + wrapper = control.createMock(InstanceWrapper.class); + implementation = control.createMock(ScopedImplementation.class); + EasyMock.expect(component.getImplementation()).andReturn(implementation).anyTimes(); + } + + protected void preRegisterComponent() throws Exception { + scopeContainer.start(); + EasyMock.expect(implementation.isEagerInit()).andStubReturn(false); + } + + protected void expectCreateWrapper() throws Exception { + EasyMock.expect(implementation.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + } + + protected static interface ScopedImplementation extends ScopedImplementationProvider, Implementation { + + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java new file mode 100644 index 0000000000..d46d77b4b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.store; + +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.store.DuplicateRecordException; +import org.apache.tuscany.sca.store.Store; +import org.apache.tuscany.sca.store.StoreExpirationEvent; +import org.apache.tuscany.sca.store.StoreMonitor; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class MemoryStoreTestCase extends TestCase { + private StoreMonitor monitor; + + public void testEviction() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, 1); + Thread.sleep(200); + assertNull(store.readRecord(component, id)); + store.destroy(); + } + + public void testNotifyOnEviction() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.isA(StoreExpirationEvent.class)); + EasyMock.expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + latch.countDown(); + return null; + } + }); + EasyMock.replay(listener); + MemoryStore store = new MemoryStore(monitor); + store.addListener(listener); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, 1); + if (!latch.await(1000, TimeUnit.MILLISECONDS)) { + // failed to notify listener + fail(); + } + EasyMock.verify(listener); + } + + public void testNoEviction() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + Thread.sleep(100); + assertNotNull(store.readRecord(component, id)); + store.destroy(); + } + + public void testInsertRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + store.destroy(); + } + + public void testInsertAlreadyExists() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createMock(RuntimeComponent.class); + EasyMock.expect(component.getURI()).andReturn("component"); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + try { + store.insertRecord(component, id, value, Store.NEVER); + fail(); + } catch (DuplicateRecordException e) { + //expected + } + store.destroy(); + } + + public void testUpdateRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + Object newValue = new Object(); + + store.insertRecord(component, id, value, Store.NEVER); + store.updateRecord(component, id, newValue, 1L); + assertEquals(newValue, store.readRecord(component, id)); + store.destroy(); + } + + public void testDeleteRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + + store.insertRecord(component, id, value, Store.NEVER); + store.removeRecord(component, id); + assertNull(store.readRecord(component, id)); + store.destroy(); + } + + @Override + protected void setUp() throws Exception { + monitor = EasyMock.createNiceMock(StoreMonitor.class); + EasyMock.replay(monitor); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java new file mode 100644 index 0000000000..1aba9656d8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.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.sca.core.wire; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.core.invocation.CallbackInterfaceInterceptor; +import org.apache.tuscany.sca.core.invocation.MessageFactoryImpl; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Message; +import org.easymock.EasyMock; +import org.osoa.sca.NoRegisteredCallbackException; + +/** + * @version $Rev$ $Date$ + */ +public class CallbackInterfaceInterceptorTestCase extends TestCase { + + public void testHasCallbackObject() { + CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(); + Interceptor next = EasyMock.createMock(Interceptor.class); + EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(null); + EasyMock.replay(next); + interceptor.setNext(next); + Message msg = new MessageFactoryImpl().createMessage(); + msg.setFrom(new EndpointReferenceImpl("uri")); + msg.getFrom().getReferenceParameters().setCallbackObjectID("ABC"); + interceptor.invoke(msg); + EasyMock.verify(next); + } + + public void testNoCallbackObject() { + CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(); + Message msg = new MessageFactoryImpl().createMessage(); + msg.setFrom(new EndpointReferenceImpl("uri")); + msg.getFrom().getReferenceParameters().setCallbackObjectID(null); + try { + interceptor.invoke(msg); + fail(); + } catch (NoRegisteredCallbackException e) { + // expected + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java new file mode 100644 index 0000000000..1ad0927d16 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.wire; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.InvocationChainImpl; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.Phase; + +/** + * @version $Rev$ $Date$ + */ +public class InvocationChainImplTestCase extends TestCase { + + public void testInsertAtEnd() throws Exception { + Operation op = newOperation("foo"); + InvocationChain chain = new InvocationChainImpl(op, op, true); + Interceptor inter2 = new MockInterceptor(); + Interceptor inter1 = new MockInterceptor(); + chain.addInterceptor(inter1); + chain.addInterceptor(inter2); + Interceptor head = (Interceptor)chain.getHeadInvoker(); + assertEquals(inter1, head); + assertEquals(inter2, head.getNext()); + assertEquals(inter2, chain.getTailInvoker()); + + } + + public void testAddByPhase() throws Exception { + Operation op = newOperation("foo"); + InvocationChain chain = new InvocationChainImpl(op, op, false); + Interceptor inter1 = new MockInterceptor(); + Interceptor inter2 = new MockInterceptor(); + Interceptor inter3 = new MockInterceptor(); + Interceptor inter4 = new MockInterceptor(); + chain.addInterceptor(inter3); // SERVICE + chain.addInterceptor(Phase.IMPLEMENTATION_POLICY, inter4); + chain.addInterceptor(Phase.SERVICE_POLICY, inter2); + chain.addInterceptor(Phase.SERVICE_BINDING, inter1); + Interceptor head = (Interceptor)chain.getHeadInvoker(); + assertEquals(inter1, head); + assertEquals(inter2, inter1.getNext()); + assertEquals(inter3, inter2.getNext()); + assertEquals(inter4, inter3.getNext()); + assertEquals(inter4, chain.getTailInvoker()); + } + + private class MockInterceptor implements Interceptor { + + private Invoker next; + + public Message invoke(Message msg) { + return null; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Invoker getNext() { + return next; + } + + } + + private static Operation newOperation(String name) { + Operation operation = new OperationImpl(); + operation.setName(name); + return operation; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java new file mode 100644 index 0000000000..b8150d4edc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.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.sca.core.wire; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.getCurrentArguments; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor; +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class NonBlockingInterceptorTestCase extends TestCase { + + public void testInvoke() throws Exception { + WorkScheduler scheduler = createMock(WorkScheduler.class); + scheduler.scheduleWork(isA(Runnable.class)); + expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + Runnable runnable = (Runnable) getCurrentArguments()[0]; + runnable.run(); + return null; + } + }); + replay(scheduler); + Message context = createMock(Message.class); + //String convID = "convID"; + //TODO port to the new way of dealing with conversation IDs later + //EasyMock.expect(context.getConversationID()).andReturn(convID); + EasyMock.replay(context); + ThreadMessageContext.setMessageContext(context); + Message msg = createMock(Message.class); + //TODO port to the new way of dealing with conversation IDs later + //msg.setConversationID(convID); + Interceptor next = EasyMock.createMock(Interceptor.class); + EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg); + EasyMock.expect(msg.isFault()).andReturn(false); + EasyMock.replay(next); + EasyMock.replay(msg); + Interceptor interceptor = new NonBlockingInterceptor(scheduler, next); + interceptor.invoke(msg); + verify(context); + verify(next); + verify(msg); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java new file mode 100644 index 0000000000..c69a1908e8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.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.sca.core.work; + + +/** + * Simple Work item that will throw an exception + * + * @version $Rev$ $Date$ + */ +public class FailingWork extends Work { + + public FailingWork() { + super(null); + } + + /** + * {@inheritDoc} + */ + public boolean isDaemon() { + return false; + } + + /** + * {@inheritDoc} + */ + public void release() { + } + + /** + * Throws an IllegalArgumentException + */ + public void run() { + System.out.println("Starting " + this + " and throwing an Exception"); + throw new IllegalArgumentException("Sample exception from " + this); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyFailingRunnable.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyFailingRunnable.java new file mode 100644 index 0000000000..91b45dfbcb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyFailingRunnable.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.sca.core.work; + +/** + * Simple Runnable that throws an IllegalArgumentException + * + * @version $Rev$ $Date$ + */ +public class JSR237MyFailingRunnable extends JSR237MyRunnable { + + /** + * Constructor + */ + public JSR237MyFailingRunnable() { + super(-1); + } + + /** + * Sleeps for a period of time defined by sleepTime + */ + @Override + public void run() { + System.out.println("Starting " + this + " and throwing an Exception"); + throw new IllegalArgumentException("Sample exception from " + this); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnable.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnable.java new file mode 100644 index 0000000000..a7617f7a70 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnable.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.sca.core.work; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Simple Runnable that is used for testing Jsr237WorkScheduler + * + * @version $Rev$ $Date$ + */ +public class JSR237MyRunnable implements Runnable { + + /** + * Count of workAccepted() method calls + */ + private AtomicInteger runCompletedCount = new AtomicInteger(); + + /** + * The amount of time to sleep in the Run loop + */ + private final long sleepTime; + + /** + * Constructor + * + * @param sleepTime The amount of time to sleep (in milliseconds) in the run() method + */ + public JSR237MyRunnable(long sleepTime) { + this.sleepTime = sleepTime; + } + + /** + * Sleeps for a period of time defined by sleepTime + */ + public void run() { + System.out.println("Starting " + this); + try { + Thread.sleep(sleepTime); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("Done " + this); + runCompletedCount.incrementAndGet(); + } + + /** + * Returns the number of completed calls to run() + * + * @return The number of completed calls to run() + */ + public int getRunCompletedCount() { + return runCompletedCount.get(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnerListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnerListener.java new file mode 100644 index 0000000000..75840efef4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnerListener.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.tuscany.sca.work.NotificationListener; + +/** + * Simple NotificationListener that is used for testing Jsr237WorkScheduler + * + * @version $Rev$ $Date$ + */ +public class JSR237MyRunnerListener implements NotificationListener { + + /** + * Count of workAccepted() method calls + */ + private AtomicInteger workAcceptedCallCount = new AtomicInteger(); + + /** + * Count of workStarted() method calls + */ + private AtomicInteger workStartedCallCount = new AtomicInteger(); + + /** + * Count of workCompleted() method calls + */ + private AtomicInteger workCompletedCallCount = new AtomicInteger(); + + /** + * Count of workFailed() method calls + */ + private AtomicInteger workFailedCallCount = new AtomicInteger(); + + /** + * Count of workRejected() method calls + */ + private AtomicInteger workRejectedCallCount = new AtomicInteger(); + + /** + * List of all exceptions thrown by Work items + */ + private List workExceptions = Collections.synchronizedList(new ArrayList()); + + /** + * {@inheritDoc} + */ + public void workAccepted(JSR237MyRunnable work) { + workAcceptedCallCount.incrementAndGet(); + } + + /** + * {@inheritDoc} + */ + public void workCompleted(JSR237MyRunnable work) { + workCompletedCallCount.incrementAndGet(); + } + + /** + * {@inheritDoc} + */ + public void workFailed(JSR237MyRunnable work, Throwable error) { + workExceptions.add(error); + workFailedCallCount.incrementAndGet(); + } + + /** + * {@inheritDoc} + */ + public void workRejected(JSR237MyRunnable work) { + workRejectedCallCount.incrementAndGet(); + } + + /** + * {@inheritDoc} + */ + public void workStarted(JSR237MyRunnable work) { + workStartedCallCount.incrementAndGet(); + } + + /** + * Returns the number of calls to workAccepted() + * + * @return The number of calls to workAccepted() + */ + public int getWorkAcceptedCallCount() { + return workAcceptedCallCount.get(); + } + + /** + * Returns the number of calls to workStarted() + * + * @return The number of calls to workStarted() + */ + public int getWorkStartedCallCount() { + return workStartedCallCount.get(); + } + + /** + * Returns the number of calls to workCompleted() + * + * @return The number of calls to workCompleted() + */ + public int getWorkCompletedCallCount() { + return workCompletedCallCount.get(); + } + + /** + * Returns the number of calls to workFailed() + * + * @return The number of calls to workFailed() + */ + public int getWorkFailedCallCount() { + return workFailedCallCount.get(); + } + + /** + * Returns the number of calls to workRejected() + * + * @return The number of calls to workRejected() + */ + public int getWorkRejectedCallCount() { + return workRejectedCallCount.get(); + } + + /** + * Returns a List of all exceptions that are thrown by the Work items + * + * @return A List of all exceptions that are thrown by the Work items + */ + public List getWorkExceptions() { + return Collections.unmodifiableList(workExceptions); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java new file mode 100644 index 0000000000..185394d7e8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java @@ -0,0 +1,240 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test case for Jsr237WorkScheduler + * + * @version $Rev$ $Date$ + */ +public class Jsr237WorkSchedulerTestCase { + + /** + * Wait up to 20 seconds for the Work units to complete + */ + private static final long WAIT_TIMEOUT = 20000; + + /** + * This is the shared instance of the ThreadPoolWorkManager used by the tests + */ + private static DefaultWorkScheduler workSchedular = null; + + /** + * Setup the Jsr237WorkScheduler + */ + @BeforeClass + public static void setup() { + workSchedular = new DefaultWorkScheduler(); + } + + /** + * Make sure that the Jsr237WorkScheduler is stopped after running the tests + */ + @AfterClass + public static void destroy() { + if (workSchedular != null) { + workSchedular.destroy(); + } + } + + /** + * Tests running a single fast job on the Jsr237WorkScheduler + */ + @Test + public void testSingleFastJob() { + // Create the work and register it + JSR237MyRunnable fast = new JSR237MyRunnable(10); + JSR237MyRunnerListener listener = new JSR237MyRunnerListener(); + workSchedular.scheduleWork(fast, listener); + + // Wait for the 1 job to complete + waitForWorkToComplete(listener, 1); + + // Test that the job completed successfully. + Assert.assertEquals(1, listener.getWorkAcceptedCallCount()); + Assert.assertEquals(0, listener.getWorkRejectedCallCount()); + Assert.assertEquals(1, listener.getWorkStartedCallCount()); + Assert.assertEquals(1, listener.getWorkCompletedCallCount()); + Assert.assertEquals(0, listener.getWorkExceptions().size()); + } + + /** + * Tests running a single job that fails on the Jsr237WorkScheduler + */ + @Test + public void testSingleFailingJob() { + // Create the work and register it + JSR237MyFailingRunnable fail = new JSR237MyFailingRunnable(); + JSR237MyRunnerListener listener = new JSR237MyRunnerListener(); + workSchedular.scheduleWork(fail, listener); + + // Wait for the 1 job to complete + waitForWorkToComplete(listener, 1); + + // Test that the job completed successfully. + Assert.assertEquals(1, listener.getWorkAcceptedCallCount()); + Assert.assertEquals(0, listener.getWorkRejectedCallCount()); + Assert.assertEquals(1, listener.getWorkStartedCallCount()); + Assert.assertEquals(0, listener.getWorkCompletedCallCount()); + Assert.assertEquals(1, listener.getWorkFailedCallCount()); + Assert.assertEquals(1, listener.getWorkExceptions().size()); + } + + /** + * Tests running a mixture of fast and slow jobs on the Jsr237WorkScheduler + */ + @Test + public void testMultipleJobs() { + // Create the work and register it + JSR237MyRunnable fast1 = new JSR237MyRunnable(50); + JSR237MyRunnable fast2 = new JSR237MyRunnable(100); + JSR237MyRunnable fast3 = new JSR237MyRunnable(200); + JSR237MyRunnable slow1= new JSR237MyRunnable(2000); + JSR237MyRunnable slow2 = new JSR237MyRunnable(2000); + JSR237MyRunnerListener listener = new JSR237MyRunnerListener(); + workSchedular.scheduleWork(fast1, listener); + workSchedular.scheduleWork(fast2, listener); + workSchedular.scheduleWork(fast3, listener); + workSchedular.scheduleWork(slow1, listener); + workSchedular.scheduleWork(slow2, listener); + + // Wait for the 5 jobs to complete + waitForWorkToComplete(listener, 5); + + // Test that the job completed successfully. + Assert.assertEquals(5, listener.getWorkAcceptedCallCount()); + Assert.assertEquals(0, listener.getWorkRejectedCallCount()); + Assert.assertEquals(5, listener.getWorkStartedCallCount()); + Assert.assertEquals(5, listener.getWorkCompletedCallCount()); + Assert.assertEquals(0, listener.getWorkExceptions().size()); + } + + /** + * Tests running a mixture of fast and slow jobs some of which fail on the + * Jsr237WorkScheduler + */ + @Test + public void testMultipleJobsSomeFail() { + // Create the work and register it + JSR237MyRunnable fast1 = new JSR237MyRunnable(50); + JSR237MyRunnable fast2 = new JSR237MyRunnable(100); + JSR237MyRunnable fast3 = new JSR237MyRunnable(200); + JSR237MyRunnable slow1= new JSR237MyRunnable(2000); + JSR237MyRunnable slow2 = new JSR237MyRunnable(2000); + JSR237MyFailingRunnable fail1 = new JSR237MyFailingRunnable(); + JSR237MyFailingRunnable fail2 = new JSR237MyFailingRunnable(); + JSR237MyRunnerListener listener = new JSR237MyRunnerListener(); + workSchedular.scheduleWork(fast1, listener); + workSchedular.scheduleWork(fast2, listener); + workSchedular.scheduleWork(fail1, listener); + workSchedular.scheduleWork(fast3, listener); + workSchedular.scheduleWork(slow1, listener); + workSchedular.scheduleWork(fail2, listener); + workSchedular.scheduleWork(slow2, listener); + + // Wait for the 7 jobs to complete + waitForWorkToComplete(listener, 7); + + // Test that the job completed successfully. + Assert.assertEquals(7, listener.getWorkAcceptedCallCount()); + Assert.assertEquals(0, listener.getWorkRejectedCallCount()); + Assert.assertEquals(7, listener.getWorkStartedCallCount()); + Assert.assertEquals(5, listener.getWorkCompletedCallCount()); + Assert.assertEquals(2, listener.getWorkFailedCallCount()); + Assert.assertEquals(2, listener.getWorkExceptions().size()); + } + + /** + * Tests running a single job that has no listener + */ + @Test + public void testSingleFastJobWithNoListener() { + // Create the work and register it + JSR237MyRunnable fast = new JSR237MyRunnable(10); + workSchedular.scheduleWork(fast); + + // Wait for the job to complete + long startTime = System.currentTimeMillis(); + while (true) { + int completedCount = fast.getRunCompletedCount(); + if (completedCount == 1) { + break; + } + + if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) { + Assert.fail("Only " + completedCount + " work items completed before timeout"); + return; + } + + // Lets wait for the job to complete + try { + Thread.sleep(25); + } catch (InterruptedException ex) { + Assert.fail("Unexpected exception: " + ex); + } + } + } + + /** + * Tests scheduling a null as the work item + */ + @Test + public void testNullWork() { + try { + workSchedular.scheduleWork(null); + Assert.fail("Should have thrown IllegalArgumentException "); + } catch (IllegalArgumentException ex) { + // As expected + Assert.assertTrue(ex.toString().indexOf("null") != -1); + } + } + + /** + * Waits for the specified number of jobs to complete or the timeout to fire. + * + * @param listener The listener to use to track Work unit completion + * @param completedWorkItemsToWaitFor The number of Work items to complete + */ + private void waitForWorkToComplete(JSR237MyRunnerListener listener, int completedWorkItemsToWaitFor) { + long startTime = System.currentTimeMillis(); + while (true) { + int completedCount = listener.getWorkCompletedCallCount() + listener.getWorkFailedCallCount(); + if (completedCount == completedWorkItemsToWaitFor) { + return; + } + + if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) { + Assert.fail("Only " + completedCount + " work items completed before timeout"); + return; + } + + // Lets wait for more jobs to complete + try { + Thread.sleep(25); + } catch (InterruptedException ex) { + Assert.fail("Unexpected exception: " + ex); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java new file mode 100644 index 0000000000..58a1b87c48 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.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.sca.core.work; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.tuscany.sca.work.WorkSchedulerException; +import org.junit.Assert; + +/** + * A simple WorkListener that tracks invocations to it. + * + * @version $Rev$ $Date$ + */ +public class TestWorkListener implements WorkListener { + + /** + * Count of workAccepted() method calls + */ + private AtomicInteger workAcceptedCallCount = new AtomicInteger(); + + /** + * Count of workStarted() method calls + */ + private AtomicInteger workStartedCallCount = new AtomicInteger(); + + /** + * Count of workCompleted() method calls + */ + private AtomicInteger workCompletedCallCount = new AtomicInteger(); + + /** + * Count of workRejected() method calls + */ + private AtomicInteger workRejectedCallCount = new AtomicInteger(); + + /** + * List of all exceptions thrown by Work items + */ + private List workExceptions = Collections.synchronizedList(new ArrayList()); + + /** + * {@inheritDoc} + */ + public void workAccepted(WorkEvent work) { + workAcceptedCallCount.incrementAndGet(); + + // Validate the WorkEvent + Assert.assertNotNull(work.getWorkItem()); + Assert.assertEquals(WorkEvent.WORK_ACCEPTED, work.getType()); + } + + /** + * {@inheritDoc} + */ + public void workStarted(WorkEvent work) { + workStartedCallCount.incrementAndGet(); + + // Validate the WorkEvent + Assert.assertNotNull(work.getWorkItem()); + Assert.assertEquals(WorkEvent.WORK_STARTED, work.getType()); + } + + /** + * {@inheritDoc} + */ + public void workCompleted(WorkEvent work) { + if (work.getException() != null) { + workExceptions.add(work.getException()); + } + + // Validate the WorkEvent + Assert.assertNotNull(work.getWorkItem()); + Assert.assertEquals(WorkEvent.WORK_COMPLETED, work.getType()); + + workCompletedCallCount.incrementAndGet(); + } + + /** + * {@inheritDoc} + */ + public void workRejected(WorkEvent work) { + workRejectedCallCount.incrementAndGet(); + + // Validate the WorkEvent + Assert.assertNotNull(work.getWorkItem()); + Assert.assertEquals(WorkEvent.WORK_REJECTED, work.getType()); + } + + /** + * Returns the number of calls to workAccepted() + * + * @return The number of calls to workAccepted() + */ + public int getWorkAcceptedCallCount() { + return workAcceptedCallCount.get(); + } + + /** + * Returns the number of calls to workStarted() + * + * @return The number of calls to workStarted() + */ + public int getWorkStartedCallCount() { + return workStartedCallCount.get(); + } + + /** + * Returns the number of calls to workCompleted() + * + * @return The number of calls to workCompleted() + */ + public int getWorkCompletedCallCount() { + return workCompletedCallCount.get(); + } + + /** + * Returns the number of calls to workRejected() + * + * @return The number of calls to workRejected() + */ + public int getWorkRejectedCallCount() { + return workRejectedCallCount.get(); + } + + /** + * Returns a List of all exceptions that are thrown by the Work items + * + * @return A List of all exceptions that are thrown by the Work items + */ + public List getWorkExceptions() { + return Collections.unmodifiableList(workExceptions); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java new file mode 100644 index 0000000000..9e5b8d035e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java @@ -0,0 +1,238 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * This test case will test the ThreadPoolWorkManager + * + * @version $Rev$ $Date$ + */ +public class ThreadPoolWorkManagerTestCase { + + /** + * Wait up to 20 seconds for the Work units to complete + */ + private static final long WAIT_TIMEOUT = 20000; + + /** + * This is the shared instance of the ThreadPoolWorkManager used by the tests + */ + private static ThreadPoolWorkManager workManager = null; + + /** + * Setup the ThreadPoolWorkManager + */ + @BeforeClass + public static void setup() { + workManager = new ThreadPoolWorkManager(10); + } + + /** + * Make sure that the ThreadPoolWorkManager is stopped after running the tests + */ + @AfterClass + public static void destroy() { + if (workManager != null) { + workManager.destroy(); + } + } + + /** + * Tests running a single fast job on the ThreadPoolWorkManager + */ + @Test + public void testSingleFastJob() { + // Create the work and register it + TimeDelayWork fast = new TimeDelayWork(10); + TestWorkListener listener = new TestWorkListener(); + workManager.schedule(fast, listener); + + // Wait for the 1 job to complete + waitForWorkToComplete(listener, 1); + + // Test that the job completed successfully. + Assert.assertEquals(1, listener.getWorkAcceptedCallCount()); + Assert.assertEquals(0, listener.getWorkRejectedCallCount()); + Assert.assertEquals(1, listener.getWorkStartedCallCount()); + Assert.assertEquals(1, listener.getWorkCompletedCallCount()); + Assert.assertEquals(0, listener.getWorkExceptions().size()); + } + + /** + * Tests running a single job that fails on the ThreadPoolWorkManager + */ + @Test + public void testSingleFailingJob() { + // Create the work and register it + FailingWork fail = new FailingWork(); + TestWorkListener listener = new TestWorkListener(); + workManager.schedule(fail, listener); + + // Wait for the 1 job to complete + waitForWorkToComplete(listener, 1); + + // Test that the job completed successfully. + Assert.assertEquals(1, listener.getWorkAcceptedCallCount()); + Assert.assertEquals(0, listener.getWorkRejectedCallCount()); + Assert.assertEquals(1, listener.getWorkStartedCallCount()); + Assert.assertEquals(1, listener.getWorkCompletedCallCount()); + Assert.assertEquals(1, listener.getWorkExceptions().size()); + } + + /** + * Tests running a mixture of fast and slow jobs on the ThreadPoolWorkManager + */ + @Test + public void testMultipleJobs() { + // Create the work and register it + TimeDelayWork fast1 = new TimeDelayWork(50); + TimeDelayWork fast2 = new TimeDelayWork(100); + TimeDelayWork fast3 = new TimeDelayWork(200); + TimeDelayWork slow1= new TimeDelayWork(2000); + TimeDelayWork slow2 = new TimeDelayWork(2000); + TestWorkListener listener = new TestWorkListener(); + workManager.schedule(fast1, listener); + workManager.schedule(fast2, listener); + workManager.schedule(fast3, listener); + workManager.schedule(slow1, listener); + workManager.schedule(slow2, listener); + + // Wait for the 5 jobs to complete + waitForWorkToComplete(listener, 5); + + // Test that the job completed successfully. + Assert.assertEquals(5, listener.getWorkAcceptedCallCount()); + Assert.assertEquals(0, listener.getWorkRejectedCallCount()); + Assert.assertEquals(5, listener.getWorkStartedCallCount()); + Assert.assertEquals(5, listener.getWorkCompletedCallCount()); + Assert.assertEquals(0, listener.getWorkExceptions().size()); + } + + /** + * Tests running a mixture of fast and slow jobs some of which fail on the + * ThreadPoolWorkManager + */ + @Test + public void testMultipleJobsSomeFail() { + // Create the work and register it + TimeDelayWork fast1 = new TimeDelayWork(50); + TimeDelayWork fast2 = new TimeDelayWork(100); + TimeDelayWork fast3 = new TimeDelayWork(200); + TimeDelayWork slow1= new TimeDelayWork(2000); + TimeDelayWork slow2 = new TimeDelayWork(2000); + FailingWork fail1 = new FailingWork(); + FailingWork fail2 = new FailingWork(); + TestWorkListener listener = new TestWorkListener(); + workManager.schedule(fast1, listener); + workManager.schedule(fast2, listener); + workManager.schedule(fail1, listener); + workManager.schedule(fast3, listener); + workManager.schedule(slow1, listener); + workManager.schedule(fail2, listener); + workManager.schedule(slow2, listener); + + // Wait for the 7 jobs to complete + waitForWorkToComplete(listener, 7); + + // Test that the job completed successfully. + Assert.assertEquals(7, listener.getWorkAcceptedCallCount()); + Assert.assertEquals(0, listener.getWorkRejectedCallCount()); + Assert.assertEquals(7, listener.getWorkStartedCallCount()); + Assert.assertEquals(7, listener.getWorkCompletedCallCount()); + Assert.assertEquals(2, listener.getWorkExceptions().size()); + } + + /** + * Tests creating a ThreadPoolWorkManager with invalid pool sizes of -10 to 0 + * inclusive + */ + @Test + public void testThreadPoolWorkManagerLessThan1Size() { + for (int i = 0; i >= -10; i--) { + new ThreadPoolWorkManager(i); + } + } + + /** + * Tests running a single job that has no listener + */ + @Test + public void testSingleFastJobWithNoListener() { + // Create the work and register it + TimeDelayWork fast = new TimeDelayWork(10); + workManager.schedule(fast); + + // Wait for the job to complete + long startTime = System.currentTimeMillis(); + while (true) { + int completedCount = fast.getRunCompletedCount(); + if (completedCount == 1) { + break; + } + + if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) { + Assert.fail("Only " + completedCount + " work items completed before timeout"); + return; + } + + // Lets wait for the job to complete + try { + Thread.sleep(25); + } catch (InterruptedException ex) { + Assert.fail("Unexpected exception: " + ex); + } + } + + // Make sure we have got one completed run + Assert.assertEquals(1, fast.getRunCompletedCount()); + } + + /** + * Waits for the specified number of jobs to complete or the timeout to fire. + * + * @param listener The listener to use to track Work unit completion + * @param completedWorkItemsToWaitFor The number of Work items to complete + */ + private void waitForWorkToComplete(TestWorkListener listener, int completedWorkItemsToWaitFor) { + long startTime = System.currentTimeMillis(); + while (true) { + int completedCount = listener.getWorkCompletedCallCount(); + if (completedCount == completedWorkItemsToWaitFor) { + return; + } + + if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) { + Assert.fail("Only " + completedCount + " work items completed before timeout"); + return; + } + + // Lets wait for more jobs to complete + try { + Thread.sleep(25); + } catch (InterruptedException ex) { + Assert.fail("Unexpected exception: " + ex); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java new file mode 100644 index 0000000000..6c10057046 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Simple Work item that will sleep in the run() method for the specified + * period of time + * + * @version $Rev$ $Date$ + */ +public class TimeDelayWork extends Work { + + /** + * Count of completed run() method calls + */ + private AtomicInteger runCompletedCount = new AtomicInteger(); + + /** + * The amount of time to sleep in the Run loop + */ + private final long sleepTime; + + /** + * Constructor + * + * @param sleepTime The amount of time to sleep (in milliseconds) in the run() method + */ + public TimeDelayWork(long sleepTime) { + super(null); + this.sleepTime = sleepTime; + } + + /** + * {@inheritDoc} + */ + public boolean isDaemon() { + return false; + } + + /** + * {@inheritDoc} + */ + public void release() { + } + + /** + * Sleeps for a period of time defined by sleepTime + */ + public void run() { + System.out.println("Starting " + this); + try { + Thread.sleep(sleepTime); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("Done " + this); + runCompletedCount.incrementAndGet(); + } + + /** + * Returns the number of completed calls to run() + * + * @return The number of completed calls to run() + */ + public int getRunCompletedCount() { + return runCompletedCount.get(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java new file mode 100644 index 0000000000..341d889b7d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.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.sca.scope; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.scope.Scope; + +/** + * @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 { + String scope; + + public Bar(String scope) { + this.scope = scope; + } + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest new file mode 100644 index 0000000000..ad23df3761 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name=implementation.last, stage=implementation, after=* +name=reference.first, stage=reference, before=* +name=reference.transaction, stage=reference, after=reference.interface +name=reference.binding.header, stage=reference.binding, after=reference.binding.transport +name=service.binding.header, stage=service.binding, after=service.binding.transport +name=service.transaction, stage=service, after=service.binding, before=component.service +name=implementation.transaction, stage=implementation, before=implementation.policy diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/pom.xml new file mode 100644 index 0000000000..2c7a152917 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-data-api + Apache Tuscany SCA Data API + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.6-SNAPSHOT + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.data.api + ${pom.name} + org.apache.tuscany.sca.data* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Collection.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Collection.java new file mode 100644 index 0000000000..f559d5d914 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Collection.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.sca.data.collection; + +import org.osoa.sca.annotations.Remotable; + +/** + * Provides access to a collection of data items. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Collection { + + /** + * Get the whole collection. + * + * @return the whole collection. + */ + Entry[] getAll(); + + /** + * Returns a collection resulting from a query. + * + * @return the collection. + */ + Entry[] query(String queryString); + + /** + * Creates a new item. + * + * @param key + * @param item + * @return + */ + K post(K key, D item); + + /** + * Retrieves an item. + * + * @param key + * @return + */ + D get(K key) throws NotFoundException; + + /** + * Updates an item. + * + * @param key + * @param item + * @return + */ + void put(K key, D item) throws NotFoundException; + + /** + * Delete an item. + * + * @param key + */ + void delete(K key) throws NotFoundException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Entry.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Entry.java new file mode 100644 index 0000000000..5903fd95a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Entry.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.sca.data.collection; + + +/** + * Represents a key/data pair in a data collection. + * + * @version $Rev$ $Date$ + */ +public class Entry { + + private K key; + private D data; + + /** + * Constructs a new entry. + */ + public Entry() { + } + + /** + * Constructs a new entry. + * @param key the entry key + * @param data the entry data + */ + public Entry(K key, D data) { + this.key = key; + this.data = data; + } + + /** + * Returns the entry key. + * @return the key + */ + public K getKey() { + return key; + } + + /** + * Sets the entry key. + * @param key the key + */ + public void setKey(K key) { + this.key = key; + } + + /** + * Returns the entry data. + * @return the entry data + */ + public D getData() { + return data; + } + + /** + * Sets the entry data + * @param data the entry data + */ + public void setData(D data) { + this.data = data; + } + + //FIXME Temporary methods to make JAXB register the Item + // class when the Entry class is registered in a JAXB context + public void setDummy(Item item) {} + public Item getDummy() { return null; } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Item.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Item.java new file mode 100644 index 0000000000..37042c0895 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/Item.java @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.data.collection; + +import java.util.Date; + + +/** + * Represents a data item. + * + * @version $Rev$ $Date$ + */ +public class Item { + + private String title; + private String contents; + private String link; + private String related; + private String alternate; + private Date date; + + /** + * Constructs a new item. + */ + public Item() { + } + + /** + * Constructs a new item. + * @param title the item title + * @param contents the item contents + * @param link the item link to a web resource + * @param related the item link to a related web resource + * @param date the item date + */ + public Item(String title, String contents, String link, String related, Date date) { + this.title = title; + this.contents = contents; + this.link = link; + this.related = related; + this.date = date; + } + + /** + * Returns the item title. + * @return the item title + */ + public String getTitle() { + return title; + } + + /** + * Sets the item title. + * @param title the item title + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * Returns the item contents + * @return the item contents + */ + public String getContents() { + return contents; + } + + /** + * Sets the item contents + * @param contents the item contents + */ + public void setContents(String contents) { + this.contents = contents; + } + + /** + * Returns the item link to a web resource + * @return the item link to a web resource + */ + public String getLink() { + return link; + } + + /** + * Sets the item link to a web resource + * @param link the item link to a web resource + */ + public void setLink(String link) { + this.link = link; + } + + /** + * Returns the item link to a related web resource + * @return the item link to a related web resource + */ + public String getRelated() { + return related; + } + + /** + * Sets the item link to a related web resource. + * + * @param related the item link to a related web resource + */ + public void setRelated(String related) { + this.related = related; + } + + /** + * Returns the item link to an alternate web resource + * @return the item link to an alternate web resource + */ + public String getAlternate() { + return alternate; + } + + /** + * Sets the item link to an alternate web resource. + * + * @param alternate the item link to an alternate web resource + */ + public void setAlternate(String alternate) { + this.alternate = alternate; + } + + /** + * Returns the item date + * @return the item date + */ + public Date getDate() { + return date; + } + + /** + * Sets the item date + * @param date the item date + */ + public void setDate(Date date) { + this.date = date; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/ItemCollection.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/ItemCollection.java new file mode 100644 index 0000000000..c30bbc771a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/ItemCollection.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.sca.data.collection; + +import org.osoa.sca.annotations.Remotable; + +/** + * Provides access to a collection of data items. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface ItemCollection extends Collection { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/LocalItemCollection.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/LocalItemCollection.java new file mode 100644 index 0000000000..69512058b7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/LocalItemCollection.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.sca.data.collection; + + +/** + * Provides access to a collection of data items. + * + * @version $Rev$ $Date$ + */ +public interface LocalItemCollection extends Collection { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/NotFoundException.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/NotFoundException.java new file mode 100644 index 0000000000..7f13db5228 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/data/collection/NotFoundException.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.sca.data.collection; + +/** + * Indicates that an item could not be found in a collection. + * + * @version $Rev$ $Date$ + */ +public class NotFoundException extends Exception { + private static final long serialVersionUID = 6792367409396084646L; + + public NotFoundException() { + } + + public NotFoundException(String message) { + super(message); + } + + public NotFoundException(Throwable cause) { + super(cause); + } + + public NotFoundException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Collection.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Collection.java new file mode 100644 index 0000000000..c2332ae2c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Collection.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.sca.implementation.data.collection; + +import org.osoa.sca.annotations.Remotable; + +/** + * Provides access to a collection of data items. + * + * @version $Rev$ $Date$ + */ +@Remotable +@Deprecated +public interface Collection extends org.apache.tuscany.sca.data.collection.Collection { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Entry.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Entry.java new file mode 100644 index 0000000000..a0d232a201 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Entry.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.sca.implementation.data.collection; + + +/** + * Represents a key/data pair in a data collection. + * + * @version $Rev$ $Date$ + */ +@Deprecated +public class Entry extends org.apache.tuscany.sca.data.collection.Entry { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Item.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Item.java new file mode 100644 index 0000000000..77d8173521 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/Item.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.sca.implementation.data.collection; + + + +/** + * Represents a data item. + * + * @version $Rev$ $Date$ + */ +@Deprecated +public class Item extends org.apache.tuscany.sca.data.collection.Item { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/ItemCollection.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/ItemCollection.java new file mode 100644 index 0000000000..757152725d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/ItemCollection.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.sca.implementation.data.collection; + +import org.osoa.sca.annotations.Remotable; + +/** + * Provides access to a collection of data items. + * + * @version $Rev$ $Date$ + */ +@Remotable +@Deprecated +public interface ItemCollection extends Collection { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/LocalItemCollection.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/LocalItemCollection.java new file mode 100644 index 0000000000..047ab8829e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/LocalItemCollection.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.sca.implementation.data.collection; + + +/** + * Provides access to a collection of data items. + * + * @version $Rev$ $Date$ + */ +@Deprecated +public interface LocalItemCollection extends Collection { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/NotFoundException.java b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/NotFoundException.java new file mode 100644 index 0000000000..ed71471d9e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/data-api/src/main/java/org/apache/tuscany/sca/implementation/data/collection/NotFoundException.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.sca.implementation.data.collection; + +/** + * Indicates that an item could not be found in a collection. + * + * @version $Rev$ $Date$ + */ +@Deprecated +public class NotFoundException extends org.apache.tuscany.sca.data.collection.NotFoundException { + private static final long serialVersionUID = 2812975065056330240L; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/pom.xml new file mode 100644 index 0000000000..2ea580d9ef --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/pom.xml @@ -0,0 +1,122 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding-axiom + Apache Tuscany SCA Data Binding for Axiom + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + javax.xml.stream + stax-api + 1.0-2 + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.7 + + + xerces + xercesImpl + + + stax + stax-api + + + xml-apis + xml-apis + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.7 + runtime + + + stax + stax-api + + + + + + commons-logging + commons-logging + 1.1.1 + runtime + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding.axiom + ${pom.name} + org.apache.tuscany.sca.databinding.axiom* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java new file mode 100644 index 0000000000..142229f4f6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.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.sca.databinding.axiom; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * DataBinding for AXIOM + * + * @version $Rev$ $Date$ + */ +public class AxiomDataBinding extends BaseDataBinding { + + public static final String NAME = OMElement.class.getName(); + + public AxiomDataBinding() { + super(NAME, OMElement.class); + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseDataBinding#getWrapperHandler() + */ + @Override + public WrapperHandler getWrapperHandler() { + return new OMElementWrapperHandler(); + } + + @Override + public Object copy(Object source, DataType dataType, Operation operation) { + if ( OMElement.class.isAssignableFrom(source.getClass()) ) { + try { + OMElement sourceElement = (OMElement)source; + return sourceElement.cloneOMElement(); + } catch ( Exception e ) { + throw new IllegalArgumentException(e); + } + } + return super.copy(source, dataType, operation); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java new file mode 100644 index 0000000000..cd820ab4b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.axiom; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMDataSource; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.OMXMLParserWrapper; +import org.apache.axiom.om.impl.builder.StAXBuilder; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Helper for AXIOM + * + * @version $Rev$ $Date$ + */ +public class AxiomHelper { + private static final String DEFAULT_PREFIX = "_ns_"; + + private AxiomHelper() { + } + + /** + * See http://issues.apache.org/jira/browse/WSCOMMONS-240 + * @param om + */ + public static void completeAndClose(OMElement om) { + // Get the builder associated with the om element + OMXMLParserWrapper builder = om.getBuilder(); + if (builder != null) { + if (builder instanceof StAXBuilder) { + ((StAXBuilder)builder).releaseParserOnClose(true); + } + OMElement document = builder.getDocumentElement(); + if (document != null) { + document.build(); + } + } + if (builder instanceof StAXBuilder) { + ((StAXBuilder)builder).close(); + } + } + + /** + * This method will close the builder immediately. Any subsequent Axiom objects won't + * be built or accessible. + */ + public static void closeImmediately(OMElement om) { + // Get the builder associated with the om element + OMXMLParserWrapper builder = om.getBuilder(); + if (builder != null) { + if (builder instanceof StAXBuilder) { + ((StAXBuilder)builder).releaseParserOnClose(true); + ((StAXBuilder)builder).close(); + } + // builder.close(); + } + } + + /** + * @param context + * @param element + */ + public static void adjustElementName(TransformationContext context, OMElement element) { + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType == null ? null : dataType.getLogical(); + if (!(logical instanceof XMLType)) { + return; + } + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement() && !xmlType.getElementName().equals(element.getQName())) { + // FIXME:: Throw exception or switch to the new Element? + OMFactory factory = OMAbstractFactory.getOMFactory(); + QName name = xmlType.getElementName(); + OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(name.getLocalPart()); + } + } + } + + public static OMElement createOMElement(OMFactory factory, QName element) { + String localName = element.getLocalPart(); + OMNamespace ns = createOMNamespace(factory, element); + + return factory.createOMElement(localName, ns); + + } + + public static OMElement createOMElement(OMFactory factory, QName element, OMDataSource dataSource) { + String localName = element.getLocalPart(); + OMNamespace ns = createOMNamespace(factory, element); + + return factory.createOMElement(dataSource, localName, ns); + + } + + /** + * @param factory + * @param name + * @return + */ + public static OMNamespace createOMNamespace(OMFactory factory, QName name) { + String namespaceURI = name.getNamespaceURI(); + String prefix = name.getPrefix(); + + OMNamespace ns = null; + + // Qualified Element: we need an OMNamespace + if (prefix.length() == 0) { + // The prefix does not appear to be specified, let's create one + prefix = DEFAULT_PREFIX; + } + ns = factory.createOMNamespace(namespaceURI, prefix); + + return ns; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Exception2OMElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Exception2OMElement.java new file mode 100644 index 0000000000..429a6dbe5d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Exception2OMElement.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.axiom; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMAttribute; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.javabeans.Java2XMLMapperException; +import org.apache.tuscany.sca.databinding.javabeans.JavaBean2XMLTransformer; + +/** + * + * @version $Rev$ $Date$ + */ +public class Exception2OMElement extends JavaBean2XMLTransformer { + + public static final String GETCAUSE = "getCause"; + public static final String GETLOCALIZEDMESSAGE = "getLocalizedMessage"; + public static final String GETSTACKTRACE = "getStackTrace"; + public static final String GETCLASS = "getClass"; + + private OMFactory factory; + + public Exception2OMElement() { + super(); + factory = OMAbstractFactory.getOMFactory(); + } + + @Override + public OMElement transform(Object source, TransformationContext context) { + OMElement element = super.transform(source, context); + AxiomHelper.adjustElementName(context, element); + return element; + } + + @Override + protected boolean isMappedGetter(String methodName) { + if (GETCAUSE.equals(methodName) + || GETLOCALIZEDMESSAGE.equals(methodName) + || GETSTACKTRACE.equals(methodName) + || GETCLASS.equals(methodName)) { + return false; + } else { + return true; + } + } + + @Override + public void appendChild(OMElement parentElement, OMElement childElement) throws Java2XMLMapperException { + parentElement.addChild(childElement); + } + + @Override + public OMElement createElement(QName qName) throws Java2XMLMapperException { + return factory.createOMElement(qName); + } + + @Override + public void appendText(OMElement parentElement, String textData) throws Java2XMLMapperException { + if (textData == null) { + OMNamespace xsi = factory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi"); + OMAttribute nil = factory.createOMAttribute("nil", xsi, "true"); + parentElement.addAttribute(nil); + } else { + factory.createOMText(parentElement, textData); + } + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Externalizable2OMElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Externalizable2OMElement.java new file mode 100644 index 0000000000..e23d89327c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Externalizable2OMElement.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.sca.databinding.axiom; + +import java.io.ByteArrayOutputStream; +import java.io.Externalizable; +import java.io.ObjectOutputStream; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.XSDDataTypeConverter.Base64Binary; + +/** + * + * @version $Rev$ $Date$ + */ +public class Externalizable2OMElement extends BaseTransformer implements + PullTransformer { + + @Override + protected Class getSourceType() { + return Externalizable.class; + } + + @Override + protected Class getTargetType() { + return OMElement.class; + } + + public OMElement transform(Externalizable source, TransformationContext context) { + OMElement element = null; + + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(bos); + out.writeObject(source); + out.close(); + OMFactory factory = OMAbstractFactory.getOMFactory(); + OMNamespace ns = AxiomHelper.createOMNamespace(factory, new QName("http://callable")); + element = factory.createOMElement("reference",ns); + element.setText(Base64Binary.encode(bos.toByteArray())); + return element; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Exception.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Exception.java new file mode 100644 index 0000000000..3dc73c89cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Exception.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.sca.databinding.axiom; + +import java.util.Iterator; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMNode; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.databinding.javabeans.XML2JavaBeanTransformer; +import org.apache.tuscany.sca.databinding.javabeans.XML2JavaMapperException; + +/** + * Transformer to convert data from an OMElement to a Java Exception + * + * @version $Rev$ $Date$ + */ +public class OMElement2Exception extends XML2JavaBeanTransformer { + + @Override + public OMElement getRootElement(OMElement element) throws XML2JavaMapperException { + return element; + } + + @Override + public Iterator getChildElements(OMElement parent) throws XML2JavaMapperException { + return parent.getChildElements(); + } + + @Override + public String getElementName(OMElement element) throws XML2JavaMapperException { + return element.getLocalName(); + } + + @Override + public String getText(OMElement element) throws XML2JavaMapperException { + return element.getText(); + } + + @Override + public boolean isTextElement(OMElement element) throws XML2JavaMapperException { + return false; + } + + @Override + public boolean isTextOnly(OMElement element) throws XML2JavaMapperException { + OMNode firstChild = element.getFirstOMChild(); + return firstChild instanceof OMText && firstChild.getNextOMSibling() == null; + } + + @Override + public OMElement getFirstChildWithName(OMElement element, QName name) throws XML2JavaMapperException { + return element.getFirstChildWithName(name); + } + + @Override + public Class getSourceType() { + return OMElement.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Externalizable.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Externalizable.java new file mode 100644 index 0000000000..ef7359fbcd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Externalizable.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.sca.databinding.axiom; + +import java.io.ByteArrayInputStream; +import java.io.Externalizable; +import java.io.ObjectInputStream; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.XSDDataTypeConverter.Base64Binary; + +/** + * Transformer to convert data from an OMElement to XML String + * + * @version $Rev$ $Date$ + */ +public class OMElement2Externalizable extends BaseTransformer implements PullTransformer { + // private XmlOptions options; + + public Externalizable transform(OMElement source, TransformationContext context) { + try { + String value = source.getText(); + ByteArrayInputStream bis = new ByteArrayInputStream(Base64Binary.decode(value)); + ObjectInputStream ois = new ObjectInputStream(bis); + Object obj = ois.readObject(); + ois.close(); + Externalizable aReference = (Externalizable) obj; + return aReference; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return OMElement.class; + } + + @Override + protected Class getTargetType() { + return Externalizable.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java new file mode 100644 index 0000000000..ea40e61746 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.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.sca.databinding.axiom; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.impl.SimpleType2JavaTransformer; + +/** + * Transformer to convert data from a simple java Object to OMElement. + * + * @version $Rev$ $Date$ + */ +public class OMElement2Object extends SimpleType2JavaTransformer { + + /** + * @see org.apache.tuscany.sca.databinding.impl.SimpleType2JavaTransformer#close(java.lang.Object) + */ + @Override + protected void close(OMElement source) { + if (source != null) { + AxiomHelper.completeAndClose(source); + } + } + + @Override + protected String getText(OMElement source) { + return source.getText(); + } + + @Override + public Class getSourceType() { + return OMElement.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java new file mode 100644 index 0000000000..b2c004324c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.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.sca.databinding.axiom; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * Transformer to convert data from an OMElement to XML String + * + * @version $Rev$ $Date$ + */ +public class OMElement2String extends BaseTransformer implements PullTransformer { + // private XmlOptions options; + + public String transform(OMElement source, TransformationContext context) { + try { + StringWriter writer = new StringWriter(); + source.serialize(writer); + return writer.toString(); + } catch (XMLStreamException e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return OMElement.class; + } + + @Override + protected Class getTargetType() { + return String.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java new file mode 100644 index 0000000000..01e7003b20 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.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.sca.databinding.axiom; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * + * @version $Rev$ $Date$ + */ +public class OMElement2XMLStreamReader extends BaseTransformer implements + PullTransformer { + // private XmlOptions options; + + public static final QName QNAME_NIL = new QName("http://www.w3.org/2001/XMLSchema-instance", "nil"); + + public XMLStreamReader transform(OMElement source, TransformationContext context) { + if (source == null) { + return null; + } else { + if ("true".equals(source.getAttributeValue(QNAME_NIL))) { + return null; + } else { + return source.getXMLStreamReader(); + } + } + } + + @Override + protected Class getSourceType() { + return OMElement.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java new file mode 100644 index 0000000000..be8d1a2ead --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java @@ -0,0 +1,267 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.axiom; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMAttribute; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * OMElement wrapper handler implementation + * + * @version $Rev$ $Date$ + */ +public class OMElementWrapperHandler implements WrapperHandler { + + private OMFactory factory; + + public OMElementWrapperHandler() { + super(); + this.factory = OMAbstractFactory.getOMFactory(); + } + + public OMElement create(Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : + outputWrapperInfo.getWrapperElement(); + + OMElement wrapper = AxiomHelper.createOMElement(factory, element.getQName()); + return wrapper; + } + + public void setChildren(OMElement wrapper, Object[] childObjects, Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + List childElements = input? inputWrapperInfo.getChildElements(): + outputWrapperInfo.getChildElements(); + + for (int i = 0; i < childElements.size(); i++) { + setChild(wrapper, i, childElements.get(i), childObjects[i]); + } + + } + + public void setChild(OMElement wrapper, int i, ElementInfo childElement, Object value) { + if (childElement.isMany()) { + Object[] elements = (Object[])value; + if (value != null) { + for (Object e : elements) { + addChild(wrapper, childElement, (OMElement)e); + } + } + } else { + OMElement element = (OMElement)value; + addChild(wrapper, childElement, element); + } + } + + private void addChild(OMElement wrapper, ElementInfo childElement, OMElement element) { + if (element == null) { + OMElement e = wrapper.getOMFactory().createOMElement(childElement.getQName(), wrapper); + attachXSINil(e); + return; + } + QName elementName = childElement.getQName(); + // Make it a bit tolerating of element QName + if (!elementName.equals(element.getQName())) { + OMNamespace namespace = factory.createOMNamespace(elementName.getNamespaceURI(), elementName.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(childElement.getQName().getLocalPart()); + } + wrapper.addChild(element); + } + + public List getChildren(OMElement wrapper, Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + List childElements = input? inputWrapperInfo.getChildElements(): + outputWrapperInfo.getChildElements(); + + List elements = new ArrayList(); + int i = 0; + for (ElementInfo e : childElements) { + elements.add(getChild(wrapper, e, i)); + i++; + } + return elements; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(Operation, boolean) + */ + public DataType getWrapperType(Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : + outputWrapperInfo.getWrapperElement(); + + DataType wrapperType = + new DataTypeImpl(AxiomDataBinding.NAME, OMElement.class, new XMLType(element)); + return wrapperType; + } + + public boolean isInstance(Object wrapperObj, Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : + outputWrapperInfo.getWrapperElement(); + + OMElement wrapper = (OMElement)wrapperObj; + if (!element.getQName().equals(wrapper.getQName())) { + return false; + } + return true; + /* + Set names = new HashSet(); + for (ElementInfo e : childElements) { + names.add(e.getQName()); + } + for (Iterator i = wrapper.getChildElements(); i.hasNext();) { + OMElement child = (OMElement)i.next(); + if (!names.contains(child.getQName())) { + return false; + } + } + return true; + */ + } + + private static final QName XSI_TYPE_QNAME = new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"); + + private List> getElements(OMElement wrapper) { + List> elements = new ArrayList>(); + List current = new ArrayList(); + elements.add(current); + boolean first = true; + QName last = null; + + for (Iterator i = wrapper.getChildElements(); i.hasNext();) { + OMElement element = (OMElement)i.next(); + if (first || element.getQName().equals(last)) { + current.add(element); + last = element.getQName(); + } else { + current = new ArrayList(); + elements.add(current); + current.add(element); + last = element.getQName(); + } + first = false; + } + return elements; + } + + public Object getChild(OMElement wrapper, ElementInfo childElement, int index) { + Iterator children = wrapper.getChildrenWithName(childElement.getQName()); + if (!children.hasNext()) { + // No name match, try by index + List> list = getElements(wrapper); + List elements = list.get(index); + if (!childElement.isMany()) { + return elements.isEmpty() ? null : attachXSIType(childElement, elements.get(0)); + } else { + Object[] array = elements.toArray(); + for (Object item : array) { + attachXSIType(childElement, (OMElement)item); + } + return array; + } + } + if (!childElement.isMany()) { + if (children.hasNext()) { + OMElement child = (OMElement)children.next(); + attachXSIType(childElement, child); + return child; + } else { + return null; + } + } else { + List elements = new ArrayList(); + for (; children.hasNext();) { + OMElement child = (OMElement)children.next(); + attachXSIType(childElement, child); + elements.add(child); + } + return elements.toArray(); + } + } + + /** + * Create xis:type if required + * @param childElement + * @param element + * @return + */ + private OMElement attachXSIType(ElementInfo childElement, OMElement element) { + TypeInfo type = childElement.getType(); + if (type != null && type.getQName() != null) { + OMAttribute attr = element.getAttribute(XSI_TYPE_QNAME); + if (attr == null) { + String typeNS = type.getQName().getNamespaceURI(); + if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(typeNS)) { + return element; + } + OMNamespace ns = element.getOMFactory().createOMNamespace(typeNS, "_typens_"); + element.declareNamespace(ns); + OMNamespace xsiNS = + element.getOMFactory().createOMNamespace(XSI_TYPE_QNAME.getNamespaceURI(), + XSI_TYPE_QNAME.getPrefix()); + element.declareNamespace(xsiNS); + attr = + element.getOMFactory().createOMAttribute("type", + xsiNS, + "_typens_:" + type.getQName().getLocalPart()); + element.addAttribute(attr); + } + } + return element; + } + + private void attachXSINil(OMElement element) { + OMNamespace xsiNS = + element.getOMFactory().createOMNamespace(XSI_TYPE_QNAME.getNamespaceURI(), XSI_TYPE_QNAME.getPrefix()); + element.declareNamespace(xsiNS); + OMAttribute attr = element.getOMFactory().createOMAttribute("nil", xsiNS, "true"); + element.addAttribute(attr); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java new file mode 100644 index 0000000000..88d6b462c1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.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.sca.databinding.axiom; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMAttribute; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.Java2SimpleTypeTransformer; + +/** + * Transformer to convert data from an simple OMElement to Java Object + * + * @version $Rev$ $Date$ + */ +public class Object2OMElement extends Java2SimpleTypeTransformer { + + private OMFactory factory; + + public Object2OMElement() { + super(); + factory = OMAbstractFactory.getOMFactory(); + } + + @Override + protected OMElement createElement(QName element, String text, TransformationContext context) { + OMElement omElement = AxiomHelper.createOMElement(factory, element); + if (text == null) { + OMNamespace xsi = factory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi"); + OMAttribute nil = factory.createOMAttribute("nil", xsi, "true"); + omElement.addAttribute(nil); + } else { + factory.createOMText(omElement, text); + } + return omElement; + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java new file mode 100644 index 0000000000..9eccd52d74 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.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.sca.databinding.axiom; + +import java.io.ByteArrayInputStream; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * + * @version $Rev$ $Date$ + */ +public class String2OMElement extends BaseTransformer implements + PullTransformer { + + @SuppressWarnings("unchecked") + public OMElement transform(String source, TransformationContext context) { + try { + StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(source.getBytes())); + OMElement element = builder.getDocumentElement(); + AxiomHelper.adjustElementName(context, element); + return element; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getTargetType() { + return OMElement.class; + } + + @Override + protected Class getSourceType() { + return String.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java new file mode 100644 index 0000000000..761185c297 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.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.sca.databinding.axiom; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * + * @version $Rev$ $Date$ + */ +public class XMLStreamReader2OMElement extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader2OMElement() { + super(); + } + + public OMElement transform(XMLStreamReader source, TransformationContext context) { + if (source == null) { + return null; + } + try { + StAXOMBuilder builder = new StAXOMBuilder(source); + OMElement element = builder.getDocumentElement(); + AxiomHelper.adjustElementName(context, element); + return element; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getTargetType() { + return OMElement.class; + } + + @Override + protected Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..183270f9b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# implementation classes for the databindings +org.apache.tuscany.sca.databinding.axiom.AxiomDataBinding;name=org.apache.axiom.om.OMElement + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..a1f18f9638 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -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. + +# Implementation classes for the transformers +# org.apache.tuscany.sca.databinding.axiom.CallableReference2OMElement;source=org.osoa.sca.CallableReference,target=org.apache.axiom.om.OMElement,weight=10 +# org.apache.tuscany.sca.databinding.axiom.OMElement2CallableReference;source=org.apache.axiom.om.OMElement,target=org.osoa.sca.CallableReference,weight=10 +org.apache.tuscany.sca.databinding.axiom.Externalizable2OMElement;source=java.io.Externalizable,target=org.apache.axiom.om.OMElement,weight=10 +org.apache.tuscany.sca.databinding.axiom.OMElement2Externalizable;source=org.apache.axiom.om.OMElement,target=java.io.Externalizable,weight=10 +org.apache.tuscany.sca.databinding.axiom.Exception2OMElement;source=java:exception,target=org.apache.axiom.om.OMElement,weight=10 +org.apache.tuscany.sca.databinding.axiom.OMElement2Exception;source=org.apache.axiom.om.OMElement,target=java:exception,weight=10 +# org.apache.tuscany.sca.databinding.axiom.Object2OMElement;source=java:simpleType,target=org.apache.axiom.om.OMElement,weight=80000 +# org.apache.tuscany.sca.databinding.axiom.OMElement2Object;source=org.apache.axiom.om.OMElement,target=java:simpleType,weight=80000 +org.apache.tuscany.sca.databinding.axiom.OMElement2String;source=org.apache.axiom.om.OMElement,target=java.lang.String,weight=80 +org.apache.tuscany.sca.databinding.axiom.OMElement2XMLStreamReader;source=org.apache.axiom.om.OMElement,target=javax.xml.stream.XMLStreamReader,weight=60 +org.apache.tuscany.sca.databinding.axiom.String2OMElement;source=java.lang.String,target=org.apache.axiom.om.OMElement,weight=80 +org.apache.tuscany.sca.databinding.axiom.XMLStreamReader2OMElement;source=javax.xml.stream.XMLStreamReader,target=org.apache.axiom.om.OMElement,weight=60 diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java new file mode 100644 index 0000000000..7453cb787a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.axiom; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMAttribute; +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * + * @version $Rev$ $Date$ + */ +public class OMElementTestCase extends TestCase { + private static final String IPO_XML = + "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + public final void testStringTransform() { + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(IPO_XML, null); + OMElement2String t2 = new OMElement2String(); + String xml = t2.transform(element, null); + Assert.assertNotNull(xml); + Assert.assertNotNull(xml.indexOf("") != -1); + } + + public final void testStringTransform2() { + String str = + "Robert"; + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(str, null); + OMElement2String t2 = new OMElement2String(); + String xml = t2.transform(element, null); + Assert.assertNotNull(xml); + Assert.assertNotNull(xml.indexOf("") != -1); + } + + public final void testStAXTransform() { + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(IPO_XML, null); + + OMElement2XMLStreamReader t2 = new OMElement2XMLStreamReader(); + XMLStreamReader reader = t2.transform(element, null); + + XMLStreamReader2OMElement t3 = new XMLStreamReader2OMElement(); + OMElement element2 = t3.transform(reader, null); + + Assert.assertEquals(element2.getQName(), element.getQName()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), element2.getQName()); + } + + public final void testCopy() { + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(IPO_XML, null); + OMElement copy = (OMElement)new AxiomDataBinding().copy(element, null, null); + assertNotSame(element, copy); + assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), copy.getQName()); + } + + private static final QName XSI_NIL = new QName("http://www.w3.org/2001/XMLSchema-instance", "nil", "xsi"); + + public final void testNil() { + Object2OMElement t1 = new Object2OMElement(); + TransformationContext context = new TransformationContextImpl(); + DataType dataType = + new DataTypeImpl(int.class, new XMLType(new QName("http://ns1", "nilElement"), + SimpleTypeMapperImpl.XSD_INT)); + context.setTargetDataType(dataType); + OMElement element = t1.transform(null, context); + OMAttribute attribute = element.getAttribute(XSI_NIL); + Assert.assertNotNull(attribute); + Assert.assertEquals("true", attribute.getAttributeValue()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/ipo.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/ipo.xml new file mode 100644 index 0000000000..df901d183d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/ipo.xml @@ -0,0 +1,51 @@ + + + + + + Helen Zoe + 47 Eden Street + Cambridge + CB1 1JR + + + + Robert Smith + 8 Oak Avenue + Old Town + PA + 95819 + + + + + Lapis necklace + 1 + 99.95 + Want this for the holidays + 1999-12-05 + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..af1e73172d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/ipo.xsd @@ -0,0 +1,137 @@ + + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/order.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/order.wsdl new file mode 100644 index 0000000000..a5ead60382 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-axiom/src/test/resources/order.wsdl @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/LICENSE @@ -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, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/NOTICE new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/NOTICE @@ -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/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/pom.xml new file mode 100644 index 0000000000..78cc507308 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/pom.xml @@ -0,0 +1,87 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding-fastinfoset + Apache Tuscany SCA Data Binding for FastInfoset + Tuscany FastInfoset Data Binding + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + com.sun.xml.fastinfoset + FastInfoset + 1.2.2 + compile + + + + junit + junit + 4.1 + + + + + + true + + java.net + java.net Maven 1.x Repository + http://download.java.net/maven/1 + legacy + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding.fastinfoset + ${pom.name} + org.apache.tuscany.sca.databinding.fastinfoset* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2Node.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2Node.java new file mode 100644 index 0000000000..2e0aa629f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2Node.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.sca.databinding.fastinfoset; + +import java.io.InputStream; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import com.sun.xml.fastinfoset.dom.DOMDocumentParser; + +/** + * @version $Rev$ $Date$ + */ +public class FastInfoset2Node extends BaseTransformer implements + PullTransformer { + + @Override + protected Class getSourceType() { + return InputStream.class; + } + + @Override + protected Class getTargetType() { + return Node.class; + } + + public Node transform(InputStream source, TransformationContext context) { + try { + DOMDocumentParser parser = new DOMDocumentParser(); + Document doc = DOMHelper.newDocument(); + parser.parse(doc, source); + return doc.getDocumentElement(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 20; + } + + @Override + public String getSourceDataBinding() { + return "xml:fastinfoset:java.io.InputStream"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2SAX.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2SAX.java new file mode 100644 index 0000000000..77f6b77636 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2SAX.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.sca.databinding.fastinfoset; + +import java.io.InputStream; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.xml.sax.ContentHandler; + +import com.sun.xml.fastinfoset.sax.SAXDocumentParser; + +/** + * @version $Rev$ $Date$ + */ +public class FastInfoset2SAX extends BaseTransformer implements + PushTransformer { + + @Override + protected Class getSourceType() { + return InputStream.class; + } + + @Override + protected Class getTargetType() { + return ContentHandler.class; + } + + + /** + * @see org.apache.tuscany.sca.databinding.PushTransformer#transform(java.lang.Object, java.lang.Object, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public void transform(InputStream source, ContentHandler target, TransformationContext context) { + try { + SAXDocumentParser parser = new SAXDocumentParser(); + parser.setContentHandler(target); + parser.parse(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 20; + } + + @Override + public String getSourceDataBinding() { + return "xml:fastinfoset:java.io.InputStream"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2XMLStreamReader.java new file mode 100644 index 0000000000..73d549f4f8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfoset2XMLStreamReader.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.sca.databinding.fastinfoset; + +import java.io.InputStream; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +import com.sun.xml.fastinfoset.stax.StAXDocumentParser; + +/** + * @version $Rev$ $Date$ + */ +public class FastInfoset2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + @Override + protected Class getSourceType() { + return InputStream.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + public XMLStreamReader transform(InputStream source, TransformationContext context) { + try { + StAXDocumentParser parser = new StAXDocumentParser(source); + return parser; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 20; + } + + @Override + public String getSourceDataBinding() { + return "xml:fastinfoset:java.io.InputStream"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/Node2FastInfoset.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/Node2FastInfoset.java new file mode 100644 index 0000000000..1c12a5dcad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/Node2FastInfoset.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.sca.databinding.fastinfoset; + +import java.io.OutputStream; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +import com.sun.xml.fastinfoset.dom.DOMDocumentSerializer; + +/** + * @version $Rev$ $Date$ + */ +public class Node2FastInfoset extends BaseTransformer implements + PushTransformer { + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + protected Class getTargetType() { + return OutputStream.class; + } + + + /** + * @see org.apache.tuscany.sca.databinding.PushTransformer#transform(java.lang.Object, java.lang.Object, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public void transform(Node source, OutputStream target, TransformationContext context) { + try { + DOMDocumentSerializer serializer = new DOMDocumentSerializer(); + serializer.setOutputStream(target); + serializer.serialize(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 20; + } + + @Override + public String getTargetDataBinding() { + return "xml:fastinfoset:java.io.OutputStream"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/XMLInputStream2FastInfoset.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/XMLInputStream2FastInfoset.java new file mode 100644 index 0000000000..b0d56b3bb6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/XMLInputStream2FastInfoset.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.fastinfoset; + +import java.io.InputStream; +import java.io.OutputStream; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +import com.sun.xml.fastinfoset.sax.SAXDocumentSerializer; + +/** + * @version $Rev$ $Date$ + */ +public class XMLInputStream2FastInfoset extends BaseTransformer implements + PushTransformer { + + @Override + protected Class getSourceType() { + return InputStream.class; + } + + @Override + protected Class getTargetType() { + return OutputStream.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.PushTransformer#transform(java.lang.Object, java.lang.Object, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public void transform(InputStream source, OutputStream target, TransformationContext context) { + try { + + // Create Fast Infoset SAX serializer + SAXDocumentSerializer saxDocumentSerializer = new SAXDocumentSerializer(); + // Set the output stream + saxDocumentSerializer.setOutputStream(target); + + // Instantiate JAXP SAX parser factory + SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); + /* Set parser to be namespace aware + * Very important to do otherwise invalid FI documents will be + * created by the SAXDocumentSerializer + */ + saxParserFactory.setNamespaceAware(true); + // Instantiate the JAXP SAX parser + SAXParser saxParser = saxParserFactory.newSAXParser(); + // Set the lexical handler + saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", saxDocumentSerializer); + // Parse the XML document and convert to a fast infoset document + saxParser.parse(source, saxDocumentSerializer); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 20; + } + + @Override + public String getTargetDataBinding() { + return "xml:fastinfoset:java.io.OutputStream"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/XMLStreamReader2FastInfoset.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/XMLStreamReader2FastInfoset.java new file mode 100644 index 0000000000..d18206600c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/java/org/apache/tuscany/sca/databinding/fastinfoset/XMLStreamReader2FastInfoset.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.sca.databinding.fastinfoset; + +import java.io.OutputStream; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.xml.XMLStreamSerializer; + +import com.sun.xml.fastinfoset.stax.StAXDocumentSerializer; + +/** + * @version $Rev$ $Date$ + */ +public class XMLStreamReader2FastInfoset extends BaseTransformer implements + PushTransformer { + + @Override + protected Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + protected Class getTargetType() { + return OutputStream.class; + } + + + /** + * @see org.apache.tuscany.sca.databinding.PushTransformer#transform(java.lang.Object, java.lang.Object, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public void transform(XMLStreamReader source, OutputStream target, TransformationContext context) { + try { + StAXDocumentSerializer serializer = new StAXDocumentSerializer(target); + XMLStreamSerializer streamSerializer = new XMLStreamSerializer(); + streamSerializer.serialize(source, serializer); + serializer.flush(); + source.close(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 20; + } + + @Override + public String getTargetDataBinding() { + return "xml:fastinfoset:java.io.OutputStream"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..ea47ee7191 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.fastinfoset.FastInfoset2Node;source=xml:fastinfoset:java.io.InputStream,target=org.w3c.dom.Node,weight=100 +org.apache.tuscany.sca.databinding.fastinfoset.FastInfoset2XMLStreamReader;source=xml:fastinfoset:java.io.InputStream,target=javax.xml.stream.XMLStreamReader,weight=80 + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer new file mode 100644 index 0000000000..1610b4f54d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.fastinfoset.FastInfoset2SAX;source=xml:fastinfoset:java.io.InputStream,target=org.xml.sax.ContentHandler ,weight=80 +org.apache.tuscany.sca.databinding.fastinfoset.Node2FastInfoset;source=org.w3c.dom.Node,target=xml:fastinfoset:java.io.OutputStream,weight=100 +org.apache.tuscany.sca.databinding.fastinfoset.XMLInputStream2FastInfoset;source=java.io.InputStream,target=xml:fastinfoset:java.io.OutputStream,weight=120 +org.apache.tuscany.sca.databinding.fastinfoset.XMLStreamReader2FastInfoset;source=javax.xml.stream.XMLStreamReader,target=xml:fastinfoset:java.io.OutputStream,weight=70 diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/test/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfosetTransformerTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/test/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfosetTransformerTestCase.java new file mode 100644 index 0000000000..bb8adf39be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/test/java/org/apache/tuscany/sca/databinding/fastinfoset/FastInfosetTransformerTestCase.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.sca.databinding.fastinfoset; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.xml.InputStream2Node; +import org.apache.tuscany.sca.databinding.xml.Node2OutputStream; +import org.apache.tuscany.sca.databinding.xml.Node2String; +import org.w3c.dom.Node; + +/** + * + * @version $Rev$ $Date$ + */ +public class FastInfosetTransformerTestCase extends TestCase { + private static final String IPO_XML = + "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + public void testXML2FastInfoset() throws Exception { + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(IPO_XML)); + XMLStreamReader2FastInfoset t1 = new XMLStreamReader2FastInfoset(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + t1.transform(reader, bos, null); + // System.out.println(bos.toString()); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + FastInfoset2Node t2 = new FastInfoset2Node(); + Node node = t2.transform(bis, null); + String xml = new Node2String().transform(node, null); + + // System.out.println(xml); + + } + + public void testPerf() throws Exception { + byte[] str = IPO_XML.getBytes(); + ByteArrayInputStream bis = new ByteArrayInputStream(str); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLInputStream2FastInfoset t = new XMLInputStream2FastInfoset(); + t.transform(bis, bos, null); + byte[] fast = bos.toByteArray(); + System.out.println(str.length + ".vs." + fast.length); + + long d1 = 0L; + long d2 = 0L; + for (int i = 0; i < 100; i++) { + InputStream2Node t1 = new InputStream2Node(); + FastInfoset2Node t2 = new FastInfoset2Node(); + InputStream is1 = new ByteArrayInputStream(str); + InputStream is2 = new ByteArrayInputStream(fast); + long s1 = System.currentTimeMillis(); + Node n1 = t1.transform(is1, null); + long s2 = System.currentTimeMillis(); + Node n2 = t2.transform(is2, null); + long s3 = System.currentTimeMillis(); + d1 += s2 - s1; // from plain xml + d2 += s3 - s2; // from fastinfoset + Node2OutputStream t3 = new Node2OutputStream(); + Node2FastInfoset t4 = new Node2FastInfoset(); + ByteArrayOutputStream os1 = new ByteArrayOutputStream(); + ByteArrayOutputStream os2 = new ByteArrayOutputStream(); + long s4 = System.currentTimeMillis(); + t3.transform(n1, os1, null); + long s5 = System.currentTimeMillis(); + t4.transform(n2, os2, null); + long s6 = System.currentTimeMillis(); + d1 += s5 - s4; // to plain xml + d2 += s6 - s5; // to fastinfoset + } + System.out.println("POX " + d1 + ".vs. FIS " + d2); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/test/resources/ipo.xsd new file mode 100644 index 0000000000..5a493e1746 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-fastinfoset/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/pom.xml new file mode 100644 index 0000000000..1c36d65b59 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/pom.xml @@ -0,0 +1,189 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding-jaxb-axiom + Apache Tuscany SCA Data Binding for JAXB-AXIOM + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding-jaxb + 1.6-SNAPSHOT + + + org.apache.ws.commons.axiom + axiom-api + 1.2.7 + + + xerces + xercesImpl + + + javax.mail + mail + + + commons-logging + commons-logging + + + xml-apis + xml-apis + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.7 + runtime + + + + + + + true + + java.net + java.net Maven 1.x Repository + http://download.java.net/maven/1 + legacy + + + + + + java.net2 + java.net Maven 2.x Repository + http://download.java.net/maven/2 + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy + generate-sources + + copy + + + + + javax.xml.bind + jaxb-api + 2.1 + jar + + + ${project.build.directory}/endorsed + false + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -Djava.endorsed.dirs=target/endorsed + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/jaxb-source + + + + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + 0.5 + + + generate-jaxb + generate-test-sources + + generate + + + + + com.example.ipo.jaxb + ${project.build.directory}/jaxb-source + ${basedir}/src/test/resources + + ipo.xsd + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding.jaxb.axiom + ${pom.name} + org.apache.tuscany.sca.databinding.jaxb.axiom* + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/AxiomHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/AxiomHelper.java new file mode 100644 index 0000000000..93277e77bf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/AxiomHelper.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.sca.databinding.jaxb.axiom; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMDataSource; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.OMXMLParserWrapper; +import org.apache.axiom.om.impl.builder.StAXBuilder; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Helper for AXIOM + * + * @version $Rev$ $Date$ + */ +public class AxiomHelper { + private static final String DEFAULT_PREFIX = "_ns_"; + + private AxiomHelper() { + } + + /** + * See http://issues.apache.org/jira/browse/WSCOMMONS-240 + * @param om + */ + public static void completeAndClose(OMElement om) { + // Get the builder associated with the om element + OMXMLParserWrapper builder = om.getBuilder(); + if (builder != null) { + if (builder instanceof StAXBuilder) { + ((StAXBuilder)builder).releaseParserOnClose(true); + } + OMElement document = builder.getDocumentElement(); + if (document != null) { + document.build(); + } + } + if (builder instanceof StAXBuilder) { + ((StAXBuilder)builder).close(); + } + } + + /** + * This method will close the builder immediately. Any subsequent Axiom objects won't + * be built or accessible. + */ + public static void closeImmediately(OMElement om) { + // Get the builder associated with the om element + OMXMLParserWrapper builder = om.getBuilder(); + if (builder != null) { + if (builder instanceof StAXBuilder) { + ((StAXBuilder)builder).releaseParserOnClose(true); + ((StAXBuilder)builder).close(); + } + // builder.close(); + } + } + + /** + * @param context + * @param element + */ + public static void adjustElementName(TransformationContext context, OMElement element) { + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType == null ? null : dataType.getLogical(); + if (!(logical instanceof XMLType)) { + return; + } + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement() && !xmlType.getElementName().equals(element.getQName())) { + // FIXME:: Throw exception or switch to the new Element? + OMFactory factory = OMAbstractFactory.getOMFactory(); + QName name = xmlType.getElementName(); + OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(name.getLocalPart()); + } + } + } + + public static OMElement createOMElement(OMFactory factory, QName element) { + String localName = element.getLocalPart(); + OMNamespace ns = createOMNamespace(factory, element); + + return factory.createOMElement(localName, ns); + + } + + public static OMElement createOMElement(OMFactory factory, QName element, OMDataSource dataSource) { + String localName = element.getLocalPart(); + OMNamespace ns = createOMNamespace(factory, element); + + return factory.createOMElement(dataSource, localName, ns); + + } + + /** + * @param factory + * @param name + * @return + */ + public static OMNamespace createOMNamespace(OMFactory factory, QName name) { + String namespaceURI = name.getNamespaceURI(); + String prefix = name.getPrefix(); + + OMNamespace ns = null; + // Qualified Element: we need an OMNamespace + if (prefix.length() == 0) { + // The prefix does not appear to be specified, let's create one + prefix = DEFAULT_PREFIX; + } + ns = factory.createOMNamespace(namespaceURI, prefix); + return ns; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXB2OMElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXB2OMElement.java new file mode 100644 index 0000000000..c4726ad8fa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXB2OMElement.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.sca.databinding.jaxb.axiom; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.jaxb.JAXBContextHelper; +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; + +/** + * JAXB Object --> AXIOM OMElement transformer + * + * @version $Rev$ $Date$ + */ +public class JAXB2OMElement extends BaseTransformer implements PullTransformer { + private OMFactory factory = OMAbstractFactory.getOMFactory(); + + @Override + public String getSourceDataBinding() { + return JAXBDataBinding.NAME; + } + + @SuppressWarnings("unchecked") + public OMElement transform(Object source, TransformationContext context) throws TransformationException { + JAXBContext jaxbContext; + try { + jaxbContext = JAXBContextHelper.createJAXBContext(context, true); + } catch (JAXBException e) { + throw new TransformationException(e); + } + Object element = JAXBContextHelper.createJAXBElement(jaxbContext, context.getTargetDataType(), source); + QName name = jaxbContext.createJAXBIntrospector().getElementName(element); + JAXBDataSource dataSource = new JAXBDataSource(element, jaxbContext); + OMElement omElement = AxiomHelper.createOMElement(factory, name, dataSource); + return omElement; + } + + @Override + public Class getSourceType() { + return Object.class; + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + + @Override + public int getWeight() { + return 3000; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBCustomBuilder.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBCustomBuilder.java new file mode 100644 index 0000000000..4876396495 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBCustomBuilder.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb.axiom; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMContainer; +import org.apache.axiom.om.OMDataSource; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMException; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.impl.builder.CustomBuilder; + +/** + * JAXBCustomBuilder creates an OMSourcedElement backed by a JAXBDataSource + * for the specified namespace and localPart. + */ +public class JAXBCustomBuilder implements CustomBuilder { + private Class type; + private JAXBContext jaxbContext; + private Unmarshaller unmarshaller; + + /** + * Create a JAXBCustomBuilder + * @param context JAXBDSContext + */ + public JAXBCustomBuilder(JAXBContext context, Class type, Unmarshaller unmarshaller) { + super(); + this.type = type; + this.jaxbContext = context; + this.unmarshaller = unmarshaller; + } + + public OMElement create(String namespace, + String localPart, + OMContainer parent, + XMLStreamReader reader, + OMFactory factory) throws OMException { + + // There are some situations where we want to use normal + // unmarshalling, so return null + if (!shouldUnmarshal(namespace, localPart)) { + return null; + } + try { + // Create an OMSourcedElement backed by an unmarshalled JAXB object + OMNamespace ns = factory.createOMNamespace(namespace, reader.getPrefix()); + + Object jaxb = unmarshaller.unmarshal(reader, type); + + OMDataSource ds = new JAXBDataSource(jaxb, jaxbContext); + OMElement omse = factory.createOMElement(ds, localPart, ns); + + parent.addChild(omse); + return omse; + } catch (JAXBException e) { + throw new OMException(e); + } + } + + /** + * The namespace identifier for the SOAP 1.1 envelope. + */ + public static final String URI_NS_SOAP_1_1_ENVELOPE = "http://schemas.xmlsoap.org/soap/envelope/"; + /** + * The namespace identifier for the SOAP 1.2 envelope. + */ + public static final String URI_NS_SOAP_1_2_ENVELOPE = "http://www.w3.org/2003/05/soap-envelope"; + + /** + * @param namespace + * @param localPart + * @return true if this ns and local part is acceptable for unmarshalling + */ + private boolean shouldUnmarshal(String namespace, String localPart) { + + // Don't unmarshall SOAPFaults or anything else in the SOAP + // namespace. + // Don't unmarshall elements that are unqualified + if (localPart == null || namespace == null + || namespace.length() == 0 + || URI_NS_SOAP_1_1_ENVELOPE.equals(namespace) + || URI_NS_SOAP_1_2_ENVELOPE.equals(namespace)) { + return false; + } + + // Don't unmarshal if this looks like encrypted data + if (localPart.equals("EncryptedData")) { + return false; + } + + return true; + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java new file mode 100644 index 0000000000..27c46cdb21 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java @@ -0,0 +1,206 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb.axiom; + +import java.io.OutputStream; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.axiom.om.OMDataSourceExt; +import org.apache.axiom.om.OMOutputFormat; +import org.apache.axiom.om.ds.OMDataSourceExtBase; +import org.apache.axiom.om.impl.MTOMXMLStreamWriter; +import org.apache.axiom.om.util.StAXUtils; +import org.apache.tuscany.sca.databinding.jaxb.JAXBContextHelper; + +/** + * + * @version $Rev$ $Date$ + */ +public class JAXBDataSource extends OMDataSourceExtBase { + private JAXBContext context; + private Object element; + + public JAXBDataSource(Object element, JAXBContext context) { + this.element = element; + this.context = context; + } + + private Marshaller getMarshaller() throws JAXBException { + return JAXBContextHelper.getMarshaller(context); + } + + private void releaseMarshaller(Marshaller marshaller) { + JAXBContextHelper.releaseJAXBMarshaller(context, marshaller); + } + + public XMLStreamReader getReader() throws XMLStreamException { + // FIXME: [rfeng] This is a quick and dirty implementation + // We could use the fastinfoset to optimize the roundtrip + StringWriter writer = new StringWriter(); + serialize(writer, new OMOutputFormat()); + StringReader reader = new StringReader(writer.toString()); + return StAXUtils.createXMLStreamReader(reader); + } + + /** + * If the writer is backed by an OutputStream, then return the OutputStream + * @param writer + * @return OutputStream or null + */ + private static OutputStream getOutputStream(XMLStreamWriter writer) throws XMLStreamException { + if (writer.getClass() == MTOMXMLStreamWriter.class) { + return ((MTOMXMLStreamWriter)writer).getOutputStream(); + } + + try { + Method method = writer.getClass().getMethod("getOutputStream"); + return (OutputStream)method.invoke(writer); + + } catch (NoSuchMethodException e) { + return null; + } catch (Exception e) { + return null; + } + } + + public void serialize(final XMLStreamWriter xmlWriter) throws XMLStreamException { + try { + // marshaller.setProperty(Marshaller.JAXB_ENCODING, format.getCharSetEncoding()); + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Marshaller marshaller = null; + try { + marshaller = getMarshaller(); + // Marshalling directly to the output stream is faster than marshalling through the + // XMLStreamWriter. Take advantage of this optimization if there is an output stream. + OutputStream os = getOutputStream(xmlWriter); + if (os != null) { + marshaller.marshal(element, os); + } else { + marshaller.marshal(element, xmlWriter); + } + } finally { + releaseMarshaller(marshaller); + } + return null; + } + }); + } catch (PrivilegedActionException e) { + throw new XMLStreamException(e.getException()); + } + } + + public void serialize(final OutputStream output, OMOutputFormat format) throws XMLStreamException { + try { + // marshaller.setProperty(Marshaller.JAXB_ENCODING, format.getCharSetEncoding()); + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Marshaller marshaller = null; + try { + marshaller = getMarshaller(); + marshaller.marshal(element, output); + } finally { + releaseMarshaller(marshaller); + } + return null; + } + }); + } catch (PrivilegedActionException e) { + throw new XMLStreamException(e.getException()); + } + } + + public void serialize(final Writer writer, OMOutputFormat format) throws XMLStreamException { + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Marshaller marshaller = null; + try { + marshaller = getMarshaller(); + marshaller.marshal(element, writer); + } finally { + releaseMarshaller(marshaller); + } + return null; + } + }); + } catch (PrivilegedActionException e) { + throw new XMLStreamException(e.getException()); + } + } + + public Object getObject() { + return element; + } + + public void close() { + } + + public OMDataSourceExt copy() { + return new JAXBDataSource(element, context); + } + + public byte[] getXMLBytes(final String encoding) throws UnsupportedEncodingException { + try { + return AccessController.doPrivileged(new PrivilegedExceptionAction() { + public byte[] run() throws JAXBException, XMLStreamException, UnsupportedEncodingException { + Marshaller marshaller = null; + try { + StringWriter sw = new StringWriter(); + marshaller = getMarshaller(); + marshaller.marshal(element, sw); + return sw.toString().getBytes(encoding); + } finally { + releaseMarshaller(marshaller); + } + } + }); + } catch (PrivilegedActionException e) { + Throwable t = e.getCause(); + if (t instanceof UnsupportedEncodingException) { + throw (UnsupportedEncodingException)t; + } else { + throw new RuntimeException(t); + } + } + } + + public boolean isDestructiveRead() { + return false; + } + + public boolean isDestructiveWrite() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/OMElement2JAXB.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/OMElement2JAXB.java new file mode 100644 index 0000000000..848f6d1a85 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/OMElement2JAXB.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb.axiom; + +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.jaxb.JAXBContextHelper; + +/** + * @version $Rev$ $Date$ + */ +public class OMElement2JAXB extends BaseTransformer implements PullTransformer { + + @Override + public String getSourceDataBinding() { + return org.apache.axiom.om.OMElement.class.getName(); + } + + public Object transform(final OMElement source, final TransformationContext context) throws TransformationException { + try { + return AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws JAXBException, XMLStreamException { + Unmarshaller unmarshaller = null; + XMLStreamReader reader = null; + Object result = null; + + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + try { + Class type = JAXBContextHelper.getJavaType(context.getTargetDataType()); + unmarshaller = JAXBContextHelper.getUnmarshaller(jaxbContext); + reader = source.getXMLStreamReaderWithoutCaching(); + result = unmarshaller.unmarshal(reader, type); + } finally { + if (reader != null) { + reader.close(); + } + JAXBContextHelper.releaseJAXBUnmarshaller(jaxbContext, unmarshaller); + } + return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result); + } + }); + } catch (PrivilegedActionException e) { + throw new TransformationException(e.getException()); + } + } + + @Override + public Class getSourceType() { + return OMElement.class; + } + + @Override + public Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 3000; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..b48e629927 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -0,0 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.jaxb.axiom.JAXB2OMElement;source=javax.xml.bind.JAXBElement,target=org.apache.axiom.om.OMElement,weight=3000 +org.apache.tuscany.sca.databinding.jaxb.axiom.JAXB2OMElement;source=java:simpleType,target=org.apache.axiom.om.OMElement,weight=3000 +org.apache.tuscany.sca.databinding.jaxb.axiom.JAXB2OMElement;source=java:complexType,target=org.apache.axiom.om.OMElement,weight=3000 + +org.apache.tuscany.sca.databinding.jaxb.axiom.OMElement2JAXB;source=org.apache.axiom.om.OMElement,target=javax.xml.bind.JAXBElement,weight=3000,public=false +org.apache.tuscany.sca.databinding.jaxb.axiom.OMElement2JAXB;source=org.apache.axiom.om.OMElement,target=java:complexType,weight=90000,public=false +org.apache.tuscany.sca.databinding.jaxb.axiom.OMElement2JAXB;source=org.apache.axiom.om.OMElement,target=java:simpleType,weight=90000,public=false + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/java/org/apache/tuscany/databinding/jaxb/axiom/JAXB2OMTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/java/org/apache/tuscany/databinding/jaxb/axiom/JAXB2OMTestCase.java new file mode 100644 index 0000000000..543a76594f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/java/org/apache/tuscany/databinding/jaxb/axiom/JAXB2OMTestCase.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.jaxb.axiom; + +import java.io.StringWriter; + +import javax.xml.bind.JAXBElement; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.databinding.jaxb.JAXB2Node; +import org.apache.tuscany.sca.databinding.jaxb.JAXBContextHelper; +import org.apache.tuscany.sca.databinding.jaxb.axiom.JAXB2OMElement; +import org.apache.tuscany.sca.databinding.xml.Node2XMLStreamReader; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.junit.Test; +import org.w3c.dom.Node; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; +import com.example.ipo.jaxb.USAddress; +import com.example.ipo.jaxb.USState; + +/** + * @version $Rev$ $Date$ + */ +public class JAXB2OMTestCase { + @Test + public void testTransformElement() throws Exception { + JAXBElement po = createPO(); + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, XMLType.UNKNOWN); + DataType targetDataType = new DataTypeImpl(PurchaseOrderType.class, new XMLType(po.getName(), null)); + TransformationContext tContext = new TransformationContextImpl(); + tContext.setSourceDataType(sourceDataType); + tContext.setTargetDataType(targetDataType); + + // Force the JAXBContext to be cached + JAXBContextHelper.createJAXBContext(tContext, true); + + long start = System.currentTimeMillis(); + JAXB2OMElement t1 = new JAXB2OMElement(); + OMElement om = t1.transform(po, tContext); + long duration1 = System.currentTimeMillis() - start; + StringWriter sw = new StringWriter(); + // serializeAndConsume() will trigger the JAXBDataSource.serialize(Writer, OMOutputFormat) + om.serializeAndConsume(sw); + System.out.println(sw.toString()); + + start = System.currentTimeMillis(); + Node node = new JAXB2Node().transform(po, tContext); + XMLStreamReader reader = new Node2XMLStreamReader().transform(node, null); + om = new StAXOMBuilder(reader).getDocumentElement(); + sw = new StringWriter(); + om.serializeAndConsume(sw); + long duration2 = System.currentTimeMillis() - start; + System.out.println(sw.toString()); + System.out.println(duration1 + " vs. " + duration2); + } + + @Test + public void testTransformType() throws Exception { + JAXBElement po = createPO(); + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, XMLType.UNKNOWN); + DataType targetDataType = new DataTypeImpl(PurchaseOrderType.class, new XMLType(po.getName(), null)); + TransformationContext tContext = new TransformationContextImpl(); + tContext.setSourceDataType(sourceDataType); + tContext.setTargetDataType(targetDataType); + OMElement om = new JAXB2OMElement().transform(po.getValue(), tContext); + StringWriter sw = new StringWriter(); + om.serializeAndConsume(sw); + System.out.println(sw.toString()); + } + + private JAXBElement createPO() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType type = factory.createPurchaseOrderType(); + JAXBElement po = factory.createPurchaseOrder(type); + type.setItems(factory.createItems()); + type.setComment("123"); + USAddress address = factory.createUSAddress(); + address.setCity("San Jose"); + address.setStreet("ABC St."); + address.setState(USState.CA); + type.setShipTo(address); + return po; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/java/org/apache/tuscany/databinding/jaxb/axiom/OMElement2JAXBTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/java/org/apache/tuscany/databinding/jaxb/axiom/OMElement2JAXBTestCase.java new file mode 100644 index 0000000000..3c00307941 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/java/org/apache/tuscany/databinding/jaxb/axiom/OMElement2JAXBTestCase.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.databinding.jaxb.axiom; + +import java.io.ByteArrayInputStream; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.databinding.jaxb.axiom.OMElement2JAXB; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.junit.Test; + +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * @version $Rev$ $Date$ + */ +public class OMElement2JAXBTestCase { + private static final String XML = + "" + "" + + "" + + "" + + "ABC St.San JoseCA" + + "123" + + "" + + "" + + ""; + + @Test + public void testTransform() throws Exception { + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, XMLType.UNKNOWN); + QName qname = new QName("http://www.example.com/IPO", "purchaseOrder"); + DataType targetDataType = new DataTypeImpl(PurchaseOrderType.class, new XMLType(qname, null)); + TransformationContext tContext = new TransformationContextImpl(); + tContext.setSourceDataType(sourceDataType); + tContext.setTargetDataType(targetDataType); + + StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(XML.getBytes("UTF-8"))); + OMElement root = builder.getDocumentElement(); + OMElement next = (OMElement)root.getChildElements().next(); + OMElement po = (OMElement)next.getChildElements().next(); + Object jaxb = new OMElement2JAXB().transform(po, tContext); + Assert.assertTrue(jaxb instanceof PurchaseOrderType); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/resources/ipo.xsd new file mode 100644 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb-axiom/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/pom.xml new file mode 100644 index 0000000000..fea6048954 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/pom.xml @@ -0,0 +1,183 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding-jaxb + Apache Tuscany SCA Data Binding for JAXB + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-java + 1.6-SNAPSHOT + + + javax.xml.bind + jaxb-api + 2.1 + + + + com.sun.xml.bind + jaxb-impl + 2.1.7 + runtime + + + + org.jvnet.jaxb.reflection + jaxb2-reflection + 2.1.4 + test + + + + + + + true + + java.net + java.net Maven 1.x Repository + http://download.java.net/maven/1 + legacy + + + + + + java.net2 + java.net Maven 2.x Repository + http://download.java.net/maven/2 + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy + generate-sources + + copy + + + + + javax.xml.bind + jaxb-api + 2.1 + jar + + + ${project.build.directory}/endorsed + false + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -Djava.endorsed.dirs=target/endorsed + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/jaxb-source + + + + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + 0.5 + + + generate-jaxb + generate-test-sources + + generate + + + + + com.example.ipo.jaxb + ${project.build.directory}/jaxb-source + ${basedir}/src/test/resources + + ipo.xsd + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding.jaxb + ${pom.name} + org.apache.tuscany.sca.databinding.jaxb* + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/AnyTypeXmlAdapter.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/AnyTypeXmlAdapter.java new file mode 100644 index 0000000000..57922e1c89 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/AnyTypeXmlAdapter.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.sca.databinding.jaxb; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +/** + * This special XmlAdapter can be used by JAXB classes to annotate the references to java interfaces + */ +public class AnyTypeXmlAdapter extends XmlAdapter { + + @Override + public Object marshal(Object v) throws Exception { + return v; + } + + @Override + public Object unmarshal(Object v) throws Exception { + return v; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DOMElementXmlAdapter.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DOMElementXmlAdapter.java new file mode 100644 index 0000000000..91cb39b0f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DOMElementXmlAdapter.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.sca.databinding.jaxb; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.w3c.dom.Element; + +/** + * A generic XmlAdapter for JAXB to marshal/unmarshal between the java objects and DOM elements + */ +public class DOMElementXmlAdapter extends XmlAdapter { + private Mediator mediator; + private DataType dataType; + private DataType domType; + + public DOMElementXmlAdapter(Mediator mediator, DataType dataType) { + this.mediator = mediator; + this.dataType = dataType; + this.domType = new DataTypeImpl(DOMDataBinding.NAME, Element.class, dataType.getLogical()); + } + + @Override + public Element marshal(Object value) throws Exception { + return (Element) mediator.mediate(value, dataType, domType, null); + } + + @Override + public Object unmarshal(Element element) throws Exception { + return mediator.mediate(element, domType, dataType, null); + } + + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DataConverter.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DataConverter.java new file mode 100644 index 0000000000..003b4fb992 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DataConverter.java @@ -0,0 +1,378 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.awt.Image; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import javax.activation.DataHandler; +import javax.imageio.ImageIO; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.osoa.sca.ServiceRuntimeException; + +/** + * Provides utilities to convert an object into a different kind of Object. For example, convert a + * String[] into a List + */ +public class DataConverter { + + /** + * This method should return true if the convert method will succeed. + *

+ * Note that any changes to isConvertable() must also be accompanied by similar changes to + * convert() + * + * @param obj source object or class + * @param dest destination class + * @return boolean true if convert(..) can convert obj to the destination class + */ + public static boolean isConvertable(Object obj, Class dest) { + Class src = null; + + if (obj != null) { + if (obj instanceof Class) { + src = (Class)obj; + } else { + src = obj.getClass(); + } + } + + if (dest == null) { + return false; + } + + if (src == null) { + return true; + } + + // If we're directly assignable, we're good. + if (dest.isAssignableFrom(src)) { + return true; + } + + // If it's a wrapping conversion, we're good. + if (getWrapperClass(src) == dest) { + return true; + } + if (getWrapperClass(dest) == src) { + return true; + } + + // If it's List -> Array or vice versa, we're good. + if ((Collection.class.isAssignableFrom(src) || src.isArray()) && (Collection.class.isAssignableFrom(dest) || dest + .isArray())) { + + // TODO this should consider the component types instead of returning true. + return true; + } + + // Allow mapping of HashMaps to Hashtables + if (src == HashMap.class && dest == Hashtable.class) + return true; + + // Allow mapping of Calendar to Date + if (Calendar.class.isAssignableFrom(src) && dest == Date.class) { + return true; + } + + if (src.isPrimitive()) { + return isConvertable(getWrapperClass(src), dest); + } + + if (InputStream.class.isAssignableFrom(src) && dest == byte[].class) { + return true; + } + + if (Source.class.isAssignableFrom(src) && dest == byte[].class) { + return true; + } + + if (DataHandler.class.isAssignableFrom(src) && isConvertable(byte[].class, dest)) { + return true; + } + + if (DataHandler.class.isAssignableFrom(src) && dest == Image.class) { + return true; + } + + if (DataHandler.class.isAssignableFrom(src) && dest == Source.class) { + return true; + } + + if (byte[].class.isAssignableFrom(src) && dest == String.class) { + return true; + } + + // If it's a MIME type mapping and we want a DataHandler, + // then we're good. + // REVIEW Do we want to support this + /* + if (dest.getName().equals("javax.activation.DataHandler")) { + String name = src.getName(); + if (src == String.class + || src == java.awt.Image.class + || name.equals("javax.mail.internet.MimeMultipart") + || name.equals("javax.xml.transform.Source")) + return true; + } + */ + + return false; + } + + /** + * Utility function to convert an Object to some desired Class. + *

+ * Normally this is used for T[] to List processing. Other conversions are also done (i.e. + * HashMap <->Hashtable, etc.) + *

+ * Use the isConvertable() method to determine if conversion is possible. Note that any changes + * to convert() must also be accompanied by similar changes to isConvertable() + * + * @param arg the array to convert + * @param destClass the actual class we want + * @return object of destClass if conversion possible, otherwise returns arg + */ + public static Object convert(Object arg, Class destClass) { + if (destClass == null) { + return arg; + } + + if (arg != null && destClass.isAssignableFrom(arg.getClass())) { + return arg; + } + + // Convert between Calendar and Date + if (arg instanceof Calendar && destClass == Date.class) { + return ((Calendar)arg).getTime(); + } + + // Convert between HashMap and Hashtable + if (arg instanceof HashMap && destClass == Hashtable.class) { + return new Hashtable((HashMap)arg); + } + + if (arg instanceof InputStream && destClass == byte[].class) { + + try { + InputStream is = (InputStream)arg; + return getBytesFromStream(is); + } catch (IOException e) { + throw new ServiceRuntimeException(e); + } + } + + if (arg instanceof Source && destClass == byte[].class) { + try { + if (arg instanceof StreamSource) { + InputStream is = ((StreamSource)arg).getInputStream(); + if (is != null) { + return getBytesFromStream(is); + } + } + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Result result = new StreamResult(out); + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform((Source)arg, result); + byte[] bytes = out.toByteArray(); + return bytes; + + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + if (arg instanceof DataHandler) { + try { + InputStream is = ((DataHandler)arg).getInputStream(); + if (destClass == Image.class) { + return ImageIO.read(is); + } else if (destClass == Source.class) { + return new StreamSource(is); + } + byte[] bytes = getBytesFromStream(is); + return convert(bytes, destClass); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + if (arg instanceof byte[] && destClass == String.class) { + return new String((byte[])arg); + } + + // If the destination is an array and the source + // is a suitable component, return an array with + // the single item. + /* REVIEW do we need to support atomic to array conversion ? + if (arg != null && + destClass.isArray() && + !destClass.getComponentType().equals(Object.class) && + destClass.getComponentType().isAssignableFrom(arg.getClass())) { + Object array = + Array.newInstance(destClass.getComponentType(), 1); + Array.set(array, 0, arg); + return array; + } + */ + + // Return if no conversion is available + if (!(arg instanceof Collection || (arg != null && arg.getClass().isArray()))) { + return arg; + } + + if (arg == null) { + return null; + } + + // The arg may be an array or List + Object destValue = null; + int length = 0; + if (arg.getClass().isArray()) { + length = Array.getLength(arg); + } else { + length = ((Collection)arg).size(); + } + + try { + if (destClass.isArray()) { + if (destClass.getComponentType().isPrimitive()) { + + Object array = Array.newInstance(destClass.getComponentType(), length); + // Assign array elements + if (arg.getClass().isArray()) { + for (int i = 0; i < length; i++) { + Array.set(array, i, Array.get(arg, i)); + } + } else { + int idx = 0; + for (Iterator i = ((Collection)arg).iterator(); i.hasNext();) { + Array.set(array, idx++, i.next()); + } + } + destValue = array; + + } else { + Object[] array; + try { + array = (Object[])Array.newInstance(destClass.getComponentType(), length); + } catch (Exception e) { + return arg; + } + + // Use convert to assign array elements. + if (arg.getClass().isArray()) { + for (int i = 0; i < length; i++) { + array[i] = convert(Array.get(arg, i), destClass.getComponentType()); + } + } else { + int idx = 0; + for (Iterator i = ((Collection)arg).iterator(); i.hasNext();) { + array[idx++] = convert(i.next(), destClass.getComponentType()); + } + } + destValue = array; + } + } else if (Collection.class.isAssignableFrom(destClass)) { + Collection newList = null; + try { + // if we are trying to create an interface, build something + // that implements the interface + if (destClass == Collection.class || destClass == List.class) { + newList = new ArrayList(); + } else if (destClass == Set.class) { + newList = new HashSet(); + } else { + newList = (Collection)destClass.newInstance(); + } + } catch (Exception e) { + // No FFDC code needed + // Couldn't build one for some reason... so forget it. + return arg; + } + + if (arg.getClass().isArray()) { + for (int j = 0; j < length; j++) { + newList.add(Array.get(arg, j)); + } + } else { + for (Iterator j = ((Collection)arg).iterator(); j.hasNext();) { + newList.add(j.next()); + } + } + destValue = newList; + } else { + destValue = arg; + } + } catch (Throwable t) { + throw new ServiceRuntimeException(t); + } + + return destValue; + } + + private static byte[] getBytesFromStream(InputStream is) throws IOException { + // TODO This code assumes that available is the length of the stream. + byte[] bytes = new byte[is.available()]; + is.read(bytes); + return bytes; + } + + public static Class getWrapperClass(Class primitive) { + if (primitive == int.class) { + return java.lang.Integer.class; + } else if (primitive == short.class) { + return java.lang.Short.class; + } else if (primitive == boolean.class) { + return java.lang.Boolean.class; + } else if (primitive == byte.class) { + return java.lang.Byte.class; + } else if (primitive == long.class) { + return java.lang.Long.class; + } else if (primitive == double.class) { + return java.lang.Double.class; + } else if (primitive == float.class) { + return java.lang.Float.class; + } else if (primitive == char.class) { + return java.lang.Character.class; + } + + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DefaultXMLAdapterExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DefaultXMLAdapterExtensionPoint.java new file mode 100644 index 0000000000..062da48206 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/DefaultXMLAdapterExtensionPoint.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.sca.databinding.jaxb; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +/** + * @version $Rev$ $Date$ + */ +public class DefaultXMLAdapterExtensionPoint implements XMLAdapterExtensionPoint { + private Map, Class> adapters = + new ConcurrentHashMap, Class>(); + + public void addAdapter(Class boundType, Class adapter) { + adapters.put(boundType, adapter); + } + + public Class getAdapter(Class boundType) { + Class cls = adapters.get(boundType); + if (cls != null) { + return cls; + } + for (Map.Entry, Class> e : adapters.entrySet()) { + if (e.getKey().isAssignableFrom(boundType)) { + return e.getValue(); + } + } + return null; + } + + @SuppressWarnings("unchecked") + public Class removeAdapter(Class boundType) { + return adapters.remove(boundType); + } + + public Map, Class> getAdapters() { + return adapters; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java new file mode 100644 index 0000000000..3e262c7d12 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.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.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * + * @version $Rev$ $Date$ + */ +public class JAXB2Node extends BaseTransformer implements PullTransformer { + + public Node transform(Object source, TransformationContext tContext) { +// if (source == null) { +// return null; +// } + try { + JAXBContext context = JAXBContextHelper.createJAXBContext(tContext, true); + Marshaller marshaller = context.createMarshaller(); + // FIXME: The default Marshaller doesn't support + // marshaller.getNode() + Document document = DOMHelper.newDocument(); + Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source); + marshaller.marshal(jaxbElement, document); + return DOMHelper.adjustElementName(tContext, document.getDocumentElement()); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + protected Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getSourceDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java new file mode 100644 index 0000000000..eee5c77285 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.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.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.xml.sax.ContentHandler; + +/** + * @version $Rev$ $Date$ + */ +public class JAXB2SAX extends BaseTransformer implements + PushTransformer { + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + protected Class getTargetType() { + return ContentHandler.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.PushTransformer#transform(java.lang.Object, java.lang.Object, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public void transform(Object source, ContentHandler target, TransformationContext tContext) { + try { + JAXBContext context = JAXBContextHelper.createJAXBContext(tContext, true); + Marshaller marshaller = context.createMarshaller(); + Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source); + marshaller.marshal(jaxbElement, target); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 20; + } + + @Override + public String getSourceDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java new file mode 100644 index 0000000000..29951a5e16 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.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.sca.databinding.jaxb; + +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.transform.stream.StreamResult; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.xml.XMLStringDataBinding; + +/** + * + * @version $Rev$ $Date$ + */ +public class JAXB2String extends BaseTransformer implements PullTransformer { + + public String transform(Object source, TransformationContext tContext) { + try { + JAXBContext context = JAXBContextHelper.createJAXBContext(tContext, true); + Marshaller marshaller = context.createMarshaller(); + StringWriter writer = new StringWriter(); + StreamResult result = new StreamResult(writer); + Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source); + marshaller.marshal(jaxbElement, result); + return writer.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + protected Class getTargetType() { + return String.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getSourceDataBinding() { + return JAXBDataBinding.NAME; + } + + @Override + public String getTargetDataBinding() { + return XMLStringDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java new file mode 100644 index 0000000000..c685f5cc19 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java @@ -0,0 +1,563 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import java.awt.Image; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.ref.SoftReference; +import java.net.MalformedURLException; +import java.net.URI; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +import javax.activation.DataHandler; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.bind.annotation.XmlTransient; +import javax.xml.bind.annotation.XmlType; +import javax.xml.transform.Source; + +import org.apache.tuscany.sca.databinding.util.LRUCache; + +/** + * @version $Rev$ $Date$ + */ +public class JAXBContextCache { + private static final int CACHE_SIZE = 128; + + private static HashMap> loadClassMap = new HashMap>(); + + static { + loadClassMap.put("byte", byte.class); + loadClassMap.put("int", int.class); + loadClassMap.put("short", short.class); + loadClassMap.put("long", long.class); + loadClassMap.put("float", float.class); + loadClassMap.put("double", double.class); + loadClassMap.put("boolean", boolean.class); + loadClassMap.put("char", char.class); + loadClassMap.put("void", void.class); + } + + protected static Class[] JAXB_BUILTIN_CLASSES = + {byte[].class, boolean.class, byte.class, char.class, double.class, float.class, int.class, long.class, + short.class, void.class, java.awt.Image.class, java.io.File.class, java.lang.Boolean.class, + java.lang.Byte.class, java.lang.Character.class, java.lang.Class.class, java.lang.Double.class, + java.lang.Float.class, java.lang.Integer.class, java.lang.Long.class, java.lang.Object.class, + java.lang.Short.class, java.lang.String.class, java.lang.Void.class, java.math.BigDecimal.class, + java.math.BigInteger.class, java.net.URI.class, java.net.URL.class, java.util.Calendar.class, + java.util.Date.class, java.util.GregorianCalendar.class, java.util.UUID.class, + javax.activation.DataHandler.class, javax.xml.bind.JAXBElement.class, javax.xml.datatype.Duration.class, + javax.xml.datatype.XMLGregorianCalendar.class, javax.xml.namespace.QName.class, + javax.xml.transform.Source.class}; + + protected static final Set> BUILTIN_CLASSES_SET = new HashSet>(Arrays.asList(JAXB_BUILTIN_CLASSES)); + + /* + protected static Class[] COMMON_ARRAY_CLASSES = + new Class[] {char[].class, short[].class, int[].class, long[].class, float[].class, double[].class, + String[].class + }; + + protected static final Set> COMMON_CLASSES_SET = new HashSet>(Arrays.asList(COMMON_ARRAY_CLASSES)); + */ + + protected LRUCache cache; + protected Pool mpool; + protected Pool upool; + + // protected JAXBContext commonContext; + protected JAXBContext defaultContext; + + public JAXBContextCache() { + this(CACHE_SIZE, CACHE_SIZE, CACHE_SIZE); + } + + public JAXBContextCache(int contextSize, int marshallerSize, int unmarshallerSize) { + cache = new LRUCache(contextSize); + mpool = new Pool(); + upool = new Pool(); + defaultContext = getDefaultJAXBContext(); + } + + private static JAXBContext newJAXBContext(final Class... classesToBeBound) throws JAXBException { + try { + return AccessController.doPrivileged(new PrivilegedExceptionAction() { + public JAXBContext run() throws JAXBException { + return JAXBContext.newInstance(classesToBeBound); + } + }); + } catch (PrivilegedActionException e) { + throw (JAXBException)e.getException(); + } + } + + private static JAXBContext newJAXBContext(final String contextPath, final ClassLoader classLoader) + throws JAXBException { + try { + return AccessController.doPrivileged(new PrivilegedExceptionAction() { + public JAXBContext run() throws JAXBException { + return JAXBContext.newInstance(contextPath, classLoader); + } + }); + } catch (PrivilegedActionException e) { + throw (JAXBException)e.getException(); + } + } + + public static JAXBContext getDefaultJAXBContext() { + try { + return newJAXBContext(); + } catch (JAXBException e) { + throw new IllegalArgumentException(e); + } + } + + /** + * @param name of primitive type + * @return primitive Class or null + */ + public static Class getPrimitiveClass(String text) { + return loadClassMap.get(text); + } + + /** + * Return the class for this name + * + * @return Class + */ + private static Class forName(final String className, final boolean initialize, final ClassLoader classloader) + throws ClassNotFoundException { + // NOTE: This method must remain private because it uses AccessController + Class cl = null; + try { + cl = AccessController.doPrivileged(new PrivilegedExceptionAction>() { + public Class run() throws ClassNotFoundException { + // Class.forName does not support primitives + Class cls = getPrimitiveClass(className); + if (cls == null) { + cls = Class.forName(className, initialize, classloader); + } + return cls; + } + }); + } catch (PrivilegedActionException e) { + throw (ClassNotFoundException)e.getException(); + } + + return cl; + } + + public Marshaller getMarshaller(JAXBContext context) throws JAXBException { + Marshaller marshaller = mpool.get(context); + if (marshaller == null) { + marshaller = context.createMarshaller(); + } + marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); + return marshaller; + } + + public void releaseJAXBMarshaller(JAXBContext context, Marshaller marshaller) { + if (marshaller != null) { + marshaller.setAttachmentMarshaller(null); + mpool.put(context, marshaller); + // No point unsetting marshaller's JAXB_FRAGMENT property, since we'll just reset it when + // doing the next get. + } + } + + public Unmarshaller getUnmarshaller(JAXBContext context) throws JAXBException { + Unmarshaller unmarshaller = upool.get(context); + if (unmarshaller == null) { + unmarshaller = context.createUnmarshaller(); + } + return unmarshaller; + } + + public void releaseJAXBUnmarshaller(JAXBContext context, Unmarshaller unmarshaller) { + if (unmarshaller != null) { + unmarshaller.setAttachmentUnmarshaller(null); + upool.put(context, unmarshaller); + } + } + + public LRUCache getCache() { + return cache; + } + + public JAXBContext getJAXBContext(Class cls) throws JAXBException { + if (BUILTIN_CLASSES_SET.contains(cls)) { + return defaultContext; + } + return getJAXBContext(new Class[] {cls}); + } + + public JAXBContext getJAXBContext(Class[] classes) throws JAXBException { + Set> classSet = new HashSet>(Arrays.asList(classes)); + return getJAXBContext(classSet); + } + + public JAXBContext getJAXBContext(Set> classes) throws JAXBException { + // Remove the JAXB built-in types to maximize the cache hit + Set> classSet = new HashSet>(classes); + classSet.removeAll(BUILTIN_CLASSES_SET); + + // FIXME: [rfeng] Remove java classes that are mapped to the same XSD type to avoid + // conflicts + if (classSet.contains(Date[].class)) { + classSet.remove(Calendar[].class); + } + + if (classSet.contains(URI[].class)) { + classSet.remove(UUID[].class); + } + + if (classSet.contains(Source[].class)) { + classSet.remove(Image[].class); + classSet.remove(DataHandler[].class); + } + + classSet = getJAXBClasses(classSet); + + if(classSet.isEmpty()) { + return defaultContext; + } + + synchronized (cache) { + JAXBContext context = cache.get(classSet); + if (context != null) { + return context; + } + context = newJAXBContext(classSet.toArray(new Class[classSet.size()])); + cache.put(classSet, context); + return context; + } + } + + public void clear() { + synchronized (cache) { + cache.clear(); + } + /* + synchronized (upool) { + upool.clear(); + } + synchronized (upool) { + upool.clear(); + } + */ + } + + // + // This inner class is copied in its entirety from the Axis2 utility class, + // org.apache.axis2.jaxws.message.databinding.JAXBUtils. We could look into extending but it's such a basic data structure + // without other dependencies so we might be better off copying it and avoiding a new + // Axis2 dependency here. + // + + /** + * Pool a list of items for a specific key + * + * @param Key + * @param Pooled object + */ + private static class Pool { + private SoftReference>> softMap = + new SoftReference>>( + new ConcurrentHashMap>()); + + // The maps are freed up when a LOAD FACTOR is hit + private static final int MAX_LIST_FACTOR = 50; + private static final int MAX_LOAD_FACTOR = 32; // Maximum number of JAXBContext to store + + /** + * @param key + * @return removed item from pool or null. + */ + public V get(K key) { + List values = getValues(key); + synchronized (values) { + if (values.size()>0) { + V v = values.remove(values.size()-1); + return v; + + } + } + return null; + } + + /** + * Add item back to pool + * @param key + * @param value + */ + public void put(K key, V value) { + adjustSize(); + List values = getValues(key); + synchronized (values) { + if (values.size() < MAX_LIST_FACTOR) { + values.add(value); + } + } + } + + /** + * Get or create a list of the values for the key + * @param key + * @return list of values. + */ + private List getValues(K key) { + Map> map = softMap.get(); + List values = null; + if (map != null) { + values = map.get(key); + if(values !=null) { + return values; + } + } + synchronized (this) { + if (map != null) { + values = map.get(key); + } + if (values == null) { + if (map == null) { + map = new ConcurrentHashMap>(); + softMap = + new SoftReference>>(map); + } + values = new ArrayList(); + map.put(key, values); + + } + return values; + } + } + + /** + * AdjustSize + * When the number of keys exceeds the maximum load, half + * of the entries are deleted. + * + * The assumption is that the JAXBContexts, UnMarshallers, Marshallers, etc. require + * a large footprint. + */ + private void adjustSize() { + Map> map = softMap.get(); + if (map != null && map.size() > MAX_LOAD_FACTOR) { + // Remove every other Entry in the map. + Iterator it = map.entrySet().iterator(); + boolean removeIt = false; + while (it.hasNext()) { + it.next(); + if (removeIt) { + it.remove(); + } + removeIt = !removeIt; + } + } + } + } + + /** + * Find the JAXB classes (looking into packages) to be bound + * @param classes A collection of classes + * @return A set of classes that include the ObjectFactory and indexed JAXB classes + * @throws JAXBException + */ + private static Set> getJAXBClasses(Collection> classes) throws JAXBException { + Set> classSet = new HashSet>(); + // Index the packages + Map pkgs = getPackages(classes); + Set nonJAXBPackages = new HashSet(); + for (Map.Entry p : pkgs.entrySet()) { + Package pkg = p.getKey(); + if (pkg == null) { + continue; + } + Set> set = getJAXBClasses(pkg.getName(), p.getValue()); + if (set.isEmpty()) { + // No JAXB package + nonJAXBPackages.add(pkg); + } else { + // Add JAXB ObjectFactory and indexed classes + classSet.addAll(set); + } + } + // Adding classes that are not part of JAXB packages + for (Class cls : classes) { + + Package pkg = getPackage(cls); + if (pkg == null || nonJAXBPackages.contains(pkg)) { + classSet.add(cls); + } else { + // TUSCANY-3162: Test if a class is generated by JAXB + // There might be the case that non-JAXB classes are in the same package as the JAXB classes + if (!cls.isAnnotationPresent(XmlType.class) + && !cls.isAnnotationPresent(XmlEnum.class) + && !cls.isAnnotationPresent(XmlSeeAlso.class) + && !cls.isAnnotationPresent(XmlRootElement.class) + && !cls.isAnnotationPresent(XmlTransient.class)) { + classSet.add(cls); + } + } + } + return classSet; + } + + /** + * Get the package for a class, taking array into account + * @param cls + * @return + */ + private static Package getPackage(Class cls) { + Class type = cls; + while (type.isArray()) { + type = type.getComponentType(); + } + return type.getPackage(); + } + + /** + * Get a map of packages + * @param classes + * @return + */ + private static Map getPackages(Collection> classes) { + Map pkgs = new HashMap(); + for (Class cls : classes) { + Package pkg = getPackage(cls); + if (pkg != null) { + pkgs.put(pkg, getClassLoader(cls)); + } + } + return pkgs; + } + + private static ClassLoader getClassLoader(final Class cls) { + return AccessController.doPrivileged(new PrivilegedAction() { + public ClassLoader run(){ //throws ClassNotFoundException{ + return cls.getClassLoader(); + } + }); + } + + /** + * Find ObjectFactory and indexed JAXB classes for the package + * @param pkg + * @param classLoader + * @return + * @throws JAXBException + */ + private static Set> getJAXBClasses(String pkg, ClassLoader classLoader) throws JAXBException { + Set> classes = new HashSet>(); + List> indexedClasses; + + // look for ObjectFactory and load it + final Class o; + try { + o = forName(pkg + ".ObjectFactory", false, classLoader); + classes.add(o); + } catch (ClassNotFoundException e) { + // not necessarily an error + } + + // look for jaxb.index and load the list of classes + try { + indexedClasses = loadIndexedClasses(pkg, classLoader); + } catch (IOException e) { + throw new JAXBException(e); + } + if (indexedClasses != null) { + classes.addAll(indexedClasses); + } + + return classes; + } + + /** + * Look for jaxb.index file in the specified package and load it's contents + * + * @param pkg package name to search in + * @param classLoader ClassLoader to search in + * @return a List of Class objects to load, null if there weren't any + * @throws IOException if there is an error reading the index file + * @throws JAXBException if there are any errors in the index file + */ + private static List> loadIndexedClasses(String pkg, ClassLoader classLoader) throws IOException, + JAXBException { + if (classLoader == null) { + return null; + } + final String resource = pkg.replace('.', '/') + "/jaxb.index"; + final InputStream resourceAsStream = classLoader.getResourceAsStream(resource); + + if (resourceAsStream == null) { + return null; + } + + BufferedReader in = new BufferedReader(new InputStreamReader(resourceAsStream, "UTF-8")); + try { + List> classes = new ArrayList>(); + String className = in.readLine(); + while (className != null) { + className = className.trim(); + if (className.startsWith("#") || (className.length() == 0)) { + className = in.readLine(); + continue; + } + + try { + classes.add(forName(pkg + '.' + className, false, classLoader)); + } catch (ClassNotFoundException e) { + throw new JAXBException(e); + } + + className = in.readLine(); + } + return classes; + } finally { + in.close(); + } + } + +} + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java new file mode 100644 index 0000000000..d129ae6256 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java @@ -0,0 +1,486 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.lang.reflect.WildcardType; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.JAXBIntrospector; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.databinding.util.LRUCache; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * + * @version $Rev$ $Date$ + */ +// FIXME: [rfeng] We probably should turn this into a pluggable system service +public class JAXBContextHelper { + + private static final JAXBContextCache cache = new JAXBContextCache(); + + private JAXBContextHelper() { + } + + /** + * Create a JAXBContext for a given class + * @param cls + * @return + * @throws JAXBException + */ + public static JAXBContext createJAXBContext(Class cls) throws JAXBException { + return cache.getJAXBContext(cls); + } + + public static JAXBContext createJAXBContext(TransformationContext tContext, boolean source) throws JAXBException { + if (tContext == null) + throw new TransformationException("JAXB context is not set for the transformation."); + + // TODO: [rfeng] Need to figure out what's the best granularity to create the JAXBContext + // per interface, operation or parameter + Operation op = source ? tContext.getSourceOperation() : tContext.getTargetOperation(); + if (op != null) { + synchronized (op) { + JAXBContext context = op.getInputType().getMetaData(JAXBContext.class); + if (context == null) { + context = createJAXBContext(getDataTypes(op, true)); + op.getInputType().setMetaData(JAXBContext.class, context); + } + return context; + } + } + + // For property transformation, the operation can be null + DataType dataType = source ? tContext.getSourceDataType() : tContext.getTargetDataType(); + return createJAXBContext(dataType); + + } + + private static Class[] getSeeAlso(Class interfaze) { + if (interfaze == null) { + return null; + } + XmlSeeAlso seeAlso = interfaze.getAnnotation(XmlSeeAlso.class); + if (seeAlso == null) { + return null; + } else { + return seeAlso.value(); + } + } + + @SuppressWarnings("unchecked") + public static JAXBContext createJAXBContext(DataType dataType) throws JAXBException { + return createJAXBContext(findClasses(dataType)); + } + + public static Unmarshaller getUnmarshaller(JAXBContext context) throws JAXBException { + return cache.getUnmarshaller(context); + } + + public static void releaseJAXBUnmarshaller(JAXBContext context, Unmarshaller unmarshaller) { + cache.releaseJAXBUnmarshaller(context, unmarshaller); + } + + public static Marshaller getMarshaller(JAXBContext context) throws JAXBException { + return cache.getMarshaller(context); + } + + public static void releaseJAXBMarshaller(JAXBContext context, Marshaller marshaller) { + cache.releaseJAXBMarshaller(context, marshaller); + } + + @SuppressWarnings("unchecked") + public static Object createJAXBElement(JAXBContext context, DataType dataType, Object value) { + Class type = dataType == null ? value.getClass() : dataType.getPhysical(); + QName name = JAXBDataBinding.ROOT_ELEMENT; + if (context != null) { + Object logical = dataType == null ? null : dataType.getLogical(); + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement()) { + name = xmlType.getElementName(); + } else { + /** + * Set the declared type to Object.class so that xsi:type + * will be produced + */ + type = Object.class; + } + } else { + type = Object.class; + } + } + + JAXBIntrospector introspector = context.createJAXBIntrospector(); + Object element = null; + if (value != null && introspector.isElement(value)) { + // NOTE: [rfeng] We cannot wrap an element in a JAXBElement + element = value; + } + if (element == null) { + element = new JAXBElement(name, Object.class, value); + } + return element; + } + + @SuppressWarnings("unchecked") + public static Object createReturnValue(JAXBContext context, DataType dataType, Object value) { + Class cls = getJavaType(dataType); + if (cls == JAXBElement.class) { + return createJAXBElement(context, dataType, value); + } else { + if (value instanceof JAXBElement) { + return ((JAXBElement)value).getValue(); + } else { + return value; + } + } + } + + /** + * Create a JAXContext for an array of classes + * @param classes + * @return + * @throws JAXBException + */ + public static JAXBContext createJAXBContext(Class[] classes) throws JAXBException { + return cache.getJAXBContext(classes); + } + + public static JAXBContext createJAXBContext(Set> classes) throws JAXBException { + return cache.getJAXBContext(classes); + } + + /** + * Create a JAXBContext for a given java interface + * @param intf + * @return + * @throws JAXBException + */ + @SuppressWarnings("unchecked") + public static JAXBContext createJAXBContext(Interface intf, boolean useWrapper) throws JAXBException { + synchronized (cache) { + LRUCache map = cache.getCache(); + Integer key = new Integer(System.identityHashCode(intf)); + JAXBContext context = map.get(key); + if (context != null) { + return context; + } + List dataTypes = getDataTypes(intf, useWrapper); + context = createJAXBContext(dataTypes); + map.put(key, context); + return context; + } + } + + @SuppressWarnings("unchecked") + public static JAXBContext createJAXBContext(List dataTypes) throws JAXBException { + JAXBContext context; + Set> classes = new HashSet>(); + Set visited = new HashSet(); + for (DataType d : dataTypes) { + findClasses(d, classes, visited); + } + + context = createJAXBContext(classes); + return context; + } + + @SuppressWarnings("unchecked") + private static Set> findClasses(DataType d) { + Set> classes = new HashSet>(); + Set visited = new HashSet(); + findClasses(d, classes, visited); + return classes; + } + + @SuppressWarnings("unchecked") + private static void findClasses(DataType d, Set> classes, Set visited) { + if (d == null) { + return; + } + String db = d.getDataBinding(); + if (JAXBDataBinding.NAME.equals(db) || (db != null && db.startsWith("java:")) || db == null) { + if (!d.getPhysical().isInterface() && !JAXBElement.class.isAssignableFrom(d.getPhysical())) { + classes.add(d.getPhysical()); + } + } + if (d.getPhysical() != d.getGenericType()) { + findClasses(d.getGenericType(), classes, visited); + } + } + + /** + * Find referenced classes in the generic type + * @param type + * @param classSet + * @param visited + */ + @SuppressWarnings("unchecked") + private static void findClasses(Type type, Set> classSet, Set visited) { + if (visited.contains(type) || type == null) { + return; + } + visited.add(type); + if (type instanceof Class) { + Class cls = (Class)type; + if (!cls.isInterface()) { + classSet.add(cls); + } + return; + } else if (type instanceof ParameterizedType) { + ParameterizedType pType = (ParameterizedType)type; + findClasses(pType.getRawType(), classSet, visited); + for (Type t : pType.getActualTypeArguments()) { + findClasses(t, classSet, visited); + } + } else if (type instanceof TypeVariable) { + TypeVariable tv = (TypeVariable)type; + for (Type t : tv.getBounds()) { + findClasses(t, classSet, visited); + } + } else if (type instanceof GenericArrayType) { + GenericArrayType gType = (GenericArrayType)type; + findClasses(gType.getGenericComponentType(), classSet, visited); + } else if (type instanceof WildcardType) { + WildcardType wType = (WildcardType)type; + for (Type t : wType.getLowerBounds()) { + findClasses(t, classSet, visited); + } + for (Type t : wType.getUpperBounds()) { + findClasses(t, classSet, visited); + } + } + } + + public static JAXBContext createJAXBContext(Interface intf) throws JAXBException { + return createJAXBContext(intf, true); + } + + /** + * @param intf + * @param useWrapper Use wrapper classes? + * @return + */ + @SuppressWarnings("unchecked") + private static List getDataTypes(Interface intf, boolean useWrapper) { + List dataTypes = new ArrayList(); + for (Operation op : intf.getOperations()) { + getDataTypes(dataTypes, op, useWrapper); + } + return dataTypes; + } + + @SuppressWarnings("unchecked") + private static List getDataTypes(Operation op, boolean useWrapper) { + List dataTypes = new ArrayList(); + getDataTypes(dataTypes, op, useWrapper); + // Adding classes referenced by @XmlSeeAlso in the java interface + Interface interface1 = op.getInterface(); + if (interface1 instanceof JavaInterface) { + JavaInterface javaInterface = (JavaInterface)interface1; + Class[] seeAlso = getSeeAlso(javaInterface.getJavaClass()); + if (seeAlso != null) { + for (Class cls : seeAlso) { + dataTypes.add(new DataTypeImpl(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN)); + } + } + seeAlso = getSeeAlso(javaInterface.getCallbackClass()); + if (seeAlso != null) { + for (Class cls : seeAlso) { + dataTypes.add(new DataTypeImpl(JAXBDataBinding.NAME, cls, XMLType.UNKNOWN)); + } + } + } + return dataTypes; + } + + @SuppressWarnings("unchecked") + private static void getDataTypes(List dataTypes, Operation op, boolean useWrapper) { + WrapperInfo inputWrapperInfo = op.getInputWrapper(); + WrapperInfo outputWrapperInfo = op.getOutputWrapper(); + + if (useWrapper && (inputWrapperInfo != null)) { + DataType dt1 = inputWrapperInfo.getWrapperType(); + if (dt1 != null) { + dataTypes.add(dt1); + } + } + if (useWrapper && (outputWrapperInfo != null)) { + DataType dt2 = outputWrapperInfo.getWrapperType(); + if (dt2 != null) { + dataTypes.add(dt2); + } + } + // FIXME: [rfeng] We may need to find the referenced classes in the child types + // else + { + for (DataType dt1 : op.getInputType().getLogical()) { + dataTypes.add(dt1); + } + DataType dt2 = op.getOutputType(); + if (dt2 != null) { + dataTypes.add(dt2); + } + } + for (DataType dt3 : op.getFaultTypes()) { + DataType dt4 = dt3.getLogical(); + if (dt4 != null) { + dataTypes.add(dt4); + } + } + } + + @SuppressWarnings("unchecked") + public static Class getJavaType(DataType dataType) { + if (dataType == null) { + return null; + } + Class type = dataType.getPhysical(); + if (JAXBElement.class.isAssignableFrom(type)) { + Type generic = dataType.getGenericType(); + type = Object.class; + } + if (type == Object.class && dataType.getLogical() instanceof XMLType) { + XMLType xType = (XMLType)dataType.getLogical(); + Class javaType = SimpleTypeMapperImpl.getJavaType(xType.getTypeName()); + if (javaType != null) { + type = javaType; + } + } + return type; + } + + public static XMLType getXmlTypeName(Class javaType) { + if (javaType.isInterface()) { + // JAXB doesn't support interfaces + return null; + } + String namespace = null; + String name = null; + Package pkg = javaType.getPackage(); + if (pkg != null) { + XmlSchema schema = pkg.getAnnotation(XmlSchema.class); + if (schema != null) { + namespace = schema.namespace(); + } + } + + QName elementQName = null; + QName typeQName = null; + XmlRootElement rootElement = javaType.getAnnotation(XmlRootElement.class); + if (rootElement != null) { + String elementName = rootElement.name(); + String elementNamespace = rootElement.namespace(); + if (elementNamespace.equals("##default")) { + elementNamespace = namespace; + } + if (elementName.equals("##default")) { + elementName = jaxbDecapitalize(javaType.getSimpleName()); + } + elementQName = new QName(elementNamespace, elementName); + } + XmlType type = javaType.getAnnotation(XmlType.class); + if (type != null) { + String typeNamespace = type.namespace(); + String typeName = type.name(); + + if (typeNamespace.equals("##default")) { + // namespace is from the package + typeNamespace = namespace; + } + + if (typeName.equals("##default")) { + typeName = jaxbDecapitalize(javaType.getSimpleName()); + } + typeQName = new QName(typeNamespace, typeName); + } else { + XmlEnum xmlEnum = javaType.getAnnotation(XmlEnum.class); + // POJO can have the @XmlSchema on the package-info too + if (xmlEnum != null || namespace != null) { + name = jaxbDecapitalize(javaType.getSimpleName()); + typeQName = new QName(namespace, name); + } + } + if (elementQName == null && typeQName == null) { + return null; + } + return new XMLType(elementQName, typeQName); + } + + /** + * The JAXB RI doesn't implement the decapitalization algorithm in the + * JAXB spec. See Sun bug 6505643 for details. This means that instead + * of calling java.beans.Introspector.decapitalize() as the JAXB spec says, + * Tuscany needs to mimic the incorrect JAXB RI algorithm. + */ + public static String jaxbDecapitalize(String name) { + // find first lower case char in name + int lower = name.length(); + for (int i = 0; i < name.length(); i++) { + if (Character.isLowerCase(name.charAt(i))) { + lower = i; + break; + } + } + + int decap; + if (name.length() == 0) { + decap = 0; // empty string: nothing to do + } else if (lower == 0) { + decap = 0; // first char is lower case: nothing to do + } else if (lower == 1) { + decap = 1; // one upper followed by lower: decapitalize 1 char + } else if (lower < name.length()) { + decap = lower - 1; // n uppers followed by at least one lower: decapitalize n-1 chars + } else { + decap = name.length(); // all upper case: decapitalize all chars + } + + return name.substring(0, decap).toLowerCase() + name.substring(decap); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java new file mode 100644 index 0000000000..38efd288cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Document; + +/** + * JAXB DataBinding + * + * @version $Rev$ $Date$ + */ +public class JAXBDataBinding extends BaseDataBinding { + public static final String NAME = JAXBElement.class.getName(); + + public static final String ROOT_NAMESPACE = "http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "root"); + + private JAXBWrapperHandler wrapperHandler; + private JAXBTypeHelper xmlTypeHelper; + + public JAXBDataBinding() { + super(NAME, JAXBElement.class); + this.wrapperHandler = new JAXBWrapperHandler(); + this.xmlTypeHelper = new JAXBTypeHelper(); + } + + @Override + public boolean introspect(DataType dataType, Operation operation) { + Class javaType = dataType.getPhysical(); + if (JAXBElement.class.isAssignableFrom(javaType)) { + Type type = javaType.getGenericSuperclass(); + if (type instanceof ParameterizedType) { + ParameterizedType parameterizedType = ((ParameterizedType)type); + Type rawType = parameterizedType.getRawType(); + if (rawType == JAXBElement.class) { + Type actualType = parameterizedType.getActualTypeArguments()[0]; + if (actualType instanceof Class) { + XMLType xmlType = JAXBContextHelper.getXmlTypeName((Class)actualType); + dataType.setLogical(xmlType); + dataType.setDataBinding(NAME); + return true; + } + } + } + if (dataType.getLogical() == null) { + dataType.setLogical(XMLType.UNKNOWN); + } + dataType.setDataBinding(NAME); + return true; + } + + XMLType xmlType = JAXBContextHelper.getXmlTypeName(javaType); + if (xmlType == null) { + return false; + } + dataType.setLogical(xmlType); + dataType.setDataBinding(NAME); + return true; + } + + @SuppressWarnings("unchecked") + @Override + public Object copy(Object arg, DataType dataType, Operation operation) { + try { + boolean isElement = false; + if (dataType == null) { + Class cls = arg.getClass(); + if (arg instanceof JAXBElement) { + isElement = true; + cls = ((JAXBElement)arg).getDeclaredType(); + } + dataType = new DataTypeImpl(NAME, cls, XMLType.UNKNOWN); + } + JAXBContext context = JAXBContextHelper.createJAXBContext(dataType); + arg = JAXBContextHelper.createJAXBElement(context, dataType, arg); + Document doc = DOMHelper.newDocument(); + context.createMarshaller().marshal(arg, doc); + Object value = context.createUnmarshaller().unmarshal(doc, dataType.getPhysical()); + if (isElement && value instanceof JAXBElement) { + return value; + } + return JAXBContextHelper.createReturnValue(context, dataType, value); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + @Override + public WrapperHandler getWrapperHandler() { + return wrapperHandler; + } + + @Override + public XMLTypeHelper getXMLTypeHelper() { + // return new JAXBTypeHelper(); + return xmlTypeHelper; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBPropertyDescriptor.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBPropertyDescriptor.java new file mode 100644 index 0000000000..8805d72627 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBPropertyDescriptor.java @@ -0,0 +1,302 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.beans.IndexedPropertyDescriptor; +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collection; + +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import org.osoa.sca.ServiceRuntimeException; + +/** + * A PropertyDescriptor provides acesss to a bean property. Values can be queried/changed using the + * read and writer methods of the PropertyDescriptor. + *

+ * A PropertyDescriptorPlus object wraps a PropertyDescriptor and supplies enhanced set/get methods + * that match JAXB semantis. + *

+ * For example, the set(..) method is smart enough to add lists, arrays and atomic values on JAXB + * beans. + *

+ * The PropertyDescriptorPlus object also stores the xmlName of the property. + * + * @See XMLRootElementUtil.createPropertyDescriptorMap , which creates the PropertyDescriptorPlus + * objects + */ +public class JAXBPropertyDescriptor implements Comparable { + PropertyDescriptor descriptor; + QName xmlName = null; + int index; + + /** + * Package protected constructor. Only created by XMLRootElementUtil.createPropertyDescriptorMap + * @param descriptor + * @param index TODO + * @param propertyName + * + * @see XMLRootElementUtil.createPropertyDescriptorMap + */ + JAXBPropertyDescriptor(PropertyDescriptor descriptor, QName xmlName, int index) { + super(); + this.descriptor = descriptor; + this.xmlName = xmlName; + } + + /** + * Package protected constructor. Only created by XMLRootElementUtil.createPropertyDescriptorMap + * @param descriptor + * @param index TODO + * @param propertyName + * + * @see XMLRootElementUtil.createPropertyDescriptorMap + */ + JAXBPropertyDescriptor(PropertyDescriptor descriptor, String xmlName, int index) { + super(); + this.descriptor = descriptor; + this.xmlName = new QName("", xmlName); + } + + public int compareTo(JAXBPropertyDescriptor o) { + return index - o.index; + } + + /** @return xmlname */ + public String getXmlName() { + return xmlName.getLocalPart(); + } + + public QName getXmlQName() { + return xmlName; + } + + /** @return property type */ + public Class getPropertyType() { + return descriptor.getPropertyType(); + } + + /** @return property name */ + public String getPropertyName() { + return descriptor.getName(); + } + + /** + * Get the object + * + * @param targetBean + * @return Object for this property or null + * @throws InvocationTargetException + * @throws IllegalAccessException + */ + public Object get(Object targetBean) throws InvocationTargetException, IllegalAccessException { + Method method = descriptor.getReadMethod(); + if (method == null && descriptor.getPropertyType() == Boolean.class) { + String propertyName = descriptor.getName(); + if (propertyName != null) { + String methodName = "is"; + methodName = + methodName + ((propertyName.length() > 0) ? propertyName.substring(0, 1).toUpperCase() : ""); + methodName = methodName + ((propertyName.length() > 1) ? propertyName.substring(1) : ""); + try { + method = targetBean.getClass().getMethod(methodName); + } catch (NoSuchMethodException e) { + } + } + } + if (method == null) { + throw new ServiceRuntimeException("No getter is found"); + } + Object ret = method.invoke(targetBean); + if (method.getReturnType() == JAXBElement.class) { + ret = ((JAXBElement)ret).getValue(); + } + return ret; + } + + /** + * Set the object + * + * @param targetBean + * @param propValue + * @throws InvocationTargetException + * @throws IllegalAccessException + * @throws JAXBWrapperException + */ + public void set(Object targetBean, Object propValue) throws InvocationTargetException, IllegalAccessException, + JAXBWrapperException { + + Method writeMethod = null; + try { + // No set occurs if the value is null + if (propValue == null) { + return; + } + + // There are 3 different types of setters that can occur. + // 1) Normal Attomic Setter : setFoo(type) + // 2) Indexed Array Setter : setFoo(type[]) + // 3) No Setter case if the property is a List. + + writeMethod = descriptor.getWriteMethod(); + if (descriptor instanceof IndexedPropertyDescriptor) { + // Set for indexed T[] + setIndexedArray(targetBean, propValue, writeMethod); + } else if (writeMethod == null) { + // Set for List + setList(targetBean, propValue); + } else if (descriptor.getPropertyType() == JAXBElement.class) { + if (propValue != null) { + Class clazz = propValue.getClass(); + JAXBElement element = new JAXBElement(xmlName, clazz, propValue); + setAtomic(targetBean, element, writeMethod); + } + } else { + // Normal case + setAtomic(targetBean, propValue, writeMethod); + } + } catch (RuntimeException e) { + throw e; + } + } + + /** + * Set the property value onto targetBean using the writeMethod + * + * @param targetBean + * @param propValue + * @param writeMethod (set(T)) + * @throws InvocationTargetException + * @throws IllegalAccessException + * @throws JAXBWrapperException + */ + private void setAtomic(Object targetBean, Object propValue, Method writeMethod) throws InvocationTargetException, + IllegalAccessException, JAXBWrapperException { + // JAXB provides setters for atomic value. + + if (propValue != null) { + // Normal case + Object[] SINGLE_PARAM = new Object[1]; + SINGLE_PARAM[0] = propValue; + writeMethod.invoke(targetBean, SINGLE_PARAM); + } else { + Class[] paramTypes = writeMethod.getParameterTypes(); + + if (paramTypes != null && paramTypes.length == 1) { + Class paramType = paramTypes[0]; + if (paramType.isPrimitive() && propValue == null) { + //Ignoring null value for primitive type, this could potentially be the way of a customer indicating to set + //default values defined in JAXBObject/xmlSchema. + return; + } + } + } + + } + + /** + * Set the property value using the indexed array setter + * + * @param targetBean + * @param propValue + * @param writeMethod set(T[]) + * @throws InvocationTargetException + * @throws IllegalAccessException + * @throws JAXBWrapperException + */ + private void setIndexedArray(Object targetBean, Object propValue, Method writeMethod) + throws InvocationTargetException, IllegalAccessException, JAXBWrapperException { + + Class paramType = writeMethod.getParameterTypes()[0]; + Object value = asArray(propValue, paramType); + // JAXB provides setters for atomic value. + Object[] SINGLE_PARAM = new Object[1]; + SINGLE_PARAM[0] = value; + + writeMethod.invoke(targetBean, SINGLE_PARAM); + } + + /** + * Set the property value for the collection case. + * + * @param targetBean + * @param propValue + * @throws InvocationTargetException + * @throws IllegalAccessException + * @throws JAXBWrapperException + */ + private void setList(Object targetBean, Object propValue) throws InvocationTargetException, IllegalAccessException, + JAXBWrapperException { + // For the List case, there is no setter. + // You are supposed to use the getter to obtain access to the collection and then add the collection + + Collection value = asCollection(propValue, descriptor.getPropertyType()); + Collection collection = (Collection)get(targetBean); + + // Now add our our object to the collection + collection.clear(); + if (propValue != null) { + collection.addAll(value); + } + } + + /** + * @param propValue + * @param destType + * @return propValue as a Collection + */ + private static Collection asCollection(Object propValue, Class destType) { + // TODO Missing function + // Convert the object into an equivalent object that is a collection + if (DataConverter.isConvertable(propValue, destType)) { + return (Collection)DataConverter.convert(propValue, destType); + } else { + String objectClass = (propValue == null) ? "null" : propValue.getClass().getName(); + throw new ServiceRuntimeException("Cannot convert " + objectClass); + } + } + + /** + * @param propValue + * @param destType T[] + * @return array of component type + */ + private static Object asArray(Object propValue, Class destType) { + if (DataConverter.isConvertable(propValue, destType)) { + return DataConverter.convert(propValue, destType); + } else { + String objectClass = (propValue == null) ? "null" : propValue.getClass().getName(); + throw new ServiceRuntimeException("Cannot convert " + objectClass); + + } + } + + @Override + public String toString() { + String value = "PropertyDescriptorPlus["; + value += " name=" + this.getPropertyName(); + value += " type=" + this.getPropertyType().getName(); + value += " propertyDecriptor=" + this.descriptor; + return value + "]"; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTypeHelper.java new file mode 100644 index 0000000000..a60a882801 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTypeHelper.java @@ -0,0 +1,245 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.namespace.QName; +import javax.xml.transform.Result; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.stream.StreamResult; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.XSDefinition; +import org.apache.ws.commons.schema.resolver.URIResolver; +import org.osoa.sca.ServiceRuntimeException; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; + +public class JAXBTypeHelper implements XMLTypeHelper { + private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; + private static final String ANYTYPE_NAME = "anyType"; + private static final QName ANYTYPE_QNAME = new QName(SCHEMA_NS, ANYTYPE_NAME); + + // private List> types = new ArrayList>(); + + public JAXBTypeHelper() { + super(); + } + + public TypeInfo getTypeInfo(Class javaType, Object logical) { + QName xmlType = JavaXMLMapper.getXMLType(javaType); + if (xmlType != null) { + return new TypeInfo(xmlType, true, null); + } else if (javaType.isInterface()) { + return new TypeInfo(ANYTYPE_QNAME, true, null); + } else { + // types.add(javaType); + if (logical instanceof XMLType) { + xmlType = ((XMLType)logical).getTypeName(); + } + if (xmlType == null) { + xmlType = new QName(JAXBContextHelper.jaxbDecapitalize(javaType.getSimpleName())); + } + return new TypeInfo(xmlType, false, null); + } + } + + /* + public List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver) { + List definitions = new ArrayList(); + generateJAXBSchemas(definitions, factory); + return definitions; + } + */ + + public static Map generateSchema(JAXBContext context) throws IOException { + StringResolverImpl resolver = new StringResolverImpl(); + context.generateSchema(resolver); + Map xsds = new HashMap(); + for (Map.Entry xsd : resolver.getResults().entrySet()) { + xsds.put(xsd.getKey(), xsd.getValue().getWriter().toString()); + } + return xsds; + } + + private static class XSDResolver implements URIResolver { + private Map xsds; + + public XSDResolver(Map xsds) { + super(); + this.xsds = xsds; + } + + public InputSource resolveEntity(java.lang.String namespace, + java.lang.String schemaLocation, + java.lang.String baseUri) { + String xsd = xsds.get(schemaLocation); + if (xsd == null) { + return null; + } + return new InputSource(new StringReader(xsd)); + } + + } + + /* + private void generateJAXBSchemas1(List definitions, XSDFactory factory) { + if (types.size() > 0) { + try { + XmlSchemaCollection collection = new XmlSchemaCollection(); + Class[] typesArray = new Class[types.size()]; + typesArray = types.toArray(typesArray); + JAXBContext context = JAXBContextHelper.createJAXBContext(typesArray); + Map results = generateSchema(context); + collection.setSchemaResolver(new XSDResolver(results)); + + for (Map.Entry entry : results.entrySet()) { + XSDefinition definition = factory.createXSDefinition(); + int index = entry.getKey().lastIndexOf('#'); + String ns = entry.getKey().substring(0, index); + String file = entry.getKey().substring(index + 1); + definition.setUnresolved(true); + definition.setNamespace(ns); + definition.setSchema(collection.read(new StringReader(entry.getValue()), null)); + definition.setSchemaCollection(collection); + definition.setUnresolved(false); + definitions.add(definition); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + */ + + private static class DOMResolverImpl extends SchemaOutputResolver { + private Map results = new HashMap(); + + @Override + public Result createOutput(String ns, String file) throws IOException { + DOMResult result = new DOMResult(); + // TUSCANY-2498: Set the system id to "" so that the xsd:import doesn't produce + // an illegal schemaLocation attr + result.setSystemId(""); + results.put(ns, result); + return result; + } + + public Map getResults() { + return results; + } + } + + /* + private void generateJAXBSchemas(List definitions, XSDFactory factory) { + if (types.size() > 0) { + try { + Class[] typesArray = new Class[types.size()]; + typesArray = types.toArray(typesArray); + JAXBContext context = JAXBContext.newInstance(typesArray); + generateSchemas(definitions, factory, context); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + */ + + private void generateSchemas(List definitions, XSDFactory factory, JAXBContext context) + throws IOException { + DOMResolverImpl resolver = new DOMResolverImpl(); + context.generateSchema(resolver); + Map results = resolver.getResults(); + for (Map.Entry entry : results.entrySet()) { + XSDefinition definition = factory.createXSDefinition(); + definition.setUnresolved(true); + definition.setDocument((Document)entry.getValue().getNode()); + definition.setNamespace(entry.getKey()); + URI location = null; + try { + location = new URI(entry.getValue().getSystemId()); + } catch (URISyntaxException e) { + // ignore: use null value + } + definition.setLocation(location); + definitions.add(definition); + } + } + + private static class StringResolverImpl extends SchemaOutputResolver { + private Map results = new HashMap(); + + @Override + public Result createOutput(String ns, String file) throws IOException { + StringWriter sw = new StringWriter(); + StreamResult result = new StreamResult(sw); + String sysId = ns + '#' + file; + result.setSystemId(sysId); + results.put(sysId, result); + return result; + } + + public Map getResults() { + return results; + } + } + + public List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, Interface intf) { + try { + JAXBContext context = JAXBContextHelper.createJAXBContext(intf, false); + List definitions = new ArrayList(); + generateSchemas(definitions, factory, context); + return definitions; + } catch (Throwable e) { + throw new ServiceRuntimeException(e); + } + } + + public List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, List dataTypes) { + try { + + JAXBContext context = JAXBContextHelper.createJAXBContext(dataTypes); + List definitions = new ArrayList(); + generateSchemas(definitions, factory, context); + return definitions; + } catch (Throwable e) { + throw new ServiceRuntimeException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperException.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperException.java new file mode 100644 index 0000000000..f83c7f09d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperException.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.sca.databinding.jaxb; + +import org.osoa.sca.ServiceRuntimeException; + +public class JAXBWrapperException extends ServiceRuntimeException { + private static final long serialVersionUID = 1L; + + /** + * + */ + public JAXBWrapperException() { + super(); + + } + + /** + * @param message + * @param cause + */ + public JAXBWrapperException(String message, Throwable cause) { + super(message, cause); + + } + + /** @param message */ + public JAXBWrapperException(String message) { + super(message); + + } + + /** @param cause */ + public JAXBWrapperException(Throwable cause) { + super(cause); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java new file mode 100644 index 0000000000..9cb781a3e1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.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.sca.databinding.jaxb; + +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; + +/** + * JAXB WrapperHandler implementation + * + * @version $Rev$ $Date$ + */ +public class JAXBWrapperHandler implements WrapperHandler { + private JAXBWrapperHelper helper = new JAXBWrapperHelper(); + + public Object create(Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : outputWrapperInfo.getWrapperElement(); + final Class wrapperClass = input ? inputWrapperInfo.getWrapperClass() : outputWrapperInfo.getWrapperClass(); + try { + if (wrapperClass == null) { + return null; + } + return AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + return wrapperClass.newInstance(); + } + }); + } catch (PrivilegedActionException e) { + throw new TransformationException(e); + } + } + + public void setChildren(Object wrapper, Object[] childObjects, Operation operation, boolean input) { + List childElements = + input ? operation.getInputWrapper().getChildElements() : operation.getOutputWrapper().getChildElements(); + List childNames = new ArrayList(); + Map values = new HashMap(); + for (int i = 0; i < childElements.size(); i++) { + ElementInfo e = childElements.get(i); + String name = e.getQName().getLocalPart(); + childNames.add(name); + values.put(name, childObjects[i]); + } + // Get the property descriptor map + Map pdMap = null; + try { + pdMap = XMLRootElementUtil.createPropertyDescriptorMap(wrapper.getClass()); + } catch (Throwable t) { + throw new JAXBWrapperException(t); + } + helper.wrap(wrapper, childNames, values, pdMap); + } + + public void setChild(Object wrapper, int i, ElementInfo childElement, Object value) { + Object wrapperValue = wrapper; + Class wrapperClass = wrapperValue.getClass(); + + // FIXME: We probably should use the jaxb-reflection to handle the properties + try { + String prop = childElement.getQName().getLocalPart(); + boolean collection = (value instanceof Collection); + Method getter = null; + for (Method m : wrapperClass.getMethods()) { + Class[] paramTypes = m.getParameterTypes(); + if (paramTypes.length == 1 && m.getName().equals("set" + capitalize(prop))) { + m.invoke(wrapperValue, new Object[] {value}); + return; + } + if (collection && paramTypes.length == 0 && m.getName().equals("get" + capitalize(prop))) { + getter = m; + } + } + if (getter != null && Collection.class.isAssignableFrom(getter.getReturnType())) { + ((Collection)getter.invoke(wrapperValue)).addAll((Collection)value); + } + + } catch (Throwable e) { + throw new TransformationException(e); + } + } + + private static String capitalize(String name) { + char first = Character.toUpperCase(name.charAt(0)); + return first + name.substring(1); + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getChildren(java.lang.Object, Operation, boolean) + */ + public List getChildren(Object wrapper, Operation operation, boolean input) { + List childElements = input? operation.getInputWrapper().getChildElements(): + operation.getOutputWrapper().getChildElements(); + + List childNames = new ArrayList(); + for (ElementInfo e : childElements) { + childNames.add(e.getQName().getLocalPart()); + } + return Arrays.asList(helper.unwrap(wrapper, childNames)); + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(Operation, boolean) + */ + public DataType getWrapperType(Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + DataType dt = input ? inputWrapperInfo.getWrapperType() : outputWrapperInfo.getWrapperType(); + return dt; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#isInstance(java.lang.Object, Operation, boolean) + */ + public boolean isInstance(Object wrapper, Operation operation, boolean input) { + Class wrapperClass = + input ? operation.getInputWrapper().getWrapperClass() : operation.getOutputWrapper().getWrapperClass(); + return wrapperClass == null ? false : wrapperClass.isInstance(wrapper); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java new file mode 100644 index 0000000000..5f90aa4d7a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * The JAXBWrapper tool is used to create a JAXB Object from a series of child objects (wrap) or get + * the child objects from a JAXB Object (unwrap) + */ +public class JAXBWrapperHelper { + + /** + * unwrap Returns the list of child objects of the jaxb object + * + * @param jaxbObject that represents the type + * @param childNames list of xml child names as String + * @param pdMap PropertyDescriptor map for this jaxbObject + * @return list of Objects in the same order as the element names. + */ + public Object[] unwrap(Object jaxbObject, List childNames, Map pdMap) + throws JAXBWrapperException { + + // Get the object that will have the property descriptors (i.e. the object representing the complexType) + Object jaxbComplexTypeObj = jaxbObject; + + // Get the PropertyDescriptorPlus map. + // The method makes sure that each child name has a matching jaxb property + // checkPropertyDescriptorMap(jaxbComplexTypeObj.getClass(), childNames, pdMap); + + // Get the corresponsing objects from the jaxb bean + ArrayList objList = new ArrayList(); + int index = 0; + for (String childName : childNames) { + JAXBPropertyDescriptor propInfo = getPropertyDescriptor(pdMap, childName, index); + + Object object = null; + try { + object = propInfo.get(jaxbComplexTypeObj); + } catch (Throwable e) { + throw new JAXBWrapperException(e); + } + + objList.add(object); + index++; + } + Object[] jaxbObjects = objList.toArray(); + objList = null; + return jaxbObjects; + + } + + private JAXBPropertyDescriptor getPropertyDescriptor(Map pdMap, + String childName, + int index) { + JAXBPropertyDescriptor propInfo = pdMap.get(childName); + if (propInfo == null) { + // FIXME: [rfeng] Sometimes the child element names don't match. Get chilld by location? + List props = new ArrayList(pdMap.values()); + // Sort the properties by index. We might need to take propOrder into consideration + Collections.sort(props); + propInfo = props.get(index); + } + return propInfo; + } + + /** + * wrap Creates a jaxb object that is initialized with the child objects. + *

+ * Note that the jaxbClass must be the class the represents the complexType. (It should never be + * JAXBElement) + * + * @param jaxbClass + * @param childNames list of xml child names as String + * @param childObjects, component type objects + * @param pdMap PropertyDescriptor map for this jaxbObject + */ + public Object wrap(Class jaxbClass, + List childNames, + Map childObjects, + Map pdMap) throws JAXBWrapperException { + + // Just like unWrap, get the property info map + // checkPropertyDescriptorMap(jaxbClass, childNames, pdMap); + + // The jaxb object always has a default constructor. Create the object + Object jaxbObject = null; + try { + jaxbObject = jaxbClass.newInstance(); + } catch (Throwable t) { + throw new JAXBWrapperException(t); + } + + wrap(jaxbObject, childNames, childObjects, pdMap); + + // Return the jaxb object + return jaxbObject; + } + + public void wrap(Object jaxbObject, + List childNames, + Map childObjects, + Map pdMap) { + // Now set each object onto the jaxb object + int index = 0; + for (String childName : childNames) { + JAXBPropertyDescriptor propInfo = getPropertyDescriptor(pdMap, childName, index); + Object value = childObjects.get(childName); + try { + propInfo.set(jaxbObject, value); + } catch (Throwable t) { + throw new JAXBWrapperException(t); + } + index++; + } + } + + public Object[] unwrap(Object jaxbObject, List childNames) throws JAXBWrapperException { + // Get the property descriptor map for this JAXBClass + Class jaxbClass = jaxbObject.getClass(); + Map pdMap = null; + try { + pdMap = XMLRootElementUtil.createPropertyDescriptorMap(jaxbClass); + } catch (Throwable t) { + throw new JAXBWrapperException(t); + } + + // Delegate + return unwrap(jaxbObject, childNames, pdMap); + } + + public Object wrap(Class jaxbClass, List childNames, Map childObjects) + throws JAXBWrapperException { + // Get the property descriptor map + Map pdMap = null; + try { + pdMap = XMLRootElementUtil.createPropertyDescriptorMap(jaxbClass); + } catch (Throwable t) { + throw new JAXBWrapperException(t); + } + + // Delegate + return wrap(jaxbClass, childNames, childObjects, pdMap); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java new file mode 100644 index 0000000000..e375a9b85e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.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.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +/** + * + * @version $Rev$ $Date$ + */ +public class Node2JAXB extends BaseTransformer implements PullTransformer { + + public Node2JAXB() { + super(); + } + + public Object transform(Node source, TransformationContext context) { + if (source == null) + return null; + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + Object result = unmarshaller.unmarshal(source, JAXBContextHelper.getJavaType(context.getTargetDataType())); + return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java new file mode 100644 index 0000000000..840edfd234 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.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.sca.databinding.jaxb; + +import java.io.Reader; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * + * @version $Rev$ $Date$ + */ +public class Reader2JAXB extends BaseTransformer implements + PullTransformer { + + public Object transform(final Reader source, final TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + StreamSource streamSource = new StreamSource(source); + Object result = unmarshaller.unmarshal(streamSource, JAXBContextHelper.getJavaType(context.getTargetDataType())); + return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Reader.class; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java new file mode 100644 index 0000000000..5559690de8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.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.sca.databinding.jaxb; + +import java.io.StringReader; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.xml.XMLStringDataBinding; + +/** + * + * @version $Rev$ $Date$ + */ +public class String2JAXB extends BaseTransformer implements + PullTransformer { + + public Object transform(final String source, final TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + StreamSource streamSource = new StreamSource(new StringReader(source)); + Object result = unmarshaller.unmarshal(streamSource, JAXBContextHelper.getJavaType(context.getTargetDataType())); + return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return String.class; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getSourceDataBinding() { + return XMLStringDataBinding.NAME; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLAdapterExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLAdapterExtensionPoint.java new file mode 100644 index 0000000000..5fa98b5ed1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLAdapterExtensionPoint.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.sca.databinding.jaxb; + +import java.util.Map; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +/** + * @version $Rev$ $Date$ + */ +public interface XMLAdapterExtensionPoint { + /** + * @param boundType + * @param adapter + */ + void addAdapter(Class boundType, Class adapter); + + /** + * @param boundType + * @return + */ + Class getAdapter(Class boundType); + + /** + * @param boundType + * @return + */ + Class removeAdapter(Class boundType); + + /** + * @return + */ + Map, Class> getAdapters(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java new file mode 100644 index 0000000000..d177d53eda --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java @@ -0,0 +1,299 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Field; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; +import java.util.WeakHashMap; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.namespace.QName; + +/** + * + */ +public class XMLRootElementUtil { + + /** + * TUSCANY-3167 + * Cache for property descriptors + */ + private static Map, Map> PROPERTY_MAP = + new WeakHashMap, Map>(); + + /** Constructor is intentionally private. This class only provides static utility methods */ + private XMLRootElementUtil() { + + } + + /** + * @param clazz + * @return namespace of root element qname or null if this is not object does not represent a + * root element + */ + public static QName getXmlRootElementQNameFromObject(Object obj) { + + // A JAXBElement stores its name + if (obj instanceof JAXBElement) { + return ((JAXBElement)obj).getName(); + } + + Class clazz = (obj instanceof java.lang.Class) ? (Class)obj : obj.getClass(); + return getXmlRootElementQName(clazz); + } + + /** + * @param clazz + * @return namespace of root element qname or null if this is not object does not represent a + * root element + */ + public static QName getXmlRootElementQName(Class clazz) { + + // See if the object represents a root element + XmlRootElement root = (XmlRootElement)getAnnotation(clazz, XmlRootElement.class); + if (root == null) { + return null; + } + + String name = root.name(); + String namespace = root.namespace(); + + // The name may need to be defaulted + if (name == null || name.length() == 0 || name.equals("##default")) { + name = getSimpleName(clazz.getCanonicalName()); + } + + // The namespace may need to be defaulted + if (namespace == null || namespace.length() == 0 || namespace.equals("##default")) { + Package pkg = clazz.getPackage(); + XmlSchema schema = (XmlSchema)getAnnotation(pkg, XmlSchema.class); + if (schema != null) { + namespace = schema.namespace(); + } else { + namespace = ""; + } + } + + return new QName(namespace, name); + } + + /** + * @param clazz + * @return namespace of root element qname or null if this is not object does not represent a root element + */ + public static String getEnumValue(Enum myEnum) { + Field f; + String value; + try { + f = myEnum.getClass().getField(myEnum.name()); + + f.setAccessible(true); + + XmlEnumValue xev = (XmlEnumValue)getAnnotation(f, XmlEnumValue.class); + if (xev == null) { + value = f.getName(); + } else { + value = xev.value(); + } + } catch (SecurityException e) { + value = null; + } catch (NoSuchFieldException e) { + value = null; + } + + return value; + } + + /** + * utility method to get the last token in a "."-delimited package+classname string + * + * @return + */ + private static String getSimpleName(String in) { + if (in == null || in.length() == 0) { + return in; + } + String out = null; + StringTokenizer tokenizer = new StringTokenizer(in, "."); + if (tokenizer.countTokens() == 0) + out = in; + else { + while (tokenizer.hasMoreTokens()) { + out = tokenizer.nextToken(); + } + } + return out; + } + + /** + * The JAXBClass has a set of bean properties each represented by a PropertyDescriptor Each of + * the fields of the class has an associated xml name. The method returns a map where the key is + * the xml name and value is the PropertyDescriptor + * + * @param jaxbClass + * @return map + */ + public synchronized static Map createPropertyDescriptorMap(Class jaxbClass) + throws NoSuchFieldException, IntrospectionException { + + Map map = PROPERTY_MAP.get(jaxbClass); + if (map != null) { + return map; + } + + map = new HashMap(); + PropertyDescriptor[] pds = Introspector.getBeanInfo(jaxbClass).getPropertyDescriptors(); + + // Unfortunately the element names are stored on the fields. + // Get all of the fields in the class and super classes + + List fields = getFields(jaxbClass); + + // Now match up the fields with the property descriptors...Sigh why didn't JAXB put the @XMLElement annotations on the + // property methods! + for (PropertyDescriptor pd : pds) { + + // Skip over the class property..it is never represented as an xml element + if (pd.getName().equals("class")) { + continue; + } + + // For the current property, find a matching field...so that we can get the xml name + boolean found = false; + + int index = 0; + for (Field field : fields) { + String fieldName = field.getName(); + + // Use the name of the field and property to find the match + if (fieldName.equalsIgnoreCase(pd.getDisplayName()) || fieldName.equalsIgnoreCase(pd.getName())) { + // Get the xmlElement name for this field + QName xmlName = getXmlElementRefOrElementQName(field.getDeclaringClass(), field); + found = true; + map.put(xmlName.getLocalPart(), new JAXBPropertyDescriptor(pd, xmlName, index)); + index++; + break; + } + + // Unfortunately, sometimes the field name is preceeded by an underscore + if (fieldName.startsWith("_")) { + fieldName = fieldName.substring(1); + if (fieldName.equalsIgnoreCase(pd.getDisplayName()) || fieldName.equalsIgnoreCase(pd.getName())) { + // Get the xmlElement name for this field + QName xmlName = getXmlElementRefOrElementQName(field.getDeclaringClass(), field); + found = true; + + map.put(xmlName.getLocalPart(), new JAXBPropertyDescriptor(pd, xmlName, index)); + index++; + break; + } + } + } + + // We didn't find a field. Default the xmlname to the property name + if (!found) { + String xmlName = pd.getName(); + + map.put(xmlName, new JAXBPropertyDescriptor(pd, xmlName, index)); + index++; + } + } + PROPERTY_MAP.put(jaxbClass, map); + return map; + } + + /** + * Gets all of the fields in this class and the super classes + * + * @param beanClass + * @return + */ + static private List getFields(final Class beanClass) { + // This class must remain private due to Java 2 Security concerns + List fields = AccessController.doPrivileged(new PrivilegedAction>() { + public List run() { + List fields = new ArrayList(); + Class cls = beanClass; + while (cls != null) { + Field[] fieldArray = cls.getDeclaredFields(); + for (Field field : fieldArray) { + fields.add(field); + } + cls = cls.getSuperclass(); + } + return fields; + } + }); + + return fields; + } + + /** + * Get the name of the field by looking at the XmlElement annotation. + * + * @param jaxbClass + * @param fieldName + * @return + * @throws NoSuchFieldException + */ + private static QName getXmlElementRefOrElementQName(Class jaxbClass, Field field) throws NoSuchFieldException { + XmlElementRef xmlElementRef = (XmlElementRef)getAnnotation(field, XmlElementRef.class); + if (xmlElementRef != null) { + return new QName(xmlElementRef.namespace(), xmlElementRef.name()); + } + XmlElement xmlElement = (XmlElement)getAnnotation(field, XmlElement.class); + + // If XmlElement does not exist, default to using the field name + if (xmlElement == null || xmlElement.name().equals("##default")) { + return new QName("", field.getName()); + } + return new QName(xmlElement.namespace(), xmlElement.name()); + } + + /** + * Get an annotation. This is wrappered to avoid a Java2Security violation. + * @param cls Class that contains annotation + * @param annotation Class of requrested Annotation + * @return annotation or null + */ + private static T getAnnotation(final AnnotatedElement element, final Class annotation) { + return AccessController.doPrivileged(new PrivilegedAction() { + public T run() { + return element.getAnnotation(annotation); + } + }); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java new file mode 100644 index 0000000000..af3fa3fb66 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.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.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * + * @version $Rev$ $Date$ + */ +public class XMLStreamReader2JAXB extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader2JAXB() { + super(); + } + + public Object transform(XMLStreamReader source, TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + // FIXME: [rfeng] If the java type is Object.class, the unmarshalled result will be + // a DOM Node + Object result = unmarshaller.unmarshal(source, JAXBContextHelper.getJavaType(context.getTargetDataType())); + source.close(); + return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + public Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 10; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..3f2978ad25 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# implementation classes for the databindings +org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding;name=javax.xml.bind.JAXBElement diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..4e062e4c22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -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. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.jaxb.JAXB2Node;source=javax.xml.bind.JAXBElement,target=org.w3c.dom.Node,weight=500 +org.apache.tuscany.sca.databinding.jaxb.Node2JAXB;source=org.w3c.dom.Node,target=javax.xml.bind.JAXBElement,weight=500 +org.apache.tuscany.sca.databinding.jaxb.Reader2JAXB;source=java.io.Reader,target=javax.xml.bind.JAXBElement,weight=510 +org.apache.tuscany.sca.databinding.jaxb.XMLStreamReader2JAXB;source=javax.xml.stream.XMLStreamReader,target=javax.xml.bind.JAXBElement,weight=490 + +org.apache.tuscany.sca.databinding.jaxb.JAXB2Node;source=java:complexType,target=org.w3c.dom.Node,weight=90000 +org.apache.tuscany.sca.databinding.jaxb.Node2JAXB;source=org.w3c.dom.Node,target=java:complexType,weight=90000 + +org.apache.tuscany.sca.databinding.jaxb.Node2JAXB;source=org.w3c.dom.Node,target=java:simpleType,weight=90000 +org.apache.tuscany.sca.databinding.jaxb.JAXB2Node;source=java:simpleType,target=org.w3c.dom.Node,weight=90000 + +org.apache.tuscany.sca.databinding.jaxb.XMLStreamReader2JAXB;source=javax.xml.stream.XMLStreamReader,target=java:complexType,weight=90000 +org.apache.tuscany.sca.databinding.jaxb.XMLStreamReader2JAXB;source=javax.xml.stream.XMLStreamReader,target=java:simpleType,weight=90000 + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint new file mode 100644 index 0000000000..d1f6d9f1e3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +org.apache.tuscany.sca.databinding.jaxb.DefaultXMLAdapterExtensionPoint \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/com/example/stock/StockQuoteOffer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/com/example/stock/StockQuoteOffer.java new file mode 100644 index 0000000000..5c5c892f33 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/com/example/stock/StockQuoteOffer.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 com.example.stock; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +/** + *

Java class for anonymous complex type. + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = {"input"}) +@XmlRootElement(name = "stockQuoteOffer") +public class StockQuoteOffer { + + protected String input; + + public String getInput() { + return this.input; + } + + public void setInput(String input) { + this.input = input; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/BeanXMLStreamReaderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/BeanXMLStreamReaderImpl.java new file mode 100644 index 0000000000..602bc66569 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/BeanXMLStreamReaderImpl.java @@ -0,0 +1,324 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.lang.reflect.Array; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.databinding.xml.SimpleXmlNodeImpl; +import org.apache.tuscany.sca.databinding.xml.XmlNode; +import org.apache.tuscany.sca.databinding.xml.XmlTreeStreamReaderImpl; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.jvnet.jaxb.reflection.model.annotation.RuntimeInlineAnnotationReader; +import org.jvnet.jaxb.reflection.model.core.Ref; +import org.jvnet.jaxb.reflection.model.impl.RuntimeModelBuilder; +import org.jvnet.jaxb.reflection.model.runtime.RuntimeClassInfo; +import org.jvnet.jaxb.reflection.model.runtime.RuntimePropertyInfo; +import org.jvnet.jaxb.reflection.model.runtime.RuntimeTypeInfoSet; +import org.jvnet.jaxb.reflection.runtime.IllegalAnnotationsException; +import org.jvnet.jaxb.reflection.runtime.JAXBContextImpl; + + + +/** + * @version $Rev$ $Date$ + */ +public class BeanXMLStreamReaderImpl extends XmlTreeStreamReaderImpl { + private static final Comparator COMPARATOR = new Comparator() { + public int compare(Accessor o1, Accessor o2) { + return o1.getName().compareTo(o2.getName()); + } + }; + + private static final String XSI_PREFIX = "xsi"; + private static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance"; + + private static XmlNode getXSIType(QName realType) { + QName xsiType = new QName(XSI_NS, "type", XSI_PREFIX); + String prefix = realType.getPrefix(); + String typeName = realType.getLocalPart(); + if (prefix != null && !prefix.equals("")) { + typeName = prefix + ":" + realType.getLocalPart(); + } + return new SimpleXmlNodeImpl(xsiType, XmlNode.Type.ATTRIBUTE); + } + + /** + * Represent a Map.Entry XML node + * @version $Rev$ $Date$ + */ + public static class MapEntryXmlNodeImpl extends SimpleXmlNodeImpl implements XmlNode { + private Map.Entry entry; + + public MapEntryXmlNodeImpl(Entry entry) { + super(new QName("", "entry"), entry); + this.entry = entry; + } + + @Override + public Iterator children() { + List nodes = new ArrayList(); + XmlNode key = new BeanXmlNodeImpl(new QName("", "key"), entry.getKey()); + XmlNode value = new BeanXmlNodeImpl(new QName("", "value"), entry.getValue()); + nodes.add(key); + nodes.add(value); + return nodes.iterator(); + } + } + + public static class BeanXmlNodeImpl extends SimpleXmlNodeImpl implements XmlNode { + private static final Object[] NULL = null; + private static final SimpleTypeMapperImpl MAPPER = new SimpleTypeMapperImpl(); + + public BeanXmlNodeImpl(Object bean) { + super(getName(bean == null ? null : bean.getClass()), bean); + } + + public BeanXmlNodeImpl(QName name, Object bean) { + super(name, bean); + } + + private static boolean isSimpleType(Class javaType) { + return SimpleTypeMapperImpl.getXMLType(javaType) != null; + } + + private static String getStringValue(Object o) { + if (o == null) { + return null; + } + TypeInfo info = SimpleTypeMapperImpl.getXMLType(o.getClass()); + if (info != null) { + return MAPPER.toXMLLiteral(info.getQName(), o, null); + } else { + return String.valueOf(o); + } + } + + @Override + public Iterator children() { + if (name == null) { + return null; + } + if (value == null) { + return super.children(); + } + if (isSimpleType(value.getClass())) { + XmlNode textNode = new BeanXmlNodeImpl(null, value); + return Arrays.asList(textNode).iterator(); + } + if (Map.class.isAssignableFrom(value.getClass())) { + List entries = new ArrayList(); + Map map = (Map)value; + if (map != null) { + for (Object e : map.entrySet()) { + Map.Entry entry = (Map.Entry)e; + entries.add(new MapEntryXmlNodeImpl(entry)); + } + } + return entries.iterator(); + } + try { + Map accessorMap = getAccessors(value); + List accessorList = new ArrayList(accessorMap.values()); + Collections.sort(accessorList, COMPARATOR); + + List props = new ArrayList(); + for (Accessor accessor : accessorList) { + Class pType = accessor.getType(); + + QName pName = new QName(name.getNamespaceURI(), accessor.getName()); + Object pValue = accessor.getValue(); + if (pType.isArray()) { + if (pValue != null) { + int i1 = Array.getLength(pValue); + for (int j = 0; j < i1; j++) { + Object o = Array.get(pValue, j); + props.add(new BeanXmlNodeImpl(pName, o)); + } + } else { + // TODO: How to handle null? + } + } else if (Collection.class.isAssignableFrom(pType)) { + Collection objList = (Collection)pValue; + if (objList != null && objList.size() > 0) { + for (Iterator j = objList.iterator(); j.hasNext();) { + Object o = j.next(); + props.add(new BeanXmlNodeImpl(pName, o)); + } + + } else { + // How to handle null + } + } else { + props.add(new BeanXmlNodeImpl(pName, pValue)); + } + } + return props.iterator(); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + @Override + public QName getName() { + return name; + } + + @Override + public String getValue() { + return getStringValue(value); + } + + private static String getPackageName(Class cls) { + String name = cls.getName(); + int index = name.lastIndexOf('.'); + return index == -1 ? "" : name.substring(0, index); + } + + public static QName getName(Class cls) { + if (cls == null) { + return null; + } + + String packageName = getPackageName(cls); + + if ("".equals(packageName)) { + return new QName("", cls.getSimpleName()); + } + StringBuffer ns = new StringBuffer("http://"); + String[] names = packageName.split("\\."); + for (int i = names.length - 1; i >= 0; i--) { + ns.append(names[i]); + if (i != 0) { + ns.append('.'); + } + } + ns.append('/'); + return new QName(ns.toString(), cls.getSimpleName()); + } + } + + public BeanXMLStreamReaderImpl(QName name, Object bean) { + super(getXmlNode(name, bean)); + } + + private static BeanXmlNodeImpl getXmlNode(QName name, Object bean) { + BeanXmlNodeImpl root = null; + if (name != null) { + root = new BeanXmlNodeImpl(name, bean); + } else { + root = new BeanXmlNodeImpl(bean); + } + return root; + } + + public static interface Accessor { + String getName(); + + Class getType(); + + Object getValue() throws Exception; + + void setValue(Object value) throws Exception; + } + + private static RuntimeTypeInfoSet create(Class... classes) throws Exception { + IllegalAnnotationsException.Builder errorListener = new IllegalAnnotationsException.Builder(); + RuntimeInlineAnnotationReader reader = new RuntimeInlineAnnotationReader(); + JAXBContextImpl context = + new JAXBContextImpl(classes, null, Collections. emptyMap(), null, false, reader, false, false); + RuntimeModelBuilder builder = + new RuntimeModelBuilder(context, reader, Collections. emptyMap(), null); + builder.setErrorHandler(errorListener); + for (Class c : classes) + builder.getTypeInfo(new Ref(c)); + + RuntimeTypeInfoSet r = builder.link(); + errorListener.check(); + return r; + } + + private static class JAXBAccessor implements Accessor { + private Object target; + private RuntimePropertyInfo prop; + + public JAXBAccessor(Object target, RuntimePropertyInfo field) { + super(); + this.target = target; + this.prop = field; + } + + public String getName() { + return prop.getName(); + } + + public Object getValue() throws Exception { + return prop.getAccessor().get(target); + } + + public void setValue(Object value) throws Exception { + prop.getAccessor().set(target, value); + } + + public Class getType() { + Type type = prop.getRawType(); + if (type instanceof Class) { + return (Class)type; + } else if (type instanceof ParameterizedType) { + ParameterizedType pType = (ParameterizedType)type; + type = pType.getRawType(); + if (type instanceof Class) { + return (Class)type; + } + } + return Object.class; + } + + } + + private static Map getAccessors(Object target) throws Exception { + if (target == null) { + return Collections.emptyMap(); + } + Map map = new HashMap(); + Class type = target.getClass(); + RuntimeTypeInfoSet set = create(type); + RuntimeClassInfo clsInfo = (RuntimeClassInfo)set.getTypeInfo(type); + for (RuntimePropertyInfo f : clsInfo.getProperties()) { + map.put(f.getName(), new JAXBAccessor(target, f)); + } + return map; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2XMLStreamReader.java new file mode 100644 index 0000000000..e2151e23a1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2XMLStreamReader.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.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * + * @version $Rev$ $Date$ + */ +public class JAXB2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + public JAXB2XMLStreamReader() { + super(); + } + + public XMLStreamReader transform(Object source, TransformationContext context) { + if (source == null) { + return null; + } + try { + QName name = null; + Object bean = null; + if (source instanceof JAXBElement) { + bean = ((JAXBElement)source).getValue(); + name = ((JAXBElement)source).getName(); + } else { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, true); + Object element = JAXBContextHelper.createJAXBElement(jaxbContext, context.getSourceDataType(), source); + name = jaxbContext.createJAXBIntrospector().getElementName(element); + bean = source; + } + BeanXMLStreamReaderImpl reader = new BeanXMLStreamReaderImpl(name, bean); + return reader; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCacheTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCacheTestCase.java new file mode 100644 index 0000000000..761414e92b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCacheTestCase.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache; +import org.apache.tuscany.sca.databinding.util.LRUCache; +import org.junit.Test; + +import com.example.ipo.jaxb.Address; +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * @version $Rev$ $Date$ + */ +public class JAXBContextCacheTestCase { + @Test + public void testCache() throws JAXBException { + JAXBContextCache cache = new JAXBContextCache(); + JAXBContext context1 = cache.getJAXBContext(String.class); + JAXBContext context2 = cache.getJAXBContext(int.class); + JAXBContext context3 = cache.getJAXBContext(String[].class); + JAXBContext context4 = cache.getJAXBContext(Source.class); + Assert.assertSame(context1, context2); + Assert.assertNotSame(context2, context3); + Assert.assertSame(context1, context4); + + QName name = new QName("http://example.com/ns1", "e1"); + JAXBElement element = new JAXBElement(name, String.class, "123"); + StringWriter sw = new StringWriter(); + context4.createMarshaller().marshal(element, sw); + StreamSource source = new StreamSource(new StringReader(sw.toString()), null); + context4.createUnmarshaller().unmarshal(source, String.class); + + JAXBContext context5 = cache.getJAXBContext(Address.class); + JAXBContext context6 = cache.getJAXBContext(PurchaseOrderType.class); + Assert.assertSame(context5, context6); + } + + @Test + public void testLRUCache() { + LRUCache cache = new LRUCache(3); + cache.put("1", "A"); + Assert.assertEquals(1, cache.size()); + cache.put("2", "B"); + Assert.assertEquals(2, cache.size()); + cache.put("3", "C"); + Assert.assertEquals(3, cache.size()); + cache.put("4", "D"); + Assert.assertEquals(3, cache.size()); + String data = cache.get("1"); + Assert.assertNull(data); + data = cache.get("2"); + Assert.assertEquals("B", data); + cache.put("5", "E"); + data = cache.get("2"); + Assert.assertEquals("B", data); + } + + @Test + public void testPerf() throws JAXBException { + JAXBContextCache cache = new JAXBContextCache(); + + // Test JAXBContext for simple java classes + long start = System.currentTimeMillis(); + for (int i = 0; i < 100; i++) { + JAXBContext context = JAXBContext.newInstance(String.class); + } + long end = System.currentTimeMillis(); + long d1 = end - start; + start = System.currentTimeMillis(); + for (int i = 0; i < 100; i++) { + JAXBContext context = cache.getJAXBContext(String.class); + } + end = System.currentTimeMillis(); + long d2 = end - start; + System.out.println(d1 + "ms vs. " + d2 + "ms"); + + // Test JAXBContext for generated JAXB classes + start = System.currentTimeMillis(); + for (int i = 0; i < 20; i++) { + JAXBContext context = JAXBContext.newInstance(PurchaseOrderType.class); + } + end = System.currentTimeMillis(); + d1 = end - start; + start = System.currentTimeMillis(); + for (int i = 0; i < 20; i++) { + JAXBContext context = cache.getJAXBContext(PurchaseOrderType.class); + } + end = System.currentTimeMillis(); + d2 = end - start; + System.out.println(d1 + "ms vs. " + d2 + "ms"); + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBindingTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBindingTestCase.java new file mode 100644 index 0000000000..5452175c54 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBindingTestCase.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; +import com.example.ipo.jaxb.USAddress; +import com.example.ipo.jaxb.USState; + +/** + * + * @version $Rev$ $Date$ + */ +public class JAXBDataBindingTestCase extends TestCase { + private JAXBDataBinding binding; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + binding = new JAXBDataBinding(); + } + + /** + * Test method for + * {@link org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding#introspect(java.lang.Class, Operation)}. + */ + public final void testIntrospect() { + DataType dataType = new DataTypeImpl(JAXBElement.class, null); + Operation op = null; + boolean yes = binding.introspect(dataType, op); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertTrue(dataType.getPhysical() == JAXBElement.class && dataType.getLogical() == XMLType.UNKNOWN); + dataType = new DataTypeImpl(MockJAXBElement.class, null); + yes = binding.introspect(dataType, op); + assertTrue(yes); + assertEquals(MockJAXBElement.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataTypeImpl(USAddress.class, null); + yes = binding.introspect(dataType, op); + assertTrue(yes); + assertEquals(USAddress.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USAddress"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataTypeImpl(USState.class, null); + yes = binding.introspect(dataType, op); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertEquals(USState.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USState"), ((XMLType)dataType.getLogical()).getTypeName()); + + } + + private static class MockJAXBElement extends JAXBElement { + + private static final long serialVersionUID = -2767569071002707973L; + + /** + * @param elementName + * @param type + * @param value + */ + public MockJAXBElement(QName elementName, Class type, PurchaseOrderType value) { + super(elementName, type, value); + } + + } + + @SuppressWarnings("unchecked") + public void testCopy() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType poType = factory.createPurchaseOrderType(); + JAXBElement po = factory.createPurchaseOrder(poType); + JAXBElement copy = (JAXBElement)binding.copy(po, null, null); + assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), copy.getName()); + } + + @SuppressWarnings("unchecked") + public void testCopyNonElement() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType poType = factory.createPurchaseOrderType(); + poType.setComment("Comment"); + PurchaseOrderType copy = (PurchaseOrderType)binding.copy(poType, null, null); + assertTrue(copy instanceof PurchaseOrderType); + assertEquals("Comment", (copy).getComment()); + } + + @SuppressWarnings("unchecked") + public void testCopyNonRoot() { + ObjectFactory factory = new ObjectFactory(); + USAddress address = factory.createUSAddress(); + address.setCity("San Jose"); + USAddress copy = (USAddress)binding.copy(address, null, null); + assertTrue(copy instanceof USAddress); + assertEquals("San Jose", (copy).getCity()); + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBReflectionTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBReflectionTestCase.java new file mode 100644 index 0000000000..500422c9c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBReflectionTestCase.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.sca.databinding.jaxb; + +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.Map; + +import javax.xml.bind.JAXBContext; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.jvnet.jaxb.reflection.model.annotation.RuntimeInlineAnnotationReader; +import org.jvnet.jaxb.reflection.model.core.Ref; +import org.jvnet.jaxb.reflection.model.impl.RuntimeModelBuilder; +import org.jvnet.jaxb.reflection.model.runtime.RuntimeClassInfo; +import org.jvnet.jaxb.reflection.model.runtime.RuntimePropertyInfo; +import org.jvnet.jaxb.reflection.model.runtime.RuntimeTypeInfoSet; +import org.jvnet.jaxb.reflection.runtime.IllegalAnnotationsException; +import org.jvnet.jaxb.reflection.runtime.JAXBContextImpl; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; +import com.example.ipo.jaxb.USAddress; +import com.example.ipo.jaxb.USState; + +/** + * @version $Rev$ $Date$ + */ +public class JAXBReflectionTestCase extends TestCase { + + public void testGenerateSchema() throws Exception { + JAXBContext context = JAXBContext.newInstance("com.example.ipo.jaxb"); + Map schemas = JAXBTypeHelper.generateSchema(context); + System.out.println(schemas); + } + + /** + * This is a workaround for the NPE bug in jaxb-reflection + * @param classes + * @return + * @throws Exception + */ + @SuppressWarnings("unchecked") + private static RuntimeTypeInfoSet create(Class... classes) throws Exception { + IllegalAnnotationsException.Builder errorListener = new IllegalAnnotationsException.Builder(); + RuntimeInlineAnnotationReader reader = new RuntimeInlineAnnotationReader(); + JAXBContextImpl context = + new JAXBContextImpl(classes, null, Collections. emptyMap(), null, false, reader, false, false); + RuntimeModelBuilder builder = + new RuntimeModelBuilder(context, reader, Collections. emptyMap(), null); + builder.setErrorHandler(errorListener); + for (Class c : classes) + builder.getTypeInfo(new Ref(c)); + + RuntimeTypeInfoSet r = builder.link(); + errorListener.check(); + return r; + } + + public void testReflection() throws Exception { + org.jvnet.jaxb.reflection.model.runtime.RuntimeTypeInfoSet model = create(PurchaseOrderType.class); + RuntimeClassInfo type = (RuntimeClassInfo)model.getTypeInfo(PurchaseOrderType.class); + Assert.assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), type.getTypeName()); + type = (RuntimeClassInfo)model.getTypeInfo(USAddress.class); + Assert.assertEquals(new QName("http://www.example.com/IPO", "USAddress"), type.getTypeName()); + RuntimePropertyInfo prop = type.getProperty("state"); + Assert.assertNotNull(prop); + USAddress address = new ObjectFactory().createUSAddress(); + prop.getAccessor().set(address, USState.CA); + Assert.assertEquals(USState.CA, address.getState()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java new file mode 100644 index 0000000000..53779a1af6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.io.StringReader; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.jaxb.JAXB2Node; +import org.apache.tuscany.sca.databinding.jaxb.Node2JAXB; +import org.apache.tuscany.sca.databinding.jaxb.Reader2JAXB; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Node; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * + * @version $Rev$ $Date$ + */ +public class JAXBTestCase extends TestCase { + private static final String IPO_XML = + "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testTransform() throws Exception { + Reader2JAXB t0 = new Reader2JAXB(); + + DataType targetDataType = new DataTypeImpl(PurchaseOrderType.class, null); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + expect(tContext.getTargetOperation()).andReturn(null).anyTimes(); + replay(tContext); + + Object object1 = t0.transform(new StringReader(IPO_XML), tContext); + + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, null); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + expect(tContext1.getTargetDataType()).andReturn(null).anyTimes(); + expect(tContext1.getSourceOperation()).andReturn(null).anyTimes(); + expect(tContext1.getTargetOperation()).andReturn(null).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + Node node = t1.transform(object1, tContext1); + + Assert.assertNotNull(node); + + Node2JAXB t2 = new Node2JAXB(); + Object object2 = t2.transform(node, tContext); + Assert.assertNotNull(object2); + + } + + public void testTransform2() throws Exception { + Reader2JAXB t0 = new Reader2JAXB(); + + QName root = new QName("http://www.example.com/IPO", "purchaseOrder"); + DataType targetDataType = new DataTypeImpl(PurchaseOrderType.class, new XMLType(root, null)); + // targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + expect(tContext.getTargetOperation()).andReturn(null).anyTimes(); + replay(tContext); + + Object object1 = t0.transform(new StringReader(IPO_XML), tContext); + + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, new XMLType(root, null)); + // sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + expect(tContext1.getTargetDataType()).andReturn(null).anyTimes(); + expect(tContext1.getSourceOperation()).andReturn(null).anyTimes(); + expect(tContext1.getTargetOperation()).andReturn(null).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + Node node = t1.transform(object1, tContext1); + + Assert.assertNotNull(node); + + Node2JAXB t2 = new Node2JAXB(); + Object object2 = t2.transform(node, tContext); + Assert.assertNotNull(object2); + + } + + public void testTransform3() throws Exception { + + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, null); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + expect(tContext1.getTargetDataType()).andReturn(null).anyTimes(); + expect(tContext1.getSourceOperation()).andReturn(null).anyTimes(); + expect(tContext1.getTargetOperation()).andReturn(null).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + PurchaseOrderType po = new ObjectFactory().createPurchaseOrderType(); + Node node = t1.transform(po, tContext1); + + Assert.assertNotNull(node); + + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandlerTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandlerTestCase.java new file mode 100644 index 0000000000..501f5b21b7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandlerTestCase.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.databinding.jaxb.JAXBWrapperHandler; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.stock.StockQuoteOffer; + +/** + * Test case for JAXBExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class JAXBWrapperHandlerTestCase extends TestCase { + private static final QName ELEMENT = new QName("http://www.example.com/stock", "stockQuoteOffer"); + private static final QName INPUT = new QName("", "input"); + private JAXBWrapperHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.handler = new JAXBWrapperHandler(); + } + + public void testCreate() { + ElementInfo element = new ElementInfo(ELEMENT, null); + Operation op = new OperationImpl(); + WrapperInfo wrapperInfo = new WrapperInfo(JAXBDataBinding.NAME, element, null); + wrapperInfo.setWrapperType(new DataTypeImpl(JAXBDataBinding.NAME, StockQuoteOffer.class, + XMLType.UNKNOWN)); + op.setInputWrapper(wrapperInfo); + Object offer = handler.create(op, true); + Assert.assertTrue(offer instanceof StockQuoteOffer); + } + + public void testSetChild() { + StockQuoteOffer wrapper = new StockQuoteOffer(); + handler.setChild(wrapper, 0, new ElementInfo(INPUT, null), "IBM"); + Assert.assertEquals("IBM", wrapper.getInput()); + } + + public void testGetChildren() { + StockQuoteOffer wrapper = new StockQuoteOffer(); + wrapper.setInput("IBM"); + List elements = new ArrayList(); + elements.add(new ElementInfo(INPUT, null)); + WrapperInfo wrapperInfo = new WrapperInfo(JAXBDataBinding.NAME, null, elements); + Operation op = new OperationImpl(); + op.setInputWrapper(wrapperInfo); + List children = handler.getChildren(wrapper, op, true); + assertNotNull(children); + assertEquals(1, children.size()); + assertEquals("IBM", children.get(0)); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyBean.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyBean.java new file mode 100644 index 0000000000..9bdfb108fe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyBean.java @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * + * @version $Rev$ $Date$ + */ +public class MyBean { + private int age; + private String name; + private float[] rates = new float[] {1.0f, 2.0f}; + private List notes = new ArrayList(); + private Map map = new HashMap(); + private Object service; + private Object otherService; + private boolean good; + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getNotes() { + return notes; + } + + public void setNotes(List notes) { + this.notes = notes; + } + + public float[] getRates() { + return rates; + } + + public void setRates(float[] rates) { + this.rates = rates; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + + public Object getService() { + return service; + } + + public void setService(Object service) { + this.service = service; + } + + public Object getOtherService() { + return otherService; + } + + public void setOtherService(Object otherService) { + this.otherService = otherService; + } + + public boolean isGood() { + return good; + } + + public void setGood(boolean good) { + this.good = good; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + age; + result = prime * result + (good ? 1231 : 1237); + result = prime * result + ((map == null) ? 0 : map.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((notes == null) ? 0 : notes.hashCode()); + result = prime * result + ((otherService == null) ? 0 : otherService.hashCode()); + result = prime * result + Arrays.hashCode(rates); + result = prime * result + ((service == null) ? 0 : service.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final MyBean other = (MyBean)obj; + if (age != other.age) + return false; + if (good != other.good) + return false; + if (map == null) { + if (other.map != null) + return false; + } else if (!map.equals(other.map)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (notes == null) { + if (other.notes != null) + return false; + } else if (!notes.equals(other.notes)) + return false; + if (otherService == null) { + if (other.otherService != null) + return false; + } else if (!otherService.equals(other.otherService)) + return false; + if (!Arrays.equals(rates, other.rates)) + return false; + if (service == null) { + if (other.service != null) + return false; + } else if (!service.equals(other.service)) + return false; + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyInterface.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyInterface.java new file mode 100644 index 0000000000..b8e9ee7f7d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyInterface.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.sca.databinding.jaxb; + +/** + * @version $Rev$ $Date$ + */ +public interface MyInterface { + void setId(String id); + + String getId(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyInterfaceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyInterfaceImpl.java new file mode 100644 index 0000000000..5c511e6ccb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyInterfaceImpl.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.sca.databinding.jaxb; + +/** + * @version $Rev$ $Date$ + */ +public class MyInterfaceImpl implements MyInterface { + private String id; + + /** + * @see org.apache.tuscany.databinding.jaxb.MyInterface#getId() + */ + public String getId() { + return id; + } + + /** + * @see org.apache.tuscany.databinding.jaxb.MyInterface#setId(java.lang.String) + */ + public void setId(String id) { + this.id = id; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final MyInterfaceImpl other = (MyInterfaceImpl)obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyJaxbBean.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyJaxbBean.java new file mode 100644 index 0000000000..3c3992524a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MyJaxbBean.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.sca.databinding.jaxb; + +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +import org.w3c.dom.Element; + +/** + * + */ +@XmlRootElement(name = "myBean", namespace = "http://ns1") +public class MyJaxbBean { + public MyBean myBean; + + @XmlJavaTypeAdapter(AnyTypeXmlAdapter.class) + public MyInterface myInterface; + + @XmlElement(type = MyInterfaceImpl.class) + public MyInterface myInterface1; + + @XmlJavaTypeAdapter(MyInterfaceAdapter.class) + public MyInterface myInterface2; + + public Object myObject; + + @XmlAnyElement + public Element anyElement; + + public static class MyInterfaceAdapter extends XmlAdapter { + + @Override + public MyInterfaceImpl marshal(MyInterface v) throws Exception { + return (MyInterfaceImpl) v; + } + + @Override + public MyInterface unmarshal(MyInterfaceImpl v) throws Exception { + return (MyInterface) v; + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MySubBean.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MySubBean.java new file mode 100644 index 0000000000..62dfa6f73c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/MySubBean.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.sca.databinding.jaxb; + +/** + * @version $Rev$ $Date$ + */ +public class MySubBean extends MyBean { + private String addtional; + + public String getAddtional() { + return addtional; + } + + public void setAddtional(String addtional) { + this.addtional = addtional; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/POJOTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/POJOTestCase.java new file mode 100644 index 0000000000..fdfa87ff43 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/POJOTestCase.java @@ -0,0 +1,268 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import java.io.StringReader; +import java.io.StringWriter; +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.stream.StreamSource; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; + +import com.sun.xml.bind.v2.model.annotation.RuntimeInlineAnnotationReader; +import com.sun.xml.bind.v2.model.core.Ref; +import com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder; +import com.sun.xml.bind.v2.model.runtime.RuntimeClassInfo; +import com.sun.xml.bind.v2.model.runtime.RuntimePropertyInfo; +import com.sun.xml.bind.v2.model.runtime.RuntimeTypeInfoSet; +import com.sun.xml.bind.v2.runtime.IllegalAnnotationsException; +import com.sun.xml.bind.v2.runtime.JAXBContextImpl; + +/** + * + * @version $Rev$ $Date$ + */ +public class POJOTestCase extends TestCase { + public void testAdapter() throws Exception { + JAXBContext context = JAXBContext.newInstance(MyJaxbBean.class, MyInterfaceImpl.class); + StringWriter writer = new StringWriter(); + MyJaxbBean bean = new MyJaxbBean(); + bean.myBean = new MySubBean(); + bean.myBean.setName("Ray"); + bean.myInterface = new MyInterfaceImpl(); + bean.myInterface.setId("001"); + bean.myObject = new MyBean(); + ((MyBean) bean.myObject).setName("Y"); + context.createMarshaller().marshal(bean, writer); + System.out.println(writer.toString()); + Object result = context.createUnmarshaller().unmarshal(new StringReader(writer.toString())); + assertTrue(result instanceof MyJaxbBean); + Map schemas = JAXBTypeHelper.generateSchema(context); + System.out.println(schemas); + } + + public void testPOJO() throws Exception { + JAXBContext context = JAXBContext.newInstance(MyBean.class, MyInterfaceImpl.class); + StringWriter writer = new StringWriter(); + MyBean bean = new MyBean(); + bean.setName("Test"); + bean.setAge(20); + bean.getNotes().add("1"); + bean.getNotes().add("2"); + bean.getMap().put("1", 1); + MyInterface service = new MyInterfaceImpl(); + service.setId("ID001"); + bean.setService(service); + bean.setOtherService(service); + JAXBElement element = new JAXBElement(new QName("http://ns1", "bean"), Object.class, bean); + context.createMarshaller().marshal(element, writer); + // System.out.println(writer.toString()); + + Object result = context.createUnmarshaller().unmarshal(new StringReader(writer.toString())); + assertTrue(result instanceof JAXBElement); + JAXBElement e2 = (JAXBElement)result; + assertTrue(e2.getValue() instanceof MyBean); + MyBean newBean = (MyBean)e2.getValue(); + assertEquals(bean, newBean); + } + + public void testPOJOArray() throws Exception { + JAXBContext context = JAXBContext.newInstance(MyBean[].class, MySubBean.class); + StringWriter writer = new StringWriter(); + MySubBean bean = new MySubBean(); + bean.setAddtional("SUB"); + bean.setName("Test"); + bean.setAge(20); + bean.getNotes().add("1"); + bean.getNotes().add("2"); + bean.getMap().put("1", 1); + + JAXBElement element = + new JAXBElement(new QName("http://ns1", "beans"), Object.class, new MyBean[] {bean}); + context.createMarshaller().marshal(element, writer); + System.out.println(writer.toString()); + + Object result = + context.createUnmarshaller().unmarshal(new StreamSource(new StringReader(writer.toString())), + MyBean[].class); + assertTrue(result instanceof JAXBElement); + JAXBElement e2 = (JAXBElement)result; + assertTrue(e2.getValue() instanceof MyBean[]); + MyBean newBean = ((MyBean[])e2.getValue())[0]; + assertTrue(newBean instanceof MySubBean); + } + + public void testXMLStreamReader() throws Exception { + JAXBContext context = JAXBContext.newInstance(MyBean.class, MyInterfaceImpl.class); + + MyBean bean = new MyBean(); + bean.setName("Test"); + bean.setAge(20); + bean.getNotes().add("1"); + bean.getNotes().add("2"); + bean.getMap().put("1", 1); + MyInterface service = new MyInterfaceImpl(); + service.setId("ID001"); + bean.setService(service); + bean.setOtherService(service); + QName name = new QName("http://ns1", "bean"); + JAXBElement element = new JAXBElement(name, Object.class, bean); + TransformationContext tContext = new TransformationContextImpl(); + XMLStreamReader reader = new JAXB2XMLStreamReader().transform(element, tContext); + +// XMLStreamReader2String t2 = new XMLStreamReader2String(); +// String xml = t2.transform(reader, null); + // System.out.println(xml); + Object result = context.createUnmarshaller().unmarshal(reader, MyBean.class); + assertTrue(result instanceof JAXBElement); + JAXBElement e2 = (JAXBElement)result; + assertTrue(e2.getValue() instanceof MyBean); + MyBean newBean = (MyBean)e2.getValue(); + // FIXME :To be implemented + // assertEquals(bean, newBean); + } + + public void testString() throws Exception { + JAXBContext context = JAXBContext.newInstance(String.class); + StringWriter writer = new StringWriter(); + JAXBElement element = new JAXBElement(new QName("http://ns1", "bean"), Object.class, "ABC"); + context.createMarshaller().marshal(element, writer); + // System.out.println(writer.toString()); + + Object result = context.createUnmarshaller().unmarshal(new StringReader(writer.toString())); + assertTrue(result instanceof JAXBElement); + JAXBElement e2 = (JAXBElement)result; + assertEquals("ABC", e2.getValue()); + } + + public void testNull() throws Exception { + JAXBContext context = JAXBContext.newInstance(String.class); + StringWriter writer = new StringWriter(); + JAXBElement element = new JAXBElement(new QName("http://ns1", "bean"), Object.class, null); + element.setNil(true); + context.createMarshaller().marshal(element, writer); + // System.out.println(writer.toString()); + StreamSource source = new StreamSource(new StringReader(writer.toString())); + Object result = context.createUnmarshaller().unmarshal(source, String.class); + assertTrue(result instanceof JAXBElement); + JAXBElement e2 = (JAXBElement)result; + assertNull(e2.getValue()); + } + + public void testArray() throws Exception { + JAXBContext context = JAXBContext.newInstance(String[].class); + StringWriter writer = new StringWriter(); + JAXBElement element = + new JAXBElement(new QName("http://ns1", "bean"), Object.class, new String[] {"ABC", "123"}); + context.createMarshaller().marshal(element, writer); + // System.out.println(writer.toString()); + + Object result = context.createUnmarshaller().unmarshal(new StringReader(writer.toString())); + assertTrue(result instanceof JAXBElement); + JAXBElement e2 = (JAXBElement)result; + assertTrue(e2.getValue() instanceof String[]); + } + + public void testByteArray() throws Exception { + JAXBContext context = JAXBContext.newInstance(byte[].class); + StringWriter writer = new StringWriter(); + JAXBElement element = + new JAXBElement(new QName("http://ns1", "bean"), Object.class, "ABC".getBytes()); + context.createMarshaller().marshal(element, writer); + String xml = writer.toString(); + assertTrue(xml.contains("QUJD")); + assertTrue(xml.contains("base64Binary")); + + Object result = context.createUnmarshaller().unmarshal(new StringReader(xml)); + assertTrue(result instanceof JAXBElement); + JAXBElement e2 = (JAXBElement)result; + assertTrue(e2.getValue() instanceof byte[]); + } + + public void testPrimitive() throws Exception { + JAXBContext context = JAXBContext.newInstance(int.class); + StringWriter writer = new StringWriter(); + JAXBElement element = new JAXBElement(new QName("http://ns1", "bean"), Object.class, 1); + context.createMarshaller().marshal(element, writer); + // System.out.println(writer.toString()); + + Object result = context.createUnmarshaller().unmarshal(new StringReader(writer.toString())); + assertTrue(result instanceof JAXBElement); + JAXBElement e2 = (JAXBElement)result; + assertEquals(1, e2.getValue()); + } + + /* + public void testException() throws Exception { + JAXBContext context = JAXBContext.newInstance(IllegalArgumentException.class); + StringWriter writer = new StringWriter(); + Exception e = new IllegalArgumentException("123"); + JAXBElement element = new JAXBElement(new QName("http://ns1", "bean"), Object.class, e); + context.createMarshaller().marshal(element, writer); + System.out.println(writer.toString()); + + Object result = context.createUnmarshaller().unmarshal(new StringReader(writer.toString())); + assertTrue(result instanceof JAXBElement); + JAXBElement e2 = (JAXBElement)result; + assertTrue(e2.getValue() instanceof Exception); + } + */ + + private static RuntimeTypeInfoSet create(Class... classes) throws Exception { + IllegalAnnotationsException.Builder errorListener = new IllegalAnnotationsException.Builder(); + RuntimeInlineAnnotationReader reader = new RuntimeInlineAnnotationReader(); + JAXBContextImpl context = + new JAXBContextImpl(classes, null, Collections. emptyMap(), null, false, reader, false, false); + RuntimeModelBuilder builder = + new RuntimeModelBuilder(context, reader, Collections. emptyMap(), null); + builder.setErrorHandler(errorListener); + for (Class c : classes) + builder.getTypeInfo(new Ref(c)); + + RuntimeTypeInfoSet r = builder.link(); + errorListener.check(); + return r; + } + + public void testReflection() throws Exception { + MyBean bean = new MyBean(); + RuntimeTypeInfoSet model = create(MyBean.class); + RuntimeClassInfo clsInfo = (RuntimeClassInfo)model.getTypeInfo(MyBean.class); + for (RuntimePropertyInfo p : clsInfo.getProperties()) { + // System.out.print(p.getName()); + // System.out.println(" " + p.isCollection()); + if (p.getName().equals("notes")) { + Collection c = (Collection)p.getAccessor().get(bean); + c.add("123"); + } + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-jaxb/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/LICENSE @@ -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, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/pom.xml new file mode 100644 index 0000000000..140691460b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/pom.xml @@ -0,0 +1,136 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding-json + Apache Tuscany SCA Data Binding for JSON + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + com.metaparadigm + json-rpc + 1.0 + compile + + + + org.codehaus.jettison + jettison + 1.0.1 + compile + + + stax + stax-api + + + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.7 + + + xerces + xercesImpl + + + javax.mail + mail + + + commons-logging + commons-logging + + + stax + stax-api + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.7 + runtime + + + + junit + junit + 4.5 + + + + commons-logging + commons-logging + 1.1.1 + + + commons-logging + commons-logging + + + javax.servlet + servlet-api + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding.json + ${pom.name} + org.apache.tuscany.sca.databinding.json* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2JavaBean.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2JavaBean.java new file mode 100644 index 0000000000..b1813c9eab --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2JavaBean.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.sca.databinding.json; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; + +import com.metaparadigm.jsonrpc.JSONSerializer; +import com.metaparadigm.jsonrpc.SerializerState; + +/** + * @version $Rev$ $Date$ + */ +public class JSON2JavaBean implements PullTransformer { + private JSONSerializer serializer; + + public JSON2JavaBean() { + super(); + serializer = new JSONSerializer(); + try { + serializer.registerDefaultSerializers(); + } catch (Exception e) { + throw new TransformationException(e); + } + serializer.setMarshallClassHints(true); + serializer.setMarshallNullAttributes(true); + } + + public Object transform(Object source, TransformationContext context) { + if (source == null) { + return null; + } + + try { + SerializerState state = new SerializerState(); + return serializer.unmarshall(state, context.getTargetDataType().getPhysical(), source); + } catch (Exception e) { + throw new TransformationException(e); + } + + } + + public String getSourceDataBinding() { + return JSONDataBinding.NAME; + } + + public String getTargetDataBinding() { + return JavaBeansDataBinding.NAME; + } + + public int getWeight() { + return 5000; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2String.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2String.java new file mode 100644 index 0000000000..4e08384f09 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2String.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.sca.databinding.json; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * @version $Rev$ $Date$ + */ +public class JSON2String extends BaseTransformer implements + PullTransformer { + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + protected Class getTargetType() { + return String.class; + } + + public String transform(Object source, TransformationContext context) { + try { + return source.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 500; + } + + @Override + public String getSourceDataBinding() { + return JSONDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2XMLStreamReader.java new file mode 100644 index 0000000000..b70f772696 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2XMLStreamReader.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.sca.databinding.json; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader; +import org.codehaus.jettison.json.JSONObject; + +/** + * @version $Rev$ $Date$ + */ +public class JSON2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + public XMLStreamReader transform(Object source, TransformationContext context) { + try { + JSONObject json = JSONHelper.toJettison(source); + return new BadgerFishXMLStreamReader(json); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 500; + } + @Override + public String getSourceDataBinding() { + return JSONDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONDataBinding.java new file mode 100644 index 0000000000..28cadc6666 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONDataBinding.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.sca.databinding.json; + + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.codehaus.jettison.json.JSONObject; + +/** + * JAXB DataBinding + * + * @version $Rev$ $Date$ + */ +public class JSONDataBinding extends BaseDataBinding { + public static final String NAME = "JSON"; + + public static final String ROOT_NAMESPACE = "http://tuscany.apache.org/xmlns/sca/databinding/json/1.0"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "root"); + + public JSONDataBinding() { + super(NAME, org.json.JSONObject.class); + } + + @Override + public boolean introspect(DataType type, Operation operation) { + assert type != null; + Class cls = type.getPhysical(); + if (JSONObject.class.isAssignableFrom(cls) || org.json.JSONObject.class.isAssignableFrom(cls)) { + type.setDataBinding(getName()); + if (type.getLogical() == null) { + type.setLogical(XMLType.UNKNOWN); + } + return true; + } + return false; + } + + @SuppressWarnings("unchecked") + @Override + public Object copy(Object arg, DataType dataType, Operation operation) { + if (arg == null) { + return null; + } + try { + Class type = arg != null ? arg.getClass() : null; + return JSONHelper.toJSON(arg.toString(), type); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONHelper.java new file mode 100644 index 0000000000..fb29710506 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONHelper.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.json; + +import java.text.ParseException; + +import org.codehaus.jettison.json.JSONException; +import org.codehaus.jettison.json.JSONObject; + +/** + * @version $Rev$ $Date$ + */ +public class JSONHelper { + private JSONHelper() { + + } + + /** + * Convert to Jettison JSONObject + * @param source + * @return + */ + public static JSONObject toJettison(Object source) { + JSONObject json = null; + if (source instanceof JSONObject) { + json = (JSONObject)source; + } else if (source instanceof org.json.JSONObject) { + try { + json = new JSONObject(((org.json.JSONObject)source).toString()); + } catch (JSONException e) { + throw new IllegalArgumentException(e); + } + } + return json; + } + + /** + * Convert to org.json.JSONObject + * @param source + * @return + */ + public static org.json.JSONObject toJSONOrg(Object source) { + org.json.JSONObject json = null; + if (source instanceof JSONObject) { + try { + json = new org.json.JSONObject(((JSONObject)source).toString()); + } catch (ParseException e) { + throw new IllegalArgumentException(e); + } + } else if (source instanceof org.json.JSONObject) { + json = (org.json.JSONObject)source; + } + return json; + } + + public static T toJSON(String json, Class type) { + if (type == JSONObject.class) { + try { + return type.cast(new JSONObject(json)); + } catch (JSONException e) { + throw new IllegalArgumentException(e); + } + } else { + if (type == null) { + type = (Class)org.json.JSONObject.class; + } + try { + return type.cast(new org.json.JSONObject(json)); + } catch (ParseException e) { + throw new IllegalArgumentException(e); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSON.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSON.java new file mode 100644 index 0000000000..a928deef22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSON.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.sca.databinding.json; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; + +import com.metaparadigm.jsonrpc.JSONSerializer; +import com.metaparadigm.jsonrpc.SerializerState; + +public class JavaBean2JSON extends BaseTransformer implements PullTransformer { + private JSONSerializer serializer; + + public JavaBean2JSON() { + serializer = new JSONSerializer(); + try { + serializer.registerDefaultSerializers(); + } catch (Exception e) { + throw new TransformationException(e); + } + serializer.setMarshallClassHints(true); + serializer.setMarshallNullAttributes(true); + } + + @Override + public String getSourceDataBinding() { + return JavaBeansDataBinding.NAME; + } + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + public String getTargetDataBinding() { + return JSONDataBinding.NAME; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + public Object toJSON(Object source) throws Exception { + if (source == null) { + return org.json.JSONObject.NULL; + } + + SerializerState state = new SerializerState(); + return serializer.marshall(state, source); + } + + public Object transform(Object source, TransformationContext context) { + try { + return toJSON(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONObject.java new file mode 100644 index 0000000000..de023157bc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONObject.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.sca.databinding.json; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.codehaus.jettison.json.JSONArray; +import org.codehaus.jettison.json.JSONObject; + +public class JavaBean2JSONObject extends BaseTransformer implements PullTransformer { + private static final Comparator COMPARATOR = new Comparator() { + public int compare(PropertyDescriptor o1, PropertyDescriptor o2) { + return o1.getName().compareTo(o2.getName()); + } + }; + + private static final SimpleTypeMapperImpl MAPPER = new SimpleTypeMapperImpl(); + private static final Object[] NULL = null; + + private static String getStringValue(Object o) { + if (o == null) { + return null; + } + TypeInfo info = SimpleTypeMapperImpl.getXMLType(o.getClass()); + if (info != null) { + return MAPPER.toXMLLiteral(info.getQName(), o, null); + } else { + return String.valueOf(o); + } + } + + private static boolean isSimpleType(Class javaType) { + return SimpleTypeMapperImpl.getXMLType(javaType) != null; + } + + public JavaBean2JSONObject() { + } + + @Override + public String getSourceDataBinding() { + return JavaBeansDataBinding.NAME; + } + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + public String getTargetDataBinding() { + return JSONDataBinding.NAME; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + public Object toJSON(Object source) throws Exception { + if (source == null) { + return JSONObject.NULL; + } + Class type = source.getClass(); + if (isSimpleType(type)) { + return source; + } else if (type.isArray()) { + JSONArray array = new JSONArray(); + int i1 = Array.getLength(source); + for (int j = 0; j < i1; j++) { + Object o = Array.get(source, j); + array.put(toJSON(o)); + } + return array; + } else if (Collection.class.isAssignableFrom(type)) { + Collection c = (Collection)source; + JSONArray array = new JSONArray(); + for (Object element : c) { + array.put(toJSON(element)); + } + return array; + } + JSONObject json = new JSONObject(); + BeanInfo beanInfo = Introspector.getBeanInfo(type); + PropertyDescriptor[] propDescs = beanInfo.getPropertyDescriptors(); + Collections.sort(Arrays.asList(propDescs), COMPARATOR); + + for (int i = 0; i < propDescs.length; i++) { + PropertyDescriptor propDesc = propDescs[i]; + Class pType = propDesc.getPropertyType(); + if ("class".equals(propDesc.getName())) { + continue; + } + Object pValue = propDesc.getReadMethod().invoke(source, NULL); + json.put(propDesc.getName(), toJSON(pValue)); + } + return json; + + } + + public Object transform(Object source, TransformationContext context) { + try { + return toJSON(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/String2JSON.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/String2JSON.java new file mode 100644 index 0000000000..ff5968bccd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/String2JSON.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.sca.databinding.json; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * @version $Rev$ $Date$ + */ +public class String2JSON extends BaseTransformer implements PullTransformer { + + @Override + protected Class getSourceType() { + return String.class; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + public Object transform(String source, TransformationContext context) { + try { + Class type = null; + if (context != null && context.getTargetDataType() != null) { + type = context.getTargetDataType().getPhysical(); + } + return JSONHelper.toJSON(source, type); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 500; + } + + @Override + public String getTargetDataBinding() { + return JSONDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamReader2JSON.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamReader2JSON.java new file mode 100644 index 0000000000..aa75afc9d4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamReader2JSON.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.sca.databinding.json; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.xml.XMLStreamSerializer; +import org.codehaus.jettison.badgerfish.BadgerFishXMLStreamWriter; + +/** + * @version $Rev$ $Date$ + */ +public class XMLStreamReader2JSON extends BaseTransformer implements + PullTransformer { + + @Override + protected Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + public Object transform(XMLStreamReader source, TransformationContext context) { + try { + StringWriter writer = new StringWriter(); + XMLStreamWriter jsonWriter = new BadgerFishXMLStreamWriter(writer); + XMLStreamSerializer serializer = new XMLStreamSerializer(); + serializer.serialize(source, jsonWriter); + source.close(); + Class type = null; + if (context != null && context.getTargetDataType() != null) { + type = context.getTargetDataType().getPhysical(); + } + return JSONHelper.toJSON(writer.toString(), type); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 500; + } + + @Override + public String getTargetDataBinding() { + return JSONDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSON2OMElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSON2OMElement.java new file mode 100644 index 0000000000..1072b70029 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSON2OMElement.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.json.axiom; + + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.Transformer; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.json.JSONDataBinding; +import org.apache.tuscany.sca.databinding.json.JSONHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.codehaus.jettison.json.JSONObject; +import org.osoa.sca.annotations.Service; + +/** + * @version $Rev$ $Date$ + */ +@Service(Transformer.class) +public class JSON2OMElement extends BaseTransformer implements PullTransformer { + + private OMFactory factory = OMAbstractFactory.getOMFactory(); + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + protected Class getTargetType() { + return OMElement.class; + } + + public OMElement transform(Object source, TransformationContext context) { + try { + JSONObject json = JSONHelper.toJettison(source); + if (json == null) { + return null; + } + String ns = JSONDataBinding.ROOT_ELEMENT.getNamespaceURI(); + String name = JSONDataBinding.ROOT_ELEMENT.getLocalPart(); + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType.getLogical(); + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement()) { + ns = xmlType.getElementName().getNamespaceURI(); + name = xmlType.getElementName().getLocalPart(); + } + } + } + JSONBadgerfishDataSource ds = new JSONBadgerfishDataSource(json); + OMNamespace namespace = factory.createOMNamespace(ns, ""); + return factory.createOMElement(ds, name, namespace); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 500; + } + + @Override + public String getSourceDataBinding() { + return JSONDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONBadgerfishDataSource.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONBadgerfishDataSource.java new file mode 100644 index 0000000000..adc38772be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONBadgerfishDataSource.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.sca.databinding.json.axiom; + +import javax.xml.stream.XMLStreamException; + +import org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader; +import org.codehaus.jettison.json.JSONException; +import org.codehaus.jettison.json.JSONObject; + +/** + * JSONDataSource keeps the JSON String inside and consumes it when needed. This is to be kept in the + * OMSourcedElementImpl and can be used either to expand the tree or get the JSON String directly without expanding. + * This uses the "Badgerfish" JSON convention. + * + * @version $Rev$ $Date$ + */ + +public class JSONBadgerfishDataSource extends JSONDataSource { + + public JSONBadgerfishDataSource(JSONObject json) { + super(json); + } + + /** + * Gives the StAX reader using the "Badgerfish" formatted input JSON String. + * + * @return The XMLStreamReader according to the JSON String. + * @throws javax.xml.stream.XMLStreamException if there is an error while making the StAX reader. + */ + @Override + public javax.xml.stream.XMLStreamReader getReader() throws XMLStreamException { + try { + return new BadgerFishXMLStreamReader(json); + } catch (JSONException e) { + throw new XMLStreamException(e); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONDataSource.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONDataSource.java new file mode 100644 index 0000000000..5b0312056e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONDataSource.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.json.axiom; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMDataSource; +import org.apache.axiom.om.OMException; +import org.apache.axiom.om.OMOutputFormat; +import org.codehaus.jettison.json.JSONObject; +import org.codehaus.jettison.json.JSONTokener; +import org.codehaus.jettison.mapped.MappedXMLInputFactory; + +/** + * JSONDataSource keeps the JSON String inside and consumes it when needed. This is to be kept in the + * OMSourcedElementImpl and can be used either to expand the tree or get the JSON String directly without expanding. + * This uses the "Mapped" JSON convention. + * + * @version $Rev$ $Date$ + */ + +public class JSONDataSource implements OMDataSource { + protected JSONObject json; + + public JSONDataSource(JSONObject json) { + this.json = json; + } + + /** + * Writes JSON into the output stream. As this should write JSON, it directly gets the JSON string and writes it + * without expanding the tree. + * + * @param outputStream the stream to be written into + * @param omOutputFormat format of the message, this is ignored. + * @throws javax.xml.stream.XMLStreamException if there is an error while writing the message in to the output + * stream. + */ + public void serialize(OutputStream outputStream, OMOutputFormat omOutputFormat) + throws javax.xml.stream.XMLStreamException { + try { + String encoding = omOutputFormat == null ? "UTF-8" : omOutputFormat.getCharSetEncoding(); + outputStream.write(getJSONString().getBytes(encoding)); + } catch (IOException e) { + throw new OMException(); + } + } + + /** + * Writes JSON through the writer. As this should write JSON, it directly gets the JSON string and writes it without + * expanding the tree. + * + * @param writer Writer to be written into + * @param omOutputFormat format of the message, this is ignored. + * @throws javax.xml.stream.XMLStreamException if there is an error while writing the message through the writer. + */ + public void serialize(Writer writer, OMOutputFormat omOutputFormat) throws javax.xml.stream.XMLStreamException { + try { + writer.write(getJSONString()); + } catch (IOException e) { + throw new OMException(); + } + } + + /** + * Writes XML through the XMLStreamWriter. As the input data source is JSON, this method needs to get a StAX reader + * from that JSON String. Therefore this uses the getReader() method to get the StAX reader writes the events into + * the XMLStreamWriter. + * + * @param xmlStreamWriter StAX writer to be written into + * @throws javax.xml.stream.XMLStreamException if there is an error while writing the message through the StAX + * writer. + */ + public void serialize(javax.xml.stream.XMLStreamWriter xmlStreamWriter) throws javax.xml.stream.XMLStreamException { + XMLStreamReader reader = getReader(); + xmlStreamWriter.writeStartDocument(); + while (reader.hasNext()) { + int x = reader.next(); + switch (x) { + case XMLStreamConstants.START_ELEMENT: + xmlStreamWriter.writeStartElement(reader.getPrefix(), reader.getLocalName(), reader + .getNamespaceURI()); + int namespaceCount = reader.getNamespaceCount(); + for (int i = namespaceCount - 1; i >= 0; i--) { + xmlStreamWriter.writeNamespace(reader.getNamespacePrefix(i), reader.getNamespaceURI(i)); + } + int attributeCount = reader.getAttributeCount(); + for (int i = 0; i < attributeCount; i++) { + xmlStreamWriter.writeAttribute(reader.getAttributePrefix(i), + reader.getAttributeNamespace(i), + reader.getAttributeLocalName(i), + reader.getAttributeValue(i)); + } + break; + case XMLStreamConstants.START_DOCUMENT: + break; + case XMLStreamConstants.CHARACTERS: + xmlStreamWriter.writeCharacters(reader.getText()); + break; + case XMLStreamConstants.CDATA: + xmlStreamWriter.writeCData(reader.getText()); + break; + case XMLStreamConstants.END_ELEMENT: + xmlStreamWriter.writeEndElement(); + break; + case XMLStreamConstants.END_DOCUMENT: + xmlStreamWriter.writeEndDocument(); + break; + case XMLStreamConstants.SPACE: + break; + case XMLStreamConstants.COMMENT: + xmlStreamWriter.writeComment(reader.getText()); + break; + case XMLStreamConstants.DTD: + xmlStreamWriter.writeDTD(reader.getText()); + break; + case XMLStreamConstants.PROCESSING_INSTRUCTION: + xmlStreamWriter.writeProcessingInstruction(reader.getPITarget(), reader.getPIData()); + break; + case XMLStreamConstants.ENTITY_REFERENCE: + xmlStreamWriter.writeEntityRef(reader.getLocalName()); + break; + default: + throw new OMException(); + } + } + xmlStreamWriter.writeEndDocument(); + } + + /** + * Gives the StAX reader using the "Mapped" formatted input JSON String. + * + * @return The XMLStreamReader according to the JSON String. + * @throws javax.xml.stream.XMLStreamException if there is an error while making the StAX reader. + */ + + public javax.xml.stream.XMLStreamReader getReader() throws javax.xml.stream.XMLStreamException { + + Map nsMap = new HashMap(); + nsMap.put("", ""); + + // input factory for "Mapped" convention + MappedXMLInputFactory inputFactory = new MappedXMLInputFactory(nsMap); + String jsonString = this.getJSONString(); + return inputFactory.createXMLStreamReader(new JSONTokener(jsonString)); + } + + // returns the json string by consuming the JSON input stream. + protected String getJSONString() { + return json.toString(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..400507296f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# implementation classes for the databindings +org.apache.tuscany.sca.databinding.json.JSONDataBinding;name=JSON diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..b122533f6e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -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. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.json.JSON2XMLStreamReader;source=JSON,target=javax.xml.stream.XMLStreamReader,weight=5000 +org.apache.tuscany.sca.databinding.json.XMLStreamReader2JSON;source=javax.xml.stream.XMLStreamReader,target=JSON,weight=5000,public=false +org.apache.tuscany.sca.databinding.json.JavaBean2JSON;source=java:complexType,target=JSON,weight=80000,public=false +org.apache.tuscany.sca.databinding.json.JavaBean2JSON;source=java:simpleType,target=JSON,weight=80000,public=false +org.apache.tuscany.sca.databinding.json.axiom.JSON2OMElement;source=JSON,target=org.apache.axiom.om.OMElement,weight=500 +org.apache.tuscany.sca.databinding.json.JavaBean2JSON;source=java:array,target=JSON,weight=80000,public=false +org.apache.tuscany.sca.databinding.json.JavaBean2JSON;source=commonj.sdo.DataObject,target=JSON,weight=80000,public=false +org.apache.tuscany.sca.databinding.json.JavaBean2JSON;source=javax.xml.bind.JAXBElement,target=JSON,weight=80000,public=false +org.apache.tuscany.sca.databinding.json.JSON2JavaBean;source=JSON,target=java:complexType,weight=80000,public=false +org.apache.tuscany.sca.databinding.json.JSON2JavaBean;source=JSON,target=java:simpleType,weight=80000,public=false +org.apache.tuscany.sca.databinding.json.JSON2JavaBean;source=JSON,target=commonj.sdo.DataObject,weight=80000,public=false +org.apache.tuscany.sca.databinding.json.JSON2JavaBean;source=JSON,target=javax.xml.bind.JAXBElement,weight=80000,public=false +org.apache.tuscany.sca.databinding.json.JSON2JavaBean;source=JSON,target=java:array,weight=80000,public=false diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java new file mode 100644 index 0000000000..3c7f151ed7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.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.sca.databinding.json; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.databinding.json.axiom.JSON2OMElement; +import org.apache.tuscany.sca.databinding.xml.XMLStreamSerializer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.json.JSONObject; + +public class JSONTransformerTestCase extends TestCase { + private static final String IPO_XML = "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + private static final String JSON_STR = "{\"xsl:root\":{\"@xmlns\":{\"xsl\":\"http://foo.com\"},\"data\":{\"$\":\"my json string\"}}}"; + + public void testXML2JSON() throws Exception { + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(IPO_XML)); + XMLStreamReader2JSON t1 = new XMLStreamReader2JSON(); + JSONObject json = (JSONObject) t1.transform(reader, null); + Assert.assertNotNull(json); + + // Cannot round-trip as we hit a bug in Jettison: http://jira.codehaus.org/browse/JETTISON-37 + /* + JSON2XMLStreamReader t2 = new JSON2XMLStreamReader(); + XMLStreamReader reader2 = t2.transform(json, null); + StringWriter sw = new StringWriter(); + XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw); + new XMLStreamSerializer().serialize(reader2, streamWriter); + streamWriter.flush(); + System.out.println(sw.toString()); + */ + + } + + public void testJSON2XML() throws Exception { + JSON2XMLStreamReader t2 = new JSON2XMLStreamReader(); + XMLStreamReader reader2 = t2.transform(new JSONObject(JSON_STR), null); + StringWriter sw = new StringWriter(); + XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw); + new XMLStreamSerializer().serialize(reader2, streamWriter); + streamWriter.flush(); + Assert.assertTrue(sw.toString() + .contains("my json string")); + } + + public void testJSON2OMElement() throws Exception { + JSON2OMElement t1 = new JSON2OMElement(); + TransformationContext context = new TransformationContextImpl(); + DataType dt = new DataTypeImpl(Object.class, new XMLType(new QName("http://foo.com", "root"), null)); + context.setTargetDataType(dt); + OMElement element = t1.transform(new JSONObject(JSON_STR), context); + StringWriter writer = new StringWriter(); + element.serialize(writer); + // System.out.println(writer.toString()); + } + + public void testString2JSON() throws Exception { + String json = "{\"name\":\"John\",\"age\":25}"; + String2JSON t1 = new String2JSON(); + JSONObject jsonObject = (JSONObject) t1.transform(json, null); + assertEquals(jsonObject.getString("name"), "John"); + assertEquals(jsonObject.getInt("age"), 25); + JSON2String t2 = new JSON2String(); + String str = t2.transform(jsonObject, null); + assertTrue(str.contains("\"name\":\"John\"")); + assertTrue(str.contains("\"age\":25")); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java new file mode 100644 index 0000000000..3b36f5be74 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONTestCase.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.json; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.json.JSONObject; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class JavaBean2JSONTestCase { + + public static class MyBean { + private String name; + private int age; + private boolean vip; + private String friends[]; + private List books; + private YourBean you; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public boolean isVip() { + return vip; + } + + public void setVip(boolean vip) { + this.vip = vip; + } + + public String[] getFriends() { + return friends; + } + + public void setFriends(String[] friends) { + this.friends = friends; + } + + public List getBooks() { + return books; + } + + public void setBooks(List books) { + this.books = books; + } + + public YourBean getYou() { + return you; + } + + public void setYou(YourBean you) { + this.you = you; + } + + } + + public static class YourBean { + private int id; + private String name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + @Test + public void testBean2JSON() throws Exception { + MyBean me = new MyBean(); + me.setAge(30); + me.setBooks(new ArrayList()); + me.setFriends(new String[] {"John", "Mike"}); + me.setVip(true); + me.setName("Me"); + YourBean you = new YourBean(); + you.setId(123); + you.setName(null); + me.setYou(you); + JavaBean2JSON t1 = new JavaBean2JSON(); + Object result = t1.transform(me, null); + System.out.println(result); + JSON2JavaBean t2 = new JSON2JavaBean(); + TransformationContext context = new TransformationContextImpl(); + context.setTargetDataType(new DataTypeImpl(MyBean.class, null)); + Object v = t2.transform(new JSONObject(result.toString()), context); + Assert.assertTrue(v instanceof MyBean); + // String json = + // "{\"age\":30,\"books\":[],\"friends\":[\"John\",\"Mike\"],\"name\":\"Me\",\"vip\":true,\"you\":{\"id\":123,\"name\":null}}"; + // Assert.assertEquals(json, result.toString()); + } + + @Test + public void testString2JSON() throws Exception { + JavaBean2JSONObject t1 = new JavaBean2JSONObject(); + Object result = t1.transform("ABC", null); + System.out.println(result); + JSON2JavaBean t2 = new JSON2JavaBean(); + TransformationContext context = new TransformationContextImpl(); + context.setTargetDataType(new DataTypeImpl(String.class, null)); + Object v = t2.transform(result, context); + Assert.assertTrue(v instanceof String); + Assert.assertEquals("ABC", v); + } + + @Test + public void testStringArray2JSON() throws Exception { + JavaBean2JSON t1 = new JavaBean2JSON(); + Object result = t1.transform(new String[] {"ABC", "DF"}, null); + System.out.println(result); + JSON2JavaBean t2 = new JSON2JavaBean(); + TransformationContext context = new TransformationContextImpl(); + context.setTargetDataType(new DataTypeImpl(String[].class, null)); + Object v = t2.transform(result, context); + Assert.assertTrue(v instanceof String[]); + String[] strs = (String[])v; + Assert.assertEquals("ABC", strs[0]); + Assert.assertEquals("DF", strs[1]); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyBean.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyBean.java new file mode 100644 index 0000000000..60b293c1d4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyBean.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.sca.databinding.json; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MyBean { + private int age; + private String name; + private float[] rates = new float[] {1.0f, 2.0f}; + private List notes = new ArrayList(); + private Map map = new HashMap(); + private Object service; + private Object otherService; + private boolean good; + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getNotes() { + return notes; + } + + public void setNotes(List notes) { + this.notes = notes; + } + + public float[] getRates() { + return rates; + } + + public void setRates(float[] rates) { + this.rates = rates; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + + public Object getService() { + return service; + } + + public void setService(Object service) { + this.service = service; + } + + public Object getOtherService() { + return otherService; + } + + public void setOtherService(Object otherService) { + this.otherService = otherService; + } + + public boolean isGood() { + return good; + } + + public void setGood(boolean good) { + this.good = good; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + age; + result = prime * result + (good ? 1231 : 1237); + result = prime * result + ((map == null) ? 0 : map.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((notes == null) ? 0 : notes.hashCode()); + result = prime * result + ((otherService == null) ? 0 : otherService.hashCode()); + result = prime * result + Arrays.hashCode(rates); + result = prime * result + ((service == null) ? 0 : service.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final MyBean other = (MyBean)obj; + if (age != other.age) + return false; + if (good != other.good) + return false; + if (map == null) { + if (other.map != null) + return false; + } else if (!map.equals(other.map)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (notes == null) { + if (other.notes != null) + return false; + } else if (!notes.equals(other.notes)) + return false; + if (otherService == null) { + if (other.otherService != null) + return false; + } else if (!otherService.equals(other.otherService)) + return false; + if (!Arrays.equals(rates, other.rates)) + return false; + if (service == null) { + if (other.service != null) + return false; + } else if (!service.equals(other.service)) + return false; + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterface.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterface.java new file mode 100644 index 0000000000..d32e0763c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterface.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.sca.databinding.json; + +/** + * @version $Rev$ $Date$ + */ +public interface MyInterface { + void setId(String id); + + String getId(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterfaceImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterfaceImpl.java new file mode 100644 index 0000000000..3a2b95a4e2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/MyInterfaceImpl.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.sca.databinding.json; + +/** + * @version $Rev$ $Date$ + */ +public class MyInterfaceImpl implements MyInterface { + private String id; + + /** + * @see org.apache.tuscany.databinding.jaxb.MyInterface#getId() + */ + public String getId() { + return id; + } + + /** + * @see org.apache.tuscany.databinding.jaxb.MyInterface#setId(java.lang.String) + */ + public void setId(String id) { + this.id = id; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final MyInterfaceImpl other = (MyInterfaceImpl)obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java new file mode 100644 index 0000000000..84995baadf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.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.sca.databinding.json; + +import java.lang.reflect.Array; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; + +public class POJOTestCase extends TestCase { + public void testPOJO() throws Exception { + MyBean bean = new MyBean(); + bean.setName("Test"); + bean.setAge(20); + bean.getNotes().add("1"); + bean.getNotes().add("2"); + bean.getMap().put("1", 1); + MyInterface service = new MyInterfaceImpl(); + service.setId("ID001"); + bean.setService(service); + bean.setOtherService(service); + + roundTrip(bean); + } + + private void roundTrip(T bean) { + JavaBean2JSON t1 = new JavaBean2JSON(); + + Object json = t1.transform(bean, null); + System.out.println(json); + JSON2JavaBean t2 = new JSON2JavaBean(); + + TransformationContext context = new TransformationContextImpl(); + context.setTargetDataType(new DataTypeImpl(bean == null ? Object.class : bean.getClass(), null)); + Object newBean = t2.transform(json, context); + + if (newBean != null && newBean.getClass().isArray()) { + int len = Array.getLength(newBean); + assertEquals(Array.getLength(bean), len); + for (int i = 0; i < len; i++) { + assertEquals(Array.get(bean, i), Array.get(newBean, i)); + } + return; + } + assertEquals(bean, newBean); + } + + public void testString() throws Exception { + roundTrip("ABC"); + } + + public void testNull() throws Exception { + roundTrip(null); + } + + public void testArray() throws Exception { + roundTrip(new String[] {"123", "ABC"}); + } + + public void testByteArray() throws Exception { + roundTrip("ABC".getBytes()); + } + + public void testPrimitive() throws Exception { + roundTrip(123); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/resources/ipo.xsd new file mode 100644 index 0000000000..5a493e1746 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-json/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/LICENSE @@ -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, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/pom.xml new file mode 100644 index 0000000000..2e6e5b01b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/pom.xml @@ -0,0 +1,137 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding-saxon + Apache Tuscany SCA Data Binding for Saxon + + + + + false + + rfeng + Tuscany Maven 2.0 Repository + http://svn.apache.org/repos/asf/incubator/tuscany/maven + default + + + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + + + net.sf.saxon + saxon + 8.7 + + + + net.sf.saxon + saxon-dom + 8.7 + + + + org.apache.tuscany.sdo + tuscany-sdo-lib + 1.1.1 + + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.1.1 + + + backport-util-concurrent + backport-util-concurrent + + + + + + backport-util-concurrent + backport-util-concurrent + 3.1 + + + + junit + junit + 4.5 + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding.saxon + ${pom.name} + org.apache.tuscany.sca.databinding.saxon* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java new file mode 100644 index 0000000000..25f8ee886f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.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.sca.databinding.saxon; + +import javax.xml.transform.dom.DOMResult; + +import net.sf.saxon.om.NodeInfo; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +/** + * Transforms SDO DataObject-s to NodeInfo objects needed by Saxon parser. + * + * For root element when Serializing the DataObject the name of its + * implemented interface is used with its first letter made lowercase. + * Also any namespaces that are defined are deleted, because otherwise + * the SaxonB parser does not work + * + * @version $Rev$ $Date$ + */ +public class DataObject2NodeInfoTransformer extends BaseTransformer implements + PullTransformer { + + private Node2NodeInfoTransformer node2NodeInfoTransformer; + + public DataObject2NodeInfoTransformer(Node2NodeInfoTransformer node2NodeInfoTransformer) { + this.node2NodeInfoTransformer = node2NodeInfoTransformer; + } + + public DataObject2NodeInfoTransformer() { + this.node2NodeInfoTransformer = new Node2NodeInfoTransformer(); + } + + public NodeInfo transform(DataObject source, TransformationContext context) { + // FIXME: Need to create the HelperContext from the transformation context + // FIXME: This is a big hack to create a document using the class name + XMLHelper helper = XMLHelper.INSTANCE; + String name = null; + if (source.getClass().getInterfaces().length > 0) { + name = source.getClass().getInterfaces()[0].getSimpleName(); + } else { + name = source.getClass().getName(); + } + + if (name.length() > 0) { + name = Character.toLowerCase(name.charAt(0)) + name.substring(1, name.length()); + } + + try { + DOMResult domResult = new DOMResult(DOMHelper.newDocument()); + XMLDocument xmlDoc = helper.createDocument(source, null, name); + helper.save(xmlDoc, domResult, null); + return node2NodeInfoTransformer.transform(domResult.getNode(), context); + } catch (Exception e) { + throw new TransformationException(e); + } + + } + + @Override + protected Class getSourceType() { + return DataObject.class; + } + + @Override + protected Class getTargetType() { + return NodeInfo.class; + } + + @Override + public int getWeight() { + return 30 + node2NodeInfoTransformer.getWeight(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.java new file mode 100644 index 0000000000..7122217b8b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/ItemList2ObjectTransformer.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.sca.databinding.saxon; + +import java.lang.reflect.Array; + +import net.sf.saxon.om.Item; +import net.sf.saxon.om.NodeInfo; +import net.sf.saxon.trans.XPathException; +import net.sf.saxon.value.Value; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.saxon.collection.ItemList; + +/** + * Transforms each object contained in the ItemList object. + * + * If the object type is the same as the target type, it is not transformed. + * + * If the object is a NodeInfo, it's transformed to a DataObject. + * + * If the object is a Value, it's transformed to a Java object. + * + * If the target type is not an array, the first transformed object is returned. + * + * If the first transformed object type is not a target type, then a + * TransformException is thrown + * + * If the target type is an array, a array of this type is created containing + * all transformed objects and it is returned + * + * If any transformed object is not a target type, then a TransformException is + * thrown + * + * @version $Rev: 659284 $ $Date: 2008-05-22 14:26:18 -0800 (Thu, 22 May 2008) $ + */ +public class ItemList2ObjectTransformer extends BaseTransformer implements + PullTransformer { + + private NodeInfo2DataObjectTransformer nodeInfo2DataObjectTransformer = new NodeInfo2DataObjectTransformer(); + + public ItemList2ObjectTransformer() { + } + + @Override + protected Class getSourceType() { + return ItemList.class; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 30 + nodeInfo2DataObjectTransformer.getWeight(); + } + + public Object transform(ItemList source, TransformationContext context) { + + if (source.size() == 0) { + return null; + } + + Class targetType = context.getTargetDataType().getPhysical(); + + if (targetType.isArray()) { + int i = 0; + Class componentClass = targetType.getComponentType(); + Object[] result = (Object[])Array.newInstance(componentClass, source.size()); + + try { + + if (componentClass.isAssignableFrom(NodeInfo.class) || componentClass.isAssignableFrom(Value.class)) { + + for (Item item : source) { + result[i++] = item; + } + + } else { + + for (Item item : source) { + + if (item instanceof NodeInfo) { + result[i] = nodeInfo2DataObjectTransformer.transform((NodeInfo)item, context); + + } else if (item instanceof Value) { + result[i] = Value.convert(item); + + } else { + result[i] = item; + } + + i++; + + } + + } + + } catch (ArrayStoreException ex) { + throw new TransformationException(ex); + + } catch (XPathException ex) { + throw new TransformationException(ex); + } + + return result; + + } else { + Item item = source.iterator().next(); + + if (item.getClass().isAssignableFrom(targetType)) { + return item; + + } else if (item instanceof NodeInfo) { + return nodeInfo2DataObjectTransformer.transform((NodeInfo)item, context); + + } else { + + try { + return Value.convert(item); + + } catch (XPathException e) { + throw new TransformationException(e); + } + + } + + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java new file mode 100644 index 0000000000..fabadd34ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.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.sca.databinding.saxon; + +import javax.xml.transform.dom.DOMSource; + +import net.sf.saxon.Configuration; +import net.sf.saxon.event.Builder; +import net.sf.saxon.om.NodeInfo; +import net.sf.saxon.trans.XPathException; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Node; + +/** + * Transforms DOM Node-s to NodeInfo objects needed by Saxon parser. + * + * Any namespaces that are defined are deleted, because otherwise + * the SaxonB parser does not work + * + * @version $Rev$ $Date$ + */ +public class Node2NodeInfoTransformer extends BaseTransformer implements + PullTransformer { + + public NodeInfo transform(Node source, TransformationContext context) { + Configuration configuration = SaxonDataBindingHelper.CURR_EXECUTING_CONFIG; + if (configuration == null) { + configuration = new Configuration(); + } + + NodeInfo docInfo = null; + try { + source = DOMHelper.promote(source); + docInfo = Builder.build(new DOMSource(source), null, configuration); + } catch (XPathException e) { + throw new TransformationException(e); + } + return docInfo; + } + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + protected Class getTargetType() { + return NodeInfo.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java new file mode 100644 index 0000000000..a5093f8cdf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.saxon; + +import java.io.IOException; + +import javax.xml.transform.dom.DOMSource; + +import net.sf.saxon.om.NodeInfo; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Document; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.XMLHelper; + +/** + * Transforms NodeInfo objects to SDO DataObjects. + * + * Before constructing the data object, resulting XML is populated + * with correct namespaces (which are taken from the logical target data type) + * These namespaces are crucial for constructing the right instance of + * the DataObject (i.e. if there is a SDO factory, an instance from this factory will + * be used, not the generic any data object) + * + * @version $Rev$ $Date$ + */ +public class NodeInfo2DataObjectTransformer extends BaseTransformer implements + PullTransformer { + + private NodeInfo2NodeTransformer nodeInfo2NodeTransformer; + + public NodeInfo2DataObjectTransformer(NodeInfo2NodeTransformer nodeInfo2NodeTransformer) { + this.nodeInfo2NodeTransformer = nodeInfo2NodeTransformer; + } + + public NodeInfo2DataObjectTransformer() { + this.nodeInfo2NodeTransformer = new NodeInfo2NodeTransformer(); + } + + @Override + protected Class getSourceType() { + return NodeInfo.class; + } + + @Override + protected Class getTargetType() { + return DataObject.class; + } + + @Override + public int getWeight() { + return 30 + nodeInfo2NodeTransformer.getWeight(); + } + + public DataObject transform(NodeInfo source, TransformationContext context) { + Document doc = (Document)nodeInfo2NodeTransformer.transform(source, context); + + return produceResult(doc); + } + + private DataObject produceResult(Document doc) { + try { + // FIXME: [rfeng] We should use the HelperContext from the context + DataObject resultingObject = + XMLHelper.INSTANCE.load(new DOMSource(doc), doc.getDocumentURI(), null).getRootObject(); + return resultingObject; + } catch (IOException e) { + throw new TransformationException(e); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.java new file mode 100644 index 0000000000..36ebac3aea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2JavaArrayTransformer.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.sca.databinding.saxon; + +import java.lang.reflect.Array; + +import net.sf.saxon.om.Item; +import net.sf.saxon.om.NodeInfo; +import net.sf.saxon.trans.XPathException; +import net.sf.saxon.value.Value; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.saxon.collection.ItemList; + +import commonj.sdo.DataObject; + +/** + * Transforms a NodeInfo object to a DataObject and return it in an array. + * + * @version $Rev: 659284 $ $Date: 2008-05-22 14:26:18 -0800 (Thu, 22 May 2008) $ + */ +public class NodeInfo2JavaArrayTransformer extends + BaseTransformer implements + PullTransformer { + + private NodeInfo2DataObjectTransformer nodeInfo2DataObjectTransformer = new NodeInfo2DataObjectTransformer(); + + public NodeInfo2JavaArrayTransformer() {} + + @Override + protected Class getSourceType() { + return NodeInfo.class; + } + + @Override + protected Class getTargetType() { + return Object[].class; + } + + @Override + public int getWeight() { + return 30 + nodeInfo2DataObjectTransformer.getWeight(); + } + + public Object[] transform(NodeInfo source, TransformationContext context) { + Object object = nodeInfo2DataObjectTransformer.transform(source, context); + + Class componentClass = context.getTargetDataType().getPhysical().getComponentType(); + Object[] result = (Object[]) Array.newInstance(componentClass, 1); + + result[0] = object; + + return result; + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2NodeTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2NodeTransformer.java new file mode 100644 index 0000000000..1e5b816662 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2NodeTransformer.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.sca.databinding.saxon; + +import java.util.Properties; + +import javax.xml.transform.OutputKeys; +import javax.xml.transform.dom.DOMResult; + +import net.sf.saxon.om.NodeInfo; +import net.sf.saxon.query.QueryResult; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +/** + * Transforms NodeInfo objects to SDO DataObjects. + * + * @version $Rev$ $Date$ + */ +public class NodeInfo2NodeTransformer extends BaseTransformer implements + PullTransformer { + + public Node transform(NodeInfo source, TransformationContext context) { + DOMResult destination = new DOMResult(); + try { + Properties props = new Properties(); + props.setProperty(OutputKeys.METHOD, "xml"); + props.setProperty(OutputKeys.INDENT, "yes"); + QueryResult.serialize(source, destination, props, source.getConfiguration()); + } catch (Exception e) { + throw new TransformationException(e); + } + return destination.getNode(); + } + + @Override + protected Class getSourceType() { + return NodeInfo.class; + } + + @Override + protected Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Object2ValueTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Object2ValueTransformer.java new file mode 100644 index 0000000000..616bcca6c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Object2ValueTransformer.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.sca.databinding.saxon; + +import net.sf.saxon.value.FloatValue; +import net.sf.saxon.value.ObjectValue; +import net.sf.saxon.value.Value; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; + +/** + * Transforms generic java objects to Value objects needed by Saxon parser. + * + * @version $Rev$ $Date$ + */ +public class Object2ValueTransformer extends BaseTransformer implements PullTransformer { + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + protected Class getTargetType() { + return Value.class; + } + + @Override + public String getSourceDataBinding() { + return JavaBeansDataBinding.NAME; + } + + @Override + public int getWeight() { + return 10000; + } + + public Value transform(Object source, TransformationContext context) { + // WORKAROUND for ClassCastException in ObjectValue.toJavaObject(float) + if (source instanceof Float) { + return new FloatValue(((Float)source).floatValue()); + } + return new ObjectValue(source); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonDataBindingHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonDataBindingHelper.java new file mode 100644 index 0000000000..ecb20b24b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonDataBindingHelper.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.sca.databinding.saxon; + +import net.sf.saxon.Configuration; + +/** + * Provides helper functionality for Saxon data bindings + * @version $Rev$ $Date$ + */ +public class SaxonDataBindingHelper { + /** + * This variable is meaningful only in the context of XQoery expression + * execution. It is used by the DataObject2NodeInfoTransformer and + * Node2NodeInfoTransformer to create the correct NodeInfo objects + * in the Output2Output transformations. + * For Input2Input transformations it is meaningless: + * - if it is null - it is ignored by the transformers as they create new + * configuration objects + * - if it is not null - it is reused + * However the XQueryInvoker transforms all NodeInfo-s to NodeInfo-s with + * its current configuration, so there is no effect for Input2Input transformations + */ + public static Configuration CURR_EXECUTING_CONFIG = null; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonNodeDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonNodeDataBinding.java new file mode 100644 index 0000000000..ccf842710d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonNodeDataBinding.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.sca.databinding.saxon; + + +import net.sf.saxon.om.NodeInfo; + +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * Represents data binding for parameters of type NodeInfo. + * + * The NodeInfo type is the type accepted by the Saxon XQuery processor for + * all XML - based content (i.e. not strings and simple types) + * + * @version $Rev$ $Date$ + */ +public class SaxonNodeDataBinding extends BaseDataBinding { + + public static final String NAME = NodeInfo.class.getName(); + public static final String[] ALIASES = new String[] {"saxon_node"}; + + public SaxonNodeDataBinding() { + super(NAME, NodeInfo.class); + } + + @Override + public boolean introspect(DataType type, Operation operation) { + if (super.introspect(type, operation)) { + // type.setLogical(XMLType.UNKNOWN); + return true; + } else { + return false; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonValueDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonValueDataBinding.java new file mode 100644 index 0000000000..2f51cf86ec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonValueDataBinding.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.sca.databinding.saxon; + + +import net.sf.saxon.value.Value; + +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * Represents data binding for parameters of type Value. + * + * The Value type is the type accepted by the Saxon XQuery processor for + * all simple types and strings + * + * @version $Rev$ $Date$ + */ +public class SaxonValueDataBinding extends BaseDataBinding { + public static final String NAME = Value.class.getName(); + public static final String[] ALIASES = new String[] {"saxon_value"}; + + public SaxonValueDataBinding() { + super(NAME, Value.class); + } + + @Override + public boolean introspect(DataType type, Operation operation) { + if (super.introspect(type, operation)) { + // type.setLogical(XMLType.UNKNOWN); + return true; + } else { + return false; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SimpleType2ValueTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SimpleType2ValueTransformer.java new file mode 100644 index 0000000000..67d89a6e0b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SimpleType2ValueTransformer.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.sca.databinding.saxon; + +import java.math.BigDecimal; + +import net.sf.saxon.value.DecimalValue; +import net.sf.saxon.value.DoubleValue; +import net.sf.saxon.value.FloatValue; +import net.sf.saxon.value.IntegerValue; +import net.sf.saxon.value.ObjectValue; +import net.sf.saxon.value.StringValue; +import net.sf.saxon.value.Value; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; + +/** + * Transforms simple types and strings to Value objects needed by Saxon parser + * @version $Rev$ $Date$ + */ +public class SimpleType2ValueTransformer extends BaseTransformer implements + PullTransformer { + + @Override + public String getSourceDataBinding() { + return SimpleJavaDataBinding.NAME; + } + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + protected Class getTargetType() { + return Value.class; + } + + @Override + public int getWeight() { + return 10000; + } + + public Value transform(Object source, TransformationContext context) { + Value result = null; + if (source instanceof Integer) { + result = new IntegerValue((Integer)source); + } else if (source instanceof Long) { + result = new IntegerValue((Long)source); + } else if (source instanceof Short) { + result = new IntegerValue((Short)source); + } else if (source instanceof Byte) { + result = new IntegerValue((Byte)source); + } else if (source instanceof Double) { + result = new DoubleValue((Double)source); + } else if (source instanceof Float) { + result = new FloatValue((Float)source); + } else if (source instanceof BigDecimal) { + result = new DecimalValue((BigDecimal)source); + } else if (source instanceof String) { + result = new StringValue(((String)source)); + } else { + result = new ObjectValue(source); + } + + return result; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.java new file mode 100644 index 0000000000..16d5f524bb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2JavaArray.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.sca.databinding.saxon; + +import java.lang.reflect.Array; + +import net.sf.saxon.trans.XPathException; +import net.sf.saxon.value.Value; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * Transforms a Value object to a Java Object and return it in an array. + * + * @version $Rev: 659284 $ $Date: 2008-05-22 14:26:18 -0800 (Thu, 22 May 2008) $ + */ +public class Value2JavaArray extends BaseTransformer implements PullTransformer { + + public Value2JavaArray() { + } + + @Override + protected Class getSourceType() { + return Value.class; + } + + @Override + protected Class getTargetType() { + return Object[].class; + } + + @Override + public int getWeight() { + return super.getWeight() + 100; + } + + public Object[] transform(Value source, TransformationContext context) { + + try { + Object object = Value.convert(Value.asItem(source)); + + Class componentClass = context.getTargetDataType().getPhysical().getComponentType(); + Object[] result = (Object[])Array.newInstance(componentClass, 1); + + result[0] = object; + + return result; + + } catch (XPathException e) { + throw new TransformationException(e.getMessage()); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2ObjectTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2ObjectTransformer.java new file mode 100644 index 0000000000..7589f6789b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2ObjectTransformer.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.sca.databinding.saxon; + +import net.sf.saxon.trans.XPathException; +import net.sf.saxon.value.Value; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; + +/** + * Transforms Value objects to generic java objects + * @version $Rev$ $Date$ + */ +public class Value2ObjectTransformer extends BaseTransformer implements PullTransformer { + + public Object transform(Value source, TransformationContext context) { + Object object; + try { + object = Value.convert(Value.asItem(source)); + } catch (XPathException e) { + throw new TransformationException(e); + } + return object; + } + + @Override + protected Class getSourceType() { + return Value.class; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + @Override + public String getTargetDataBinding() { + return JavaBeansDataBinding.NAME; + } + + @Override + public int getWeight() { + return 10000; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2SimpleTypeTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2SimpleTypeTransformer.java new file mode 100644 index 0000000000..5da4effcfd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2SimpleTypeTransformer.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.sca.databinding.saxon; + +import net.sf.saxon.trans.XPathException; +import net.sf.saxon.value.Value; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; + +/** + * Transforms Value objects to simple types + * @version $Rev$ $Date$ + */ +public class Value2SimpleTypeTransformer extends BaseTransformer implements + PullTransformer { + public Object transform(Value source, TransformationContext context) { + Object object; + try { + object = Value.convert(Value.asItem(source)); + } catch (XPathException e) { + throw new TransformationException(e); + } + return object; + } + + @Override + public String getTargetDataBinding() { + return SimpleJavaDataBinding.NAME; + } + + @Override + protected Class getSourceType() { + return Value.class; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 10000; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/collection/ItemList.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/collection/ItemList.java new file mode 100644 index 0000000000..065121520b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/collection/ItemList.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.sca.databinding.saxon.collection; + +import java.util.ArrayList; + +import net.sf.saxon.om.Item; + +/** + * Stores a list of Item objects. + * + * Used by the implementation.xquery to store a collection of results + * generated by the xquery execution. + * + * @version $Rev: 659284 $ $Date: 2008-05-22 14:26:18 -0800 (Thu, 22 May 2008) $ + */ +public class ItemList extends ArrayList {} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..e15021b972 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# implementation classes for the databindings +org.apache.tuscany.sca.databinding.saxon.SaxonNodeDataBinding;name=net.sf.saxon.om.NodeInfo +org.apache.tuscany.sca.databinding.saxon.SaxonValueDataBinding;name=net.sf.saxon.value.Value diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..4d927ce53d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -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. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.saxon.Node2NodeInfoTransformer;source=org.w3c.dom.Node,target=net.sf.saxon.om.NodeInfo,weight=2000 +org.apache.tuscany.sca.databinding.saxon.NodeInfo2NodeTransformer;source=net.sf.saxon.om.NodeInfo,target=org.w3c.dom.Node,weight=2000 +org.apache.tuscany.sca.databinding.saxon.Object2ValueTransformer;source=java:complexType,target=net.sf.saxon.value.Value,weight=80000 +org.apache.tuscany.sca.databinding.saxon.Value2ObjectTransformer;source=net.sf.saxon.value.Value,target=java:complexType,weight=80000 +org.apache.tuscany.sca.databinding.saxon.SimpleType2ValueTransformer;source=java:simpleType,target=net.sf.saxon.value.Value,weight=80000 +org.apache.tuscany.sca.databinding.saxon.Value2SimpleTypeTransformer;source=net.sf.saxon.value.Value,target=java:simpleType,weight=80000 +org.apache.tuscany.sca.databinding.saxon.NodeInfo2DataObjectTransformer;source=net.sf.saxon.om.NodeInfo,target=commonj.sdo.DataObject,weight=1000 +org.apache.tuscany.sca.databinding.saxon.DataObject2NodeInfoTransformer;source=commonj.sdo.DataObject,target=net.sf.saxon.om.NodeInfo,weight=1000 +org.apache.tuscany.sca.databinding.saxon.ItemList2ObjectTransformer;source=org.apache.tuscany.sca.databinding.saxon.collection.ItemList,target=net.sf.saxon.om.NodeInfo,weight=1000 +org.apache.tuscany.sca.databinding.saxon.ItemList2ObjectTransformer;source=org.apache.tuscany.sca.databinding.saxon.collection.ItemList,target=net.sf.saxon.value.Value,weight=1000 +org.apache.tuscany.sca.databinding.saxon.ItemList2ObjectTransformer;source=org.apache.tuscany.sca.databinding.saxon.collection.ItemList,target=commonj.sdo.DataObject,weight=1000 +org.apache.tuscany.sca.databinding.saxon.ItemList2ObjectTransformer;source=org.apache.tuscany.sca.databinding.saxon.collection.ItemList,target=java:complex,weight=1000 +org.apache.tuscany.sca.databinding.saxon.ItemList2ObjectTransformer;source=org.apache.tuscany.sca.databinding.saxon.collection.ItemList,target=java:simple,weight=1000 +org.apache.tuscany.sca.databinding.saxon.ItemList2ObjectTransformer;source=org.apache.tuscany.sca.databinding.saxon.collection.ItemList,target=java:array,weight=1000 +org.apache.tuscany.sca.databinding.saxon.NodeInfo2JavaArrayTransformer;source=net.sf.saxon.om.NodeInfo,target=java:array,weight=1000 +org.apache.tuscany.sca.databinding.saxon.Value2JavaArrayTransformer;source=net.sf.saxon.value.Value,target=java:array,weight=1000 diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/pom.xml new file mode 100644 index 0000000000..b8e8ab076f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/pom.xml @@ -0,0 +1,167 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding-sdo-axiom + Apache Tuscany SCA Data Binding for SDO/AXIOM + + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-sdo + 1.6-SNAPSHOT + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.7 + + + xerces + xercesImpl + + + javax.mail + mail + + + commons-logging + commons-logging + + + xml-apis + xml-apis + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.7 + runtime + + + + commons-logging + commons-logging + 1.1.1 + + + commons-logging + commons-logging + + + javax.servlet + servlet-api + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/sdo-source + + + + + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + 1.1.1 + + + generate-po-sdo + generate-test-sources + + ${basedir}/src/test/resources/ipo.xsd + com.example.ipo.sdo + true + true + true + + + generate + + + + generate-stock-sdo + generate-test-sources + + ${basedir}/src/test/resources/stock.xsd + com.example.stock.sdo + Stock + true + true + true + + + generate + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding.sdo.axiom + ${pom.name} + org.apache.tuscany.sca.databinding.sdo* + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java new file mode 100644 index 0000000000..02f43000b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo2om; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMDataSource; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.OMXMLParserWrapper; +import org.apache.axiom.om.impl.builder.StAXBuilder; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Helper for AXIOM + * + * @version $Rev$ $Date$ + */ +public class AxiomHelper { + private static final String DEFAULT_PREFIX = "_ns_"; + + private AxiomHelper() { + } + + /** + * See http://issues.apache.org/jira/browse/WSCOMMONS-240 + * @param om + */ + public static void completeAndClose(OMElement om) { + // Get the builder associated with the om element + OMXMLParserWrapper builder = om.getBuilder(); + if (builder != null) { + if (builder instanceof StAXBuilder) { + ((StAXBuilder)builder).releaseParserOnClose(true); + } + OMElement document = builder.getDocumentElement(); + if (document != null) { + document.build(); + } + } + if (builder instanceof StAXBuilder) { + ((StAXBuilder)builder).close(); + } + } + + /** + * This method will close the builder immediately. Any subsequent Axiom objects won't + * be built or accessible. + */ + public static void closeImmediately(OMElement om) { + // Get the builder associated with the om element + OMXMLParserWrapper builder = om.getBuilder(); + if (builder != null) { + if (builder instanceof StAXBuilder) { + ((StAXBuilder)builder).releaseParserOnClose(true); + ((StAXBuilder)builder).close(); + } + // builder.close(); + } + } + + /** + * @param context + * @param element + */ + public static void adjustElementName(TransformationContext context, OMElement element) { + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType == null ? null : dataType.getLogical(); + if (!(logical instanceof XMLType)) { + return; + } + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement() && !xmlType.getElementName().equals(element.getQName())) { + // FIXME:: Throw exception or switch to the new Element? + OMFactory factory = OMAbstractFactory.getOMFactory(); + QName name = xmlType.getElementName(); + OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(name.getLocalPart()); + } + } + } + + public static OMElement createOMElement(OMFactory factory, QName element) { + String localName = element.getLocalPart(); + OMNamespace ns = createOMNamespace(factory, element); + + return factory.createOMElement(localName, ns); + + } + + public static OMElement createOMElement(OMFactory factory, QName element, OMDataSource dataSource) { + String localName = element.getLocalPart(); + OMNamespace ns = createOMNamespace(factory, element); + + return factory.createOMElement(dataSource, localName, ns); + + } + + /** + * @param factory + * @param name + * @return + */ + public static OMNamespace createOMNamespace(OMFactory factory, QName name) { + String namespaceURI = name.getNamespaceURI(); + String prefix = name.getPrefix(); + + OMNamespace ns = null; + if (namespaceURI.length() != 0) { + // Qualified Element: we need an OMNamespace + if (prefix.length() == 0) { + // The prefix does not appear to be specified, let's create one + prefix = DEFAULT_PREFIX; + } + ns = factory.createOMNamespace(namespaceURI, prefix); + } + return ns; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java new file mode 100644 index 0000000000..aa7f99724d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo2om; + +import static org.apache.tuscany.sca.databinding.sdo.SDODataBinding.ROOT_ELEMENT; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.sdo.SDOContextHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +/** + * SDO DataObject --> AXIOM OMElement transformer + * + * @version $Rev$ $Date$ + */ +public class DataObject2OMElement extends BaseTransformer implements + PullTransformer { + + public OMElement transform(DataObject source, TransformationContext context) { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, true); + OMFactory factory = OMAbstractFactory.getOMFactory(); + + QName name = ROOT_ELEMENT; + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType == null ? null : dataType.getLogical(); + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement()) { + name = xmlType.getElementName(); + } + } + } + + XMLDocument document = helperContext.getXMLHelper().createDocument(source, + name.getNamespaceURI(), + name.getLocalPart()); + SDODataSource dataSource = new SDODataSource(document, helperContext); + OMElement element = AxiomHelper.createOMElement(factory, name, dataSource); + return element; + } + + @Override + protected Class getSourceType() { + return DataObject.class; + } + + @Override + protected Class getTargetType() { + return OMElement.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java new file mode 100644 index 0000000000..dc3c2610a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo2om; + +import static org.apache.tuscany.sca.databinding.sdo.SDODataBinding.ROOT_ELEMENT; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.axiom.om.OMDataSource; +import org.apache.axiom.om.OMOutputFormat; +import org.apache.axiom.om.impl.serialize.StreamingOMSerializer; +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.api.XMLStreamHelper; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +/** + * + * @version $Rev$ $Date$ + */ +public class SDODataSource implements OMDataSource { + private HelperContext helperContext; + private XMLDocument sourceDocument; + + public SDODataSource(XMLDocument source, HelperContext helperContext) { + this.sourceDocument = source; + this.helperContext = helperContext; + } + + public SDODataSource(DataObject obj, HelperContext helperContext) { + this.helperContext = helperContext; + this.sourceDocument = + helperContext.getXMLHelper().createDocument(obj, + ROOT_ELEMENT.getNamespaceURI(), + ROOT_ELEMENT.getLocalPart()); + } + + public XMLStreamReader getReader() throws XMLStreamException { + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext); + return streamHelper.createXMLStreamReader(sourceDocument); + } + + public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException { + StreamingOMSerializer serializer = new StreamingOMSerializer(); + serializer.serialize(getReader(), xmlWriter); + } + + public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException { + try { + helperContext.getXMLHelper().save(sourceDocument, output, null); + } catch (Exception e) { + throw new XMLStreamException(e); + } + } + + public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException { + try { + helperContext.getXMLHelper().save(sourceDocument, writer, null); + } catch (IOException e) { + throw new XMLStreamException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java new file mode 100644 index 0000000000..a55a9f37cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.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.sca.databinding.sdo2om; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.sdo.SDOContextHelper; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +/** + * SDO XMLDocument --> AXIOM OMElement transformer + * @version $Rev$ $Date$ + */ +public class XMLDocument2OMElement extends BaseTransformer implements + PullTransformer { + + public OMElement transform(XMLDocument source, TransformationContext context) { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, true); + SDODataSource dataSource = new SDODataSource(source, helperContext); + OMFactory factory = OMAbstractFactory.getOMFactory(); + QName name = new QName(source.getRootElementURI(), source.getRootElementName()); + OMElement element = AxiomHelper.createOMElement(factory, name, dataSource); + return element; + } + + @Override + protected Class getSourceType() { + return XMLDocument.class; + } + + @Override + protected Class getTargetType() { + return OMElement.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..c870ec2406 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.sdo2om.DataObject2OMElement;source=commonj.sdo.DataObject,target=org.apache.axiom.om.OMElement,weight=3000 +org.apache.tuscany.sca.databinding.sdo2om.XMLDocument2OMElement;source=commonj.sdo.helper.XMLDocument,target=org.apache.axiom.om.OMElement,weight=3000 diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java new file mode 100644 index 0000000000..57dd056526 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.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.sca.databinding.sdo2om; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamException; + +import junit.framework.Assert; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import commonj.sdo.DataObject; + +/** + * + * @version $Rev$ $Date$ + */ +public class DataObject2OMElementTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(DataObject.class.getName(), DataObject.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl(OMElement.class.getName(), OMElement.class, new XMLType(ORDER_QNAME, null)); + } + + public final void testTransform() throws XMLStreamException { + OMElement element = new DataObject2OMElement().transform(dataObject, context); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespace().getNamespaceURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName()); + // TODO: See https://issues.apache.org/jira/browse/WSCOMMONS-226 + // element.getBuilder().setCache(false); + StringWriter writer = new StringWriter(); + element.serialize(writer); + } + + public final void testTransformWrapper() throws XMLStreamException { + OMElement element = new DataObject2OMElement().transform(dataObject, context); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespace().getNamespaceURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName()); + + OMNamespace ns = OMAbstractFactory.getOMFactory().createOMNamespace("http://ns1", "ns1"); + element.setNamespace(ns); + element.setLocalName("dummy"); + // TODO: See https://issues.apache.org/jira/browse/WSCOMMONS-226 + // element.getBuilder().setCache(true); + StringWriter writer = new StringWriter(); + element.serializeAndConsume(writer); + // System.out.println(writer); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..f69ef598b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.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.sca.databinding.sdo2om; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.interfacedef.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * The base class for SDO-related test cases + * + * @version $Rev$ $Date$ + */ +public abstract class SDOTransformerTestCaseBase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + + protected HelperContext helperContext; + protected String binding = DataObject.class.getName(); + protected TransformationContext context; + protected TransformationContext reversedContext; + protected DataObject dataObject; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + helperContext = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(helperContext); + + context = new TransformationContextImpl(); + context.setSourceDataType(getSourceDataType()); + context.setTargetDataType(getTargetDataType()); + + reversedContext = new TransformationContextImpl(); + reversedContext.setSourceDataType(getTargetDataType()); + reversedContext.setTargetDataType(getSourceDataType()); + + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + address.setStreet("123 ABC St"); + address.setState("CA"); + address.setStreet("95131"); + po.setBillTo(address); + dataObject = (DataObject) po; + } + + protected abstract DataType getSourceDataType(); + + protected abstract DataType getTargetDataType(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java new file mode 100644 index 0000000000..5015a1b697 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.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.sca.databinding.sdo2om; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamException; + +import junit.framework.Assert; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import commonj.sdo.helper.XMLDocument; + +/** + * + * @version $Rev$ $Date$ + */ +public class XMLDocument2OMElementTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(XMLDocument.class.getName(), XMLDocument.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl(OMElement.class.getName(), OMElement.class, new XMLType(ORDER_QNAME, null)); + } + + public final void testTransform() throws XMLStreamException { + XMLDocument document = + helperContext.getXMLHelper().createDocument(dataObject, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + OMElement element = new XMLDocument2OMElement().transform(document, context); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespace().getNamespaceURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName()); + StringWriter writer = new StringWriter(); + element.serialize(writer); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd new file mode 100644 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/resources/stock.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/resources/stock.xsd new file mode 100644 index 0000000000..a0a6717371 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo-axiom/src/test/resources/stock.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/pom.xml new file mode 100644 index 0000000000..29937636d3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/pom.xml @@ -0,0 +1,144 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding-sdo + Apache Tuscany SCA Data Binding for SDO + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-xml + 1.6-SNAPSHOT + + + org.apache.tuscany.sdo + tuscany-sdo-lib + 1.1.1 + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.1.1 + + + backport-util-concurrent + backport-util-concurrent + + + + + backport-util-concurrent + backport-util-concurrent + 3.1 + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/sdo-source + + + + + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + 1.1.1 + + + generate-po-sdo + generate-test-sources + + ${basedir}/src/test/resources/ipo.xsd + com.example.ipo.sdo + true + true + true + + + generate + + + + generate-stock-sdo + generate-test-sources + + ${basedir}/src/test/resources/stock.xsd + com.example.stock.sdo + Stock + true + true + true + + + generate + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding.sdo + ${pom.name} + org.apache.tuscany.sca.databinding.sdo* + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2Node.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2Node.java new file mode 100644 index 0000000000..503e54e530 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2Node.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.sca.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.transform.dom.DOMResult; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +public class DataObject2Node extends BaseTransformer implements + PullTransformer { + + public Node transform(DataObject source, TransformationContext context) { + if (source == null) { + return null; + } + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, true); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + QName elementName = SDOContextHelper.getElement(context); + Document doc = DOMHelper.newDocument(); + DOMResult result = new DOMResult(doc); + XMLDocument xmlDoc = xmlHelper.createDocument(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + xmlHelper.save(xmlDoc, result, null); + return doc.getDocumentElement(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return DataObject.class; + } + + @Override + protected Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java new file mode 100644 index 0000000000..8ce8eae587 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.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.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + +public class DataObject2String extends BaseTransformer implements + PullTransformer { + + public String transform(DataObject source, TransformationContext context) { + if (source == null) { + return null; + } + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, true); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + QName elementName = SDOContextHelper.getElement(context); + return xmlHelper.save(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return DataObject.class; + } + + @Override + protected Class getTargetType() { + return String.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java new file mode 100644 index 0000000000..116ac4c553 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.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.sca.databinding.sdo; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.api.XMLStreamHelper; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +public class DataObject2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader transform(final DataObject source, TransformationContext context) { + if (source == null) { + return null; + } + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, true); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext); + final QName elementName = SDOContextHelper.getElement(context); + final XMLHelper xmlHelper = helperContext.getXMLHelper(); + // Allow privileged access to read properties. REquires java.util.PropertyPermission + // XML.load.form.lax read in security policy. + XMLDocument document = AccessController.doPrivileged(new PrivilegedAction() { + public XMLDocument run() { + return xmlHelper.createDocument(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + } + }); + + return streamHelper.createXMLStreamReader(document); + } catch (XMLStreamException e) { + // TODO: Add context to the exception + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return DataObject.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java new file mode 100644 index 0000000000..30a3e1c3a9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.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.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.BaseImpl; + +import commonj.sdo.helper.HelperContext; + +/** + * The model object for import.sdo + * + * @version $Rev$ $Date$ + */ +public class ImportSDO extends BaseImpl { + public static final QName IMPORT_SDO = + new QName("http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0", "import.sdo"); + + private HelperContext helperContext; + private String factoryClassName; + private String schemaLocation; + + public ImportSDO(HelperContext helperContext) { + super(); + this.helperContext = helperContext; + setUnresolved(true); + } + + public HelperContext getHelperContext() { + return helperContext; + } + + /** + * @return the factoryClassName + */ + public String getFactoryClassName() { + return factoryClassName; + } + + /** + * @param factoryClassName the factoryClassName to set + */ + public void setFactoryClassName(String factoryClassName) { + this.factoryClassName = factoryClassName; + } + + /** + * @return the schemaLocation + */ + public String getSchemaLocation() { + return schemaLocation; + } + + /** + * @param schemaLocation the schemaLocation to set + */ + public void setSchemaLocation(String schemaLocation) { + this.schemaLocation = schemaLocation; + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java new file mode 100644 index 0000000000..e0844117f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java @@ -0,0 +1,212 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static org.apache.tuscany.sca.databinding.sdo.ImportSDO.IMPORT_SDO; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLConnection; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XSDHelper; + +/** + * Loader that handles <import.sdo> elements. + * + * @version $Rev$ $Date$ + * @deprecated + */ +@Deprecated +public class ImportSDOProcessor implements StAXArtifactProcessor { + + private ContributionFactory contributionFactory; + private Monitor monitor; + + public ImportSDOProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "databinding-sdo-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "databinding-sdo-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public QName getXMLType() { + return IMPORT_SDO; + } + + public ImportSDO read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + assert IMPORT_SDO.equals(reader.getName()); + + // FIXME: How do we associate the application HelperContext with the one + // imported by the composite + ImportSDO importSDO = new ImportSDO(SDOContextHelper.getDefaultHelperContext()); + String factoryName = reader.getAttributeValue(null, "factory"); + if (factoryName != null) { + importSDO.setFactoryClassName(factoryName); + } + String location = reader.getAttributeValue(null, "location"); + if (location != null) { + importSDO.setSchemaLocation(location); + } + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && ImportSDO.IMPORT_SDO.equals(reader.getName())) { + break; + } + } + return importSDO; + } + + private void importFactory(ImportSDO importSDO, ModelResolver resolver) throws ContributionResolveException { + String factoryName = importSDO.getFactoryClassName(); + if (factoryName != null) { + ClassReference reference = new ClassReference(factoryName); + ClassReference resolved = resolver.resolveModel(ClassReference.class, reference); + if (resolved != null && !resolved.isUnresolved()) { + try { + Class factoryClass = resolved.getJavaClass(); + register(factoryClass, importSDO.getHelperContext()); + importSDO.setUnresolved(false); + } catch (Exception e) { + ContributionResolveException ce = new ContributionResolveException(e); + error("ContributionResolveException", resolver, ce); + //throw ce; + } + } else { + error("FailToResolveClass", resolver, factoryName); + //ContributionResolveException loaderException = + //new ContributionResolveException("Fail to resolve class: " + factoryName); + //throw loaderException; + } + } + } + + private static void register(Class factoryClass, HelperContext helperContext) throws Exception { + Field field = factoryClass.getField("INSTANCE"); + Object factory = field.get(null); + Method method = factory.getClass().getMethod("register", new Class[] {HelperContext.class}); + method.invoke(factory, new Object[] {helperContext}); + + // HelperContext defaultContext = HelperProvider.getDefaultContext(); + // method.invoke(factory, new Object[] {defaultContext}); + } + + private void importWSDL(ImportSDO importSDO, ModelResolver resolver) throws ContributionResolveException { + String location = importSDO.getSchemaLocation(); + if (location != null) { + try { + Artifact artifact = contributionFactory.createArtifact(); + artifact.setURI(location); + artifact = resolver.resolveModel(Artifact.class, artifact); + if (artifact.getLocation() != null) { + String wsdlURL = artifact.getLocation(); + URLConnection connection = new URL(wsdlURL).openConnection(); + connection.setUseCaches(false); + InputStream xsdInputStream = connection.getInputStream(); + try { + XSDHelper xsdHelper = importSDO.getHelperContext().getXSDHelper(); + xsdHelper.define(xsdInputStream, wsdlURL); + } finally { + xsdInputStream.close(); + } + importSDO.setUnresolved(false); + } else { + error("FailToResolveLocation", resolver, location); + //ContributionResolveException loaderException = new ContributionResolveException("Fail to resolve location: " + location); + //throw loaderException; + } + } catch (IOException e) { + ContributionResolveException ce = new ContributionResolveException(e); + error("ContributionResolveException", resolver, ce); + //throw ce; + } + } + } + + public QName getArtifactType() { + return ImportSDO.IMPORT_SDO; + } + + public void write(ImportSDO model, XMLStreamWriter outputSource) throws ContributionWriteException { + // Not implemented as is deprecated + } + + public Class getModelType() { + return ImportSDO.class; + } + + public void resolve(ImportSDO importSDO, ModelResolver resolver) throws ContributionResolveException { + importFactory(importSDO, resolver); + importWSDL(importSDO, resolver); + if (!importSDO.isUnresolved()) { + resolver.addModel(importSDO); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/Node2DataObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/Node2DataObject.java new file mode 100644 index 0000000000..4a05492dd8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/Node2DataObject.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.sca.databinding.sdo; + +import javax.xml.transform.dom.DOMSource; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +public class Node2DataObject extends BaseTransformer implements PullTransformer { + + public DataObject transform(Node source, TransformationContext context) { + if (source == null) { + return null; + } + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, false); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + Document doc = DOMHelper.promote(source); + DOMSource domSource = new DOMSource(doc); + XMLDocument xmlDoc = xmlHelper.load(domSource, doc.getDocumentURI(), null); + return xmlDoc.getRootObject(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + protected Class getTargetType() { + return DataObject.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java new file mode 100644 index 0000000000..ada0c94a8d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java @@ -0,0 +1,218 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.util.DataTypeHelper; +import org.apache.tuscany.sca.databinding.util.LRUCache; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.impl.HelperProvider; + +/** + * Helper class to get TypeHelper from the context + * + * @version $Rev$ $Date$ + */ +public final class SDOContextHelper { + private static final LRUCache cache = new LRUCache(1024); + + private SDOContextHelper() { + } + + public static HelperContext getHelperContext(TransformationContext context, boolean source) { + if (context == null) { + return getDefaultHelperContext(); + } + + HelperContext helperContext = null; + Operation op = source ? context.getSourceOperation() : context.getTargetOperation(); + if (op == null) { + DataType dt = source ? context.getSourceDataType() : context.getTargetDataType(); + + helperContext = dt.getMetaData(HelperContext.class); + if (helperContext != null) { + return helperContext; + } + helperContext = SDOUtil.createHelperContext(); + boolean found = register(helperContext, dt); + if (!found) { + helperContext = getDefaultHelperContext(); + } + dt.setMetaData(HelperContext.class, helperContext); + return helperContext; + } else { + return getHelperContext(op); + } + + } + + public static HelperContext getHelperContext(Operation op) { + if (op == null) { + return getDefaultHelperContext(); + } + + HelperContext helperContext = op.getInputType().getMetaData(HelperContext.class); + + if (helperContext != null) { + return helperContext; + } + + // Use the default HelperContext until a type is registered later on + helperContext = getDefaultHelperContext(); + + /* + List dataTypes = DataTypeHelper.getDataTypes(op, false); + boolean found = false; + for (DataType d : dataTypes) { + if (register(helperContext, d)) { + found = true; + } + } + if (!found) { + helperContext = getDefaultHelperContext(); + } + */ + op.getInputType().setMetaData(HelperContext.class, helperContext); + return helperContext; + } + + /** + * @param helperContext + * @param dataType + * @return + */ + private static boolean register(HelperContext helperContext, DataType dataType) { + if (dataType == null) { + return false; + } + Set> classes = DataTypeHelper.findClasses(dataType); + boolean found = false; + for (Class cls : classes) { + found = register(helperContext, dataType.getPhysical()) || found; + } + return found; + } + + /** + * FIXME: [rfeng] This is a hack to get the factory out a SDO class + * @param helperContext + * @param javaType + */ + + public static boolean register(HelperContext helperContext, Class javaType) { + if (javaType == null || DataObject.class == javaType) { + return false; + } + try { + Type type = helperContext.getTypeHelper().getType(javaType); + return register(helperContext, type); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public static boolean register(HelperContext helperContext, Type type) { + if (type != null && (!type.isDataType())) { + try { + Method method = type.getClass().getMethod("getEPackage"); + Object factory = method.invoke(type, new Object[] {}); + method = factory.getClass().getMethod("register", HelperContext.class); + method.invoke(factory, new Object[] {helperContext}); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } else { + return false; + } + } + + public static HelperContext getDefaultHelperContext() { + // SDOUtil.createHelperContext(); + return HelperProvider.getDefaultContext(); + } + + public static QName getElement(TransformationContext context) { + if (context == null) { + return SDODataBinding.ROOT_ELEMENT; + } + DataType dataType = context.getTargetDataType(); + Object logical = dataType.getLogical(); + QName elementName = null; + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + QName element = xmlType.getElementName(); + if (element != null) { + elementName = element; + } + } + if (elementName == null) { + // Try source type + dataType = context.getSourceDataType(); + logical = dataType.getLogical(); + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + QName element = xmlType.getElementName(); + if (element != null) { + elementName = element; + } + } + } + if (elementName != null) { + return elementName; + } else { + return SDODataBinding.ROOT_ELEMENT; + } + } + + public static String generateSchema(HelperContext context, Class[] classes) { + TypeHelper typeHelper = context.getTypeHelper(); + List types = new ArrayList(); + for (Class cls : classes) { + Type type = typeHelper.getType(cls); + if (type != null) { + types.add(type); + } + } + return generateSchema(context, types); + } + + public static String generateSchema(HelperContext context, List types) { + // FIXME: SDO throws IllegalArgumentException for types generated from existing XSDs + return context.getXSDHelper().generate(types); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java new file mode 100644 index 0000000000..39e9ffc161 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.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.sca.databinding.sdo; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.CopyHelper; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +/** + * SDO Databinding + * + * @version $Rev$ $Date$ + */ +public class SDODataBinding extends BaseDataBinding { + public static final String NAME = DataObject.class.getName(); + + public static final String ROOT_NAMESPACE = "commonj.sdo"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "dataObject"); + + private WrapperHandler wrapperHandler; + private XMLTypeHelper xmlTypeHelper; + + public SDODataBinding() { + super(NAME, DataObject.class); + wrapperHandler = new SDOWrapperHandler(); + xmlTypeHelper = new SDOTypeHelper(); + } + + @Override + public boolean introspect(DataType dataType, final Operation operation) { + final Class javaType = dataType.getPhysical(); + // Allow privileged access to read system properties. Requires PropertyPermission + // java.specification.version read in security policy. + final HelperContext context = AccessController.doPrivileged(new PrivilegedAction() { + public HelperContext run() { + return SDOContextHelper.getHelperContext(operation); + } + }); + + final Type type = context.getTypeHelper().getType(javaType); + if (type == null) { + // FIXME: Need a better to test dynamic SDO + if (DataObject.class.isAssignableFrom(javaType)) { + // Dynamic SDO + dataType.setDataBinding(getName()); + if (dataType.getLogical() == null) { + dataType.setLogical(XMLType.UNKNOWN); + } + return true; + } + return false; + } + if (type.isDataType()) { + // FIXME: Ignore simple types? + return false; + } + + // Found a SDO type, replace the default context with a private one + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + if (context == SDOContextHelper.getDefaultHelperContext()) { + HelperContext newContext = SDOUtil.createHelperContext(); + SDOContextHelper.register(newContext, type); + if (operation != null) { + operation.getInputType().setMetaData(HelperContext.class, newContext); + } + } else { + SDOContextHelper.register(context, type); + } + return null; + } + }); + + String namespace = type.getURI(); + String name = context.getXSDHelper().getLocalName(type); + QName xmlType = new QName(namespace, name); + dataType.setDataBinding(getName()); + QName elementName = null; + Object logical = dataType.getLogical(); + if (logical instanceof XMLType) { + elementName = ((XMLType)logical).getElementName(); + } + dataType.setLogical(new XMLType(elementName, xmlType)); + + return true; + } + + @Override + public WrapperHandler getWrapperHandler() { + return wrapperHandler; + } + + @Override + public XMLTypeHelper getXMLTypeHelper() { + // return new SDOTypeHelper(); + return xmlTypeHelper; + } + + @Override + public Object copy(Object arg, DataType dataType, Operation operation) { + HelperContext context = SDOContextHelper.getHelperContext(operation); + CopyHelper copyHelper = context.getCopyHelper(); + if (arg instanceof XMLDocument) { + XMLDocument document = (XMLDocument)arg; + DataObject dataObject = copyHelper.copy(document.getRootObject()); + return context.getXMLHelper().createDocument(dataObject, + document.getRootElementURI(), + document.getRootElementName()); + } else if (arg instanceof DataObject) { + return context.getCopyHelper().copy((DataObject)arg); + } else { + return super.copy(arg, dataType, operation); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java new file mode 100644 index 0000000000..c83ec53b01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +/** + * SDO Java/XML mapping for simple XSD types + * + * @version $Rev$ $Date$ + */ +public class SDOSimpleTypeMapper implements SimpleTypeMapper { + public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; + + public SDOSimpleTypeMapper() { + super(); + } + + public Object toJavaObject(QName typeName, String value, TransformationContext context) { + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, false); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.createFromString(type, value); + } + + public String toXMLLiteral(QName typeName, Object obj, TransformationContext context) { + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, true); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.convertToString(type, obj); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java new file mode 100644 index 0000000000..93c71cce6c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.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.sca.databinding.sdo; + +import java.beans.Introspector; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.XSDefinition; +import org.osoa.sca.ServiceRuntimeException; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.bootstrap.DOMImplementationRegistry; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSInput; +import org.w3c.dom.ls.LSParser; + +import commonj.sdo.Type; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +public class SDOTypeHelper implements XMLTypeHelper { + private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; + + private TypeHelper typeHelper; + private XSDHelper xsdHelper; + // private Map> xsdTypesMap = new HashMap>(); + // private Map> typesMap = new HashMap>(); + + public SDOTypeHelper() { + super(); + typeHelper = SDOContextHelper.getDefaultHelperContext().getTypeHelper(); + xsdHelper = SDOContextHelper.getDefaultHelperContext().getXSDHelper(); + } + + public TypeInfo getTypeInfo(Class javaType, Object logical) { + QName xmlType = JavaXMLMapper.getXMLType(javaType); + if (xmlType != null) { + return new TypeInfo(xmlType, true, null); + } else { + // introspect(javaType, xsdTypesMap, typesMap); + if (logical instanceof XMLType) { + xmlType = ((XMLType)logical).getTypeName(); + } + if (xmlType == null) { + xmlType = + new QName(JavaXMLMapper.getNamespace(javaType), Introspector.decapitalize(javaType.getSimpleName())); + } + return new TypeInfo(xmlType, false, null); + } + } + + private void introspect(Class javaType, Map> xsdTypesMap, Map> typesMap) { + Type type = typeHelper.getType(javaType); + if (type == null) { + return; + } + if (xsdHelper.isXSD(type)) { + addToMap(xsdTypesMap, type); + } else { + addToMap(typesMap, type); + } + } + + private void addToMap(Map> map, Type type) { + List types = map.get(type.getURI()); + if (types == null) { + types = new ArrayList(); + map.put(type.getURI(), types); + } + if (!types.contains(type)) { + types.add(type); + } + } + + /* + public List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver) { + List definitions = new ArrayList(); + generateSDOSchemas(definitions, factory, typesMap); + addResolvedXSDs(definitions, factory, resolver, xsdTypesMap); + return definitions; + } + */ + + private void generateSDOSchemas(List definitions, XSDFactory factory, Map> map) { + for (Map.Entry> entry : map.entrySet()) { + List types = entry.getValue(); + String ns = entry.getKey(); + generateSchema(definitions, factory, types, ns); + } + } + + private void generateSchema(List definitions, XSDFactory factory, List types, String ns) { + String schema = xsdHelper.generate(types); + DOMImplementationRegistry registry = null; + try { + registry = DOMImplementationRegistry.newInstance(); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + DOMImplementation impl = registry.getDOMImplementation("XML 3.0"); + DOMImplementationLS ls = (DOMImplementationLS)impl.getFeature("LS", "3.0"); + LSParser parser = ls.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, SCHEMA_NS); + LSInput input = ls.createLSInput(); + input.setCharacterStream(new StringReader(schema)); + Document document = parser.parse(input); + XSDefinition definition = factory.createXSDefinition(); + definition.setUnresolved(true); + definition.setDocument(document); + definition.setNamespace(ns); + definitions.add(definition); + } + + private void addResolvedXSDs(List definitions, + XSDFactory factory, + ModelResolver resolver, + Map> map) { + for (Map.Entry> entry : map.entrySet()) { + XSDefinition definition = factory.createXSDefinition(); + definition.setUnresolved(true); + definition.setNamespace(entry.getKey()); + //FIXME: set location URI + XSDefinition resolved = resolver.resolveModel(XSDefinition.class, definition); + if (resolved.getSchema() == null) { + //FIXME: create a checked exception and propagate it back up to the activator + throw new RuntimeException("No XSD found for namespace " + entry.getKey()); + } + // make sure all the required types are defined in the resolved schema + for (Type type : entry.getValue()) { + String name = xsdHelper.getLocalName(type); + QName typeName = null; + if (name.endsWith("_._type")) { + // FIXME: Anonymous tyype + name = name.substring(0, name.length() - "_._type".length()); + typeName = new QName(type.getURI(), name); + if (resolved.getXmlSchemaElement(typeName) == null) { + //FIXME: create a checked exception and propagate it back up to the activator + throw new RuntimeException("No XSD found for " + typeName.toString()); + } + } else { + typeName = new QName(type.getURI(), name); + if (resolved.getXmlSchemaType(typeName) == null) { + //FIXME: create a checked exception and propagate it back up to the activator + throw new RuntimeException("No XSD found for " + typeName.toString()); + } + } + + } + definitions.add(resolved); + } + } + + private static List getDataTypes(Interface intf) { + List dataTypes = new ArrayList(); + for (Operation op : intf.getOperations()) { + WrapperInfo inputWrapperInfo = op.getInputWrapper(); + WrapperInfo outputWrapperInfo = op.getOutputWrapper(); + if (inputWrapperInfo != null && outputWrapperInfo != null) { + DataType dt1 = inputWrapperInfo.getWrapperType(); + if (dt1 != null) { + dataTypes.add(dt1); + } + DataType dt2 = outputWrapperInfo.getWrapperType(); + if (dt2 != null) { + dataTypes.add(dt2); + } + } else { + for (DataType dt1 : op.getInputType().getLogical()) { + dataTypes.add(dt1); + } + DataType dt2 = op.getOutputType(); + if (dt2 != null) { + dataTypes.add(dt2); + } + for (DataType dt3 : op.getFaultTypes()) { + DataType dt4 = dt3.getLogical(); + if (dt4 != null) { + dataTypes.add(dt4); + } + } + } + } + return dataTypes; + } + + public List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, Interface intf) { + return getSchemaDefinitions(factory, resolver, getDataTypes(intf)); + } + + public List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, List dataTypes) { + Map> xsdTypesMap = new HashMap>(); + Map> typesMap = new HashMap>(); + for (DataType d : dataTypes) { + if (SDODataBinding.NAME.equals(d.getDataBinding())) { + introspect(d.getPhysical(), xsdTypesMap, typesMap); + } + } + List definitions = new ArrayList(); + generateSDOSchemas(definitions, factory, typesMap); + addResolvedXSDs(definitions, factory, resolver, xsdTypesMap); + return definitions; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypes.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypes.java new file mode 100644 index 0000000000..73c9711c2a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypes.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.sca.databinding.sdo; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import commonj.sdo.Type; + +/** + * The model object for sdo.types + * + * @version $Rev: 537464 $ $Date: 2007-05-12 08:37:14 -0700 (Sat, 12 May 2007) $ + * + * This extends the META-INF/sca-contribution.xml to register SDO types from static factory classes or WSDL/XSD files + * + * <contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ *     xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0">
+ *     <tuscany:sdo.types namespace="http://helloworld" location="wsdl/helloworld.wsdl"/>
+ * </contribution> + * + */ +public class SDOTypes { + public static final QName SDO_TYPES = new QName("http://tuscany.apache.org/xmlns/sca/1.0", "sdo.types"); + + private String factory; + private String schemaLocation; + private String namespace; + + private List types = new ArrayList(); + + private boolean unresolved; + + public SDOTypes() { + super(); + setUnresolved(true); + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + + /** + * @return the factoryClassName + */ + public String getFactory() { + return factory; + } + + /** + * @param factoryClassName the factoryClassName to set + */ + public void setFactory(String factoryClassName) { + this.factory = factoryClassName; + } + + /** + * @return the schemaLocation + */ + public String getSchemaLocation() { + return schemaLocation; + } + + /** + * @param schemaLocation the schemaLocation to set + */ + public void setSchemaLocation(String schemaLocation) { + this.schemaLocation = schemaLocation; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public List getTypes() { + return types; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java new file mode 100644 index 0000000000..167be60640 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java @@ -0,0 +1,192 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XSDHelper; + +/** + * SDO Wrapper Handler + * + * @version $Rev$ $Date$ + */ +public class SDOWrapperHandler implements WrapperHandler { + + public Object create(Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : + outputWrapperInfo.getWrapperElement(); + + HelperContext helperContext = SDOContextHelper.getHelperContext(operation); + Type sdoType = getSDOType(helperContext, element); + if (sdoType != null) { + DataFactory dataFactory = helperContext.getDataFactory(); + return dataFactory.create(sdoType); + } + return null; + } + + public void setChildren(Object wrapper, Object[] childObjects, Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + List childElements = input? inputWrapperInfo.getChildElements(): + outputWrapperInfo.getChildElements(); + + for (int i = 0; i < childElements.size(); i++) { + setChild(wrapper, i, childElements.get(i), childObjects[i]); + } + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#setChild(java.lang.Object, int, ElementInfo, + * java.lang.Object) + */ + public void setChild(Object wrapper, int i, ElementInfo childElement, Object value) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + String name = childElement.getQName().getLocalPart(); + if (childElement.isMany()) { + // FIXME: If we look up by name, we need to make sure the WrapperInfo has the correct element names + wrapperDO.getList(i).addAll((Collection)value); + } else { + wrapperDO.set(i, value); + } + } + + @SuppressWarnings("unchecked") + public List getChildren(Object wrapper, Operation operation, boolean input) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + List properties = wrapperDO.getInstanceProperties(); + List elements = new ArrayList(); + Type type = wrapperDO.getType(); + if (type.isSequenced()) { + // Add values in the sequence + Sequence sequence = wrapperDO.getSequence(); + for (int i = 0; i < sequence.size(); i++) { + // Skip mixed text + if (sequence.getProperty(i) != null) { + elements.add(sequence.getValue(i)); + } + } + } else { + for (Property p : properties) { + Object child = wrapperDO.get(p); + if (p.isMany()) { + for (Object c : (Collection)child) { + elements.add(c); + } + } else { + elements.add(child); + } + } + } + return elements; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(Operation, boolean) + */ + public DataType getWrapperType(Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : + outputWrapperInfo.getWrapperElement(); + + HelperContext helperContext = SDOContextHelper.getHelperContext(operation); + Type sdoType = getSDOType(helperContext, element); + if (sdoType != null) { + // Check if child elements matches + Class physical = sdoType.getInstanceClass(); + DataType wrapperType = + new DataTypeImpl(SDODataBinding.NAME, physical, new XMLType(element)); + return wrapperType; + } else { + return null; + } + } + + /** + * @param helperContext + * @param element + * @return + */ + private Type getSDOType(HelperContext helperContext, ElementInfo element) { + XSDHelper xsdHelper = helperContext.getXSDHelper(); + Type sdoType = null; + Property prop = + xsdHelper.getGlobalProperty(element.getQName().getNamespaceURI(), element.getQName().getLocalPart(), true); + if (prop != null) { + sdoType = prop.getType(); + } else { + TypeInfo type = element.getType(); + QName typeName = type != null ? type.getQName() : null; + if (typeName != null) { + sdoType = helperContext.getTypeHelper().getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + } + return sdoType; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#isInstance(java.lang.Object, Operation, boolean) + */ + public boolean isInstance(Object wrapper, Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : + outputWrapperInfo.getWrapperElement(); + + // List childElements = + // input ? wrapperInfo.getInputChildElements() : wrapperInfo.getOutputChildElements(); + HelperContext helperContext = SDOContextHelper.getHelperContext(operation); + Type sdoType = getSDOType(helperContext, element); + if (sdoType != null) { + return sdoType.isInstance(wrapper); + } + return false; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java new file mode 100644 index 0000000000..7ac423f8d8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.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.sca.databinding.sdo; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + +public class String2DataObject extends BaseTransformer implements + PullTransformer { + + public DataObject transform(String source, TransformationContext context) { + if (source == null) { + return null; + } + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, false); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + return xmlHelper.load(source).getRootObject(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return String.class; + } + + @Override + protected Class getTargetType() { + return DataObject.class; + } + + @Override + public int getWeight() { + return 50; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java new file mode 100644 index 0000000000..4e5aa1d5fd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.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.sca.databinding.sdo; + +import java.io.StringWriter; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +public class XMLDocument2String extends BaseTransformer implements + PullTransformer { + + public String transform(XMLDocument source, TransformationContext context) { + if (source == null) { + return null; + } + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, true); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + StringWriter writer = new StringWriter(); + xmlHelper.save(source, writer, null); + return writer.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return XMLDocument.class; + } + + @Override + protected Class getTargetType() { + return String.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java new file mode 100644 index 0000000000..e70fa08477 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.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.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.api.XMLStreamHelper; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class XMLDocument2XMLStreamReader extends BaseTransformer implements + PullTransformer { + /** + * @param source + * @param context + * @return + */ + public XMLStreamReader transform(XMLDocument source, TransformationContext context) { + if (source == null) { + return null; + } + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, true); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext); + return streamHelper.createXMLStreamReader(source); + } catch (XMLStreamException e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return XMLDocument.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java new file mode 100644 index 0000000000..baf3e2e90a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.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.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.api.XMLStreamHelper; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; + +public class XMLStreamReader2DataObject extends BaseTransformer implements + PullTransformer { + + public DataObject transform(XMLStreamReader source, TransformationContext context) { + if (source == null) { + return null; + } + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, false); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext); + // The XMLStreamHelper requires that the reader is positioned at + // START_ELEMENT + while (source.getEventType() != XMLStreamConstants.START_ELEMENT && source.hasNext()) { + source.next(); + } + DataObject target = streamHelper.loadObject(source); + source.close(); + return target; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getTargetType() { + return DataObject.class; + } + + @Override + protected Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 15; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java new file mode 100644 index 0000000000..ac452910f6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.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.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.api.XMLStreamHelper; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class XMLStreamReader2XMLDocument extends BaseTransformer implements + PullTransformer { + + public XMLDocument transform(XMLStreamReader source, TransformationContext context) { + if (source == null) { + return null; + } + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context, false); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext); + XMLDocument target = streamHelper.load(source); + source.close(); + return target; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getTargetType() { + return XMLDocument.class; + } + + @Override + protected Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 15; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesModelResolver.java new file mode 100644 index 0000000000..d585278572 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesModelResolver.java @@ -0,0 +1,246 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.sdo.SDOTypes; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.XSDefinition; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XSDHelper; + +/** + * SDO types model resolver that aggregates the SDO type registration for an SCA contribution + */ +public class SDOTypesModelResolver implements ModelResolver { + private Contribution contribution; + private HelperContext helperContext; + private List sdoTypes = new ArrayList(); + private ContributionFactory contributionFactory; + private XSDFactory xsdFactory; + private Monitor monitor; + + public SDOTypesModelResolver(Contribution contribution, ExtensionPointRegistry registry) { + super(); + ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); + this.xsdFactory = modelFactories.getFactory(XSDFactory.class); + this.monitor = createMonitor(registry); + this.contribution = contribution; + } + + private static Monitor createMonitor(ExtensionPointRegistry extensionPoints) { + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + if (utilities != null) { + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + if (monitorFactory != null) { + return monitorFactory.createMonitor(); + } + } + return null; + } + + public void addModel(Object resolved) { + if (helperContext == null) { + helperContext = SDOUtil.createHelperContext(); + } + SDOTypes types = (SDOTypes)resolved; + try { + loadSDOTypes(types, contribution.getModelResolver()); + } catch (ContributionResolveException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + sdoTypes.add(types); + } + + public Object removeModel(Object resolved) { + SDOTypes types = (SDOTypes)resolved; + return sdoTypes.remove(types); + } + + public T resolveModel(Class modelClass, T unresolved) { + SDOTypes types = (SDOTypes)unresolved; + String ns = types.getNamespace(); + for (SDOTypes t : sdoTypes) { + if (t.getNamespace().equals(types.getNamespace())) { + try { + loadSDOTypes(types, contribution.getModelResolver()); + } catch (ContributionResolveException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return (T)t; + } + } + return (T)types; + } + + private static void register(Class factoryClass, HelperContext helperContext) throws Exception { + Field field = factoryClass.getField("INSTANCE"); + Object factory = field.get(null); + Method method = factory.getClass().getMethod("register", new Class[] {HelperContext.class}); + method.invoke(factory, new Object[] {helperContext}); + } + + private void defineFromFactory(SDOTypes importSDO, ModelResolver resolver) throws ContributionResolveException { + String factoryName = importSDO.getFactory(); + if (factoryName != null) { + ClassReference reference = new ClassReference(factoryName); + ClassReference resolved = resolver.resolveModel(ClassReference.class, reference); + if (resolved != null && !resolved.isUnresolved()) { + try { + Class factoryClass = resolved.getJavaClass(); + // Get the namespace + Field field = factoryClass.getField("NAMESPACE_URI"); + importSDO.setNamespace((String)field.get(null)); + register(factoryClass, helperContext); + importSDO.setUnresolved(false); + } catch (Exception e) { + ContributionResolveException ce = new ContributionResolveException(e); + error("ContributionResolveException", resolver, ce); + //throw ce; + } + } else { + error("FailToResolveClass", resolver, factoryName); + //ContributionResolveException loaderException = + //new ContributionResolveException("Fail to resolve class: " + factoryName); + //throw loaderException; + } + } + } + + private void defineFromXSD(SDOTypes importSDO, ModelResolver resolver) throws ContributionResolveException { + String location = importSDO.getSchemaLocation(); + if (location != null) { + try { + Artifact artifact = contributionFactory.createArtifact(); + artifact.setURI(location); + artifact = resolver.resolveModel(Artifact.class, artifact); + if (artifact.getLocation() != null) { + String wsdlURL = artifact.getLocation(); + URLConnection connection = new URL(wsdlURL).openConnection(); + connection.setUseCaches(false); + InputStream xsdInputStream = connection.getInputStream(); + try { + XSDHelper xsdHelper = helperContext.getXSDHelper(); + List sdoTypes = xsdHelper.define(xsdInputStream, wsdlURL); + for (Type t : sdoTypes) { + importSDO.setNamespace(t.getURI()); + break; + } + importSDO.getTypes().addAll(sdoTypes); + } finally { + xsdInputStream.close(); + } + importSDO.setUnresolved(false); + } else { + error("FailToResolveLocation", resolver, location); + //ContributionResolveException loaderException = new ContributionResolveException("Fail to resolve location: " + location); + //throw loaderException; + } + } catch (IOException e) { + ContributionResolveException ce = new ContributionResolveException(e); + error("ContributionResolveException", resolver, ce); + //throw ce; + } + } else { + String ns = importSDO.getNamespace(); + if (ns != null) { + XSDefinition xsd = xsdFactory.createXSDefinition(); + xsd.setUnresolved(true); + xsd.setNamespace(ns); + xsd = resolver.resolveModel(XSDefinition.class, xsd); + if (!xsd.isUnresolved()) { + XSDHelper xsdHelper = helperContext.getXSDHelper(); + xsdHelper.define(xsd.getLocation().toString()); + } + } + } + } + + private void loadSDOTypes(SDOTypes types, ModelResolver resolver) throws ContributionResolveException { + synchronized (types) { + if (types.isUnresolved()) { + defineFromFactory(types, resolver); + defineFromXSD(types, resolver); + types.setUnresolved(false); + } + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = + new ProblemImpl(this.getClass().getName(), "databinding-sdo-validation-messages", Severity.ERROR, + model, message, ex); + monitor.problem(problem); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + new ProblemImpl(this.getClass().getName(), "databinding-sdo-validation-messages", Severity.ERROR, + model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesProcessor.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesProcessor.java new file mode 100644 index 0000000000..3d703afd14 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesProcessor.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.databinding.sdo.SDOTypes; +import org.apache.tuscany.sca.monitor.Monitor; + + +/** + * Loader that handles <import.sdo> elements. + * + * @version $Rev: 667376 $ $Date: 2008-06-12 23:29:16 -0700 (Thu, 12 Jun 2008) $ + */ +public class SDOTypesProcessor implements StAXArtifactProcessor { + + public SDOTypesProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + public QName getXMLType() { + return SDOTypes.SDO_TYPES; + } + + public SDOTypes read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + assert SDOTypes.SDO_TYPES.equals(reader.getName()); + + // FIXME: How do we associate the application HelperContext with the one + // imported by the composite + SDOTypes sdoTypes = new SDOTypes(); + String factoryName = reader.getAttributeValue(null, "factory"); + if (factoryName != null) { + sdoTypes.setFactory(factoryName); + } + String location = reader.getAttributeValue(null, "location"); + if (location != null) { + sdoTypes.setSchemaLocation(location); + } + String ns = reader.getAttributeValue(null, "namespace"); + sdoTypes.setNamespace(ns); + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && SDOTypes.SDO_TYPES.equals(reader.getName())) { + break; + } + } + return sdoTypes; + } + + public QName getArtifactType() { + return SDOTypes.SDO_TYPES; + } + + public void write(SDOTypes model, XMLStreamWriter writer) throws ContributionWriteException { + try { + writer.writeStartElement(SDOTypes.SDO_TYPES.getNamespaceURI(), SDOTypes.SDO_TYPES.getLocalPart()); + if (model.getNamespace() != null) { + writer.writeAttribute("namespace", model.getNamespace()); + } + if (model.getSchemaLocation() != null) { + writer.writeAttribute("location", model.getSchemaLocation()); + } + if (model.getFactory() != null) { + writer.writeAttribute("factory", model.getFactory()); + } + writer.writeEndElement(); + } catch (XMLStreamException e) { + throw new ContributionWriteException(e); + } + } + + public Class getModelType() { + return SDOTypes.class; + } + + public void resolve(SDOTypes types, ModelResolver resolver) throws ContributionResolveException { + // Defer the resolution to SDOTypesResolver which aggragates the type registrations into an instance of HelperContext + resolver.addModel(types); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..7ff9478431 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.databinding.sdo.ImportSDOProcessor;qname=http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0#import.sdo,model=org.apache.tuscany.sca.databinding.sdo.ImportSDO +org.apache.tuscany.sca.databinding.sdo.xml.SDOTypesProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#sdo.types,model=org.apache.tuscany.sca.databinding.sdo.SDOTypes diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..6252de51c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +org.apache.tuscany.sca.databinding.sdo.xml.SDOTypesModelResolver;model=org.apache.tuscany.sca.databinding.sdo.SDOTypes \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..5ae557cc74 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# implementation classes for the databindings +org.apache.tuscany.sca.databinding.sdo.SDODataBinding;name=commonj.sdo.DataObject diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..b1916fd32a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -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. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.sdo.DataObject2String;source=commonj.sdo.DataObject,target=java.lang.String,weight=510 +org.apache.tuscany.sca.databinding.sdo.DataObject2XMLStreamReader;source=commonj.sdo.DataObject,target=javax.xml.stream.XMLStreamReader,weight=490 +org.apache.tuscany.sca.databinding.sdo.XMLDocument2String;source=commonj.sdo.helper.XMLDocument,target=java.lang.String,weight=510 +org.apache.tuscany.sca.databinding.sdo.String2DataObject;source=java.lang.String,target=commonj.sdo.DataObject,weight=500 +org.apache.tuscany.sca.databinding.sdo.XMLDocument2XMLStreamReader;source=commonj.sdo.helper.XMLDocument,target=javax.xml.stream.XMLStreamReader,weight=490 +org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2DataObject;source=javax.xml.stream.XMLStreamReader,target=commonj.sdo.DataObject,weight=490 +org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2XMLDocument;source=javax.xml.stream.XMLStreamReader,target=commonj.sdo.helper.XMLDocument,weight=490 +org.apache.tuscany.sca.databinding.sdo.DataObject2Node;source=commonj.sdo.DataObject,target=org.w3c.dom.Node,weight=500 +org.apache.tuscany.sca.databinding.sdo.Node2DataObject;source=org.w3c.dom.Node,target=commonj.sdo.DataObject,weight=500 diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/databinding-sdo-validation-messages.properties b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/databinding-sdo-validation-messages.properties new file mode 100644 index 0000000000..f53f08f377 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/main/resources/databinding-sdo-validation-messages.properties @@ -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. +# +# +FailToResolveClass = Fail to resolve class: {0} +FailToResolveLocation = Fail to resolve location: {0} +ContributionResolveException = ContributionResolveException occured due to: diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java new file mode 100644 index 0000000000..5a0208b290 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.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 com.example.stock.sdo.fault; + +import javax.xml.namespace.QName; + +import com.example.stock.sdo.InvalidSymbolFault; + +/** + * Hand-crafted java exception for SDO fault + * + * @version $Rev$ $Date$ + */ +public class InvalidSymbolFault_Exception extends Exception { + private static final long serialVersionUID = 8602157311925253920L; + + /** + * Generated QName for the fault element + */ + public static final QName FAULT_ELEMENT = new QName("http://www.example.com/stock", "InvalidSymbolFault"); + /** + * Java type that goes as soapenv:Fault detail element. + */ + private InvalidSymbolFault faultInfo; + + /** + * @param faultInfo + * @param message + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * @param faultInfo + * @param message + * @param cause + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * @return returns fault bean: + * org.apache.tuscany.sca.test.exceptions.impl.jaxb.InvalidSymbolFault + */ + public InvalidSymbolFault getFaultInfo() { + return faultInfo; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java new file mode 100644 index 0000000000..4bc41a5541 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.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.sca.databinding.sdo; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.DataObject; + +/** + * + * @version $Rev$ $Date$ + */ +public class DataObject2NodeTestCase extends SDOTransformerTestCaseBase { + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl>(String.class, String.class); + } + + public final void testTransform() { + Node node = new DataObject2Node().transform(dataObject, context); + Assert.assertNotNull(node); + Element element = (Element) node; + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespaceURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName()); + DataObject po = new Node2DataObject().transform(node, reversedContext); + Assert.assertTrue(po instanceof PurchaseOrderType); + PurchaseOrderType orderType = (PurchaseOrderType)po; + Assert.assertEquals("San Jose", orderType.getBillTo().getCity()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java new file mode 100644 index 0000000000..44d11cd586 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.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.sca.databinding.sdo; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.DataObject; + +/** + * + * @version $Rev$ $Date$ + */ +public class DataObject2StringTestCase extends SDOTransformerTestCaseBase { + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl>(String.class, String.class); + } + + public final void testTransform() { + String xml = new DataObject2String().transform(dataObject, context); + Assert.assertTrue(xml.indexOf("San Jose") != -1); + DataObject po = new String2DataObject().transform(xml, reversedContext); + Assert.assertTrue(po instanceof PurchaseOrderType); + PurchaseOrderType orderType = (PurchaseOrderType)po; + Assert.assertEquals("San Jose", orderType.getBillTo().getCity()); + } + + public final void testXML() { + String xml = + ""; + DataObject dataObject = new String2DataObject().transform(xml, reversedContext); + context.setSourceDataType(new DataTypeImpl(DataObject.class.getName(), DataObject.class, null)); + xml = new DataObject2String().transform(dataObject, context); + Assert.assertTrue(xml.contains("xsi:type=\"ipo:USAddress\"")); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..6a82a7fb18 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.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.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.xml.Node2String; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2Node; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.DataObject; +import commonj.sdo.helper.EqualityHelper; + +/** + * + * @version $Rev$ $Date$ + */ +public class DataObject2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl>(XMLStreamReader.class, XMLStreamReader.class); + } + + public final void testTransform() throws XMLStreamException { + XMLStreamReader reader = new DataObject2XMLStreamReader().transform(dataObject, context); + while (reader.hasNext()) { + int event = reader.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + break; + } + } + DataObject d = new XMLStreamReader2DataObject().transform(reader, reversedContext); + assertNotNull(d); + assertTrue(EqualityHelper.INSTANCE.equal(dataObject, d)); + } + + public final void testTransform1() throws XMLStreamException { + XMLStreamReader reader = new DataObject2XMLStreamReader().transform(dataObject, context); + XMLStreamReader2Node t2 = new XMLStreamReader2Node(); + org.w3c.dom.Node node = t2.transform(reader, context); + assertNotNull(node); + Node2String t3 = new Node2String(); + String xml = t3.transform(node, context); + assertTrue(xml.contains("xmlns:xsi")); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java new file mode 100644 index 0000000000..fa765f9bf4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +import com.example.ipo.sdo.SdoFactory; + +/** + * @version $Rev$ $Date$ + */ +public class ImportSDOProcessorTestCase extends TestCase { + private static boolean inited; + + private ImportSDOProcessor loader; + private XMLInputFactory xmlFactory; + + public void testMinimal() throws Exception { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.read(reader) instanceof ImportSDO); + } + + public void testLocation() throws Exception { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.read(reader) instanceof ImportSDO); + } + + public void testFactory() throws Exception { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertFalse(inited); + ImportSDO importSDO = loader.read(reader); + assertNotNull(importSDO); + ModelResolver resolver = new TestModelResolver(); + resolver.addModel(new ClassReference(MockFactory.class)); + loader.resolve(importSDO, resolver); + assertTrue(inited); + } + + @Override + protected void setUp() throws Exception { + loader = new ImportSDOProcessor(new DefaultModelFactoryExtensionPoint(), null); + xmlFactory = XMLInputFactory.newInstance(); + } + + protected XMLStreamReader getReader(String xml) throws XMLStreamException { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); + reader.next(); + return reader; + } + + public static class MockFactory { + public static final Object INSTANCE = SdoFactory.INSTANCE; + + static { + ImportSDOProcessorTestCase.inited = true; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java new file mode 100644 index 0000000000..e0d1c9bf12 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.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.sca.databinding.sdo; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import junit.framework.Assert; + +import org.apache.tuscany.sdo.api.SDOUtil; +import org.junit.Test; + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * @version $Rev$ $Date$ + */ +public class SDOContextHelperTestCase { + @Test + public void testGenerateSchema() throws IOException { + HelperContext context = SDOUtil.createHelperContext(); + URL url = getClass().getResource("/ipo.xsd"); + Assert.assertNotNull(url); + InputStream is = url.openStream(); + XSDHelper xsdHelper = context.getXSDHelper(); + xsdHelper.define(is, url.toExternalForm()); + TypeHelper typeHelper = context.getTypeHelper(); + Type type = typeHelper.getType("http://www.example.com/IPO", "PurchaseOrderType"); + Assert.assertNotNull(type); + /* + SDOContextHelper.generateSchema(context, Arrays.asList(type)); + */ + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java new file mode 100644 index 0000000000..3c21b56c9f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.impl.HelperProvider; + +/** + * + * @version $Rev$ $Date$ + */ +public class SDODataBindingTestCase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + private SDODataBinding binding; + private HelperContext context; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + binding = new SDODataBinding(); + context = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(context); + } + + public final void testIntrospect() { + Operation op = null; + DataType dataType = new DataTypeImpl(DataObject.class, null); + boolean yes = binding.introspect(dataType, op); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertTrue(dataType.getPhysical() == DataObject.class && dataType.getLogical() == XMLType.UNKNOWN); + dataType = new DataTypeImpl(PurchaseOrderType.class, null); + yes = binding.introspect(dataType, op); + assertTrue(yes); + assertEquals(PurchaseOrderType.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataTypeImpl(USAddress.class, null); + yes = binding.introspect(dataType, op); + assertTrue(yes); + assertEquals(USAddress.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USAddress"), ((XMLType)dataType.getLogical()) + .getTypeName()); + } + + public final void testCopyRoot() { + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + po.setComment("Comment"); + Object copy = binding.copy(po, null, null); + assertTrue(copy instanceof PurchaseOrderType); + assertTrue(po != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)po, (DataObject)copy)); + assertEquals("Comment", ((PurchaseOrderType)copy).getComment()); + } + + public final void testCopyNonRoot() { + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + Object copy = binding.copy(address, null, null); + assertTrue(copy instanceof USAddress); + assertTrue(address != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)address, (DataObject)copy)); + assertEquals("San Jose", ((USAddress)copy).getCity()); + } + + public final void testCopyXMLDocument() { + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + po.setComment("Comment"); + XMLDocument doc = + context.getXMLHelper().createDocument((DataObject)po, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + Object copy = binding.copy(doc, null, null); + assertTrue(copy instanceof XMLDocument); + XMLDocument docCopy = (XMLDocument)copy; + assertTrue(doc != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)po, docCopy.getRootObject())); + assertEquals("Comment", ((PurchaseOrderType)docCopy.getRootObject()).getComment()); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..2aaae3c6d8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.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.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.interfacedef.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * The base class for SDO-related test cases + * + * @version $Rev$ $Date$ + */ +public abstract class SDOTransformerTestCaseBase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + + protected HelperContext helperContext; + protected String binding = DataObject.class.getName(); + protected TransformationContext context; + protected TransformationContext reversedContext; + protected DataObject dataObject; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + helperContext = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(helperContext); + + context = new TransformationContextImpl(); + context.setSourceDataType(getSourceDataType()); + context.setTargetDataType(getTargetDataType()); + + reversedContext = new TransformationContextImpl(); + reversedContext.setSourceDataType(getTargetDataType()); + reversedContext.setTargetDataType(getSourceDataType()); + + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + address.setStreet("123 ABC St"); + address.setState("CA"); + address.setStreet("95131"); + po.setBillTo(address); + dataObject = (DataObject) po; + } + + protected abstract DataType getSourceDataType(); + + protected abstract DataType getTargetDataType(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java new file mode 100644 index 0000000000..805a1ab5ce --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.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.sca.databinding.sdo; + +import java.util.List; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; +import commonj.sdo.impl.HelperProvider; + +/** + * @version $Rev$ $Date$ + */ +public class SDOWrapperHandlerTestCase extends TestCase { + private HelperContext context; + private SDOWrapperHandler handler; + + @Override + public void setUp() throws Exception { + context = SDOUtil.createHelperContext(); + handler = new SDOWrapperHandler(); + } + + public void testWrapperAnyType() throws Exception { + XMLHelper xmlHelper = context.getXMLHelper(); + XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml")); + Operation op = new OperationImpl(); + List children = handler.getChildren(document, op, true); + assertEquals(5, children.size()); + } + + public void testWrapper() throws Exception { + XSDHelper xsdHelper = context.getXSDHelper(); + xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null); + XMLHelper xmlHelper = context.getXMLHelper(); + XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml")); + Operation op = new OperationImpl(); + List children = handler.getChildren(document, op, true); + assertEquals(5, children.size()); + } + + public void testCreate() { + HelperContext context = HelperProvider.getDefaultContext(); + XSDHelper xsdHelper = context.getXSDHelper(); + xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null); + ElementInfo element = new ElementInfo(new QName("http://www.example.com/wrapper", "op"), null); + Operation op = new OperationImpl(); + WrapperInfo wrapperInfo = new WrapperInfo(SDODataBinding.NAME, element, null); + op.setInputWrapper(wrapperInfo); + DataObject wrapper = (DataObject) handler.create(op, true); + assertNotNull(wrapper); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java new file mode 100644 index 0000000000..ce04f5be3f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.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.sca.databinding.sdo; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * A default implementation of an artifact resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class TestModelResolver implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map map = new HashMap(); + + public TestModelResolver() { + } + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + if (resolved != null) { + + // Return the resolved object + return modelClass.cast(resolved); + + } else { + + // Return the unresolved object + return unresolved; + } + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(resolved); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..114c568c38 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.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.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.helper.XMLDocument; + +/** + * + * @version $Rev$ $Date$ + */ +public class XMLDocument2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(XMLDocument.class.getName(), XMLDocument.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl>(XMLStreamReader.class, XMLStreamReader.class); + } + + public final void testTransform() throws XMLStreamException { + XMLDocument document = + helperContext.getXMLHelper().createDocument(dataObject, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + XMLStreamReader reader = new XMLDocument2XMLStreamReader().transform(document, context); + XMLDocument document2 = new XMLStreamReader2XMLDocument().transform(reader, reversedContext); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), document2.getRootElementURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), document2.getRootElementName()); + Assert.assertTrue(document2.getRootObject() instanceof PurchaseOrderType); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/stock.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/stock.xsd new file mode 100644 index 0000000000..a0a6717371 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/stock.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/wrapper.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/wrapper.xml new file mode 100644 index 0000000000..2526629409 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/wrapper.xml @@ -0,0 +1,27 @@ + + + + message + symbol + message1 + symbol1 + symbol2 + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/wrapper.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/wrapper.xsd new file mode 100644 index 0000000000..ea4dc5f7f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-sdo/src/test/resources/wrapper.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/LICENSE new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/LICENSE @@ -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, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/pom.xml new file mode 100644 index 0000000000..504cf501c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/pom.xml @@ -0,0 +1,125 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding-xmlbeans + Apache Tuscany SCA Data Binding for XmlBeans + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + org.apache.xmlbeans + xmlbeans + 2.3.0 + compile + + + junit + junit + 4.5 + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/xmlbeans-source + + + + + + + maven-antrun-plugin + + + + ant + ant-trax + 1.6.5 + + + + + + generate-xmlbeans + generate-sources + + + + + + + + run + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding.xmlbeans + ${pom.name} + org.apache.tuscany.sca.databinding.xmlbeans* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/Node2XmlObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/Node2XmlObject.java new file mode 100644 index 0000000000..e7b240b781 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/Node2XmlObject.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.sca.databinding.xmlbeans; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Node; + +/** + * Transforms a DOM Node to an XML Object. + * + * @version $Rev$ $Date$ + */ +public class Node2XmlObject extends BaseTransformer implements + PullTransformer { + // private XmlOptions options; + + public XmlObject transform(Node source, TransformationContext context) { + try { + return XmlObject.Factory.parse(source); + } catch (XmlException e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getTargetType() { + return XmlObject.class; + } + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + public int getWeight() { + return 30; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansDataBinding.java new file mode 100644 index 0000000000..15616979c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansDataBinding.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.sca.databinding.xmlbeans; + +import java.lang.reflect.Field; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.xmlbeans.SchemaType; +import org.apache.xmlbeans.XmlObject; +import org.osoa.sca.ServiceRuntimeException; + +/** + * XMLBeans DataBinding + * + * @version $Rev$ $Date$ + */ +public class XMLBeansDataBinding extends BaseDataBinding { + public static final String NAME = XmlObject.class.getName(); + public static final String[] ALIASES = {"xmlbeans"}; + + public XMLBeansDataBinding() { + super(NAME, XmlObject.class); + } + + @Override + public WrapperHandler getWrapperHandler() { + return new XMLBeansWrapperHandler(); + } + + @Override + public boolean introspect(DataType type, Operation operation) { + if (XmlObject.class.isAssignableFrom(type.getPhysical())) { + Class cls = type.getPhysical(); + SchemaType schemaType = null; + try { + Field f = cls.getField("type"); + schemaType = (SchemaType)f.get(null); + } catch (Throwable e) { + throw new ServiceRuntimeException(e); + } + QName typeName = schemaType.getName(); + Object logical = type.getLogical(); + QName elementName = null; + if (logical instanceof XMLType) { + elementName = ((XMLType)logical).getElementName(); + } + type.setLogical(new XMLType(elementName, typeName)); + type.setMetaData(SchemaType.class, schemaType); + return true; + } + return false; + } + + @Override + public Object copy(Object object, DataType dataType, Operation operation) { + return ((XmlObject)object).copy(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansWrapperHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansWrapperHandler.java new file mode 100644 index 0000000000..ccf48174e6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansWrapperHandler.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.xmlbeans; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.xmlbeans.SchemaProperty; +import org.apache.xmlbeans.SimpleValue; +import org.apache.xmlbeans.XmlObject; + +/** + * @version $Rev$ $Date$ + */ +public class XMLBeansWrapperHandler implements WrapperHandler { + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#create(org.apache.tuscany.sca.interfacedef.Operation, boolean) + */ + public XmlObject create(Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : + outputWrapperInfo.getWrapperElement(); + + return null; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getChildren(java.lang.Object, org.apache.tuscany.sca.interfacedef.Operation, boolean) + */ + public List getChildren(XmlObject wrapper, Operation operation, boolean input) { + List children = new ArrayList(); + + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + List childElements = input? inputWrapperInfo.getChildElements(): + outputWrapperInfo.getChildElements(); + + for (ElementInfo e : childElements) { + XmlObject[] objects = wrapper.selectChildren(e.getQName()); + if (objects != null && objects.length == 1) { + if (objects[0] instanceof SimpleValue) { + children.add(((SimpleValue)objects[0]).getObjectValue()); + } else { + children.add(objects[0]); + } + } + // FIXME: What should we do for many-value? + } + return children; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(org.apache.tuscany.sca.interfacedef.Operation, boolean) + */ + public DataType getWrapperType(Operation operation, boolean input) { + // TODO Auto-generated method stub + return null; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#isInstance(java.lang.Object, org.apache.tuscany.sca.interfacedef.Operation, boolean) + */ + public boolean isInstance(Object wrapper, Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : + outputWrapperInfo.getWrapperElement(); + + return true; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#setChildren(java.lang.Object, java.lang.Object[], org.apache.tuscany.sca.interfacedef.Operation, boolean) + */ + public void setChildren(XmlObject wrapper, Object[] childObjects, Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + + List childElements = input? inputWrapperInfo.getChildElements(): + outputWrapperInfo.getChildElements(); + + int i = 0; + for (ElementInfo c : childElements) { + SchemaProperty property = wrapper.schemaType().getElementProperty(c.getQName()); + + String prop = property.getJavaPropertyName(); + + Method setter; + try { + setter = wrapper.schemaType().getJavaClass().getMethod("set" + prop, property.getType().getJavaClass()); + setter.invoke(wrapper, childObjects[i++]); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLStreamReader2XmlObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLStreamReader2XmlObject.java new file mode 100644 index 0000000000..ca84f961b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLStreamReader2XmlObject.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.sca.databinding.xmlbeans; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.xmlbeans.XmlObject; + +/** + * Transforms an XMLStreamReader to an XML Object. + * + * @version $Rev$ $Date$ + */ +public class XMLStreamReader2XmlObject extends BaseTransformer implements PullTransformer { + // private XmlOptions options; + + public XmlObject transform(XMLStreamReader source, TransformationContext context) { + try { + XmlObject target = XmlObject.Factory.parse(source); + source.close(); + return target; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getTargetType() { + return XmlObject.class; + } + + @Override + protected Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2Node.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2Node.java new file mode 100644 index 0000000000..c820d9d250 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2Node.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.sca.databinding.xmlbeans; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.Transformer; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.xmlbeans.XmlObject; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Node; + +/** + * Transforms an XML Object to a DOM Node. + * + * @version $Rev$ $Date$ + */ +@Service(Transformer.class) +public class XmlObject2Node extends BaseTransformer implements + PullTransformer { + // private XmlOptions options; + + public Node transform(XmlObject source, TransformationContext context) { + if (source == null) + return null; + return source.newDomNode(); + } + + @Override + protected Class getSourceType() { + return XmlObject.class; + } + + @Override + protected Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 30; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2XMLStreamReader.java new file mode 100644 index 0000000000..bbffb7d748 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2XMLStreamReader.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.sca.databinding.xmlbeans; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.xmlbeans.XmlObject; + +/** + * Transforms an XML Object to an XMLStreamReader. + * + * @version $Rev$ $Date$ + */ +public class XmlObject2XMLStreamReader extends BaseTransformer implements PullTransformer { + // private XmlOptions options; + + public XMLStreamReader transform(XmlObject source, TransformationContext context) { + return source.newXMLStreamReader(); + } + + @Override + protected Class getSourceType() { + return XmlObject.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..ac76c6ca9b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# implementation classes for the databindings +org.apache.tuscany.sca.databinding.xmlbeans.XMLBeansDataBinding;name=org.apache.xmlbeans.XmlObject diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..4e419de051 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.xmlbeans.Node2XmlObject;source=org.w3c.dom.Node,target=org.apache.xmlbeans.XmlObject,weight=500 +org.apache.tuscany.sca.databinding.xmlbeans.XmlObject2Node;source=org.apache.xmlbeans.XmlObject,target=org.w3c.dom.Node,weight=500 +org.apache.tuscany.sca.databinding.xmlbeans.XmlObject2XMLStreamReader;source=org.apache.xmlbeans.XmlObject,target=javax.xml.stream.XMLStreamReader,weight=490 +org.apache.tuscany.sca.databinding.xmlbeans.XMLStreamReader2XmlObject;source=javax.xml.stream.XMLStreamReader,target=org.apache.xmlbeans.XmlObject,weight=490 diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObjectTestCase.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObjectTestCase.java new file mode 100644 index 0000000000..7b98ddb021 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObjectTestCase.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.sca.databinding.xmlbeans; + +import java.io.StringReader; + +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Node; + +import com.example.ipo.xmlbeans.PurchaseOrderDocument; + +/** + * Test cases for testing XML Object transformations. + * + * @version $Rev$ $Date$ + */ +public class XmlObjectTestCase extends TestCase { + private static final String IPO_XML = "" + "" + + " " + " Helen Zoe" + " 47 Eden Street" + + " Cambridge" + " CB1 1JR" + " " + " " + + " Robert Smith" + " 8 Oak Avenue" + " Old Town" + " PA" + + " 95819" + " " + " " + " " + + " Lapis necklace" + " 1" + " 99.95" + + " Want this for the holidays" + " 1999-12-05" + " " + " " + + ""; + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testXmlObject() throws Exception { + // URL/Stream/Reader to XmlObject + XmlObject object = XmlObject.Factory.parse(new StringReader(IPO_XML)); + + // XmlObject to XMLStreamReader + XmlObject2XMLStreamReader t1 = new XmlObject2XMLStreamReader(); + XMLStreamReader reader = t1.transform(object, null); + + // XMLStreamReader to XmlObject + XMLStreamReader2XmlObject t2 = new XMLStreamReader2XmlObject(); + XmlObject object2 = t2.transform(reader, null); + + // XmlObject to Node + XmlObject2Node t3 = new XmlObject2Node(); + Node node = t3.transform(object2, null); + + // Node to XmlObject + Node2XmlObject t4 = new Node2XmlObject(); + XmlObject object3 = t4.transform(node, null); + Assert.assertNotNull(object3); + } + + public void testGeneratedXmlObject() throws Exception { + // URL xmlFile = getClass().getClassLoader().getResource("ipo.xml"); + // URL/Stream/Reader to XmlObject + PurchaseOrderDocument object = PurchaseOrderDocument.Factory.parse(new StringReader(IPO_XML)); + + // XmlObject to XMLStreamReader + XmlObject2XMLStreamReader t1 = new XmlObject2XMLStreamReader(); + XMLStreamReader reader = t1.transform(object, null); + + // XMLStreamReader to XmlObject + XMLStreamReader2XmlObject t2 = new XMLStreamReader2XmlObject(); + PurchaseOrderDocument object2 = (PurchaseOrderDocument) t2.transform(reader, null); + + // XmlObject to Node + XmlObject2Node t3 = new XmlObject2Node(); + Node node = t3.transform(object2, null); + + // Node to XmlObject + Node2XmlObject t4 = new Node2XmlObject(); + PurchaseOrderDocument object3 = (PurchaseOrderDocument) t4.transform(node, null); + Assert.assertNotNull(object3); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5a493e1746 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/resources/ipo.xsdconfig b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/resources/ipo.xsdconfig new file mode 100755 index 0000000000..a397182672 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xmlbeans/src/test/resources/ipo.xsdconfig @@ -0,0 +1,21 @@ + + + + + com.example.ipo.xmlbeans + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/pom.xml new file mode 100644 index 0000000000..8469398b9a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/pom.xml @@ -0,0 +1,121 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding-xstream + Apache Tuscany SCA Data Binding for XStream + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.6-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 1.6-SNAPSHOT + + + + javax.xml.stream + stax-api + 1.0-2 + + + + com.thoughtworks.xstream + xstream + 1.3 + + + + org.apache.ws.commons.axiom + axiom-api + + + xerces + xercesImpl + + + 1.2.7 + + + + xerces + xercesImpl + 2.8.1 + runtime + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.7 + runtime + + + commons-logging + commons-logging + 1.1.1 + runtime + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding.xstream + ${pom.name} + org.apache.tuscany.sca.databinding.xstream* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObject.java new file mode 100644 index 0000000000..4c57cfe06b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObject.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.sca.databinding.xstream; + +/** + * Wrapper for XObject + * @version $Rev$ $Date$ + */ +public interface MetaObject { + void setName(String name); + + String getName(); + + Class getType(); + + String getID(); + + XObject getInstance(); + //byte[] getByteCode(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObjectImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObjectImpl.java new file mode 100644 index 0000000000..d223a4db23 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObjectImpl.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xstream; + +import java.io.FileNotFoundException; +import java.io.IOException; + +/** + * Implementation of a wrapper for XObject. + * + * @version $Rev$ $Date$ + */ +public class MetaObjectImpl implements MetaObject { + private String obID; + private String name; + private XObject obInstance; + + //private byte[] bytecode = null; + + public MetaObjectImpl() { + this.obID = Utils.uniqueID(); + } + + public MetaObjectImpl(XObject x) { + //this.name = path; + this.obID = Utils.uniqueID(); + this.obInstance = x; + + try { + initMetaOb(this.obInstance.getClass()); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void initMetaOb(Class class1) throws FileNotFoundException, IOException { + /* + File file = new File(cname); + DataInputStream cstream = new DataInputStream(new FileInputStream(file)); + bytecode = new byte[(int)file.length()]; + cstream.readFully(bytecode); + */ + name = class1.getName(); + + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getID() { + return obID; + } + + public Class getType() { + + return this.obInstance.getClass(); + } + + public XObject getInstance() { + return this.obInstance; + } + /* + * TODO Add bytecode with Serialization + public byte[] getByteCode() { + return bytecode; + } + */ + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Node2XObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Node2XObject.java new file mode 100644 index 0000000000..2b7fa9d506 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Node2XObject.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.sca.databinding.xstream; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.xml.DomReader; + +/** + * DOM Node --> XStream transformer + * + * @version $Rev$ $Date$ + */ +public class Node2XObject extends BaseTransformer implements PullTransformer { + + public XObject transform(Node source, TransformationContext context) { + try { + DomReader in = null; + if (source instanceof Document) { + in = new DomReader((Document)source); + } else if (source instanceof Element) { + in = new DomReader((Element)source); + } + XStream xs = new XStream(); + return (XObject)xs.unmarshal(in); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return Node.class; + } + + @Override + public Class getTargetType() { + return XObject.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/OMElement2XObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/OMElement2XObject.java new file mode 100644 index 0000000000..a465e92e65 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/OMElement2XObject.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.sca.databinding.xstream; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +import com.thoughtworks.xstream.XStream; + +/** + * Job DataObject --> AXIOM OMElement transformer + * + * @version $Rev$ $Date$ + */ +public class OMElement2XObject extends BaseTransformer implements + PullTransformer { + + public XObject transform(OMElement source, TransformationContext context) { + + XStream xs = new XStream(); + xs.alias("xobject", MetaObjectImpl.class); + MetaObjectImpl mo; + try { + java.io.StringWriter writer = new StringWriter(); + source.serialize(writer); + String w = writer.toString(); + // FIXME: a better way to get eliminate param0 + w = w.replaceAll("param0", "xobject"); + w = w.replaceAll("xmlns=\"\"", ""); + mo = (MetaObjectImpl)xs.fromXML(w.trim()); + return mo.getInstance(); + } catch (XMLStreamException e) { + + e.printStackTrace(); + } + return null; + } + + @Override + public Class getSourceType() { + return OMElement.class; + } + + @Override + public Class getTargetType() { + return XObject.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Utils.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Utils.java new file mode 100644 index 0000000000..d819975910 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Utils.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.sca.databinding.xstream; + +import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +/** + * Utility methods. + * + * @version $Rev$ $Date$ + */ +public class Utils { + public static String toBase64(byte[] array) { + String code = null; + code = new sun.misc.BASE64Encoder().encode(array); + return code; + } + + public static byte[] fromBase64(String bytecode) { + byte[] dec = null; + try { + dec = new sun.misc.BASE64Decoder().decodeBuffer(bytecode); + } catch (IOException e) { + e.printStackTrace(); + } + return dec; + } + + public static String uniqueID() { + try { + //Initialize SecureRandom + //This is a lengthy operation, to be done only upon + //initialization of the application + SecureRandom prng = SecureRandom.getInstance("SHA1PRNG"); + + //generate a random number + String randomNum = Integer.toString(prng.nextInt()); + + //get its digest + MessageDigest sha = MessageDigest.getInstance("SHA-1"); + byte[] result = sha.digest(randomNum.getBytes()); + return hexEncode(result); + } catch (NoSuchAlgorithmException ex) { + ex.printStackTrace(); + } + return null; + } + + private static String hexEncode(byte[] aInput) { + StringBuffer result = new StringBuffer(); + char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + for (int idx = 0; idx < aInput.length; ++idx) { + byte b = aInput[idx]; + result.append(digits[(b & 0xf0) >> 4]); + result.append(digits[b & 0x0f]); + } + return result.toString(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject.java new file mode 100644 index 0000000000..21112efcf5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject.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.sca.databinding.xstream; + +/** + * Marker interface for XStream Serializable objects + * + * @version $Rev$ $Date$ + */ +// FIXME: Why do we require a marker interface? +public interface XObject { +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2Node.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2Node.java new file mode 100644 index 0000000000..98e0e69f9b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2Node.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.sca.databinding.xstream; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.xml.DomWriter; + +/** + * XObject --> DOM Node transformer + * + * @version $Rev$ $Date$ + */ +public class XObject2Node extends BaseTransformer implements PullTransformer { + + public Node transform(XObject source, TransformationContext context) { + try { + MetaObject mj = new MetaObjectImpl(source); + Document root = DOMHelper.newDocument(); + DomWriter out = new DomWriter(DOMHelper.newDocument()); + XStream xs = new XStream(); + xs.alias("xobject", mj.getClass()); + xs.marshal(source, out); + DOMHelper.adjustElementName(context, root.getDocumentElement()); + return root; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return XObject.class; + } + + @Override + public Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2OMElement.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2OMElement.java new file mode 100644 index 0000000000..ff4305491a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2OMElement.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.sca.databinding.xstream; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.thoughtworks.xstream.XStream; + +/** + * XObject --> AXIOM OMElement transformer + * + * @version $Rev$ $Date$ + */ +public class XObject2OMElement extends BaseTransformer implements + PullTransformer { + + public OMElement transform(XObject source, TransformationContext context) { + MetaObject mj = new MetaObjectImpl(source); + OMElement element = null; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + XStream xs = new XStream(); + xs.alias("xobject", mj.getClass()); + xs.toXML(mj, out); + /* TODO: Maybe a base64 conversion...? or not? + * ie. new ByteArrayInputStream(Utils.toBase64(out.toByteArray()).getBytes()) + */ + try { + // what's better this one: + StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(out.toByteArray())); + // or this one: + // StaAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(Utils.toBase64(out.toByteArray()).getBytes())) + element = builder.getDocumentElement(); + adjustElementName(context, element); + } catch (Exception e) { + throw new TransformationException(e); + } + return element; + + } + + private static void adjustElementName(TransformationContext context, OMElement element) { + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType == null ? null : dataType.getLogical(); + if (!(logical instanceof XMLType)) { + return; + } + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement() && !xmlType.getElementName().equals(element.getQName())) { + // FIXME:: Throw exception or switch to the new Element? + OMFactory factory = OMAbstractFactory.getOMFactory(); + QName name = xmlType.getElementName(); + OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(name.getLocalPart()); + } + } + } + + @Override + public Class getSourceType() { + return XObject.class; + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.java new file mode 100644 index 0000000000..b319c7d557 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.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.sca.databinding.xstream; + +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; + +/** + * DataBinding for Jobs + * + * @version $Rev$ $Date$ + */ +public class XObjectDataBinding extends BaseDataBinding { + + public static final String NAME = XObject.class.getName(); + + public XObjectDataBinding() { + super(NAME, XObject.class); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..e2f467b8dd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# implementation classes for the databindings +org.apache.tuscany.sca.databinding.xstream.XObjectDataBinding;name=org.apache.tuscany.sca.databinding.xstream.XObject + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..a733ad7b7d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +org.apache.tuscany.sca.databinding.xstream.XObject2OMElement;source=org.apache.tuscany.sca.databinding.xstream.XObject,target=org.apache.axiom.om.OMElement,weight=10 +org.apache.tuscany.sca.databinding.xstream.OMElement2XObject;source=org.apache.axiom.om.OMElement,target=org.apache.tuscany.sca.databinding.xstream.XObject,weight=10 diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/ipo.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/ipo.xml new file mode 100644 index 0000000000..1699538d62 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/ipo.xml @@ -0,0 +1,48 @@ + + + + + + Helen Zoe + 47 Eden Street + Cambridge + CB1 1JR + + + + Robert Smith + 8 Oak Avenue + Old Town + PA + 95819 + + + + + Lapis necklace + 1 + 99.95 + Want this for the holidays + 1999-12-05 + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/ipo.xsd new file mode 100644 index 0000000000..aac7ded180 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/ipo.xsd @@ -0,0 +1,132 @@ + + + + + + + International Purchase order schema for Example.com Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/order.wsdl b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/order.wsdl new file mode 100644 index 0000000000..65da5b602a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding-xstream/src/test/resources/order.wsdl @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/LICENSE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/LICENSE new file mode 100644 index 0000000000..616bec99ed --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/LICENSE @@ -0,0 +1,244 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +----------------------------------------------------------------- +The test cases use xmlunit with the following license: +----------------------------------------------------------------- + +/* +****************************************************************** +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/NOTICE b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/pom.xml b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/pom.xml new file mode 100644 index 0000000000..16cc3e5cdd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/pom.xml @@ -0,0 +1,108 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.6-SNAPSHOT + ../pom.xml + + tuscany-databinding + Apache Tuscany SCA DataBinding Framework + + + + org.apache.tuscany.sca + tuscany-extensibility + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-xsd + 1.6-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.6-SNAPSHOT + + + + javax.xml.stream + stax-api + 1.0-2 + + + + org.codehaus.woodstox + wstx-asl + 3.2.4 + runtime + + + stax + stax-api + + + + + + xmlunit + xmlunit + 1.1 + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.databinding + ${pom.name} + org.apache.tuscany.sca.databinding* + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java new file mode 100644 index 0000000000..7c4ed35eb3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding; + + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * DataBinding represents a data representation, for example, SDO, JAXB and AXIOM + * + * @version $Rev$ $Date$ + */ +public interface DataBinding { + /** + * A special databinding for input message of an operation + */ + String IDL_INPUT = "idl:input"; + /** + * A special databinding for output message of an operation + */ + String IDL_OUTPUT = "idl:output"; + /** + * A special databinding for fault message of an operation + */ + String IDL_FAULT = "idl:fault"; + /** + * The name of a databinding should be case-insensitive and unique + * + * @return The name of the databinding + */ + String getName(); + + /** + * Introspect and populate information to a DataType model + * + * @param dataType The data type to be introspected + * @param operation The operation + * @return true if the databinding has recognized the given data type + */ + boolean introspect(DataType dataType, Operation operation); + + /** + * Introspect the data to figure out the corresponding data type + * + * @param value The object to be checked + * @param operation The operation + * @return The DataType or null if the java type is not supported by this databinding + */ + DataType introspect(Object value, Operation operation); + + /** + * 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 source object to copy + * @param dataType The data type + * @param operation The operation + * @return copy of the object passed in as argument + */ + Object copy(Object object, DataType dataType, Operation operation); + + /** + * Get the XML type helper for Java types + * @return The databinding-specific XML type helper class + */ + XMLTypeHelper getXMLTypeHelper(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java new file mode 100644 index 0000000000..2ff5d866b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.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.sca.databinding; + + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * An extension point for data binding extensions. + * + * @version $Rev$ $Date$ + */ +public interface DataBindingExtensionPoint { + + /** + * Register a data binding + * + * @param dataBinding + */ + void addDataBinding(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 removeDataBinding(String id); + + /** + * Introspect the java class to figure out what DataType supports it. + * + * @param dataType The initial data type + * @param operation TODO + * @return A DataType representing the java type or null if no databinding + * recognizes the java type + */ + boolean introspectType(DataType dataType, Operation operation); + + /** + * Introspect the value to figure out the corresponding DataType + * + * @param value The object value + * @param operation TODO + * @return A DataType representing the value or null if no databinding + * recognizes the value + */ + DataType introspectType(Object value, Operation operation); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java new file mode 100644 index 0000000000..505a810276 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.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.sca.databinding; + +/** + * Data pipe allows a data source pushes data into its sink and pipe the data into its result + * + * @param The data binding type of the sink + * @param The data binding type of the result + * + * @version $Rev$ $Date$ + */ +public interface DataPipe { + + /** + * 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 getResult(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.java new file mode 100644 index 0000000000..1aac6d48be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.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.sca.databinding; + +/** + * Data pipe allows a data source pushes data into its sink and pipe the data into its result + * + * @version $Rev$ $Date$ + */ +public interface DataPipeTransformer extends Transformer { + + DataPipe newInstance(); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java new file mode 100644 index 0000000000..e4dd96f68f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java @@ -0,0 +1,262 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.databinding.javabeans.JavaExceptionDataBinding; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * The default implementation of a data binding extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoint { + private ExtensionPointRegistry registry; + private final Map bindings = new HashMap(); + private final List databindings = new ArrayList(); + private static final Logger logger = Logger.getLogger(DefaultDataBindingExtensionPoint.class.getName()); + private boolean loadedDataBindings; + + public DefaultDataBindingExtensionPoint() { + } + + public DefaultDataBindingExtensionPoint(ExtensionPointRegistry registry) { + this.registry = registry; + } + + public DataBinding getDataBinding(String id) { + if (id == null) { + return null; + } + DataBinding dataBinding = bindings.get(id.toLowerCase()); + if (dataBinding == null) { + loadDataBindings(); + dataBinding = bindings.get(id.toLowerCase()); + } + return dataBinding; + } + + public void addDataBinding(DataBinding dataBinding) { + if (logger.isLoggable(Level.FINE)) { + String className = dataBinding.getClass().getName(); + boolean lazy = false; + if (dataBinding instanceof LazyDataBinding) { + className = ((LazyDataBinding)dataBinding).dataBindingDeclaration.getClassName(); + lazy = true; + } + logger.fine("Adding databinding: " + className + ";name=" + dataBinding.getName() + ",lazy=" + lazy); + } + databindings.add(dataBinding); + bindings.put(dataBinding.getName().toLowerCase(), dataBinding); + + } + + public DataBinding removeDataBinding(String id) { + if (id == null) { + return null; + } + DataBinding dataBinding = bindings.remove(id.toLowerCase()); + if (dataBinding != null) { + databindings.remove(dataBinding); + } + return dataBinding; + } + + /** + * Dynamically load data bindings declared under META-INF/services + */ + private synchronized void loadDataBindings() { + if (loadedDataBindings) + return; + + // Get the databinding service declarations + Set dataBindingDeclarations; + try { + dataBindingDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(DataBinding.class); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load data bindings + for (ServiceDeclaration dataBindingDeclaration : dataBindingDeclarations) { + Map attributes = dataBindingDeclaration.getAttributes(); + String name = attributes.get("name"); + + // Create a data binding wrapper and register it + DataBinding dataBinding = new LazyDataBinding(name, dataBindingDeclaration); + addDataBinding(dataBinding); + } + + loadedDataBindings = true; + } + + /** + * A data binding facade allowing data bindings to be lazily loaded and + * initialized. + */ + private class LazyDataBinding implements DataBinding { + + private String name; + private ServiceDeclaration dataBindingDeclaration; + private DataBinding dataBinding; + + private LazyDataBinding(String type, ServiceDeclaration dataBindingDeclaration) { + this.name = type; + this.dataBindingDeclaration = dataBindingDeclaration; + } + + /** + * Load and instantiate the data binding class. + * + * @return The data binding. + */ + @SuppressWarnings("unchecked") + private DataBinding getDataBinding() { + if (dataBinding == null) { + try { + Class dataBindingClass = (Class)dataBindingDeclaration.loadClass(); + try { + Constructor constructor = dataBindingClass.getConstructor(); + dataBinding = constructor.newInstance(); + } catch (NoSuchMethodException e) { + Constructor constructor = + dataBindingClass.getConstructor(ExtensionPointRegistry.class); + dataBinding = constructor.newInstance(DefaultDataBindingExtensionPoint.this.registry); + } + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return dataBinding; + } + + public Object copy(Object object, DataType dataType, Operation operation) { + return getDataBinding().copy(object, dataType, operation); + } + + public String getName() { + return name; + } + + public XMLTypeHelper getXMLTypeHelper() { + return getDataBinding().getXMLTypeHelper(); + } + + public WrapperHandler getWrapperHandler() { + return getDataBinding().getWrapperHandler(); + } + + public boolean introspect(DataType dataType, Operation operation) { + return getDataBinding().introspect(dataType, operation); + } + + public DataType introspect(Object value, Operation operation) { + return getDataBinding().introspect(value, operation); + } + } + + //FIXME The following methods should not be on the extension point + // they should be on a separate class + public boolean introspectType(DataType dataType, Operation operation) { + loadDataBindings(); + for (DataBinding binding : databindings) { + // don't introspect for JavaBeansDatabinding as all javatypes will + // anyways match to its basetype + // which is java.lang.Object. Default to this only if no databinding + // results + if (!binding.getName().equals(JavaBeansDataBinding.NAME)) { + if (binding.introspect(dataType, operation)) { + return true; + } + } + } + // FIXME: Should we honor the databinding from operation/interface + // level? + Class physical = dataType.getPhysical(); + if (physical == Object.class) { + dataType.setDataBinding(JavaBeansDataBinding.NAME); + return false; + } + if (dataType.getPhysical().isArray()) { + introspectArray(dataType, operation); + return true; + } else if (Throwable.class.isAssignableFrom(physical)) { + dataType.setDataBinding(JavaExceptionDataBinding.NAME); + return true; + } else { + dataType.setDataBinding(JavaBeansDataBinding.NAME); + return false; + } + } + + private boolean introspectArray(DataType dataType, Operation operation) { + Class physical = dataType.getPhysical(); + if (!physical.isArray() || physical == byte[].class) { + return false; + } + Class componentType = physical.getComponentType(); + Type genericComponentType = componentType; + + if(dataType.getGenericType() instanceof GenericArrayType) { + genericComponentType = ((GenericArrayType) dataType.getGenericType()).getGenericComponentType(); + } + DataType logical = new DataTypeImpl(dataType.getDataBinding(), componentType, genericComponentType, dataType.getLogical()); + introspectType(logical, operation); + dataType.setDataBinding("java:array"); + dataType.setLogical(logical); + return true; + } + + public DataType introspectType(Object value, Operation operation) { + loadDataBindings(); + DataType dataType = null; + for (DataBinding binding : databindings) { + // don't introspect for JavaBeansDatabinding as all javatypes will + // anyways match to its basetype + // which is java.lang.Object. Default to this only if no databinding + // results + if (!binding.getName().equals(JavaBeansDataBinding.NAME)) { + dataType = binding.introspect(value, operation); + } + if (dataType != null) { + return dataType; + } + } + return new DataTypeImpl(JavaBeansDataBinding.NAME, value.getClass(), XMLType.UNKNOWN); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java new file mode 100644 index 0000000000..e99dc2e029 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java @@ -0,0 +1,306 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.databinding.impl.DirectedGraph; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; + +/** + * @version $Rev$ $Date$ + */ +public class DefaultTransformerExtensionPoint implements TransformerExtensionPoint { + private static final Logger logger = Logger.getLogger(DefaultTransformerExtensionPoint.class.getName()); + private boolean loadedTransformers; + + private final DirectedGraph graph = new DirectedGraph(); + + public DefaultTransformerExtensionPoint() { + } + + public void addTransformer(String sourceType, String resultType, int weight, Transformer transformer, boolean publicTransformer) { + if (logger.isLoggable(Level.FINE)) { + String className = transformer.getClass().getName(); + boolean lazy = false; + boolean pull = (transformer instanceof PullTransformer); + if (transformer instanceof LazyPullTransformer) { + className = ((LazyPullTransformer)transformer).transformerDeclaration.getClassName(); + lazy = true; + } + if (transformer instanceof LazyPushTransformer) { + className = ((LazyPushTransformer)transformer).transformerDeclaration.getClassName(); + lazy = true; + } + + logger.fine("Adding transformer: " + className + + ";source=" + + sourceType + + ",target=" + + resultType + + ",weight=" + + weight + + ",type=" + + (pull ? "pull" : "push") + + ",lazy=" + + lazy); + } + graph.addEdge(sourceType, resultType, transformer, weight, publicTransformer); + } + + public void addTransformer(Transformer transformer, boolean publicTransformer) { + addTransformer(transformer.getSourceDataBinding(), + transformer.getTargetDataBinding(), + transformer.getWeight(), + transformer, publicTransformer); + } + + public boolean removeTransformer(String sourceType, String resultType) { + return graph.removeEdge(sourceType, resultType); + } + + public Transformer getTransformer(String sourceType, String resultType) { + loadTransformers(); + + DirectedGraph.Edge edge = graph.getEdge(sourceType, resultType); + return (edge == null) ? null : edge.getValue(); + } + + /** + * Dynamically load transformers registered under META-INF/services. + * + */ + private synchronized void loadTransformers() { + if (loadedTransformers) { + return; + } + loadedTransformers = true; + loadTransformers(PullTransformer.class); + loadTransformers(PushTransformer.class); + + } + + /** + * Dynamically load transformers registered under META-INF/services. + * + * @param transformerClass + */ + private synchronized void loadTransformers(Class transformerClass) { + + // Get the transformer service declarations + Set transformerDeclarations; + + try { + transformerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(transformerClass); + + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load transformers + for (ServiceDeclaration transformerDeclaration : transformerDeclarations) { + Map attributes = transformerDeclaration.getAttributes(); + + String source = attributes.get("source"); + String target = attributes.get("target"); + int weight = Integer.valueOf(attributes.get("weight")); + String b = attributes.get("public"); + boolean pub = true; + if (b != null) { + pub = Boolean.valueOf(b); + } + + // Create a transformer wrapper and register it + Transformer transformer; + if (transformerClass == PullTransformer.class) { + transformer = new LazyPullTransformer(source, target, weight, transformerDeclaration); + } else { + transformer = new LazyPushTransformer(source, target, weight, transformerDeclaration); + } + addTransformer(transformer, pub); + } + } + + /** + * A transformer facade allowing transformers to be lazily loaded + * and initialized. + */ + private static class LazyPullTransformer implements PullTransformer { + + private String source; + private String target; + private int weight; + private ServiceDeclaration transformerDeclaration; + private PullTransformer transformer; + + public LazyPullTransformer(String source, String target, int weight, ServiceDeclaration transformerDeclaration) { + this.source = source; + this.target = target; + this.weight = weight; + this.transformerDeclaration = transformerDeclaration; + } + + /** + * Load and instantiate the transformer class. + * + * @return The transformer. + */ + @SuppressWarnings("unchecked") + private PullTransformer getTransformer() { + if (transformer == null) { + try { + Class> transformerClass = + (Class>)transformerDeclaration.loadClass(); + Constructor> constructor = transformerClass.getConstructor(); + transformer = constructor.newInstance(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return transformer; + } + + public String getSourceDataBinding() { + return source; + } + + public String getTargetDataBinding() { + return target; + } + + public int getWeight() { + return weight; + } + + public Object transform(Object source, TransformationContext context) { + return getTransformer().transform(source, context); + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(super.toString()); + sb.append(";className=").append(transformerDeclaration.getClassName()); + return sb.toString(); + } + } + + /** + * A transformer facade allowing transformers to be lazily loaded + * and initialized. + */ + private static class LazyPushTransformer implements PushTransformer { + + private String source; + private String target; + private int weight; + private ServiceDeclaration transformerDeclaration; + private PushTransformer transformer; + + public LazyPushTransformer(String source, String target, int weight, ServiceDeclaration transformerDeclaration) { + this.source = source; + this.target = target; + this.weight = weight; + this.transformerDeclaration = transformerDeclaration; + } + + /** + * Load and instantiate the transformer class. + * + * @return The transformer. + */ + @SuppressWarnings("unchecked") + private PushTransformer getTransformer() { + if (transformer == null) { + try { + Class> transformerClass = + (Class>)transformerDeclaration.loadClass(); + Constructor> constructor = transformerClass.getConstructor(); + transformer = constructor.newInstance(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return transformer; + } + + public String getSourceDataBinding() { + return source; + } + + public String getTargetDataBinding() { + return target; + } + + public int getWeight() { + return weight; + } + + public void transform(Object source, Object sink, TransformationContext context) { + getTransformer().transform(source, sink, context); + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(super.toString()); + sb.append(";className=").append(transformerDeclaration.getClassName()); + return sb.toString(); + } + } + + //FIXME The following methods should be on a different class from + // extension point + + public List getTransformerChain(String sourceType, String resultType) { + loadTransformers(); + + String source = sourceType; + String result = resultType; + List transformers = new ArrayList(); + // First check if there is a direct path, if yes, use it regardless of the weight + DirectedGraph.Edge link = graph.getEdge(sourceType, resultType); + if (link != null) { + transformers.add(link.getValue()); + } else { + DirectedGraph.Path path = graph.getShortestPath(source, result); + if (path == null) { + return null; + } + for (DirectedGraph.Edge edge : path.getEdges()) { + transformers.add(edge.getValue()); + } + } + return transformers; + } + + @Override + public String toString() { + loadTransformers(); + + return graph.toString(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java new file mode 100644 index 0000000000..8184d739a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.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.sca.databinding; + +import java.util.Map; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * This interface will be used as a Tuscany system service to perform data mediations + * + * Mediate the data from one type to the other one + * + * @version $Rev$ $Date$ + */ +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 + * @return + */ + Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map 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 + */ + void mediate(Object source, + Object target, + DataType sourceDataType, + DataType targetDataType, + Map context); + + /** + * Transform the input parameters for the source operation to the expected parameters for + * the target operation + * @param input The input data, typically an array of parameters + * @param sourceOperation The source operation + * @param targetOperation The target operation + * @param metadata Additional metadata + * @return The transformed input data for the target operation + */ + Object mediateInput(Object input, Operation sourceOperation, Operation targetOperation, Map metadata); + + /** + * Transform the return value for the target operation to the expected return value for + * the source operation + * @param output The output data, typically the return value + * @param sourceOperation The source operation + * @param targetOperation The target operation + * @param metadata Additional metadata + * @return The transformed output data for the source operation + */ + Object mediateOutput(Object output, + Operation sourceOperation, + Operation targetOperation, + Map metadata); + + /** + * Transform the fault data for the target operation to the expected fault data for + * the source operation + * @param fault The fault data, such as Java exception or fault message + * @param sourceOperation The source operation + * @param targetOperation The target operation + * @param metadata Additional metadata + * @return The transformed fault data for the source operation + */ + Object mediateFault(Object fault, Operation sourceOperation, Operation targetOperation, Map metadata); + + /** + * Copy the data + * @param data The orginal data + * @param dataType The data type + * @return The copy + */ + Object copy(Object data, DataType dataType); + + /** + * Copy an array of data objects passed to an operation + * @param data array of objects to copy + * @return the copy + */ + public Object copyInput(Object input, Operation operation); + + /** + * Copy the output data + * @param data The orginal output + * @param operation The operation + * @return The copy + */ + Object copyOutput(Object data, Operation operation); + + /** + * Copy the fault data + * @param fault The orginal fault data + * @param operation The operation + * @return The copy + */ + Object copyFault(Object fault, Operation operation); + + /** + * Get the DataBindings used by this mediator. + * @return + */ + DataBindingExtensionPoint getDataBindings(); + + /** + * Get the Transformers used by this mediator. + * @return + */ + TransformerExtensionPoint getTransformers(); + + /** + * Create an instance of TransformationContext + * @return + */ + TransformationContext createTransformationContext(); + + /** + * Create an instance of TransformationContext + * @param sourceDataType + * @param targetDataType + * @param metadata + * @return + */ + TransformationContext createTransformationContext(DataType sourceDataType, + DataType targetDataType, + Map metadata); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java new file mode 100644 index 0000000000..81264923eb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.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.sca.databinding; + +/** + * PullTransformer transforms data from one binding format to the other one which can be directly consumed + * + * @param The source data type + * @param the target data type + * + * @version $Rev$ $Date$ + */ +public interface PullTransformer 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/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java new file mode 100644 index 0000000000..600a6477f6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.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.sca.databinding; + +/** + * A transformer that pushes data from its source into the sink + * + * @param + * @param + * + * @version $Rev$ $Date$ + */ +public interface PushTransformer 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/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java new file mode 100644 index 0000000000..4e6d130aa9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.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.sca.databinding; + +import javax.xml.namespace.QName; + +/** + * Type Mapper between XML schema simple data types and java objects + * + * @version $Rev$ $Date$ + */ +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(QName 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(QName simpleType, Object obj, TransformationContext context); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java new file mode 100644 index 0000000000..9ffadd1eae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +import java.util.Map; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * Context for data transformation + * + * @version $Rev$ $Date$ + */ +public interface TransformationContext { + + /** + * @return + */ + Operation getSourceOperation(); + + /** + * @param sourceOperation + */ + void setSourceOperation(Operation sourceOperation); + + /** + * @return + */ + Operation getTargetOperation(); + + /** + * @param targetOperation + */ + void setTargetOperation(Operation targetOperation); + + /** + * Get the source data type + * + * @return + */ + DataType getSourceDataType(); + + /** + * Get the target data type + * + * @return + */ + DataType getTargetDataType(); + + /** + * Set the source data type + * + * @param sourceDataType + */ + void setSourceDataType(DataType sourceDataType); + + /** + * Set the target data type + * + * @param targetDataType + */ + void setTargetDataType(DataType targetDataType); + + /** + * Get the ClassLoader + * + * @return Returns the ClassLoader + */ + ClassLoader getClassLoader(); + + /** + * Get a map of metadata + * + * @return Returns a map of the metadata + */ + Map getMetadata(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java new file mode 100644 index 0000000000..4f949f7dff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.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.sca.databinding; + + +/** + * Reports problems during data transformation + * + * @version $Rev$ $Date$ + */ +public class TransformationException extends RuntimeException { + + private static final long serialVersionUID = 7662385613693006428L; + private String sourceDataBinding; + private String targetDataBinding; + + public TransformationException() { + super(); + } + + public TransformationException(String message, Throwable cause) { + super(message, cause); + } + + public TransformationException(String message) { + super(message); + } + + public TransformationException(Throwable cause) { + super(cause); + } + + public String getSourceDataBinding() { + return sourceDataBinding; + } + + public void setSourceDataBinding(String sourceDataBinding) { + this.sourceDataBinding = sourceDataBinding; + } + + public String getTargetDataBinding() { + return targetDataBinding; + } + + public void setTargetDataBinding(String targetDataBinding) { + this.targetDataBinding = targetDataBinding; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java new file mode 100644 index 0000000000..2aa0ad7c15 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.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.sca.databinding; + +/** + * A transformer provides the data transformation from source type to target type. The cost of the transformation is + * modelled as weight. + * + * @version $Rev$ $Date$ + */ +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 identifying 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 identifying 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/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java new file mode 100644 index 0000000000..ee7efe4860 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +import java.util.List; + +/** + * An extension point for data transformer extensions. + * + * @version $Rev$ $Date$ + */ +public interface TransformerExtensionPoint { + + /** + * Register a transformer + * + * @param sourceDataBinding + * @param targetDataBinding + * @param weight + * @param transformer + * @param publicTransformer TODO + */ + void addTransformer(String sourceDataBinding, + String targetDataBinding, + int weight, + Transformer transformer, + boolean publicTransformer); + + /** + * Register a transformer + * + * @param transformer + * @param publicTransformer TODO + */ + void addTransformer(Transformer transformer, boolean publicTransformer); + + /** + * Unregister a transformer + * + * @param sourceDataBinding + * @param targetDataBinding + * @return + */ + boolean removeTransformer(String sourceDataBinding, String targetDataBinding); + + /** + * Get the direct Transformer which can transform data from source type to + * result type + * + * @param sourceDataBinding + * @param targetDataBinding + * @return + */ + 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 + */ + List getTransformerChain(String sourceDataBinding, String targetDataBinding); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java new file mode 100644 index 0000000000..a91410ed71 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.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.sca.databinding; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * A contract for transformers to deal with wrapping/unwrapping for WSDL wrapper style operations + * + * @version $Rev$ $Date$ + */ +public interface WrapperHandler { + /** + * Create a wrapper element + * @param operation The operation + * @param input Is it for input or output + * @return An object representing the wrapper element + */ + T create(Operation operation, boolean input); + + /** + * Get the data type for the wrapper + * @param operation The operation + * @param input Is it for input or output? + * @return The data type of the wrapper, null if it's not a wrapper type + */ + DataType getWrapperType(Operation operation, boolean input); + + /** + * Check if the given data is an instance of the wrapper + * @param wrapper + * @param operation The operation + * @param input Input or output + * @return + */ + boolean isInstance(Object wrapper, Operation operation, boolean input); + + /** + * Populate the wrapper element with the child objects + * @param wrapper The wrapper object + * @param childObjects The child objects + * @param operation The operation + * @param input Is it for input or output + */ + public void setChildren(T wrapper, + Object[] childObjects, + Operation operation, + boolean input); + + /** + * Get a list of child elements from the wrapper + * @param wrapper The wrapper object + * @param operation The operation + * @param input Is it for input or output + * @return child elements under the wrapper + */ + List getChildren(T wrapper, Operation operation, boolean input); +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/XMLTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/XMLTypeHelper.java new file mode 100644 index 0000000000..e940f8675f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/XMLTypeHelper.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding; + +import java.util.List; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.apache.tuscany.sca.xsd.XSDFactory; +import org.apache.tuscany.sca.xsd.XSDefinition; + +/** + * XML and schema helper for Java types + */ +public interface XMLTypeHelper { + + // FIXME: This method seems to require the XMLHelper instance to be stateful + /** + * Convert a Java type into XML type information + * @param javaType the physical Java class + * @param logical the logical type information + * @return the XML type information + */ + TypeInfo getTypeInfo(Class javaType, Object logical); + + /** + * Get schema definitions for the Java types known to this helper + * @return A list of schema definitions + */ + // List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver); + + /** + * Get a list of XML schemas for the given data types + * @param factory + * @param resolver + * @param dataTypes + * @return + */ + List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, List dataTypes); + /** + * Get a list of XML schemas for the given interface + * @param factory + * @param resolver + * @param intf + * @return + */ + List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, Interface intf); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java new file mode 100644 index 0000000000..4405077e29 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.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.sca.databinding.annotation; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Used to demarcate the mapping style for an interface or operation + * + * @version $Rev$ $Date$ + */ +// FIXME: [rfeng] We should consider to use javax.jws.soap.SOAPBinding +@Target({TYPE, METHOD}) +@Retention(RUNTIME) +public @interface DataBinding { + + /** + * Indicate the effective databinding that controls the WSDL/Java mapping of the + * interface/operation + * + * @return the data binding with the MIME media type syntax + */ + String value(); + + /** + * Indicate if the operation is mapped using WRAPPED or BARE style. Originated from + * javax.jws.soap.SOAPBinding.ParameterStyle: Determines whether method parameters + * represent the entire message body, or whether the parameters are elements wrapped + * inside a top-level element named after the operation + * + * @return true if the parameter style is WRAPPED, false if BARE + */ + boolean wrapped() default false; + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java new file mode 100644 index 0000000000..650e909c61 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.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.sca.databinding.annotation; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Used to demarcate expected data types for parameters and return type + * + * @version $Rev$ $Date$ + */ +@Target( {METHOD, PARAMETER}) +@Retention(RUNTIME) +public @interface DataType { + + /** + * Returns the data binding configuration in MIME media type syntax + * @return the data binding + */ + String value(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/externalizable/ExternalizableDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/externalizable/ExternalizableDataBinding.java new file mode 100644 index 0000000000..6f3456fdf0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/externalizable/ExternalizableDataBinding.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.sca.databinding.externalizable; + +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; + +/** + * DataNinding for Externalizable objects. + * + * @version $Rev$ $Date$ + */ +public class ExternalizableDataBinding extends BaseDataBinding { + + public static final String NAME = java.io.Externalizable.class.getName(); + + public ExternalizableDataBinding() { + super(NAME, java.io.Externalizable.class); + } + + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java new file mode 100644 index 0000000000..04c2f0e0c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Base Implementation of DataBinding + * + * @version $Rev$ $Date$ + */ +public abstract class BaseDataBinding implements DataBinding { + + private Class baseType; + + private 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 BaseDataBinding(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 BaseDataBinding(String name, Class baseType) { + this.name = name; + this.baseType = baseType; + } + + @SuppressWarnings("unchecked") + public boolean introspect(DataType type, Operation operation) { + assert type != null; + Class cls = type.getPhysical(); + if (baseType != null && baseType.isAssignableFrom(cls)) { + type.setDataBinding(getName()); + if (type.getLogical() == null) { + type.setLogical(XMLType.UNKNOWN); + } + return true; + } + return false; + } + + public DataType introspect(Object value, Operation operation) { + if (value == null) { + return null; + } else { + DataType dataType = new DataTypeImpl(value.getClass(), value.getClass()); + if (introspect(dataType, (Operation) null)) { + return dataType; + } else { + return null; + } + } + } + + public final String getName() { + return name; + } + + /** + * @see org.apache.tuscany.sca.databinding.DataBinding#getWrapperHandler() + */ + public WrapperHandler getWrapperHandler() { + return null; + } + + public Object copy(Object object, DataType dataType, Operation operation) { + return object; + } + + public XMLTypeHelper getXMLTypeHelper() { + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java new file mode 100644 index 0000000000..94a2cdb0bb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.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.sca.databinding.impl; + +import org.apache.tuscany.sca.databinding.Transformer; + +/** + * Base Implementation of Transformer which provides the registration to the + * transformer registry + * + * @version $Rev$ $Date$ + */ +public abstract class BaseTransformer implements Transformer { + + protected BaseTransformer() { + super(); + } + + 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/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java new file mode 100644 index 0000000000..64b3d22c10 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.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.sca.databinding.impl; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +/** + * Helper for DOM + * + * @version $Rev$ $Date$ + */ +public final class DOMHelper { + private static DocumentBuilderFactory FACTORY; + + private DOMHelper() { + } + + public static Document newDocument() throws ParserConfigurationException { + return newDocumentBuilder().newDocument(); + } + + public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { + init(); + return FACTORY.newDocumentBuilder(); + } + + /** + * + */ + private static synchronized void init() { + if (FACTORY == null) { + FACTORY = DocumentBuilderFactory.newInstance(); + FACTORY.setNamespaceAware(true); + } + } + + 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); + } + + /** + * Wrap an element as a DOM document + * @param node + * @return + */ + public static Document promote(Node node) { + if (node instanceof Document) { + return (Document)node; + } + Element element = (Element)node; + Document doc = element.getOwnerDocument(); + if (doc.getDocumentElement() == element) { + return doc; + } + doc = (Document)element.getOwnerDocument().cloneNode(false); + Element schema = (Element)doc.importNode(element, true); + doc.appendChild(schema); + Node parent = element.getParentNode(); + while (parent instanceof Element) { + Element root = (Element)parent; + NamedNodeMap nodeMap = root.getAttributes(); + for (int i = 0; i < nodeMap.getLength(); i++) { + Attr attr = (Attr)nodeMap.item(i); + String name = attr.getName(); + if ("xmlns".equals(name) || name.startsWith("xmlns:")) { + if (schema.getAttributeNode(name) == null) { + schema.setAttributeNodeNS((Attr)doc.importNode(attr, true)); + } + } + } + parent = parent.getParentNode(); + } + return doc; + } + + /** + * @param context + * @param element + */ + public static Element adjustElementName(TransformationContext context, Element element) { + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType == null ? null : dataType.getLogical(); + if (!(logical instanceof XMLType)) { + return element; + } + XMLType xmlType = (XMLType)logical; + QName name = new QName(element.getNamespaceURI(), element.getLocalName()); + if (xmlType.isElement() && !xmlType.getElementName().equals(name)) { + QName newName = xmlType.getElementName(); + String prefix = newName.getPrefix(); + String qname = newName.getLocalPart(); + if (prefix != null && !prefix.equals("")) { + qname = prefix + ":" + qname; + } + Document doc = element.getOwnerDocument(); + Element newElement = doc.createElementNS(newName.getNamespaceURI(), qname); + // Copy the attributes to the new element + NamedNodeMap attrs = element.getAttributes(); + for (int i = 0; i < attrs.getLength(); i++) { + Attr attr = (Attr)doc.importNode(attrs.item(i), true); + newElement.getAttributes().setNamedItem(attr); + } + + // Move all the children + while (element.hasChildNodes()) { + newElement.appendChild(element.getFirstChild()); + } + + // Replace the old node with the new node + if (element.getParentNode() != null) { + element.getParentNode().replaceChild(newElement, element); + } + + return newElement; + } + } + return element; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java new file mode 100644 index 0000000000..01916dfb96 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java @@ -0,0 +1,452 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Directed, weighted graph + * + * @param The type of vertex object + * @param The type of edge object + * + * @version $Rev$ $Date$ + */ +public class DirectedGraph implements Cloneable { + private final Map vertices = new HashMap(); + + /** + * Key for the shortest path cache + */ + private final class VertexPair { + private Vertex source; + + private Vertex target; + + /** + * @param source + * @param target + */ + private VertexPair(Vertex source, Vertex target) { + super(); + this.source = source; + this.target = target; + } + + @Override + public boolean equals(Object object) { + if (!VertexPair.class.isInstance(object)) { + return false; + } + VertexPair pair = (VertexPair)object; + return source == pair.source && target == pair.target; + } + + @Override + public int hashCode() { + int x = source == null ? 0 : source.hashCode(); + int y = target == null ? 0 : target.hashCode(); + return x ^ y; + } + + } + + // Fix for TUSCANY-2069, making the map concurrent + private final Map paths = new ConcurrentHashMap(); + private final Path NULL_PATH = new Path(); + + /** + * Vertex of a graph + */ + public final class Vertex { + private V value; + + // TODO: Do we want to support multiple edges for a vertex pair? If so, + // we should use a List instead of Map + private Map outEdges = new HashMap(); + private Map inEdges = new HashMap(); + + private Vertex(V value) { + this.value = value; + } + + @Override + public String toString() { + return "(" + value + ")"; + } + + public V getValue() { + return value; + } + + public Map getOutEdges() { + return outEdges; + } + + public Map getInEdges() { + return inEdges; + } + + } + + /** + * An Edge connects two vertices in one direction + */ + public final class Edge { + private Vertex sourceVertex; + + private Vertex targetVertex; + + private E value; + + private int weight; + + private boolean pub = true; + + public Edge(Vertex source, Vertex target, E value, int weight, boolean pub) { + this.sourceVertex = source; + this.targetVertex = target; + this.value = value; + this.weight = weight; + this.pub = pub; + } + + @Override + public String toString() { + return sourceVertex + "->" + targetVertex + "[" + value + "," + weight + "]"; + } + + public E getValue() { + return value; + } + + public void setValue(E value) { + this.value = value; + } + + public Vertex getTargetVertex() { + return targetVertex; + } + + public void setTargetVertex(Vertex vertex) { + this.targetVertex = vertex; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public Vertex getSourceVertex() { + return sourceVertex; + } + + public void setSourceVertex(Vertex sourceVertex) { + this.sourceVertex = sourceVertex; + } + + public boolean isPublic() { + return pub; + } + + public void setPublic(boolean pub) { + this.pub = pub; + } + } + + private final class Node implements Comparable { + + private long distance = Integer.MAX_VALUE; + + private Node previous; // NOPMD by rfeng on 9/26/06 9:17 PM + + private Vertex vertex; // NOPMD by rfeng on 9/26/06 9:17 PM + + private Node(Vertex vertex) { + this.vertex = vertex; + } + + public int compareTo(Node o) { + return (distance > o.distance) ? 1 : ((distance == o.distance) ? 0 : -1); + } + } + + public void addEdge(V source, V target, E edgeValue, int weight, boolean publicEdge) { + Vertex s = getVertex(source); + if (s == null) { + s = new Vertex(source); + vertices.put(source, s); + } + Vertex t = getVertex(target); + if (t == null) { + t = new Vertex(target); + vertices.put(target, t); + } + Edge edge = new Edge(s, t, edgeValue, weight, publicEdge); + s.outEdges.put(t, edge); + t.inEdges.put(s, edge); + } + + public void addEdge(V soure, V target) { + addEdge(soure, target, null, 0, true); + } + + public Vertex getVertex(V source) { + Vertex s = vertices.get(source); + return s; + } + + public boolean removeEdge(V source, V target) { + Vertex s = getVertex(source); + if (s == null) { + return false; + } + + Vertex t = getVertex(target); + if (t == null) { + return false; + } + + return s.outEdges.remove(t) != null && t.inEdges.remove(s) != null; + + } + + public void removeEdge(Edge edge) { + edge.sourceVertex.outEdges.remove(edge.targetVertex); + edge.targetVertex.inEdges.remove(edge.sourceVertex); + } + + public void removeVertex(Vertex vertex) { + vertices.remove(vertex.getValue()); + for (Edge e : new ArrayList(vertex.outEdges.values())) { + removeEdge(e); + } + for (Edge e : new ArrayList(vertex.inEdges.values())) { + removeEdge(e); + } + } + + public Edge getEdge(Vertex source, Vertex target) { + return source.outEdges.get(target); + } + + public Edge getEdge(V source, V target) { + Vertex sv = getVertex(source); + if (sv == null) { + return null; + } + Vertex tv = getVertex(target); + if (tv == null) { + return null; + } + return getEdge(getVertex(source), getVertex(target)); + } + + /** + * Get the shortest path from the source vertex to the target vertex using + * Dijkstra's algorithm. If there's no path, null will be returned. If the + * source is the same as the target, it returns a path with empty edges with + * weight 0. + * + * @param sourceValue The value identifies the source + * @param targetValue The value identifies the target + * @return The shortest path + */ + public Path getShortestPath(V sourceValue, V targetValue) { + Vertex source = getVertex(sourceValue); + if (source == null) { + return null; + } + Vertex target = getVertex(targetValue); + if (target == null) { + return null; + } + + VertexPair pair = new VertexPair(source, target); + Path path = null; + if (paths.containsKey(pair)) { + path = paths.get(pair); + return path == NULL_PATH? null: path; + } + + // Check if there is a direct link, if yes, use it instead + Edge direct = getEdge(source, target); + path = new Path(); + if (direct != null) { + path.addEdge(direct); + paths.put(pair, path); + return path; + } + + Map nodes = new HashMap(); + for (Vertex v : vertices.values()) { + Node node = new Node(v); + if (v == source) { + node.distance = 0; + } + nodes.put(v, node); + } + + Set otherNodes = new HashSet(nodes.values()); + Set nodesOnPath = new HashSet(); + Node nextNode = null; + while (!otherNodes.isEmpty()) { + nextNode = extractMin(otherNodes); + if (nextNode.vertex == target) { + path = getPath(nextNode); + paths.put(pair, path); // Cache it + return path == NULL_PATH? null: path; + } + nodesOnPath.add(nextNode); + for (Edge edge : nextNode.vertex.outEdges.values()) { + Node adjacentNode = nodes.get(edge.targetVertex); + // The private edge can only be used if the edge connects to the target directly + if (edge.isPublic() || edge.getTargetVertex() == target) { + if (nextNode.distance + edge.weight < adjacentNode.distance) { + adjacentNode.distance = nextNode.distance + edge.weight; + adjacentNode.previous = nextNode; + } + } + } + } + paths.put(pair, NULL_PATH); // Cache it + return null; + } + + /** + * Searches for the vertex u in the vertex set Q that has the least d[u] + * value. That vertex is removed from the set Q and returned to the user. + * + * @param nodes + * @return + */ + private Node extractMin(Set nodes) { + Node node = Collections.min(nodes); + nodes.remove(node); + return node; + } + + /** + * The path between two vertices + */ + public final class Path { + private List edges = new LinkedList(); + + private int weight; + + public int getWeight() { + return weight; + } + + public List getEdges() { + return edges; + } + + public void addEdge(Edge edge) { + edges.add(0, edge); + weight += edge.weight; + } + + @Override + public String toString() { + return edges + ", " + weight; + } + } + + private Path getPath(Node t) { + if (t.distance == Integer.MAX_VALUE) { + return NULL_PATH; + } + Path path = new Path(); + Node u = t; + while (u.previous != null) { + Edge edge = getEdge(u.previous.vertex, u.vertex); + path.addEdge(edge); + u = u.previous; + } + return path; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + for (Vertex v : vertices.values()) { + sb.append(v.outEdges.values()).append("\n"); + } + return sb.toString(); + } + + public Map getVertices() { + return vertices; + } + + public void addGraph(DirectedGraph otherGraph) { + for (Vertex v : otherGraph.vertices.values()) { + for (Edge e : v.outEdges.values()) { + addEdge(e.sourceVertex.value, e.targetVertex.value, e.value, e.weight, true); + } + } + } + + private Vertex getFirst() { + for (Vertex v : vertices.values()) { + if (v.inEdges.isEmpty()) { + return v; + } + } + if (!vertices.isEmpty()) { + throw new IllegalArgumentException("Circular ordering has been detected: " + toString()); + } else { + return null; + } + } + + public List topologicalSort(boolean readOnly) { + DirectedGraph graph = (!readOnly) ? this : (DirectedGraph)clone(); + List list = new ArrayList(); + while (true) { + Vertex v = graph.getFirst(); + if (v == null) { + break; + } + list.add(v.getValue()); + graph.removeVertex(v); + } + + return list; + } + + @Override + public Object clone() { + DirectedGraph copy = new DirectedGraph(); + copy.addGraph(this); + return copy; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java new file mode 100644 index 0000000000..cc7b40d06b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.impl; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * This is a special transformer to transform the output from one IDL to the + * other one + * + * @version $Rev$ $Date$ + */ +public class Group2GroupTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + + /** + * @param wrapperHandler + */ + public Group2GroupTransformer() { + super(); + } + + /** + * @param mediator the mediator to set + */ + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + @Override + public String getSourceDataBinding() { + return GroupDataBinding.NAME; + } + + @Override + public String getTargetDataBinding() { + return GroupDataBinding.NAME; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + @Override + public int getWeight() { + return 10; + } + + @SuppressWarnings("unchecked") + public Object transform(Object source, TransformationContext context) { + DataType sourceType = context.getSourceDataType(); + DataType targetType = context.getTargetDataType(); + + return mediator.mediate(source, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java new file mode 100644 index 0000000000..70efd6a5c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.impl; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * The base class for a special databinding which represents a group of other databindings + * + * @version $Rev$ $Date$ + */ +public abstract class GroupDataBinding extends BaseDataBinding { + public static final String NAME = "databinding:group"; + + /** + * Marker type is a java class or interface representing the data format. + */ + protected Class[] markerTypes; + + public GroupDataBinding(Class[] types) { + super(NAME, GroupDataBinding.class); + this.markerTypes = types; + } + + @SuppressWarnings("unchecked") + @Override + public boolean introspect(DataType type, Operation operation) { + if (markerTypes == null) { + return false; + } + Type physical = type.getPhysical(); + if (physical instanceof ParameterizedType) { + physical = ((ParameterizedType)physical).getRawType(); + } + if (!(physical instanceof Class)) { + return false; + } + Class cls = (Class)physical; + for (Class c : markerTypes) { + if (isTypeOf(c, cls)) { + type.setDataBinding(getDataBinding(c)); + Object logical = getLogical(cls, null); + if (logical != null) { + type.setLogical(getLogical(cls, null)); + } else { + type.setLogical(XMLType.UNKNOWN); + } + return true; + } + } + return false; + } + + /** + * Test if the given type is a subtype of the base type + * @param markerType + * @param type + * @return + */ + protected boolean isTypeOf(Class markerType, Class type) { + return markerType.isAssignableFrom(type); + } + + /** + * Derive the databinding name from a base class + * @param baseType + * @return + */ + protected String getDataBinding(Class baseType) { + return baseType.getName(); + } + + /** + * Get the logical type + * @param type The java type + * @param operation TODO + * @return + */ + protected abstract Object getLogical(Class type, Operation operation); + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java new file mode 100644 index 0000000000..45896ca6a1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.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.sca.databinding.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Transformer to convert data from a simple java object to a databinding's representation + * + * @version $Rev$ $Date$ + */ +public abstract class Java2SimpleTypeTransformer extends BaseTransformer implements + PullTransformer { + + protected SimpleTypeMapper mapper; + + public Java2SimpleTypeTransformer() { + this.mapper = new SimpleTypeMapperImpl(); + } + + public Java2SimpleTypeTransformer(SimpleTypeMapper mapper) { + this.mapper = (mapper != null) ? mapper : new SimpleTypeMapperImpl(); + } + + public T transform(Object source, TransformationContext context) { + XMLType xmlType = (XMLType) context.getTargetDataType().getLogical(); + String text = mapper.toXMLLiteral(xmlType.getTypeName(), source, context); + return createElement(xmlType.getElementName(), text, context); + } + + @Override + public Class getSourceType() { + return Object.class; + } + + @Override + public int getWeight() { + return 10000; + } + + protected abstract T createElement(QName element, String literal, TransformationContext context); + + @Override + public String getSourceDataBinding() { + return SimpleJavaDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java new file mode 100644 index 0000000000..1fee253963 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java @@ -0,0 +1,587 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import static org.apache.tuscany.sca.databinding.DataBinding.IDL_FAULT; +import static org.apache.tuscany.sca.databinding.DataBinding.IDL_OUTPUT; + +import java.io.Serializable; +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.DataPipe; +import org.apache.tuscany.sca.databinding.DataPipeTransformer; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.Transformer; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Default Mediator implementation + * + * @version $Rev$ $Date$ + */ +public class MediatorImpl implements Mediator { + private static final String TARGET_OPERATION = "target.operation"; + private static final String SOURCE_OPERATION = "source.operation"; + private ExtensionPointRegistry registry; + private DataBindingExtensionPoint dataBindings; + private TransformerExtensionPoint transformers; + private FaultExceptionMapper faultExceptionMapper; + + MediatorImpl(DataBindingExtensionPoint dataBindings, TransformerExtensionPoint transformers) { + this.dataBindings = dataBindings; + this.transformers = transformers; + } + + public MediatorImpl(ExtensionPointRegistry registry) { + this.registry = registry; + this.dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + this.transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + this.faultExceptionMapper = + registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(FaultExceptionMapper.class); + + } + + @SuppressWarnings("unchecked") + public Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map metadata) { + if (sourceDataType == null || sourceDataType.getDataBinding() == null) { + if (source != null) { + Operation operation = (Operation)metadata.get(SOURCE_OPERATION); + sourceDataType = dataBindings.introspectType(source, operation); + } + } + if (sourceDataType == null || targetDataType == null) { + return source; + } else if (sourceDataType.equals(targetDataType)) { + return source; + } + + List path = getTransformerChain(sourceDataType, targetDataType); + + Object result = source; + int size = path.size(); + int i = 0; + while (i < size) { + Transformer transformer = path.get(i); + TransformationContext context = + createTransformationContext(sourceDataType, targetDataType, size, i, transformer, metadata); + // the source and target type + if (transformer instanceof PullTransformer) { + // For intermediate node, set data type to null + result = ((PullTransformer)transformer).transform(result, context); + } else if (transformer instanceof PushTransformer) { + DataPipeTransformer dataPipeFactory = (i < size - 1) ? (DataPipeTransformer)path.get(++i) : null; + DataPipe dataPipe = dataPipeFactory == null ? null : dataPipeFactory.newInstance(); + ((PushTransformer)transformer).transform(result, dataPipe.getSink(), context); + result = dataPipe.getResult(); + } + i++; + } + + return result; + } + + private TransformationContext createTransformationContext(DataType sourceDataType, + DataType targetDataType, + int size, + int index, + Transformer transformer, + Map metadata) { + DataType sourceType = + (index == 0) ? sourceDataType : new DataTypeImpl(transformer.getSourceDataBinding(), Object.class, + sourceDataType.getLogical()); + DataType targetType = + (index == size - 1) ? targetDataType : new DataTypeImpl(transformer.getTargetDataBinding(), + Object.class, targetDataType.getLogical()); + + //FIXME The ClassLoader should be passed in + // Allow privileged access to get ClassLoader. Requires RuntimePermission in security + // policy. + ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction() { + public ClassLoader run() { + return Thread.currentThread().getContextClassLoader(); + } + }); + + Map copy = new HashMap(); + if (metadata != null) { + copy.putAll(metadata); + } + copy.put(ExtensionPointRegistry.class.getName(), registry); + + TransformationContext context = new TransformationContextImpl(sourceType, targetType, classLoader, copy); + return context; + } + + @SuppressWarnings("unchecked") + public void mediate(Object source, + Object target, + DataType sourceDataType, + DataType targetDataType, + Map metadata) { + if (source == null) { + // Shortcut for null value + return; + } + if (sourceDataType == null || sourceDataType.getDataBinding() == null) { + Operation operation = (Operation)metadata.get(SOURCE_OPERATION); + sourceDataType = dataBindings.introspectType(source, operation); + } + if (sourceDataType == null) { + return; + } else if (sourceDataType.equals(targetDataType)) { + return; + } + + List path = getTransformerChain(sourceDataType, targetDataType); + Object result = source; + int size = path.size(); + for (int i = 0; i < size; i++) { + Transformer transformer = path.get(i); + TransformationContext context = + createTransformationContext(sourceDataType, targetDataType, size, i, transformer, metadata); + + if (transformer instanceof PullTransformer) { + result = ((PullTransformer)transformer).transform(result, context); + } else if (transformer instanceof PushTransformer) { + DataPipeTransformer dataPipeFactory = (i < size - 1) ? (DataPipeTransformer)path.get(++i) : null; + DataPipe dataPipe = dataPipeFactory == null ? null : dataPipeFactory.newInstance(); + Object sink = dataPipe != null ? dataPipe.getSink() : target; + ((PushTransformer)transformer).transform(result, sink, context); + result = (dataPipe != null) ? dataPipe.getResult() : null; + } + } + } + + private List getTransformerChain(DataType sourceDataType, DataType targetDataType) { + String sourceId = sourceDataType.getDataBinding(); + String targetId = targetDataType.getDataBinding(); + List path = transformers.getTransformerChain(sourceId, targetId); + if (path == null) { + TransformationException ex = + new TransformationException("No path found for the transformation: " + sourceId + "->" + targetId); + ex.setSourceDataBinding(sourceId); + ex.setTargetDataBinding(targetId); + throw ex; + } + return path; + } + + public DataBindingExtensionPoint getDataBindings() { + return dataBindings; + } + + public TransformerExtensionPoint getTransformers() { + return transformers; + } + + private DataType getFaultType(DataType exceptionType) { + return exceptionType == null ? null : (DataType)exceptionType.getLogical(); + } + + /** + * @param qn1 + * @param qn2 + */ + private boolean matches(QName qn1, QName qn2) { + if (qn1 == qn2) { + return true; + } + if (qn1 == null || qn2 == null) { + return false; + } + String ns1 = qn1.getNamespaceURI(); + String ns2 = qn2.getNamespaceURI(); + String e1 = qn1.getLocalPart(); + String e2 = qn2.getLocalPart(); + if (e1.equals(e2) && (ns1.equals(ns2) || ns1.equals(ns2 + "/") || ns2.equals(ns1 + "/"))) { + // Tolerating the trailing / which is required by JAX-WS java package --> xml ns mapping + return true; + } + return false; + } + + /** + * @param source The source exception + * @param sourceExType The data type for the source exception + * @param targetExType The data type for the target exception + * @param sourceType The fault type for the source + * @param targetType The fault type for the target + * @return + */ + private Object transformException(Object source, + DataType sourceExType, + DataType targetExType, + DataType sourceType, + DataType targetType, + Map metadata) { + + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return source; + } + + DataType eSourceDataType = + new DataTypeImpl(IDL_FAULT, sourceExType.getPhysical(), sourceType); + DataType eTargetDataType = + new DataTypeImpl(IDL_FAULT, targetExType.getPhysical(), targetType); + + return mediate(source, eSourceDataType, eTargetDataType, metadata); + } + + // + // Assumes we're going from target->source, knowing that we're throwing BACK an exception, rather than the more + // obvious source->target + // + public Object mediateFault(Object result, + Operation sourceOperation, + Operation targetOperation, + Map metadata) { + + // FIXME: How to match fault data to a fault type for the + // operation? + + // If the result is from an InvocationTargetException look at + // the actual cause. + if (result instanceof InvocationTargetException) { + result = ((InvocationTargetException)result).getCause(); + } + DataType targetDataType = null; + for (DataType exType : targetOperation.getFaultTypes()) { + if (((Class)exType.getPhysical()).isInstance(result)) { + if (result instanceof FaultException) { + DataType faultType = (DataType)exType.getLogical(); + if (((FaultException)result).isMatchingType(faultType.getLogical())) { + targetDataType = exType; + break; + } + } else { + targetDataType = exType; + break; + } + } + } + + /* + if (targetDataType == null) { + // Not a business exception + return resultMsg; + } + */ + + DataType targetFaultType = getFaultType(targetDataType); + if (targetFaultType == null) { + // No matching fault type, it's a system exception + Throwable cause = (Throwable)result; + throw new ServiceRuntimeException(cause); + } + + // FIXME: How to match a source fault type to a target fault + // type? + DataType sourceDataType = null; + DataType sourceFaultType = null; + for (DataType exType : sourceOperation.getFaultTypes()) { + DataType faultType = getFaultType(exType); + // Match by the QName (XSD element) of the fault type + if (faultType != null && typesMatch(targetFaultType.getLogical(), faultType.getLogical())) { + sourceDataType = exType; + sourceFaultType = faultType; + break; + } + } + + if (sourceFaultType == null) { + // No matching fault type, it's a system exception + Throwable cause = (Throwable)result; + throw new ServiceRuntimeException(cause); + } + + Map context = new HashMap(); + if (metadata != null) { + context.putAll(metadata); + } + if (targetOperation != null) { + context.put(SOURCE_OPERATION, targetOperation); + } + if (sourceOperation != null) { + context.put(TARGET_OPERATION, sourceOperation); + } + + Object newResult = + transformException(result, targetDataType, sourceDataType, targetFaultType, sourceFaultType, context); + + return newResult; + + } + + private boolean typesMatch(Object first, Object second) { + if (first.equals(second)) { + return true; + } + if (first instanceof XMLType && second instanceof XMLType) { + XMLType t1 = (XMLType)first; + XMLType t2 = (XMLType)second; + // TUSCANY-2113, we should compare element names only + return matches(t1.getElementName(), t2.getElementName()); + } + return false; + } + + /** + * Assumes we're going from target-to-source, knowing that we're sending BACK an output response, rather than the more + * obvious source-to-target. + * + * @param output + * @param sourceOperation + * @param targetOperation + * @return + */ + public Object mediateOutput(Object output, + Operation sourceOperation, + Operation targetOperation, + Map metadata) { + // Create a data type to represent the ouput produced by the target operation + DataType targetType = + new DataTypeImpl(IDL_OUTPUT, Object.class, targetOperation.getOutputType()); + + // Create a data type to represent the ouput expected by the source operation + DataType sourceType = + new DataTypeImpl(IDL_OUTPUT, Object.class, sourceOperation.getOutputType()); + + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return output; + } + Map context = new HashMap(); + if (metadata != null) { + context.putAll(metadata); + } + if (targetOperation != null) { + context.put(SOURCE_OPERATION, targetOperation); + } + if (sourceOperation != null) { + context.put(TARGET_OPERATION, sourceOperation); + } + return mediate(output, targetType, sourceType, context); + } + + public Object mediateInput(Object input, + Operation sourceOperation, + Operation targetOperation, + Map metadata) { + // Get the data type to represent the input passed in by the source operation + DataType sourceType = sourceOperation.getInputType(); + + // Get the data type to represent the input expected by the target operation + DataType targetType = targetOperation.getInputType(); + + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return input; + } + Map context = new HashMap(); + if (metadata != null) { + context.putAll(metadata); + } + if (sourceOperation != null) { + context.put(SOURCE_OPERATION, sourceOperation); + } + if (targetOperation != null) { + context.put(TARGET_OPERATION, targetOperation); + } + return mediate(input, sourceType, targetType, context); + } + + public TransformationContext createTransformationContext() { + return new TransformationContextImpl(); + } + + public TransformationContext createTransformationContext(DataType sourceDataType, + DataType targetDataType, + Map metadata) { + return new TransformationContextImpl(sourceDataType, targetDataType, metadata); + } + + public Object copy(Object data, DataType dataType) { + return copy(data, dataType, null); + } + + /** + * Copy data using the specified databinding. + * @param data input data + * @param dataType + * @return a copy of the data + */ + private Object copy(Object data, DataType dataType, Operation operation) { + if (data == null) { + return null; + } + Class clazz = data.getClass(); + if (String.class == clazz || clazz.isPrimitive() + || Number.class.isAssignableFrom(clazz) + || Boolean.class.isAssignableFrom(clazz) + || Character.class.isAssignableFrom(clazz) + || Byte.class.isAssignableFrom(clazz) + || URI.class == clazz + || UUID.class == clazz + || QName.class == clazz) { + // Immutable classes + return data; + } + + DataBinding javaBeansDataBinding = dataBindings.getDataBinding(JavaBeansDataBinding.NAME); + // FIXME: The JAXB databinding is hard-coded here + DataBinding jaxbDataBinding = dataBindings.getDataBinding("javax.xml.bind.JAXBElement"); + DataBinding dataBinding = dataBindings.getDataBinding(dataType.getDataBinding()); + // If no databinding was specified, introspect the given arg to + // determine its databinding + if (dataBinding == null) { + if(! "java:array".equals(dataType.getDataBinding())) { + dataType = dataBindings.introspectType(data, operation); + if (dataType != null) { + String db = dataType.getDataBinding(); + dataBinding = dataBindings.getDataBinding(db); + if (dataBinding == null && db != null) { + return data; + } + } + } + if (dataBinding == null) { + + // Default to the JavaBean databinding + dataBinding = dataBindings.getDataBinding(JavaBeansDataBinding.NAME); + } + } + + // Use the JAXB databinding to copy non-Serializable data + if (dataBinding == javaBeansDataBinding) { + + // If the input data is an array containing non Serializable elements + // use JAXB + clazz = data.getClass(); + if (clazz.isArray()) { + if (Array.getLength(data) != 0) { + Object element = Array.get(data, 0); + if (element != null && !(element instanceof Serializable)) { + dataBinding = jaxbDataBinding; + } + } + } else { + + // If the input data is not Serializable use JAXB + if (!((data instanceof Serializable) || (data instanceof Cloneable))) { + dataBinding = jaxbDataBinding; + } + } + } + + if (dataBinding != null) { + return dataBinding.copy(data, dataType, operation); + } else { + return data; + } + } + + /** + * Copy an array of data objects passed to an operation + * @param data array of objects to copy + * @return the copy + */ + public Object copyInput(Object input, Operation operation) { + if (input == null) { + return null; + } + Object[] data = (input instanceof Object[]) ? (Object[])input : new Object[] {input}; + List inputTypes = operation.getInputType().getLogical(); + Object[] copy = new Object[data.length]; + Map map = new IdentityHashMap(); + for (int i = 0, size = inputTypes.size(); i < size; i++) { + Object arg = data[i]; + if (arg == null) { + copy[i] = null; + } else { + Object copiedArg = map.get(arg); + if (copiedArg != null) { + copy[i] = copiedArg; + } else { + copiedArg = copy(arg, inputTypes.get(i)); + map.put(arg, copiedArg); + copy[i] = copiedArg; + } + } + } + return copy; + } + + public Object copyOutput(Object data, Operation operation) { + return copy(data, operation.getOutputType(), operation); + } + + public Object copyFault(Object fault, Operation operation) { + if (faultExceptionMapper == null) { + // try to get the fault exception mapper again. It sometime null depending on what order the + // JavaRuntimeModuleActivator and DatabindingModuleActivator are started + this.faultExceptionMapper = + registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(FaultExceptionMapper.class); + + if (faultExceptionMapper == null) { + return fault; + } + } + for (DataType et : operation.getFaultTypes()) { + if (et.getPhysical().isInstance(fault)) { + Throwable ex = (Throwable)fault; + DataType exType = + new DataTypeImpl(ex.getClass(), new DataTypeImpl(ex.getClass(), XMLType.UNKNOWN)); + faultExceptionMapper.introspectFaultDataType(exType, operation, false); + DataType faultType = exType.getLogical(); + Object faultInfo = faultExceptionMapper.getFaultInfo(ex, faultType.getPhysical(), operation); + faultInfo = copy(faultInfo, faultType); + fault = + faultExceptionMapper.wrapFaultInfo(exType, ex.getMessage(), faultInfo, ex.getCause(), operation); + return fault; + } + } + return fault; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java new file mode 100644 index 0000000000..a1a89005b3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.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.sca.databinding.impl; + +import org.apache.tuscany.sca.databinding.DataPipe; +import org.apache.tuscany.sca.databinding.DataPipeTransformer; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; + +/** + * A utility class to connect PushTransformer and DataPipe to create a + * PullTransformer + * + * @param Source type + * @param Intermediate type + * @param Result type + * + * @version $Rev$ $Date$ + */ +public class PipedTransformer implements PullTransformer { + private PushTransformer pusher; + + private DataPipeTransformer pipe; + + /** + * @param pumper + * @param pipe + */ + public PipedTransformer(PushTransformer pumper, DataPipeTransformer pipe) { + super(); + this.pusher = pumper; + this.pipe = pipe; + } + + public R transform(S source, TransformationContext context) { + DataPipe dataPipe = pipe.newInstance(); + pusher.transform(source, dataPipe.getSink(), context); + return dataPipe.getResult(); + } + + public String getSourceDataBinding() { + return pusher.getSourceDataBinding(); + } + + public String getTargetDataBinding() { + return pipe.getTargetDataBinding(); + } + + public int getWeight() { + return pusher.getWeight() + pipe.getWeight(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java new file mode 100644 index 0000000000..c91176fc2c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Transformer to convert data from a databinding's representation of simple + * types to Java Objects + * + * @version $Rev$ $Date$ + */ +public abstract class SimpleType2JavaTransformer extends BaseTransformer implements + PullTransformer { + + protected SimpleTypeMapper mapper; + + public SimpleType2JavaTransformer() { + this.mapper = new SimpleTypeMapperImpl(); + } + + public SimpleType2JavaTransformer(SimpleTypeMapper mapper) { + this.mapper = (mapper != null) ? mapper : new SimpleTypeMapperImpl(); + } + + public Object transform(T source, TransformationContext context) { + XMLType xmlType = (XMLType)context.getSourceDataType().getLogical(); + QName type = (xmlType != null) ? xmlType.getTypeName() : null; + if (type == null) { + xmlType = (XMLType)context.getTargetDataType().getLogical(); + type = (xmlType != null) ? xmlType.getTypeName() : null; + } + Object result = mapper.toJavaObject(type, getText(source), context); + close(source); + return result; + } + + @Override + protected Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + // Cannot be used for intermediate + return 10000; + } + + /** + * Get the string value from the source + * @param source + * @return A string + */ + protected abstract String getText(T source); + + /** + * To be overrided by the subclass + * @param source + */ + protected void close(T source) { + } + + @Override + public String getTargetDataBinding() { + return SimpleJavaDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java new file mode 100644 index 0000000000..32a2313f59 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java @@ -0,0 +1,401 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.impl; + +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.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; + +/** + * Simple type mapper that maps from XSD types to Java Classes and Java Classes to XSD types. + * + * @version $Rev$ $Date$ + */ +public class SimpleTypeMapperImpl extends XSDDataTypeConverter implements SimpleTypeMapper { + + public static final Map JAVA2XML = new HashMap(); + + public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; + + public static final Map XML2JAVA = new HashMap(); + + 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 XSD_SIMPLE_TYPES = new HashMap(); + + 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 DatatypeFactory factory; + + public SimpleTypeMapperImpl() { + super(); + try { + this.factory = DatatypeFactory.newInstance(); + } catch (DatatypeConfigurationException e) { + throw new IllegalArgumentException(e); + } + } + + public static Class getJavaType(QName xmlType) { + if (xmlType != null && URI_2001_SCHEMA_XSD.equals(xmlType.getNamespaceURI())) { + return XML2JAVA.get(xmlType.getLocalPart()); + } else { + return null; + } + } + + public static TypeInfo getXMLType(Class javaType) { + return XSD_SIMPLE_TYPES.get(JAVA2XML.get(javaType)); + } + + public Object toJavaObject(QName simpleType, String literal, TransformationContext context) { + /** + *
    + *
  • xsd:string --- java.lang.String + *
  • xsd:integer --- java.math.BigInteger + *
  • xsd:int --- int + *
  • xsd:long --- long + *
  • xsd:short --- short + *
  • xsd:decimal --- java.math.BigDecimal + *
  • xsd:float --- float + *
  • xsd:double --- double + *
  • xsd:boolean --- boolean + *
  • xsd:byte --- byte + *
  • xsd:QName --- javax.xml.namespace.QName + *
  • xsd:dateTime --- javax.xml.datatype.XMLGregorianCalendar + *
  • xsd:base64Binary --- byte[] + *
  • xsd:hexBinary --- byte[] + *
  • xsd:unsignedInt --- long + *
  • xsd:unsignedShort --- int + *
  • xsd:unsignedByte --- short + *
  • xsd:time --- javax.xml.datatype.XMLGregorianCalendar + *
  • xsd:date --- javax.xml.datatype.XMLGregorianCalendar + *
  • xsd:g* --- javax.xml.datatype.XMLGregorianCalendar + *
  • xsd:anySimpleType (for xsd:element of this type)a + * java.lang.Object + *
  • xsd:anySimpleType (for xsd:attribute of this type) + * java.lang.String + *
  • xsd:duration javax.xml.datatype.Duration + *
  • xsd:NOTATION javax.xml.namespace.QName + *
+ */ + + if (literal == null) { + return null; + } + String value = literal.trim(); + + QName type = simpleType; + 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.getName()) : null); + return parseQName(value, namespaceContext); + } else if (type.equals(XSD_NOTATION)) { + NamespaceContext namespaceContext = + (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : 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(QName simpleType, Object obj, TransformationContext context) { + if(obj == null) { + // It could be null if nilable=true + return null; + } + 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.equals(XSD_BASE64)) { + return printBase64Binary((byte[])obj); + } else if (simpleType.equals(XSD_HEXBIN)) { + return printHexBinary((byte[])obj); + } + } + } else if (obj instanceof QName) { + NamespaceContext namespaceContext = + (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null); + return printQName((QName)obj, namespaceContext); + } + return obj.toString(); + } + + public static boolean isSimpleXSDType(QName typeName) { + if (typeName == null) { + return false; + } + return typeName.getNamespaceURI().equals(URI_2001_SCHEMA_XSD) + && XSD_SIMPLE_TYPES.get(typeName.getLocalPart()) != null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java new file mode 100644 index 0000000000..afc6417284 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +public class TransformationContextImpl implements TransformationContext { + private DataType sourceDataType; + + private DataType targetDataType; + + private final Map metadata = new HashMap(); + + private WeakReference classLoaderRef; + + public TransformationContextImpl() { + super(); + // This is used only for testing + setClassLoader(Thread.currentThread().getContextClassLoader()); + } + + public TransformationContextImpl(DataType sourceDataType, + DataType targetDataType, + ClassLoader classLoader, + Map metadata) { + super(); + this.sourceDataType = sourceDataType; + this.targetDataType = targetDataType; + setClassLoader(classLoader); + if (metadata != null) { + this.metadata.putAll(metadata); + } + } + + public TransformationContextImpl(DataType sourceDataType, + DataType targetDataType, + Map metadata) { + super(); + this.sourceDataType = sourceDataType; + this.targetDataType = targetDataType; + setClassLoader(Thread.currentThread().getContextClassLoader()); + if (metadata != null) { + this.metadata.putAll(metadata); + } + } + + public DataType getSourceDataType() { + return sourceDataType; + } + + public DataType getTargetDataType() { + return targetDataType; + } + + public void setSourceDataType(DataType sourceDataType) { + this.sourceDataType = sourceDataType; + } + + public void setTargetDataType(DataType targetDataType) { + this.targetDataType = targetDataType; + } + + public final void setClassLoader(ClassLoader classLoader) { + this.classLoaderRef = new WeakReference(classLoader); + } + + public ClassLoader getClassLoader() { + return classLoaderRef.get(); + } + + public Map getMetadata() { + return metadata; + } + + /** + * @return the sourceOperation + */ + public Operation getSourceOperation() { + return (Operation) metadata.get("source.operation"); + } + + /** + * @param sourceOperation the sourceOperation to set + */ + public void setSourceOperation(Operation sourceOperation) { + this.metadata.put("source.operation", sourceOperation); + } + + /** + * @return the targetOperation + */ + public Operation getTargetOperation() { + return (Operation) metadata.get("target.operation"); + } + + /** + * @param targetOperation the targetOperation to set + */ + public void setTargetOperation(Operation targetOperation) { + this.metadata.put("target.operation", targetOperation); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java new file mode 100644 index 0000000000..fb747864e7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java @@ -0,0 +1,945 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.impl; + +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 + * + * @version $Rev$ $Date$ + */ +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); + } + } + } + + /** + *

+ * Utility class for xs:hexbinary.

+ */ + public static final class HexBinary { + private HexBinary() { + } + + /** + * Converts the string pValue 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 pHexBinary 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); + } + } + + /** + *

+ * An instance of {@link java.text.Format}, which may be used to parse and format xs:dateTime values. + *

+ */ + 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); + } + + @Override + 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; + } + + @Override + 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/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java new file mode 100644 index 0000000000..2f95c2a9c6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.javabeans; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import javax.xml.namespace.QName; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Transformer to convert data from DOM Node to JavaBean + * + * @version $Rev$ $Date$ + */ +public class DOMNode2JavaBeanTransformer extends XML2JavaBeanTransformer { + + @Override + public Node getRootElement(Node element) throws XML2JavaMapperException { + if (element instanceof Document) { + return ((Document)element).getDocumentElement(); + } else { + return element; + } + + } + + @Override + public Iterator getChildElements(Node parent) throws XML2JavaMapperException { + NodeList nodeList = parent.getChildNodes(); + List nodeArrayList = new ArrayList(nodeList.getLength()); + for (int count = 0; count < nodeList.getLength(); ++count) { + nodeArrayList.add(nodeList.item(count)); + } + + return nodeArrayList.iterator(); + } + + @Override + public String getElementName(Node element) throws XML2JavaMapperException { + return element.getLocalName(); + } + + @Override + public String getText(Node element) throws XML2JavaMapperException { + if (element instanceof Document) { + element = ((Document)element).getDocumentElement(); + } + return element.getTextContent(); + } + + @Override + public boolean isTextElement(Node element) throws XML2JavaMapperException { + return element.getNodeType() == Node.TEXT_NODE; + } + + @Override + public boolean isTextOnly(Node element) throws XML2JavaMapperException { + NodeList childNodes = element.getChildNodes(); + return childNodes.getLength() == 1 && isTextElement(childNodes.item(0)); + } + + @Override + public Node getFirstChildWithName(Node element, QName name) throws XML2JavaMapperException { + Node child; + for (child = element.getFirstChild(); + child != null && !(child.getNodeName() == name.getLocalPart() + && child.getNamespaceURI() == name.getNamespaceURI()) ; + child = child.getNextSibling()) { + } + return child; + } + + @Override + public Class getSourceType() { + return Node.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java new file mode 100644 index 0000000000..9615f43572 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.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.sca.databinding.javabeans; + +import javax.xml.namespace.QName; + +/** + * This exception is used to encapsulate and rethrow exceptions that arise out + * of converting JavaBean objects to XML + * + * @version $Rev$ $Date$ + */ +public class Java2XMLMapperException extends RuntimeException { + private static final long serialVersionUID = 6811924384399578686L; + + private QName xmlElementName; + private String javaFieldName; + private Class javaType; + + public Java2XMLMapperException(String message) { + super(message); + } + + public Java2XMLMapperException(Throwable cause) { + super(cause); + } + + public String getJavaFieldName() { + return javaFieldName; + } + + public void setJavaFieldName(String javaFieldName) { + this.javaFieldName = javaFieldName; + } + + public Class getJavaType() { + return javaType; + } + + public void setJavaType(Class javaType) { + this.javaType = javaType; + } + + public QName getXmlElementName() { + return xmlElementName; + } + + public void setXmlElementName(QName xmlElementName) { + this.xmlElementName = xmlElementName; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java new file mode 100644 index 0000000000..58f594751a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.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.sca.databinding.javabeans; + +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * Transformer to convert data from a JavaBean object to DOM Node + * + * @version $Rev$ $Date$ + */ +public class JavaBean2DOMNodeTransformer extends JavaBean2XMLTransformer { + + public static final String COLON = ":"; + private Document factory; + + public JavaBean2DOMNodeTransformer() { + super(); + try { + factory = DOMHelper.newDocument(); + } catch (ParserConfigurationException e) { + throw new Java2XMLMapperException(e); + } + } + + @Override + public void appendChild(Node parentElement, Node childElement) throws Java2XMLMapperException { + parentElement.appendChild(childElement); + } + + @Override + public Node createElement(QName qName) throws Java2XMLMapperException { + String qualifedName = + (qName.getPrefix() == null || qName.getPrefix().length() <= 0) ? qName.getLocalPart() + : qName.getPrefix() + COLON + qName.getLocalPart(); + return factory.createElementNS(qName.getNamespaceURI(), qualifedName); + } + + @Override + public void appendText(Node parentElement, String textData) throws Java2XMLMapperException { + Node textNode; + if (textData != null) { + textNode = factory.createTextNode(textData); + } else { + Attr nil = factory.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:nil"); + nil.setValue("true"); + textNode = nil; + } + appendChild(parentElement, textNode); + } + + @Override + public Class getTargetType() { + return Node.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReaderTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReaderTransformer.java new file mode 100644 index 0000000000..4942fef0da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReaderTransformer.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.javabeans; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.xml.BeanXMLStreamReaderImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Transformer to convert data from a JavaBean object to XMLStreamReader. + * + * @version $Rev$ $Date$ + */ +public class JavaBean2XMLStreamReaderTransformer extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader transform(Object source, TransformationContext context) { + try { + javax.xml.namespace.QName name = null; + if (context != null) { + Object logical = context.getSourceDataType().getLogical(); + if (logical instanceof XMLType) { + name = ((XMLType)logical).getElementName(); + } + } + return new BeanXMLStreamReaderImpl(name, source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Object.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 50; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java new file mode 100644 index 0000000000..b96b394bb8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java @@ -0,0 +1,262 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.javabeans; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Date; +import java.util.GregorianCalendar; + +import javax.xml.datatype.XMLGregorianCalendar; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Transformer to convert data from a JavaBean object to xml + * + * @version $Rev$ $Date$ + */ +public abstract class JavaBean2XMLTransformer extends BaseTransformer implements + PullTransformer { + + public static final String GET = "get"; + public static final String PREFIX = "n"; + public static final String PERIOD = "."; + public static final String FWD_SLASH = "/"; + public static final String HTTP = "http://"; + private static int prefixCount = 1; + + protected SimpleTypeMapperImpl mapper; + + public JavaBean2XMLTransformer() { + this.mapper = new SimpleTypeMapperImpl(); + } + + public T transform(Object source, TransformationContext context) { + QName rootElement = null; + if (context != null) { + DataType type = context.getTargetDataType(); + if (type != null) { + Object logical = type.getLogical(); + if (logical instanceof XMLType) { + rootElement = ((XMLType)logical).getElementName(); + } + } + } + //FIXME See how/if we still need to get the metadata here + //QName rootElementName = (QName)context.getTargetDataType().getMetadata("RootElementName"); + //if (rootElementName == null) { + QName rootElementName = new QName(resolveRootElementName(source.getClass())); + //} + + T root = createElement(rootElementName); + appendChildElements(root, resolveElementName(source.getClass()), source.getClass(), source, context); + return root; + } + + private void appendChildElements(T parent, + QName elementName, + Class javaType, + Object javaObject, + TransformationContext context) { + T element = null; + if (javaObject != null) { + if (javaType.isPrimitive() || isSimpleJavaType(javaObject)) { + appendText(parent, mapper.toXMLLiteral(null, javaObject, context)); + } else if (javaType.isArray()) { + int size = Array.getLength(javaObject); + for (int count = 0; count < size; ++count) { + Object item = Array.get(javaObject, count); + element = createElement(elementName); + appendChild(parent, element); + appendChildElements(element, elementName, javaType.getComponentType(), item, context); + } + } else { + Field[] javaFields = javaType.getFields(); + for (Field aField : javaFields) { + try { + QName fieldElementName = new QName(aField.getName()); + if (!aField.getType().isArray()) { + element = createElement(fieldElementName); + appendChild(parent, element); + appendChildElements(element, + fieldElementName, + aField.getType(), + aField.get(javaObject), + context); + } else { + appendChildElements(parent, + fieldElementName, + aField.getType(), + aField.get(javaObject), + context); + } + } catch (IllegalAccessException e) { + Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e); + java2xmlEx.setJavaFieldName(aField.getName()); + java2xmlEx.setJavaType(javaType); + throw java2xmlEx; + } + } + + Method[] methods = javaType.getMethods(); + String fieldName = null; + for (Method aMethod : methods) { + try { + if (Modifier.isPublic(aMethod.getModifiers()) && aMethod.getName().startsWith(GET) + && aMethod.getParameterTypes().length == 0 + && isMappedGetter(aMethod.getName())) { + fieldName = resolveFieldFromMethod(aMethod.getName()); + try { + javaType.getField(fieldName); + } catch (NoSuchFieldException e) { + QName fieldElementName = new QName(fieldName); + if (aMethod.getReturnType().isArray()) { + appendChildElements(parent, fieldElementName, aMethod.getReturnType(), aMethod + .invoke(javaObject, new Object[0]), context); + } else { + element = createElement(fieldElementName); + appendChild(parent, element); + appendChildElements(element, fieldElementName, aMethod.getReturnType(), aMethod + .invoke(javaObject, new Object[0]), context); + } + } + } + } catch (IllegalAccessException e) { + Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e); + java2xmlEx.setJavaFieldName(fieldName); + java2xmlEx.setJavaType(javaType); + throw java2xmlEx; + } catch (InvocationTargetException e) { + Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e); + java2xmlEx.setJavaFieldName(fieldName); + java2xmlEx.setJavaType(javaType); + throw java2xmlEx; + } + } + } + } + } + + /* + * Subclasses can override this method to prevent some getter methods + * from being mapped. The default implementation provided by this class + * maps all getter methods. + */ + protected boolean isMappedGetter(String methodName) { + return true; + } + + @Override + public String getSourceDataBinding() { + return JavaBeansDataBinding.NAME; + } + + @Override + public Class getSourceType() { + return Object.class; + } + + private boolean isSimpleJavaType(Object javaObject) { + if (javaObject instanceof String) { + return true; + } + if (javaObject instanceof Byte || javaObject instanceof Character + || javaObject instanceof Short + || javaObject instanceof Integer + || javaObject instanceof Long + || javaObject instanceof Float + || javaObject instanceof Double + || javaObject instanceof Boolean) { + return true; + } + if (javaObject instanceof GregorianCalendar || javaObject instanceof Date + || javaObject instanceof XMLGregorianCalendar + || javaObject instanceof byte[] + || javaObject instanceof QName) { + return true; + } + return false; + } + + private String resolveRootElementName(Class javaType) { + if (javaType.isArray()) { + return javaType.getComponentType().getSimpleName() + "_collection"; + } else { + return javaType.getSimpleName() + "_instance"; + } + } + + private QName resolveElementName(Class javaType) { + if (javaType.isArray()) { + return new QName(javaType.getComponentType().getSimpleName()); + } else { + return new QName(javaType.getSimpleName()); + } + } + + private String resolveFieldFromMethod(String methodName) { + StringBuffer fieldName = new StringBuffer(); + fieldName.append(Character.toLowerCase(methodName.charAt(GET.length()))); + fieldName.append(methodName.substring(GET.length() + 1)); + return fieldName.toString(); + } + + public String getNexPrefix() { + return PREFIX + prefixCount++; + } + + @Override + public int getWeight() { + return JavaBeansDataBinding.HEAVY_WEIGHT; + } + + /** + * Create an element with the given name + * @param qName + * @return + * @throws Java2XMLMapperException + */ + public abstract T createElement(QName qName) throws Java2XMLMapperException; + + /** + * Create a text node and add it to the parent + * @param parentElement + * @param textData + * @throws Java2XMLMapperException + */ + public abstract void appendText(T parentElement, String textData) throws Java2XMLMapperException; + + /** + * Add the child element to the parent + * @param parentElement + * @param childElement + * @throws Java2XMLMapperException + */ + public abstract void appendChild(T parentElement, T childElement) throws Java2XMLMapperException; +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java new file mode 100644 index 0000000000..9ee3c1f7d5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.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.sca.databinding.javabeans; + +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 java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.osoa.sca.ServiceRuntimeException; + +/** + * DataBinding for JavaBeans + * + * @version $Rev$ $Date$ + */ +public class JavaBeansDataBinding extends BaseDataBinding { + private final static Logger logger = Logger.getLogger(JavaBeansDataBinding.class.getName()); + /** + * Defining a weight to a very high number so that the transformer won't be picked + * up by other paths unless it's the only available path + */ + public static final int HEAVY_WEIGHT = 10000; + public static final String NAME = "java:complexType"; + + public JavaBeansDataBinding() { + super(NAME, Object.class); + } + + protected JavaBeansDataBinding(String name, Class baseType) { + super(name, baseType); + } + + @Override + public Object copy(Object arg, DataType dataType, Operation operation) { + 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(); + + // Work out which ClassLoader to use for deserializing arg + // We want to use: + // * The ClassLoader of arg if it is not the System ClassLoader + // * The ThreadContext ClassLoader if the ClassLoader of arg is the System ClassLoader + // because Collection classes are loaded by the System ClassLoader but their contents + // may be loaded from another ClassLoader + // + ClassLoader classLoaderToUse = clazz.getClassLoader(); + if (classLoaderToUse == null) + { + // ClassLoader of arg is the System ClassLoader so we will use the ThreadContext ClassLoader + // instead + classLoaderToUse = Thread.currentThread().getContextClassLoader(); + } + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = getObjectInputStream(bis, classLoaderToUse); + Object objectCopy = ois.readObject(); + ois.close(); + bis.close(); + return objectCopy; + } else if (arg instanceof Cloneable) { + Method clone; + try { + clone = arg.getClass().getMethod("clone"); + try { + return clone.invoke(arg, (Object[])null); + } catch (InvocationTargetException e) { + if (e.getTargetException() instanceof CloneNotSupportedException) { + // Ignore + } else { + throw new ServiceRuntimeException(e); + } + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } catch (NoSuchMethodException e) { + // Ignore it + } + } + // return arg; + logger.warning("Argument type '" + arg.getClass().getName() + + "' is not Serializable or Cloneable. Pass-by-value is skipped."); + return arg; + } catch (Exception e) { + throw new IllegalArgumentException("Pass-by-value is not supported for the given object: " + arg.getClass() + .getName(), 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) { + try { + // For OSGi, use context ClassLoader if the bundle ClassLoader cannot load the class + if (cl != Thread.currentThread().getContextClassLoader()) { + return Class.forName(desc.getName(), false, Thread.currentThread().getContextClassLoader()); + } + } catch (ClassNotFoundException e1) { + // ignore + } catch (NoClassDefFoundError e1) { + // ignore + } + return super.resolveClass(desc); + } + } + + }; + return ois; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaExceptionDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaExceptionDataBinding.java new file mode 100644 index 0000000000..7ae64c6a27 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaExceptionDataBinding.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.sca.databinding.javabeans; + + +/** + * DataBinding for Java Exceptions + * + * @version $Rev$ $Date$ + */ +public class JavaExceptionDataBinding extends JavaBeansDataBinding { + + public static final String NAME = "java:exception"; + + public JavaExceptionDataBinding() { + super(NAME, null); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.java new file mode 100644 index 0000000000..61a2189c72 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.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.sca.databinding.javabeans; + + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.databinding.xml.XMLStringDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * DataBinding for Java simple types + * + * @version $Rev$ $Date$ + */ +public class SimpleJavaDataBinding extends BaseDataBinding { + public static final String NAME = "java:simpleType"; + + public SimpleJavaDataBinding() { + super(NAME, Object.class); + } + + @Override + public Object copy(Object arg, DataType dataType, Operation operation) { + if (arg instanceof byte[]) { + return ((byte[])arg).clone(); + } + return arg; + } + + @Override + public boolean introspect(DataType type, Operation operation) { + Class cls = type.getPhysical(); + if (cls == Object.class) { + return false; + } + // HACK: [rfeng] By pass the one know to XMLString + String db = type.getDataBinding(); + if (db != null && (XMLStringDataBinding.NAME.equals(db))) { + return false; + } + if (SimpleTypeMapperImpl.JAVA2XML.keySet().contains(cls)) { + type.setDataBinding(NAME); + QName elementName = null; + Object logical = type.getLogical(); + if (logical instanceof XMLType) { + elementName = ((XMLType)logical).getElementName(); + } + TypeInfo typeInfo = SimpleTypeMapperImpl.getXMLType(cls); + type.setLogical(new XMLType(elementName, typeInfo == null ? null : typeInfo.getQName())); + return true; + } else { + return false; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java new file mode 100644 index 0000000000..06feeffabd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java @@ -0,0 +1,329 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.javabeans; + +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Transformer to convert data from XML to JavaBean + * + * @version $Rev$ $Date$ + */ +public abstract class XML2JavaBeanTransformer extends BaseTransformer implements + PullTransformer { + + public static final String SET = "set"; + public static final QName QNAME_MESSAGE = new QName("message"); + + protected SimpleTypeMapperImpl mapper; + + public XML2JavaBeanTransformer() { + this.mapper = new SimpleTypeMapperImpl(); + } + + @Override + public int getWeight() { + return JavaBeansDataBinding.HEAVY_WEIGHT; + } + + public Object transform(T source, TransformationContext context) { + //FIXME why is the logical type sometimes a Class instead of an XMLType? + if (context.getSourceDataType().getLogical() instanceof XMLType) { + XMLType xmlType = (XMLType) context.getSourceDataType().getLogical(); + return toJavaObject(xmlType.getTypeName(), getRootElement(source), context); + } else { + return toJavaObject(null, getRootElement(source), context); + } + } + + public Object toJavaObject(QName xmlType, T xmlElement, TransformationContext context) { + if (xmlType != null && SimpleTypeMapperImpl.isSimpleXSDType(xmlType)) { + return mapper.toJavaObject(xmlType, getText(xmlElement), context); + } else { + Class javaType = (Class)context.getTargetDataType().getPhysical(); + return createJavaObject(xmlElement, javaType, context); + } + } + + @SuppressWarnings("unchecked") + private L createJavaObject(T element, Class javaType, TransformationContext context) + throws XML2JavaMapperException { + if (isTextOnly(element)) { + return (L) mapper.toJavaObject(SimpleTypeMapperImpl.getXMLType(javaType).getQName(), + getText(element), + context); + } else { + String fieldName = null; + try { + L javaInstance; + T detailMsg = null; + if (Throwable.class.isAssignableFrom(javaType)) { + T msgElement = getFirstChildWithName(element, QNAME_MESSAGE); + if (msgElement != null && isTextOnly(msgElement)) { + detailMsg = msgElement; // skip this when handling child elements + Constructor constructor = javaType.getConstructor(new Class[] {String.class}); + javaInstance = (L)constructor.newInstance(new Object[] {getText(detailMsg)}); + } else { + javaInstance = javaType.newInstance(); + } + } else { + javaInstance = javaType.newInstance(); + } + Map> arrayFields = new Hashtable>(); + Map> arraySetters = new Hashtable>(); + + for (Iterator childElements = getChildElements(element); childElements.hasNext(); ) { + T childElement = childElements.next(); + if (!isTextElement(childElement) && childElement != detailMsg) { + fieldName = getElementName(childElement); + try { + Field javaField = javaType.getField(fieldName); + setFieldValue(javaInstance, + javaField, + childElement, + arrayFields, + context); + + } catch (NoSuchFieldException e1) { + setFieldValueUsingSetter(javaType, + javaInstance, + fieldName, + childElement, + arraySetters, + context); + } + } + } + + setArrayValues(javaInstance, arrayFields, arraySetters); + return javaInstance; + } catch (Exception e2) { + XML2JavaMapperException xml2JavaEx = new XML2JavaMapperException(e2); + xml2JavaEx.setJavaType(javaType); + xml2JavaEx.setJavaFieldName(fieldName); + throw xml2JavaEx; + } + } + } + + private void setFieldValue(Object javaInstance, + Field javaField, + T fieldValue, + Map> arrayFields, + TransformationContext context) throws IllegalAccessException { + Class javaFieldType = (Class) javaField.getType(); + + if (javaFieldType.isArray()) { + Class componentType = javaFieldType.getComponentType(); + List fldValueArray = arrayFields.get(javaField); + if (fldValueArray == null) { + fldValueArray = new ArrayList(); + arrayFields.put(javaField, fldValueArray); + } + fldValueArray.add(createJavaObject(fieldValue, componentType, context)); + } else { + javaField.setAccessible(true); + javaField.set(javaInstance, createJavaObject(fieldValue, javaFieldType, context)); + } + } + + private void setFieldValueUsingSetter(Class javaType, + Object javaInstance, + String fieldName, + T fieldValue, + Map> arraySetters, + TransformationContext context) throws IllegalAccessException, + InvocationTargetException { + char firstChar = Character.toUpperCase(fieldName.charAt(0)); + StringBuilder methodName = new StringBuilder(SET + fieldName); + methodName.setCharAt(SET.length(), firstChar); + boolean methodNotFound = true; + + for (int methodCount = 0; methodNotFound && methodCount < javaType.getMethods().length; ++methodCount) { + Method aMethod = javaType.getMethods()[methodCount]; + if (aMethod.getName().equals(methodName.toString()) + && aMethod.getParameterTypes().length == 1) { + Class paramType = aMethod.getParameterTypes()[0]; + + if (paramType.isArray()) { + Class componentType = paramType.getComponentType(); + List setterValueArray = arraySetters.get(aMethod); + if (setterValueArray == null) { + setterValueArray = new ArrayList(); + arraySetters.put(aMethod, setterValueArray); + } + setterValueArray.add(createJavaObject(fieldValue, componentType, context)); + } else { + aMethod.invoke(javaInstance, new Object[] {createJavaObject(fieldValue, + paramType, + context)}); + } + methodNotFound = false; + } + } + + if (methodNotFound) { + XML2JavaMapperException xml2JavaEx = + new XML2JavaMapperException("No field or setter method to configure xml data"); + xml2JavaEx.setJavaFieldName(fieldName); + xml2JavaEx.setJavaType(javaType); + throw xml2JavaEx; + } + } + + private void setArrayValues(Object javaInstance, + Map> arrayFields, + Map> arraySetters) throws IllegalAccessException, + InvocationTargetException { + if (arrayFields.size() > 0) { + for (Field javaField : arrayFields.keySet()) { + javaField.setAccessible(true); + + if (javaField.getType().getComponentType().isPrimitive()) { + javaField.set(javaInstance, createPrimitiveArray(javaField.getType() + .getComponentType(), + arrayFields.get(javaField))); + } else { + javaField.set(javaInstance, + createNonPrimitiveArray(javaField.getType().getComponentType(), + arrayFields.get(javaField))); + } + } + } + + if (arraySetters.size() > 0) { + for (Method aMethod : arraySetters.keySet()) { + Class paramType = aMethod.getParameterTypes()[0]; + if (paramType.getComponentType().isPrimitive()) { + aMethod.invoke(javaInstance, + new Object[] {createPrimitiveArray(paramType.getComponentType(), + arraySetters.get(aMethod))}); + } else { + aMethod.invoke(javaInstance, + new Object[] {createNonPrimitiveArray(paramType.getComponentType(), + arraySetters.get(aMethod))}); + } + } + } + } + + private Object createNonPrimitiveArray(Class fieldType, List values) { + Object objectArray = Array.newInstance(fieldType, values.size()); + for (int count = 0; count < values.size(); ++count) { + Array.set(objectArray, count, values.get(count)); + } + return objectArray; + } + + private Object createPrimitiveArray(Class fieldType, List values) { + if (fieldType.isPrimitive()) { + if (fieldType.getName().equals("int")) { + int[] primitiveValues = new int[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Integer) values.get(count)).intValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("float")) { + float[] primitiveValues = new float[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Float) values.get(count)).floatValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("boolean")) { + boolean[] primitiveValues = new boolean[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Boolean) values.get(count)).booleanValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("char")) { + char[] primitiveValues = new char[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Character) values.get(count)).charValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("byte")) { + byte[] primitiveValues = new byte[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Byte) values.get(count)).byteValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("short")) { + short[] primitiveValues = new short[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Short) values.get(count)).shortValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("long")) { + long[] primitiveValues = new long[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Long) values.get(count)).longValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("double")) { + double[] primitiveValues = new double[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Double) values.get(count)).doubleValue(); + } + return primitiveValues; + } + } + return values; + } + + public abstract String getText(T source) throws XML2JavaMapperException; + + public abstract Iterator getChildElements(T parent) throws XML2JavaMapperException; + + public abstract String getElementName(T element) throws XML2JavaMapperException; + + public abstract boolean isTextElement(T element) throws XML2JavaMapperException; + + public abstract boolean isTextOnly(T element) throws XML2JavaMapperException; + + public abstract T getFirstChildWithName(T element, QName name) throws XML2JavaMapperException; + + public abstract T getRootElement(T element) throws XML2JavaMapperException; + + @Override + public Class getTargetType() { + return Object.class; + } + + @Override + public String getTargetDataBinding() { + return JavaBeansDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java new file mode 100644 index 0000000000..a723fd445c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.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.sca.databinding.javabeans; + +import javax.xml.namespace.QName; + +/** + * This exception is used to encapsulate and rethrow exceptions that arise out + * of converting XML Data to Java Objects. + * + * @version $Rev$ $Date$ + */ +public class XML2JavaMapperException extends RuntimeException { + private static final long serialVersionUID = 6596530102591630642L; + + private QName xmlElementName; + private String javaFieldName; + private Class javaType; + + public XML2JavaMapperException(String message) { + super(message); + } + + public XML2JavaMapperException(Throwable cause) { + super(cause); + } + + public QName getXmlElementName() { + return xmlElementName; + } + + public void setXmlElementName(QName xmlElementName) { + this.xmlElementName = xmlElementName; + } + + public String getJavaFieldName() { + return javaFieldName; + } + + public void setJavaFieldName(String javaFieldName) { + this.javaFieldName = javaFieldName; + } + + public Class getJavaType() { + return javaType; + } + + public void setJavaType(Class javaType) { + this.javaType = javaType; + } + + @Override + public String getMessage() { + return super.getMessage() + " <" + getJavaFieldName() + "> " + " in <" + getJavaType() + ">"; + } + + + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java new file mode 100644 index 0000000000..ce3237a574 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.util; + +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.lang.reflect.WildcardType; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; + +/** + * + * @version $Rev$ $Date$ + */ +public class DataTypeHelper { + private DataTypeHelper() { + } + + /** + * Find all classes referenced by this data type though java generics + * @param d + * @return + */ + public static Set> findClasses(DataType d) { + Set> classes = new HashSet>(); + Set visited = new HashSet(); + findClasses(d, classes, visited); + return classes; + } + + private static void findClasses(DataType d, Set> classes, Set visited) { + if (d == null) { + return; + } + classes.add(d.getPhysical()); + if (d.getPhysical() != d.getGenericType()) { + findClasses(d.getGenericType(), classes, visited); + } + } + + /** + * Find referenced classes in the generic type + * @param type + * @param classSet + * @param visited + */ + private static void findClasses(Type type, Set> classSet, Set visited) { + if (visited.contains(type) || type == null) { + return; + } + visited.add(type); + if (type instanceof Class) { + Class cls = (Class)type; + if (!cls.isInterface()) { + classSet.add(cls); + } + return; + } else if (type instanceof ParameterizedType) { + ParameterizedType pType = (ParameterizedType)type; + findClasses(pType.getRawType(), classSet, visited); + for (Type t : pType.getActualTypeArguments()) { + findClasses(t, classSet, visited); + } + } else if (type instanceof TypeVariable) { + TypeVariable tv = (TypeVariable)type; + for (Type t : tv.getBounds()) { + findClasses(t, classSet, visited); + } + } else if (type instanceof GenericArrayType) { + GenericArrayType gType = (GenericArrayType)type; + findClasses(gType, classSet, visited); + } else if (type instanceof WildcardType) { + WildcardType wType = (WildcardType)type; + for (Type t : wType.getLowerBounds()) { + findClasses(t, classSet, visited); + } + for (Type t : wType.getUpperBounds()) { + findClasses(t, classSet, visited); + } + } + } + + /** + * Get all the data types in the interface + * @param intf The interface + * @param useWrapper Use wrapper classes? + * @return A list of DataTypes + */ + public static List getDataTypes(Interface intf, boolean useWrapper) { + List dataTypes = new ArrayList(); + for (Operation op : intf.getOperations()) { + getDataTypes(dataTypes, op, useWrapper); + } + return dataTypes; + } + + /** + * Get all the data types in the operation + * @param op The operaiton + * @param useWrapper Use wrapper classes? + * @return A list of DataTypes + */ + public static List getDataTypes(Operation op, boolean useWrapper) { + List dataTypes = new ArrayList(); + getDataTypes(dataTypes, op, useWrapper); + return dataTypes; + } + + private static void getDataTypes(List dataTypes, Operation op, boolean useWrapper) { + + WrapperInfo inputWrapperInfo = op.getInputWrapper(); + WrapperInfo outputWrapperInfo = op.getOutputWrapper(); + + if (useWrapper && (inputWrapperInfo != null) && (outputWrapperInfo != null)) { + DataType dt1 = inputWrapperInfo.getWrapperType(); + if (dt1 != null) { + dataTypes.add(dt1); + } + DataType dt2 = outputWrapperInfo.getWrapperType(); + if (dt2 != null) { + dataTypes.add(dt2); + } + } + // FIXME: [rfeng] We may need to find the referenced classes in the child types + // else + { + for (DataType dt1 : op.getInputType().getLogical()) { + dataTypes.add(dt1); + } + DataType dt2 = op.getOutputType(); + if (dt2 != null) { + dataTypes.add(dt2); + } + } + for (DataType dt3 : op.getFaultTypes()) { + DataType dt4 = dt3.getLogical(); + if (dt4 != null) { + dataTypes.add(dt4); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java new file mode 100644 index 0000000000..34a82fd2d3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.util; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * A Simple LRU Cache + * + * @version $Revision$ + * @param + * @param + */ + +public class LRUCache extends LinkedHashMap { + private static final long serialVersionUID = -342098639681884413L; + protected int maxCacheSize = 4096; + + /** + * Default constructor for an LRU Cache The default capacity is 10000 + */ + public LRUCache() { + this(0, 4096, 0.75f, true); + } + + /** + * Constructs a LRUCache with a maximum capacity + * + * @param maximumCacheSize + */ + public LRUCache(int maximumCacheSize) { + this(0, maximumCacheSize, 0.75f, true); + } + + /** + * Constructs an empty LRUCache instance with the specified + * initial capacity, maximumCacheSize,load factor and ordering mode. + * + * @param initialCapacity the initial capacity. + * @param maximumCacheSize + * @param loadFactor the load factor. + * @param accessOrder the ordering mode - true for access-order, + * false for insertion-order. + * @throws IllegalArgumentException if the initial capacity is negative or + * the load factor is non-positive. + */ + + public LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder) { + super(initialCapacity, loadFactor, accessOrder); + this.maxCacheSize = maximumCacheSize; + } + + /** + * @return Returns the maxCacheSize. + */ + public int getMaxCacheSize() { + return maxCacheSize; + } + + /** + * @param maxCacheSize The maxCacheSize to set. + */ + public void setMaxCacheSize(int maxCacheSize) { + this.maxCacheSize = maxCacheSize; + } + + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > maxCacheSize; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderImpl.java new file mode 100644 index 0000000000..3423d3e3b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderImpl.java @@ -0,0 +1,296 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.xml; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; + +/** + * @version $Rev$ $Date$ + */ +public class BeanXMLStreamReaderImpl extends XmlTreeStreamReaderImpl { + private static final Comparator COMPARATOR = new Comparator() { + public int compare(Accessor o1, Accessor o2) { + return o1.getName().compareTo(o2.getName()); + } + }; + + public static class BeanXmlNodeImpl extends SimpleXmlNodeImpl implements XmlNode { + private static final Object[] NULL = null; + private static final SimpleTypeMapperImpl MAPPER = new SimpleTypeMapperImpl(); + + public BeanXmlNodeImpl(Object bean) { + super(getName(bean == null ? null : bean.getClass()), bean); + } + + public BeanXmlNodeImpl(QName name, Object bean) { + super(name, bean); + } + + private static boolean isSimpleType(Class javaType) { + return SimpleTypeMapperImpl.getXMLType(javaType) != null; + } + + private static String getStringValue(Object o) { + if (o == null) { + return null; + } + TypeInfo info = SimpleTypeMapperImpl.getXMLType(o.getClass()); + if (info != null) { + return MAPPER.toXMLLiteral(info.getQName(), o, null); + } else { + return String.valueOf(o); + } + } + + @Override + public Iterator children() { + if (name == null) { + return null; + } + if (value == null) { + return super.children(); + } + if (isSimpleType(value.getClass())) { + XmlNode textNode = new BeanXmlNodeImpl(null, value); + return Arrays.asList(textNode).iterator(); + } + if (Map.class.isAssignableFrom(value.getClass())) { + List entries = new ArrayList(); + QName entryName = new QName(name.getNamespaceURI(), "entry"); + Map map = (Map)value; + if (map != null) { + for (Object e : map.entrySet()) { + Map.Entry entry = (Map.Entry)e; + entries.add(new BeanXmlNodeImpl(entryName, entry)); + } + } + return entries.iterator(); + } + try { + Map accessorMap = getAccessors(value); + List accessorList = new ArrayList(accessorMap.values()); + Collections.sort(accessorList, COMPARATOR); + + List props = new ArrayList(); + for (Accessor accessor : accessorList) { + Class pType = accessor.getType(); + + QName pName = new QName(name.getNamespaceURI(), accessor.getName()); + Object pValue = accessor.getValue(); + if (pType.isArray()) { + if (pValue != null) { + int i1 = Array.getLength(pValue); + for (int j = 0; j < i1; j++) { + Object o = Array.get(pValue, j); + props.add(new BeanXmlNodeImpl(pName, o)); + } + } else { + // TODO: How to handle null? + } + } else if (Collection.class.isAssignableFrom(pType)) { + Collection objList = (Collection)pValue; + if (objList != null && objList.size() > 0) { + for (Iterator j = objList.iterator(); j.hasNext();) { + Object o = j.next(); + props.add(new BeanXmlNodeImpl(pName, o)); + } + + } else { + // How to handle null + } + } else { + props.add(new BeanXmlNodeImpl(pName, pValue)); + } + } + return props.iterator(); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + @Override + public QName getName() { + return name; + } + + @Override + public String getValue() { + return getStringValue(value); + } + + private static String getPackageName(Class cls) { + String name = cls.getName(); + int index = name.lastIndexOf('.'); + return index == -1 ? "" : name.substring(0, index); + } + + public static QName getName(Class cls) { + if (cls == null) { + return null; + } + + String packageName = getPackageName(cls); + + if ("".equals(packageName)) { + return new QName("", cls.getSimpleName()); + } + StringBuffer ns = new StringBuffer("http://"); + String[] names = packageName.split("\\."); + for (int i = names.length - 1; i >= 0; i--) { + ns.append(names[i]); + if (i != 0) { + ns.append('.'); + } + } + ns.append('/'); + return new QName(ns.toString(), cls.getSimpleName()); + } + + } + + public BeanXMLStreamReaderImpl(QName name, Object bean) { + super(getXmlNode(name, bean)); + } + + private static BeanXmlNodeImpl getXmlNode(QName name, Object bean) { + BeanXmlNodeImpl root = null; + if (name != null) { + root = new BeanXmlNodeImpl(name, bean); + } else { + root = new BeanXmlNodeImpl(bean); + } + return root; + } + + public static interface Accessor { + String getName(); + + Class getType(); + + Object getValue() throws Exception; + + void setValue(Object value) throws Exception; + } + + private static class FieldAccessor implements Accessor { + private Object target; + private Field field; + + public FieldAccessor(Object target, Field field) { + super(); + this.target = target; + this.field = field; + this.field.setAccessible(true); + } + + public String getName() { + return field.getName(); + } + + public Object getValue() throws Exception { + return field.get(target); + } + + public void setValue(Object value) throws Exception { + field.set(target, value); + } + + public Class getType() { + return field.getType(); + } + + } + + private static class PropertyAccessor implements Accessor { + private Object target; + private PropertyDescriptor prop; + + public PropertyAccessor(Object target, PropertyDescriptor prop) { + super(); + this.target = target; + this.prop = prop; + } + + public String getName() { + return prop.getName(); + } + + public Class getType() { + return prop.getPropertyType(); + } + + public Object getValue() throws Exception { + Method getter = prop.getReadMethod(); + if (getter != null) { + getter.setAccessible(true); + return getter.invoke(target); + } + throw new IllegalAccessException("The property cannot be read: " + getName()); + } + + public void setValue(Object value) throws Exception { + Method setter = prop.getWriteMethod(); + if (setter != null) { + setter.setAccessible(true); + setter.invoke(target); + } + throw new IllegalAccessException("The property cannot be written: " + getName()); + } + + } + + private static Map getAccessors(Object target) throws Exception { + if (target == null) { + return Collections.emptyMap(); + } + Map map = new HashMap(); + Class type = target.getClass(); + for (Field f : type.getFields()) { + map.put(f.getName(), new FieldAccessor(target, f)); + } + BeanInfo info = Introspector.getBeanInfo(type, Object.class); + for (PropertyDescriptor p : info.getPropertyDescriptors()) { + // if (p.getReadMethod() != null && p.getWriteMethod() != null) { + map.put(p.getName(), new PropertyAccessor(target, p)); + // } + } + return map; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java new file mode 100644 index 0000000000..e029604722 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.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.sca.databinding.xml; + + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Node; + +/** + * DOM DataBinding + * + * @version $Rev$ $Date$ + */ +public class DOMDataBinding extends BaseDataBinding { + public static final String NAME = Node.class.getName(); + + public static final String ROOT_NAMESPACE = "http://tuscany.apache.org/xmlns/sca/databinding/dom/1.0"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "root"); + + public DOMDataBinding() { + super(NAME, Node.class); + } + + @Override + public WrapperHandler getWrapperHandler() { + return new DOMWrapperHandler(); + } + + @Override + public Object copy(Object source, DataType dataType, Operation operation) { + if (Node.class.isAssignableFrom(source.getClass())) { + Node nodeSource = (Node)source; + return nodeSource.cloneNode(true); + } + return super.copy(source, dataType, operation); + } + + @Override + public boolean introspect(DataType type, Operation operation) { + if (Node.class.isAssignableFrom(type.getPhysical())) { + if (type.getLogical() == null) { + type.setLogical(new XMLType(ROOT_ELEMENT, null)); + } + type.setDataBinding(NAME); + return true; + } + return false; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java new file mode 100644 index 0000000000..19a8fe32d3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.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.sca.databinding.xml; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class DOMWrapperHandler implements WrapperHandler { + + public DOMWrapperHandler() { + super(); + } + + public Node create(Operation operation, boolean input) { + try { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : outputWrapperInfo.getWrapperElement(); + + Document document = DOMHelper.newDocument(); + QName name = element.getQName(); + return DOMHelper.createElement(document, name); + } catch (ParserConfigurationException e) { + throw new TransformationException(e); + } + } + + public void setChildren(Node wrapper, + Object[] childObjects, + Operation operation, boolean input) { + List childElements = input? operation.getInputWrapper().getChildElements(): + operation.getOutputWrapper().getChildElements(); + for (int i = 0; i < childElements.size(); i++) { + setChild(wrapper, i, childElements.get(i), childObjects[i]); + } + + } + public void setChild(Node wrapper, int i, ElementInfo childElement, Object value) { + Node node = (Node)value; + if (node.getNodeType() == Node.DOCUMENT_NODE) { + node = ((Document)node).getDocumentElement(); + } + wrapper.appendChild(wrapper.getOwnerDocument().importNode(node, true)); + } + + public List getChildren(Node wrapper, Operation operation, boolean input) { + assert wrapper != null; + List childElements = input? operation.getInputWrapper().getChildElements(): + operation.getOutputWrapper().getChildElements(); + if (wrapper.getNodeType() == Node.DOCUMENT_NODE) { + wrapper = ((Document)wrapper).getDocumentElement(); + } + List elements = new ArrayList(); + NodeList nodes = wrapper.getChildNodes(); + for (int j = 0; j < nodes.getLength(); j++) { + Node node = nodes.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elements.add(node); + } + } + return elements; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(Operation, boolean) + */ + public DataType getWrapperType(Operation operation, boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : outputWrapperInfo.getWrapperElement(); + DataType wrapperType = + new DataTypeImpl(DOMDataBinding.NAME, Node.class, new XMLType(element)); + return wrapperType; + } + + public boolean isInstance(Object wrapperObj, + Operation operation, + boolean input) { + WrapperInfo inputWrapperInfo = operation.getInputWrapper(); + WrapperInfo outputWrapperInfo = operation.getOutputWrapper(); + ElementInfo element = input ? inputWrapperInfo.getWrapperElement() : outputWrapperInfo.getWrapperElement(); + + List childElements = input? inputWrapperInfo.getChildElements(): + outputWrapperInfo.getChildElements(); + + Node wrapper = (Node)wrapperObj; + if (wrapper.getNodeType() == Node.DOCUMENT_NODE) { + wrapper = ((Document)wrapper).getDocumentElement(); + } + QName elementName = new QName(wrapper.getNamespaceURI(), wrapper.getLocalName()); + if (!element.getQName().equals(elementName)) { + return false; + } + Set names = new HashSet(); + for (ElementInfo e : childElements) { + names.add(e.getQName()); + } + NodeList nodes = wrapper.getChildNodes(); + for (int j = 0; j < nodes.getLength(); j++) { + Node node = nodes.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elementName = new QName(wrapper.getNamespaceURI(), wrapper.getLocalName()); + if (!names.contains(elementName)) { + return false; + } + } + } + return true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java new file mode 100644 index 0000000000..8c7a742cdd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.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.sca.databinding.xml; + +import org.w3c.dom.Node; + +public class DOMXMLStreamReader extends XmlTreeStreamReaderImpl { + + public DOMXMLStreamReader(Node node) { + super(new DOMXmlNodeImpl(node)); + switch (node.getNodeType()) { + case Node.DOCUMENT_NODE: + break; + case Node.ELEMENT_NODE: + break; + default: + throw new IllegalArgumentException("Illegal node type: " + node); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXmlNodeImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXmlNodeImpl.java new file mode 100644 index 0000000000..507c141c33 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXmlNodeImpl.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.sca.databinding.xml; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * @version $Rev$ $Date$ + */ +public class DOMXmlNodeImpl implements XmlNode { + private Node node; + private Map namespaces; + private Type type; + + /** + * @param element + */ + public DOMXmlNodeImpl(Node element) { + super(); + if (element.getNodeType() == Node.DOCUMENT_NODE) { + this.node = ((Document)element).getDocumentElement(); + } else { + this.node = element; + } + switch (node.getNodeType()) { + case Node.CDATA_SECTION_NODE: + this.type = Type.CHARACTERS; + break; + case Node.ELEMENT_NODE: + this.type = Type.ELEMENT; + break; + case Node.TEXT_NODE: + this.type = Type.CHARACTERS; + break; + } + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#attributes() + */ + public List attributes() { + if (type != Type.ELEMENT) { + return null; + } + NamedNodeMap attrs = node.getAttributes(); + List xmlAttrs = new ArrayList(); + for (int i = 0; i < attrs.getLength(); i++) { + Attr attr = (Attr)attrs.item(i); + if (!attr.getName().equals("xmlns") && !attr.getName().startsWith("xmlns:")) { + xmlAttrs.add(new SimpleXmlNodeImpl(getQName(attr), attr.getValue(), XmlNode.Type.ATTRIBUTE)); + } + } + return xmlAttrs; + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#children() + */ + public Iterator children() { + if (type != Type.ELEMENT) { + return null; + } + NodeList nodes = node.getChildNodes(); + List xmlNodes = new ArrayList(); + for (int i = 0; i < nodes.getLength(); i++) { + Node child = (Node)nodes.item(i); + int nodeType = child.getNodeType(); + if (nodeType == Node.ELEMENT_NODE || nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { + xmlNodes.add(new DOMXmlNodeImpl(child)); + } + } + return xmlNodes.iterator(); + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getName() + */ + public QName getName() { + return getQName(node); + } + + private static QName getQName(Node node) { + int type = node.getNodeType(); + if (type == Node.ELEMENT_NODE || type == Node.ATTRIBUTE_NODE) { + String ns = node.getNamespaceURI(); + String prefix = node.getPrefix(); + String localName = node.getLocalName(); + return new QName(ns == null ? "" : ns, localName, prefix == null ? "" : prefix); + } + return null; + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getValue() + */ + public String getValue() { + return node.getNodeValue(); + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#namespaces() + */ + public Map namespaces() { + if (type != Type.ELEMENT) { + return null; + } + if (namespaces == null) { + namespaces = new HashMap(); + NamedNodeMap attrs = node.getAttributes(); + for (int i = 0; i < attrs.getLength(); i++) { + Attr attr = (Attr)attrs.item(i); + if ("xmlns".equals(attr.getPrefix())) { + namespaces.put(attr.getLocalName(), attr.getValue()); + } + if ("xmlns".equals(attr.getName())) { + namespaces.put("", attr.getValue()); + } + } + } + return namespaces; + } + + public Type getType() { + return type; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java new file mode 100644 index 0000000000..7f49a50e1e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java @@ -0,0 +1,310 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import java.util.ArrayList; +import java.util.EmptyStackException; +import java.util.Iterator; +import java.util.List; + +import javax.xml.namespace.NamespaceContext; + +public class DelegatingNamespaceContext implements NamespaceContext { + private static int count; + + private class WrappingIterator implements Iterator { + + private Iterator containedIterator; + + public WrappingIterator(Iterator containedIterator) { + this.containedIterator = containedIterator; + } + + public Iterator getContainedIterator() { + return containedIterator; + } + + public boolean hasNext() { + return containedIterator.hasNext(); + } + + public Object next() { + return containedIterator.next(); + } + + /** + * As per the contract on the API of Namespace context the returned iterator should be immutable + */ + public void remove() { + throw new UnsupportedOperationException(); + } + + public void setContainedIterator(Iterator containedIterator) { + this.containedIterator = containedIterator; + } + } + + private NamespaceContext parentNsContext; + + private FastStack prefixStack = new FastStack(); + + // Keep two ArrayLists for the prefixes and namespaces. They should be in + // sync + // since the index of the entry will be used to relate them + // use the minimum initial capacity to let things handle memory better + + private FastStack uriStack = new FastStack(); + + /** + * Generates a unique namespace prefix that is not in the scope of the NamespaceContext + * + * @return string + */ + public String generateUniquePrefix() { + String prefix = "p" + count++; + // null should be returned if the prefix is not bound! + while (getNamespaceURI(prefix) != null) { + prefix = "p" + count++; + } + + return prefix; + } + + public String getNamespaceURI(String prefix) { + // do the corrections as per the Javadoc + int index = prefixStack.search(prefix); + if (index != -1) { + return uriStack.get(index); + } + if (parentNsContext != null) { + return parentNsContext.getPrefix(prefix); + } + return null; + } + + public NamespaceContext getParentNsContext() { + return parentNsContext; + } + + public String getPrefix(String uri) { + // do the corrections as per the Javadoc + int index = uriStack.search(uri); + if (index != -1) { + return prefixStack.get(index); + } + + if (parentNsContext != null) { + return parentNsContext.getPrefix(uri); + } + return null; + } + + public Iterator getPrefixes(String uri) { + // create an ArrayList that contains the relevant prefixes + String[] uris = uriStack.toArray(new String[uriStack.size()]); + List tempList = new ArrayList(); + for (int i = uris.length - 1; i >= 0; i--) { + if (uris[i].equals(uri)) { + tempList.add(prefixStack.get(i)); + // we assume that array conversion preserves the order + } + } + // by now all the relevant prefixes are collected + // make a new iterator and provide a wrapper iterator to + // obey the contract on the API + return new WrappingIterator(tempList.iterator()); + } + + /** + * Pop a namespace + */ + public void popNamespace() { + prefixStack.pop(); + uriStack.pop(); + } + + /** + * Register a namespace in this context + * + * @param prefix + * @param uri + */ + public void pushNamespace(String prefix, String uri) { + prefixStack.push(prefix); + uriStack.push(uri); + + } + + public void setParentNsContext(NamespaceContext parentNsContext) { + this.parentNsContext = parentNsContext; + } + + /** + * An implementation of the {@link java.util.Stack} API that is based on an ArrayList instead of a + * Vector, so it is not synchronized to protect against multi-threaded access. The implementation is + * therefore operates faster in environments where you do not need to worry about multiple thread contention. + *

+ * The removal order of an ArrayStack is based on insertion order: The most recently added element is + * removed first. The iteration order is not the same as the removal order. The iterator returns elements + * from the bottom up, whereas the {@link #remove()} method removes them from the top down. + *

+ * Unlike Stack, ArrayStack accepts null entries. + */ + public static class FastStack extends ArrayList { + + /** Ensure Serialization compatibility */ + private static final long serialVersionUID = 2130079159931574599L; + + /** + * Constructs a new empty ArrayStack. The initial size is controlled by ArrayList + * and is currently 10. + */ + public FastStack() { + super(); + } + + /** + * Constructs a new empty ArrayStack with an initial size. + * + * @param initialSize the initial size to use + * @throws IllegalArgumentException if the specified initial size is negative + */ + public FastStack(int initialSize) { + super(initialSize); + } + + /** + * Return true if this stack is currently empty. + *

+ * This method exists for compatibility with java.util.Stack. New users of this class should use + * isEmpty instead. + * + * @return true if the stack is currently empty + */ + public boolean empty() { + return isEmpty(); + } + + /** + * Returns the top item off of this stack without removing it. + * + * @return the top item on the stack + * @throws EmptyStackException if the stack is empty + */ + public T peek() throws EmptyStackException { + int n = size(); + if (n <= 0) { + throw new EmptyStackException(); + } else { + return get(n - 1); + } + } + + /** + * Returns the n'th item down (zero-relative) from the top of this stack without removing it. + * + * @param n the number of items down to go + * @return the n'th item on the stack, zero relative + * @throws EmptyStackException if there are not enough items on the stack to satisfy this request + */ + public T peek(int n) throws EmptyStackException { + int m = (size() - n) - 1; + if (m < 0) { + throw new EmptyStackException(); + } else { + return get(m); + } + } + + /** + * Pops the top item off of this stack and return it. + * + * @return the top item on the stack + * @throws EmptyStackException if the stack is empty + */ + public T pop() throws EmptyStackException { + int n = size(); + if (n <= 0) { + throw new EmptyStackException(); + } else { + return remove(n - 1); + } + } + + /** + * Pushes a new item onto the top of this stack. The pushed item is also returned. This is equivalent to calling + * add. + * + * @param item the item to be added + * @return the item just pushed + */ + public Object push(T item) { + add(item); + return item; + } + + /** + * Returns the top-most index for the object in the stack + * + * @param object the object to be searched for + * @return top-most index, or -1 if not found + */ + public int search(T object) { + int i = size() - 1; // Current index + while (i >= 0) { + T current = get(i); + if ((object == null && current == null) || (object != null && object.equals(current))) { + return i; + } + i--; + } + return -1; + } + + /** + * Returns the element on the top of the stack. + * + * @return the element on the top of the stack + * @throws EmptyStackException if the stack is empty + */ + public T get() { + int size = size(); + if (size == 0) { + throw new EmptyStackException(); + } + return get(size - 1); + } + + /** + * Removes the element on the top of the stack. + * + * @return the removed element + * @throws EmptyStackException if the stack is empty + */ + public T remove() { + int size = size(); + if (size == 0) { + throw new EmptyStackException(); + } + return remove(size - 1); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java new file mode 100644 index 0000000000..5f583da283 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.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.sca.databinding.xml; + +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.stream.StreamSource; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; + +/** + * Push DOM InputSource to Node + * + * @version $Rev$ $Date$ + */ +public class InputSource2Node extends BaseTransformer implements + PullTransformer { + private static final Source2ResultTransformer TRANSFORMER = new Source2ResultTransformer(); + + public Node transform(InputSource source, TransformationContext context) { + try { + Source streamSource = new StreamSource(source.getCharacterStream()); + DOMResult result = new DOMResult(); + TRANSFORMER.transform(streamSource, result, context); + return result.getNode(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return InputSource.class; + } + + @Override + public Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java new file mode 100644 index 0000000000..39116ba4a1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.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.sca.databinding.xml; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; + +/** + * Push InputSource to SAX + * + * @version $Rev$ $Date$ + */ +public class InputSource2SAX extends BaseTransformer implements + PushTransformer { + + public void transform(InputSource source, ContentHandler target, TransformationContext context) { + try { + XMLReader reader = XMLReaderFactory.createXMLReader(); + reader.setFeature("http://xml.org/sax/features/namespaces", true); + reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false); + reader.setContentHandler(target); + reader.parse(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return InputSource.class; + } + + @Override + public Class getTargetType() { + return ContentHandler.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java new file mode 100644 index 0000000000..e40c3006fb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.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.sca.databinding.xml; + +import java.io.InputStream; + +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.sax.SAXSource; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; + +/** + * Push DOM InputSource to Node + * + * @version $Rev$ $Date$ + */ +public class InputStream2Node extends BaseTransformer implements + PullTransformer { + private static final Source2ResultTransformer TRANSFORMER = new Source2ResultTransformer(); + + public Node transform(InputStream source, TransformationContext context) { + try { + Source streamSource = new SAXSource(new InputSource(source)); + DOMResult result = new DOMResult(); + TRANSFORMER.transform(streamSource, result, context); + return result.getNode(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return InputStream.class; + } + + @Override + public Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java new file mode 100644 index 0000000000..3b7bd3088a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.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.sca.databinding.xml; + +import java.io.InputStream; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; + +/** + * Push InputStream to SAX + * + * @version $Rev$ $Date$ + */ +public class InputStream2SAX extends BaseTransformer implements + PushTransformer { + public void transform(InputStream source, ContentHandler target, TransformationContext context) { + try { + XMLReader reader = XMLReaderFactory.createXMLReader(); + reader.setContentHandler(target); + reader.parse(new InputSource(source)); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return InputStream.class; + } + + @Override + public Class getTargetType() { + return ContentHandler.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java new file mode 100644 index 0000000000..5a31d9db91 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java @@ -0,0 +1,403 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamException; + +public class NameValueArrayStreamReader implements XMLFragmentStreamReader { + + private static final int START_ELEMENT_STATE = 0; + private static final int TEXT_STATE = 1; + private static final int END_ELEMENT_STATE = 2; + private static final int FINAL_END_ELEMENT_STATE = 3; + private static final int START_ELEMENT_STATE_WITH_NULL = 4; + + private DelegatingNamespaceContext namespaceContext = new DelegatingNamespaceContext(); + // the index of the array + private int arrayIndex; + + private QName name; + private String[] values; + + // start element is the default state + private int state = START_ELEMENT_STATE; + + public NameValueArrayStreamReader(QName name, String[] values) { + this.name = name; + this.values = values; + } + + public void setParentNamespaceContext(NamespaceContext nsContext) { + this.namespaceContext.setParentNsContext(nsContext); + } + + public void init() { + // TODO what if the QName namespace has not been declared + } + + public Object getProperty(String string) throws IllegalArgumentException { + return null; + } + + /** + * @throws XMLStreamException + */ + public int next() throws XMLStreamException { + switch (state) { + case START_ELEMENT_STATE: + if (values.length > 0) { + state = TEXT_STATE; + return CHARACTERS; + } else { + state = FINAL_END_ELEMENT_STATE; + return END_ELEMENT; + } + + case START_ELEMENT_STATE_WITH_NULL: + if (arrayIndex == (values.length - 1)) { + state = FINAL_END_ELEMENT_STATE; + } else { + state = END_ELEMENT_STATE; + } + return END_ELEMENT; + case FINAL_END_ELEMENT_STATE: + // oops, not supposed to happen! + throw new XMLStreamException("end already reached!"); + case END_ELEMENT_STATE: + // we've to have more values since this is not the + // last value + // increment the counter + arrayIndex++; + if (values[arrayIndex] == null) { + state = START_ELEMENT_STATE_WITH_NULL; + } else { + state = START_ELEMENT_STATE; + } + return START_ELEMENT; + case TEXT_STATE: + if (arrayIndex == (values.length - 1)) { + state = FINAL_END_ELEMENT_STATE; + return END_ELEMENT; + } else { + state = END_ELEMENT_STATE; + return END_ELEMENT; + } + + default: + throw new XMLStreamException("unknown event type!"); + } + } + + public void require(int i, String string, String string1) throws XMLStreamException { + // nothing done here + } + + public String getElementText() throws XMLStreamException { + return null; // not implemented + } + + public int nextTag() throws XMLStreamException { + return 0; // not implemented + } + + public String getAttributeValue(String string, String string1) { + if (state == TEXT_STATE) { + // TODO something + return null; + } else { + return null; + } + + } + + public int getAttributeCount() { + if (state == START_ELEMENT_STATE_WITH_NULL) { + return 1; + } + if (state == START_ELEMENT_STATE) { + return 0; + } else { + throw new IllegalStateException(); + } + + } + + public QName getAttributeName(int i) { + if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) { + return NIL_QNAME; + } + if (state == START_ELEMENT_STATE) { + return null; + } else { + throw new IllegalStateException(); + } + } + + public String getAttributeNamespace(int i) { + if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) { + return NIL_QNAME.getNamespaceURI(); + } + if (state == START_ELEMENT_STATE) { + return null; + } else { + throw new IllegalStateException(); + } + } + + public String getAttributeLocalName(int i) { + if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) { + return NIL_QNAME.getLocalPart(); + } + if (state == START_ELEMENT_STATE) { + return null; + } else { + throw new IllegalStateException(); + } + } + + public String getAttributePrefix(int i) { + if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) { + return NIL_QNAME.getPrefix(); + } + if (state == START_ELEMENT_STATE) { + return null; + } else { + throw new IllegalStateException(); + } + } + + public String getAttributeType(int i) { + return null; // not implemented + } + + public String getAttributeValue(int i) { + if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) { + return NIL_VALUE_TRUE; + } + if (state == START_ELEMENT_STATE) { + return null; + } else { + throw new IllegalStateException(); + } + } + + public boolean isAttributeSpecified(int i) { + return false; // not supported + } + + public int getNamespaceCount() { + if (state == START_ELEMENT_STATE_WITH_NULL && isXsiNamespacePresent()) { + return 1; + } else { + return 0; + } + + } + + public String getNamespacePrefix(int i) { + if (state == START_ELEMENT_STATE_WITH_NULL && isXsiNamespacePresent() && i == 0) { + return NIL_QNAME.getPrefix(); + } else { + return null; + } + } + + public String getNamespaceURI(int i) { + if (state == START_ELEMENT_STATE_WITH_NULL && isXsiNamespacePresent() && i == 0) { + return NIL_QNAME.getNamespaceURI(); + } else { + return null; + } + } + + public NamespaceContext getNamespaceContext() { + return this.namespaceContext; + } + + public boolean isDone() { + return state == FINAL_END_ELEMENT_STATE; + } + + public int getEventType() { + switch (state) { + case START_ELEMENT_STATE: + return START_ELEMENT; + case END_ELEMENT_STATE: + return END_ELEMENT; + case TEXT_STATE: + return CHARACTERS; + case FINAL_END_ELEMENT_STATE: + return END_ELEMENT; + default: + throw new UnsupportedOperationException(); + // we've no idea what this is!!!!! + } + + } + + public String getText() { + if (state == TEXT_STATE) { + return values[arrayIndex]; + } else { + throw new IllegalStateException(); + } + } + + public char[] getTextCharacters() { + if (state == TEXT_STATE) { + return values[arrayIndex].toCharArray(); + } else { + throw new IllegalStateException(); + } + } + + public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException { + // not implemented + throw new UnsupportedOperationException(); + } + + public int getTextStart() { + if (state == TEXT_STATE) { + return 0; + } else { + throw new IllegalStateException(); + } + } + + public int getTextLength() { + if (state == TEXT_STATE) { + return values[arrayIndex].length(); + } else { + throw new IllegalStateException(); + } + + } + + public String getEncoding() { + return null; + } + + public boolean hasText() { + return state == TEXT_STATE; + } + + public Location getLocation() { + return null; // not supported + } + + public QName getName() { + if (state != TEXT_STATE) { + return name; + } else { + return null; + } + } + + public String getLocalName() { + if (state != TEXT_STATE) { + return name.getLocalPart(); + } else { + return null; + } + } + + public boolean hasName() { + return state != TEXT_STATE; + + } + + public String getNamespaceURI() { + if (state != TEXT_STATE) { + return name.getNamespaceURI(); + } else { + return null; + } + + } + + public String getPrefix() { + if (state != TEXT_STATE) { + return name.getPrefix(); + } else { + return null; + } + } + + public String getVersion() { + return null; // TODO 1.0 ? + } + + public boolean isStandalone() { + return false; + } + + public boolean standaloneSet() { + return false; + } + + public String getCharacterEncodingScheme() { + return null; + } + + public String getPITarget() { + return null; + } + + public String getPIData() { + return null; + } + + public boolean hasNext() throws XMLStreamException { + return state != FINAL_END_ELEMENT_STATE; + } + + public void close() throws XMLStreamException { + // Do nothing - we've nothing to free here + } + + public String getNamespaceURI(String prefix) { + return namespaceContext.getNamespaceURI(prefix); + } + + public boolean isStartElement() { + return state == START_ELEMENT_STATE; + } + + public boolean isEndElement() { + return state == END_ELEMENT_STATE; + } + + public boolean isCharacters() { + return state == TEXT_STATE; + } + + public boolean isWhiteSpace() { + return false; // no whitespaces here + } + + /** + * Test whether the xsi namespace is present + */ + private boolean isXsiNamespacePresent() { + return namespaceContext.getNamespaceURI(NIL_QNAME.getPrefix()) != null; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java new file mode 100644 index 0000000000..fdc3c4139b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java @@ -0,0 +1,347 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamException; + + +public class NameValuePairStreamReader implements XMLFragmentStreamReader { + + private static final int START_ELEMENT_STATE = 0; + private static final int TEXT_STATE = 1; + private static final int END_ELEMENT_STATE = 2; + + private DelegatingNamespaceContext namespaceContext = new DelegatingNamespaceContext(); + + private QName name; + private String value; + + private int state = START_ELEMENT_STATE; + // initiate at the start element state + + // keeps track whether the namespace is declared + // false by default + private boolean nsDeclared; + + public NameValuePairStreamReader(QName name, String value) { + this.name = name; + this.value = value; + } + + public Object getProperty(String key) throws IllegalArgumentException { + return null; + } + + public int next() throws XMLStreamException { + // no need to handle null here. it should have been handled + // already + switch (state) { + case START_ELEMENT_STATE: + state = TEXT_STATE; + return CHARACTERS; + case END_ELEMENT_STATE: + // oops, not supposed to happen! + throw new XMLStreamException("end already reached!"); + case TEXT_STATE: + state = END_ELEMENT_STATE; + return END_ELEMENT; + default: + throw new XMLStreamException("unknown event type!"); + } + } + + public void require(int i, String string, String string1) throws XMLStreamException { + // not implemented + } + + public String getElementText() throws XMLStreamException { + if (state == START_ELEMENT) { + // move to the end state and return the value + state = END_ELEMENT_STATE; + return value; + } else { + throw new XMLStreamException(); + } + + } + + public int nextTag() throws XMLStreamException { + return 0; // TODO + } + + public boolean hasNext() throws XMLStreamException { + return state != END_ELEMENT_STATE; + } + + public void close() throws XMLStreamException { + // Do nothing - we've nothing to free here + } + + public String getNamespaceURI(String prefix) { + return namespaceContext.getNamespaceURI(prefix); + } + + public boolean isStartElement() { + return state == START_ELEMENT_STATE; + } + + public boolean isEndElement() { + return state == END_ELEMENT_STATE; + } + + public boolean isCharacters() { + return state == TEXT_STATE; + } + + public boolean isWhiteSpace() { + return false; // no whitespaces here + } + + public String getAttributeValue(String string, String string1) { + return null; + } + + public int getAttributeCount() { + return 0; + } + + public QName getAttributeName(int i) { + return null; + } + + public String getAttributeNamespace(int i) { + return null; + } + + public String getAttributeLocalName(int i) { + return null; + } + + public String getAttributePrefix(int i) { + return null; + } + + public String getAttributeType(int i) { + return null; + } + + public String getAttributeValue(int i) { + return null; + } + + public boolean isAttributeSpecified(int i) { + return false; // no attributes here + } + + public int getNamespaceCount() { + return nsDeclared ? 1 : 0; + } + + public String getNamespacePrefix(int i) { + return (nsDeclared && i == 0) ? name.getPrefix() : null; + } + + public String getNamespaceURI(int i) { + return (nsDeclared && i == 0) ? name.getNamespaceURI() : null; + } + + public NamespaceContext getNamespaceContext() { + return this.namespaceContext; + } + + public int getEventType() { + switch (state) { + case START_ELEMENT_STATE: + return START_ELEMENT; + case END_ELEMENT_STATE: + return END_ELEMENT; + case TEXT_STATE: + return CHARACTERS; + default: + throw new UnsupportedOperationException(); + // we've no idea what this is!!!!! + } + + } + + public String getText() { + if (state == TEXT_STATE) { + return value; + } else { + throw new IllegalStateException(); + } + } + + public char[] getTextCharacters() { + if (state == TEXT_STATE) { + return value.toCharArray(); + } else { + throw new IllegalStateException(); + } + } + + public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException { + // not implemented + throw new UnsupportedOperationException(); + } + + public int getTextStart() { + if (state == TEXT_STATE) { + return 0; + } else { + throw new IllegalStateException(); + } + } + + public int getTextLength() { + if (state == TEXT_STATE) { + return value.length(); + } else { + throw new IllegalStateException(); + } + + } + + public String getEncoding() { + return null; + } + + public boolean hasText() { + return state == TEXT_STATE; + } + + public Location getLocation() { + return new Location() { + public int getLineNumber() { + return 0; + } + + public int getColumnNumber() { + return 0; + } + + public int getCharacterOffset() { + return 0; + } + + public String getPublicId() { + return null; + } + + public String getSystemId() { + return null; + } + }; + } + + public QName getName() { + if (state != TEXT_STATE) { + return name; + } else { + return null; + } + } + + public String getLocalName() { + if (state != TEXT_STATE) { + return name.getLocalPart(); + } else { + return null; + } + } + + public boolean hasName() { + return state != TEXT_STATE; + + } + + public String getNamespaceURI() { + if (state != TEXT_STATE) { + return name.getNamespaceURI(); + } else { + return null; + } + + } + + public String getPrefix() { + if (state != TEXT_STATE) { + return name.getPrefix(); + } else { + return null; + } + } + + public String getVersion() { + return null; // TODO 1.0 ? + } + + public boolean isStandalone() { + return false; + } + + public boolean standaloneSet() { + return false; + } + + public String getCharacterEncodingScheme() { + return null; + } + + public String getPITarget() { + return null; + } + + public String getPIData() { + return null; + } + + public boolean isDone() { + return state == END_ELEMENT_STATE; + } + + public void setParentNamespaceContext(NamespaceContext nsContext) { + this.namespaceContext.setParentNsContext(nsContext); + } + + public void init() { + // just add the current elements namespace and prefix to the this + // elements nscontext + addToNsMap(name.getPrefix(), name.getNamespaceURI()); + + } + + /** + * @param prefix + * @param uri + */ + private void addToNsMap(String prefix, String uri) { + // TODO - need to fix this up to cater for cases where + // namespaces are having no prefixes + if (!uri.equals(namespaceContext.getNamespaceURI(prefix))) { + // this namespace is not there. Need to declare it + namespaceContext.pushNamespace(prefix, uri); + nsDeclared = true; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java new file mode 100644 index 0000000000..04d7d65a0d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.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.sca.databinding.xml; + +import java.util.Map; + +import javax.xml.namespace.QName; + +/** + * A named property + * + * @version $Rev$ $Date$ + */ +public class NamedProperty implements Map.Entry { + private QName key; + + private Object value; + + public NamedProperty(QName key, Object value) { + this.key = key; + this.value = value; + } + + public NamedProperty(String key, Object value) { + this.key = new QName(key); + this.value = value; + } + + public QName getKey() { + return key; + } + + public Object getValue() { + return value; + } + + public Object setValue(Object value) { + Object v = this.value; + this.value = value; + return v; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java new file mode 100644 index 0000000000..abc4bf3785 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java @@ -0,0 +1,279 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamException; + +public class NilElementStreamReader implements XMLFragmentStreamReader { + + private static final int END_ELEMENT_STATE = 2; + + private static final int START_ELEMENT_STATE = 1; + private int currentState = START_ELEMENT; + + private QName elementQName; + + public NilElementStreamReader(QName elementQName) { + this.elementQName = elementQName; + } + + public void setParentNamespaceContext(NamespaceContext nsContext) { + // NOOP + } + + public void close() throws XMLStreamException { + // do nothing + } + + public int getAttributeCount() { + return 1; + } + + public String getAttributeLocalName(int i) { + return (i == 0) ? NIL_QNAME.getLocalPart() : null; + } + + public QName getAttributeName(int i) { + return (i == 0) ? NIL_QNAME : null; + } + + public String getAttributeNamespace(int i) { + return (i == 0) ? NIL_QNAME.getNamespaceURI() : null; + } + + public String getAttributePrefix(int i) { + return (i == 0) ? NIL_QNAME.getPrefix() : null; + } + + public String getAttributeType(int i) { + throw new UnsupportedOperationException(); + } + + public String getAttributeValue(int i) { + return (i == 0) ? NIL_VALUE_TRUE : null; + } + + public String getAttributeValue(String string, String string1) { + if (string == null && NIL_QNAME.getLocalPart().equals(string1)) { + return NIL_VALUE_TRUE; + } + return null; + } + + public String getCharacterEncodingScheme() { + throw new UnsupportedOperationException(); + } + + public String getElementText() throws XMLStreamException { + return null; + } + + public String getEncoding() { + return null; + } + + public int getEventType() { + int returnEvent = START_DOCUMENT; + switch (currentState) { + case START_ELEMENT_STATE: + returnEvent = START_ELEMENT; + break; + case END_ELEMENT_STATE: + returnEvent = END_ELEMENT; + break; + } + return returnEvent; + } + + public String getLocalName() { + return elementQName.getLocalPart(); + } + + public Location getLocation() { + return new Location() { + public int getCharacterOffset() { + return 0; + } + + public int getColumnNumber() { + return 0; + } + + public int getLineNumber() { + return 0; + } + + public String getPublicId() { + return null; + } + + public String getSystemId() { + return null; + } + }; + } + + public QName getName() { + return elementQName; + } + + public NamespaceContext getNamespaceContext() { + throw new UnsupportedOperationException(); + } + + public int getNamespaceCount() { + return 0; + } + + public String getNamespacePrefix(int i) { + return null; + } + + public String getNamespaceURI() { + return elementQName.getNamespaceURI(); + } + + public String getNamespaceURI(int i) { + return null; + } + + public String getNamespaceURI(String string) { + if (elementQName.getPrefix() != null && elementQName.getPrefix().equals(string)) { + return elementQName.getNamespaceURI(); + } else { + return null; + } + } + + public String getPIData() { + throw new UnsupportedOperationException(); + } + + public String getPITarget() { + throw new UnsupportedOperationException(); + } + + public String getPrefix() { + return elementQName.getPrefix(); + } + + public Object getProperty(String key) throws IllegalArgumentException { + // since optimization is a global property + // we've to implement it everywhere + return null; + } + + public String getText() { + return null; + } + + public char[] getTextCharacters() { + return new char[0]; + } + + public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException { + return 0; + } + + public int getTextLength() { + return 0; + } + + public int getTextStart() { + return 0; + } + + public String getVersion() { + throw new UnsupportedOperationException(); + } + + public boolean hasName() { + return true; + } + + public boolean hasNext() throws XMLStreamException { + return currentState != END_ELEMENT_STATE; + + } + + public boolean hasText() { + return false; + } + + public void init() { + // NOOP + } + + public boolean isAttributeSpecified(int i) { + return i == 0; + } + + public boolean isCharacters() { + return false; + } + + public boolean isDone() { + return currentState == END_ELEMENT_STATE; + } + + public boolean isEndElement() { + return currentState == END_ELEMENT_STATE; + } + + public boolean isStandalone() { + throw new UnsupportedOperationException(); + } + + public boolean isStartElement() { + return currentState == START_ELEMENT_STATE; + } + + public boolean isWhiteSpace() { + return false; + } + + public int next() throws XMLStreamException { + int returnEvent = START_DOCUMENT; + switch (currentState) { + case START_ELEMENT_STATE: + currentState = END_ELEMENT_STATE; + returnEvent = END_ELEMENT; + break; + case END_ELEMENT_STATE: + throw new XMLStreamException("parser completed!"); + + } + return returnEvent; + } + + public int nextTag() throws XMLStreamException { + throw new UnsupportedOperationException(); + } + + public void require(int i, String string, String string1) throws XMLStreamException { + // nothing + } + + public boolean standaloneSet() { + throw new UnsupportedOperationException(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java new file mode 100644 index 0000000000..5500d0bcca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import java.io.OutputStream; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +/** + * Push DOM Node to OutputStream + * + * @version $Rev$ $Date$ + */ +public class Node2OutputStream extends BaseTransformer implements + PushTransformer { + private static final Source2ResultTransformer TRANSFORMER = new Source2ResultTransformer(); + + public void transform(Node source, OutputStream writer, TransformationContext context) { + try { + Source domSource = new DOMSource(source); + Result result = new StreamResult(writer); + TRANSFORMER.transform(domSource, result, context); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + protected Class getTargetType() { + return OutputStream.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.java new file mode 100644 index 0000000000..d5bf7e76b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.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.sca.databinding.xml; + +import org.apache.tuscany.sca.databinding.impl.SimpleType2JavaTransformer; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * Transformer to convert data from a simple java Object to OMElement. + * + * @version $Rev$ $Date$ + */ +public class Node2SimpleJavaType extends SimpleType2JavaTransformer { + + @Override + protected String getText(Node source) { + if (source instanceof Document) { + source = ((Document)source).getDocumentElement(); + } + return source.getTextContent(); + + } + + @Override + public Class getSourceType() { + return Node.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SourceTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SourceTransformer.java new file mode 100644 index 0000000000..3c9022bc3c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SourceTransformer.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.sca.databinding.xml; + +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +/** + * Transform TrAX Node to Source + * + * @version $Rev$ $Date$ + */ +public class Node2SourceTransformer extends BaseTransformer implements + PullTransformer { + + public Source transform(Node source, TransformationContext context) { + try { + return new DOMSource(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + protected Class getTargetType() { + return Source.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java new file mode 100644 index 0000000000..1b54b1fd1e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.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.sca.databinding.xml; + +import java.io.StringWriter; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +/** + * Transform DOM Node to XML String + * + * @version $Rev$ $Date$ + */ +public class Node2String extends BaseTransformer implements PullTransformer { + private static final Node2Writer TRANSFORMER = new Node2Writer(); + + public String transform(Node source, TransformationContext context) { + try { + StringWriter writer = new StringWriter(); + TRANSFORMER.transform(source, writer, context); + return writer.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return Node.class; + } + + @Override + public Class getTargetType() { + return String.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java new file mode 100644 index 0000000000..c9631595dc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.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.sca.databinding.xml; + +import java.io.Writer; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +/** + * Push DOM Node to Writer + * + * @version $Rev$ $Date$ + */ +public class Node2Writer extends BaseTransformer implements PushTransformer { + private static final Source2ResultTransformer TRANSFORMER = new Source2ResultTransformer(); + + public void transform(Node source, Writer writer, TransformationContext context) { + try { + Source domSource = new DOMSource(source); + Result result = new StreamResult(writer); + TRANSFORMER.transform(domSource, result, context); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + protected Class getTargetType() { + return Writer.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java new file mode 100644 index 0000000000..1e8d14a151 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.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.sca.databinding.xml; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +/** + * Transform DOM Node to XML XMLStreamReader + * + * @version $Rev$ $Date$ + */ +public class Node2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader transform(Node source, TransformationContext context) { + if (source == null) { + return null; + } + try { + DOMXMLStreamReader reader = new DOMXMLStreamReader(source); + return reader; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java new file mode 100644 index 0000000000..70387fa862 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.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.sca.databinding.xml; + +import java.io.Reader; + +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.stream.StreamSource; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +/** + * Push DOM Reader to Node + * + * @version $Rev$ $Date$ + */ +public class Reader2Node extends BaseTransformer implements PullTransformer { + private static final Source2ResultTransformer TRANSFORMER = new Source2ResultTransformer(); + + public Node transform(Reader source, TransformationContext context) { + try { + Source streamSource = new StreamSource(source); + DOMResult result = new DOMResult(); + TRANSFORMER.transform(streamSource, result, context); + return result.getNode(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Reader.class; + } + + @Override + protected Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java new file mode 100644 index 0000000000..188ecaffa3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.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.sca.databinding.xml; + +import java.io.Reader; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; + +/** + * Transform XML string to SAX + * + * @version $Rev$ $Date$ + */ +public class Reader2SAX extends BaseTransformer implements + PushTransformer { + public void transform(Reader source, ContentHandler target, TransformationContext context) { + try { + new InputSource2SAX().transform(new InputSource(source), target, context); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Reader.class; + } + + @Override + protected Class getTargetType() { + return ContentHandler.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java new file mode 100644 index 0000000000..38c61d64c8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java @@ -0,0 +1,246 @@ +/* + * Copyright 2001-2004 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.sca.databinding.xml; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.ProcessingInstruction; +import org.w3c.dom.Text; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.ext.LexicalHandler; + +/** + * SAX2DOM adapter + * + * @version $Rev$ $Date$ + */ +public class SAX2DOM implements ContentHandler, LexicalHandler { + public static final String EMPTYSTRING = ""; + public static final String XML_PREFIX = "xml"; + public static final String XMLNS_PREFIX = "xmlns"; + public static final String XMLNS_STRING = "xmlns:"; + public static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; + + private Node root; + + private Document document; + + private Node nextSibling; + + private Stack nodeStk = new Stack(); + + private List namespaceDecls; + + private Node lastSibling; + + public SAX2DOM() throws ParserConfigurationException { + this.document = DOMHelper.newDocument(); + this.root = document; + } + + public SAX2DOM(Node root, Node nextSibling) throws ParserConfigurationException { + this.root = root; + if (root instanceof Document) { + this.document = (Document)root; + } else if (root != null) { + this.document = root.getOwnerDocument(); + } else { + this.document = DOMHelper.newDocument(); + this.root = document; + } + + this.nextSibling = nextSibling; + } + + public SAX2DOM(Node root) throws ParserConfigurationException { + this(root, null); + } + + public Node getDOM() { + return root; + } + + public void characters(char[] ch, int start, int length) { + final Node last = nodeStk.peek(); + + // No text nodes can be children of root (DOM006 exception) + if (last != document) { + final String text = new String(ch, start, length); + if (lastSibling != null && lastSibling.getNodeType() == Node.TEXT_NODE) { + ((Text)lastSibling).appendData(text); + } else if (last == root && nextSibling != null) { + lastSibling = last.insertBefore(document.createTextNode(text), nextSibling); + } else { + lastSibling = last.appendChild(document.createTextNode(text)); + } + + } + } + + public void startDocument() { + nodeStk.push(root); + } + + public void endDocument() { + nodeStk.pop(); + } + + public void startElement(String namespace, String localName, String qName, Attributes attrs) { + final Element tmp = document.createElementNS(namespace, qName); + + // Add namespace declarations first + if (namespaceDecls != null) { + final int nDecls = namespaceDecls.size(); + for (int i = 0; i < nDecls; i++) { + final String prefix = namespaceDecls.get(i++); + + if (prefix == null || prefix.equals(EMPTYSTRING)) { + tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, namespaceDecls.get(i)); + } else { + tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, namespaceDecls.get(i)); + } + } + namespaceDecls.clear(); + } + + // Add attributes to element + final int nattrs = attrs.getLength(); + for (int i = 0; i < nattrs; i++) { + if (attrs.getLocalName(i) == null) { + tmp.setAttribute(attrs.getQName(i), attrs.getValue(i)); + } else { + tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i)); + } + } + + // Append this new node onto current stack node + Node last = nodeStk.peek(); + + // If the SAX2DOM is created with a non-null next sibling node, + // insert the result nodes before the next sibling under the root. + if (last == root && nextSibling != null) { + last.insertBefore(tmp, nextSibling); + } else { + last.appendChild(tmp); + } + + // Push this node onto stack + nodeStk.push(tmp); + lastSibling = null; + } + + public void endElement(String namespace, String localName, String qName) { + nodeStk.pop(); + lastSibling = null; + } + + public void startPrefixMapping(String prefix, String uri) { + if (namespaceDecls == null) { + namespaceDecls = new ArrayList(2); + } + namespaceDecls.add(prefix); + namespaceDecls.add(uri); + } + + public void endPrefixMapping(String prefix) { + // do nothing + } + + /** + * This class is only used internally so this method should never be called. + */ + public void ignorableWhitespace(char[] ch, int start, int length) { + } + + /** + * adds processing instruction node to DOM. + */ + public void processingInstruction(String target, String data) { + final Node last = nodeStk.peek(); + ProcessingInstruction pi = document.createProcessingInstruction(target, data); + if (pi != null) { + if (last == root && nextSibling != null) { + last.insertBefore(pi, nextSibling); + } else { + last.appendChild(pi); + } + + lastSibling = pi; + } + } + + /** + * This class is only used internally so this method should never be called. + */ + public void setDocumentLocator(Locator locator) { + } + + /** + * This class is only used internally so this method should never be called. + */ + public void skippedEntity(String name) { + } + + /** + * Lexical Handler method to create comment node in DOM tree. + */ + public void comment(char[] ch, int start, int length) { + final Node last = nodeStk.peek(); + Comment comment = document.createComment(new String(ch, start, length)); + if (comment != null) { + if (last == root && nextSibling != null) { + last.insertBefore(comment, nextSibling); + } else { + last.appendChild(comment); + } + + lastSibling = comment; + } + } + + // Lexical Handler methods- not implemented + public void startCDATA() { + } + + public void endCDATA() { + } + + public void startEntity(java.lang.String name) { + } + + public void endDTD() { + } + + public void endEntity(String name) { + } + + public void startDTD(String name, String publicId, String systemId) throws SAXException { + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java new file mode 100644 index 0000000000..cb9d538389 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.tuscany.sca.databinding.DataPipe; +import org.apache.tuscany.sca.databinding.DataPipeTransformer; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; +import org.xml.sax.ContentHandler; + +public class SAX2DOMPipe extends BaseTransformer implements DataPipeTransformer { + + /** + * + */ + public SAX2DOMPipe() { + super(); + } + + /** + * @see org.apache.tuscany.sca.databinding.DataPipeTransformer#newInstance() + */ + public DataPipe newInstance() { + return new Pipe(); + } + + @Override + protected Class getTargetType() { + return Node.class; + } + + @Override + protected Class getSourceType() { + return ContentHandler.class; + } + + @Override + public int getWeight() { + return 30; + } + + private static class Pipe implements DataPipe { + private SAX2DOM pipe; + + public Pipe() { + super(); + try { + this.pipe = new SAX2DOM(); + } catch (ParserConfigurationException e) { + throw new IllegalArgumentException(e); + } + } + + public Node getResult() { + return pipe.getDOM(); + } + + public ContentHandler getSink() { + return pipe; + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.java new file mode 100644 index 0000000000..d2625fba11 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.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.sca.databinding.xml; + +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.apache.tuscany.sca.databinding.impl.Java2SimpleTypeTransformer; +import org.apache.tuscany.sca.databinding.javabeans.Java2XMLMapperException; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * Transformer to convert data from an simple OMElement to Java Object + * + * @version $Rev$ $Date$ + */ +public class SimpleJavaType2Node extends Java2SimpleTypeTransformer { + + private Document factory; + + public SimpleJavaType2Node() { + super(); + try { + factory = DOMHelper.newDocument(); + } catch (ParserConfigurationException e) { + throw new Java2XMLMapperException(e); + } + } + + @Override + protected Node createElement(QName element, String text, TransformationContext context) { + if (element == null) { + element = DOMDataBinding.ROOT_ELEMENT; + } + Node root = DOMHelper.createElement(factory, element); + if (text != null) { + root.appendChild(factory.createTextNode(text)); + } else { + Attr nil = factory.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:nil"); + nil.setValue("true"); + root.appendChild(nil); + } + return root; + } + + @Override + public Class getTargetType() { + return Node.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleXmlNodeImpl.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleXmlNodeImpl.java new file mode 100644 index 0000000000..e041f85214 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleXmlNodeImpl.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.sca.databinding.xml; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class SimpleXmlNodeImpl implements XmlNode { + private static final String XSI_PREFIX = "xsi"; + private static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance"; + private static final QName XSI_NIL = new QName(XSI_NS, "nil", XSI_PREFIX); + private static final Map NS_MAP = new HashMap(); + static { + NS_MAP.put(XSI_PREFIX, XSI_NS); + } + + protected Type type; + protected QName name; + protected Object value; + + public SimpleXmlNodeImpl(QName name, Object value) { + this(name, value, name != null ? Type.ELEMENT : Type.CHARACTERS); + } + + public SimpleXmlNodeImpl(QName name, Object value, Type type) { + super(); + this.type = type; + this.name = name; + this.value = value; + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#attributes() + */ + public List attributes() { + if (type == Type.ELEMENT && value == null) { + // Nil element + XmlNode attr = new SimpleXmlNodeImpl(XSI_NIL, "true"); + return Arrays.asList(attr); + } + return null; + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#children() + */ + public Iterator children() { + if (type == Type.ELEMENT && value != null) { + // Nil element + XmlNode node = new SimpleXmlNodeImpl(null, value); + return Arrays.asList(node).iterator(); + } + return null; + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getName() + */ + public QName getName() { + return name; + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getValue() + */ + public String getValue() { + return value == null ? null : String.valueOf(value); + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#namespaces() + */ + public Map namespaces() { + if (type == Type.ELEMENT && value == null) { + return NS_MAP; + } + return null; + } + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2NodeTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2NodeTransformer.java new file mode 100644 index 0000000000..ee9aa1bb76 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2NodeTransformer.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.sca.databinding.xml; + +import javax.xml.transform.Source; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMResult; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * Transform TrAX Source to Node + * + * @version $Rev$ $Date$ + */ +public class Source2NodeTransformer extends BaseTransformer implements + PullTransformer { + private static final TransformerFactory FACTORY = TransformerFactory.newInstance(); + + public Node transform(Source source, TransformationContext context) { + try { + javax.xml.transform.Transformer transformer = FACTORY.newTransformer(); + DOMResult result = new DOMResult(); + transformer.transform(source, result); + Document doc = (Document) result.getNode(); + return DOMHelper.adjustElementName(context, doc.getDocumentElement()); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Source.class; + } + + @Override + protected Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java new file mode 100644 index 0000000000..8a2b6b39aa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.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.sca.databinding.xml; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerFactory; + +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * Transform TrAX Source to Result + * + * @version $Rev$ $Date$ + */ +public class Source2ResultTransformer extends BaseTransformer implements + PushTransformer { + private static final TransformerFactory FACTORY = TransformerFactory.newInstance(); + + public void transform(Source source, Result result, TransformationContext context) { + try { + javax.xml.transform.Transformer transformer = FACTORY.newTransformer(); + transformer.transform(source, result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Source.class; + } + + @Override + protected Class getTargetType() { + return Result.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java new file mode 100644 index 0000000000..2ed548ad76 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import java.io.StringWriter; + +import javax.xml.transform.Source; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * Transform TrAX Source to String + * + * @version $Rev$ $Date$ + */ +public class Source2StringTransformer extends BaseTransformer implements + PullTransformer { + private static final TransformerFactory FACTORY = TransformerFactory.newInstance(); + + public String transform(Source source, TransformationContext context) { + try { + javax.xml.transform.Transformer transformer = FACTORY.newTransformer(); + StringWriter sw = new StringWriter(); + StreamResult result = new StreamResult(sw); + transformer.transform(source, result); + return sw.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + protected Class getSourceType() { + return Source.class; + } + + @Override + protected Class getTargetType() { + return String.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java new file mode 100644 index 0000000000..6257681091 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.6/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java @@ -0,0 +1,256 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +/** + * Adapter that converts from StAX to SAX event streams. Currently the following + * SAX events are not generated: + *